Skip to content

Commit 5ca9f58

Browse files
committed
Introduce retry_tick_occurred function.
We need to retry InvoiceRequest messages in a smaller time duration than timer_tick_occurred. This function provides the base for doing the retry, by getting the InvoiceRequest for PendingOutboundPayments and using a new reply_path to create and enqueue InvoiceRequest messages.
1 parent c59cf1e commit 5ca9f58

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ use crate::util::string::UntrustedString;
7676
use crate::util::ser::{BigSize, FixedLengthReader, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter};
7777
use crate::util::logger::{Level, Logger, WithContext};
7878
use crate::util::errors::APIError;
79+
use super::onion_utils::construct_invoice_request_message;
80+
7981
#[cfg(not(c_bindings))]
8082
use {
8183
crate::offers::offer::DerivedMetadata,
@@ -6010,6 +6012,20 @@ where
60106012
});
60116013
}
60126014

6015+
pub fn retry_tick_occurred(&self) {
6016+
let invoice_requests = self.pending_outbound_payments.get_invoice_request_awaiting_invoice();
6017+
6018+
if invoice_requests.is_empty() { return; }
6019+
6020+
if let Ok(reply_path) = self.create_blinded_path() {
6021+
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
6022+
6023+
for invoice_request in invoice_requests {
6024+
pending_offers_messages.extend(construct_invoice_request_message(invoice_request, reply_path.clone()));
6025+
}
6026+
}
6027+
}
6028+
60136029
/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
60146030
/// after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
60156031
/// along the path (including in our own channel on which we received it).
@@ -8745,27 +8761,7 @@ where
87458761
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
87468762

87478763
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8748-
if offer.paths().is_empty() {
8749-
let message = new_pending_onion_message(
8750-
OffersMessage::InvoiceRequest(invoice_request),
8751-
Destination::Node(offer.signing_pubkey()),
8752-
Some(reply_path),
8753-
);
8754-
pending_offers_messages.push(message);
8755-
} else {
8756-
// Send as many invoice requests as there are paths in the offer (with an upper bound).
8757-
// Using only one path could result in a failure if the path no longer exists. But only
8758-
// one invoice for a given payment id will be paid, even if more than one is received.
8759-
const REQUEST_LIMIT: usize = 10;
8760-
for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8761-
let message = new_pending_onion_message(
8762-
OffersMessage::InvoiceRequest(invoice_request.clone()),
8763-
Destination::BlindedPath(path.clone()),
8764-
Some(reply_path.clone()),
8765-
);
8766-
pending_offers_messages.push(message);
8767-
}
8768-
}
8764+
pending_offers_messages.extend(construct_invoice_request_message(invoice_request, reply_path));
87698765

87708766
Ok(())
87718767
}

lightning/src/ln/onion_utils.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10+
use crate::blinded_path::BlindedPath;
1011
use crate::crypto::chacha20::ChaCha20;
1112
use crate::crypto::streams::ChaChaReader;
1213
use crate::ln::channelmanager::{HTLCSource, RecipientOnionFields};
1314
use crate::ln::msgs;
1415
use crate::ln::wire::Encode;
1516
use crate::ln::{PaymentHash, PaymentPreimage};
17+
use crate::offers::invoice_request::InvoiceRequest;
18+
use crate::onion_message::messenger::{new_pending_onion_message, Destination, PendingOnionMessage};
19+
use crate::onion_message::offers::OffersMessage;
1620
use crate::routing::gossip::NetworkUpdate;
1721
use crate::routing::router::{BlindedTail, Path, RouteHop};
1822
use crate::sign::NodeSigner;
@@ -1235,6 +1239,32 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(
12351239
}
12361240
}
12371241

1242+
pub fn construct_invoice_request_message(invoice_request: InvoiceRequest, reply_path: BlindedPath) -> Vec<PendingOnionMessage<OffersMessage>> {
1243+
let mut messages = vec![];
1244+
if invoice_request.paths().is_empty() {
1245+
let message = new_pending_onion_message(
1246+
OffersMessage::InvoiceRequest(invoice_request.clone()),
1247+
Destination::Node(invoice_request.signing_pubkey()),
1248+
Some(reply_path),
1249+
);
1250+
messages.push(message);
1251+
} else {
1252+
// Send as many invoice requests as there are paths in the offer (with an upper bound).
1253+
// Using only one path could result in a failure if the path no longer exists. But only
1254+
// one invoice for a given payment id will be paid, even if more than one is received.
1255+
const REQUEST_LIMIT: usize = 10;
1256+
for path in invoice_request.paths().into_iter().take(REQUEST_LIMIT) {
1257+
let message = new_pending_onion_message(
1258+
OffersMessage::InvoiceRequest(invoice_request.clone()),
1259+
Destination::BlindedPath(path.clone()),
1260+
Some(reply_path.clone()),
1261+
);
1262+
messages.push(message);
1263+
}
1264+
}
1265+
messages
1266+
}
1267+
12381268
#[cfg(test)]
12391269
mod tests {
12401270
use crate::io;

0 commit comments

Comments
 (0)