Skip to content

Commit c3ed4a2

Browse files
Store async payment data in PendingOutboundPayment.
Adds a pending outbound payment variant for async payments, which indicates that we have received a static invoice to pay and have generated a keysend preimage for the eventual payment. When the recipient comes back online, we'll transition from this new state to Retryable and actually forward the HTLCs.
1 parent ad63a70 commit c3ed4a2

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,9 @@ where
33743374
PendingOutboundPayment::InvoiceReceived { .. } => {
33753375
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
33763376
},
3377+
PendingOutboundPayment::StaticInvoiceReceived { .. } => {
3378+
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
3379+
},
33773380
PendingOutboundPayment::Retryable { payment_hash, total_msat, .. } => {
33783381
Some(RecentPaymentDetails::Pending {
33793382
payment_id: *payment_id,
@@ -11722,6 +11725,7 @@ where
1172211725
}
1172311726
PendingOutboundPayment::AwaitingInvoice { .. } => {},
1172411727
PendingOutboundPayment::InvoiceReceived { .. } => {},
11728+
PendingOutboundPayment::StaticInvoiceReceived { .. } => {},
1172511729
PendingOutboundPayment::Fulfilled { .. } => {},
1172611730
PendingOutboundPayment::Abandoned { .. } => {},
1172711731
}

lightning/src/ln/outbound_payment.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ pub(crate) enum PendingOutboundPayment {
6565
// used anywhere.
6666
max_total_routing_fee_msat: Option<u64>,
6767
},
68+
StaticInvoiceReceived {
69+
payment_hash: PaymentHash,
70+
keysend_preimage: PaymentPreimage,
71+
retry_strategy: Retry,
72+
payment_release_secret: [u8; 32],
73+
route_params: RouteParameters,
74+
},
6875
Retryable {
6976
retry_strategy: Option<Retry>,
7077
attempts: PaymentAttempts,
@@ -182,6 +189,7 @@ impl PendingOutboundPayment {
182189
PendingOutboundPayment::Legacy { .. } => None,
183190
PendingOutboundPayment::AwaitingInvoice { .. } => None,
184191
PendingOutboundPayment::InvoiceReceived { payment_hash, .. } => Some(*payment_hash),
192+
PendingOutboundPayment::StaticInvoiceReceived { payment_hash, .. } => Some(*payment_hash),
185193
PendingOutboundPayment::Retryable { payment_hash, .. } => Some(*payment_hash),
186194
PendingOutboundPayment::Fulfilled { payment_hash, .. } => *payment_hash,
187195
PendingOutboundPayment::Abandoned { payment_hash, .. } => Some(*payment_hash),
@@ -196,7 +204,8 @@ impl PendingOutboundPayment {
196204
PendingOutboundPayment::Fulfilled { session_privs, .. } |
197205
PendingOutboundPayment::Abandoned { session_privs, .. } => session_privs,
198206
PendingOutboundPayment::AwaitingInvoice { .. } |
199-
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); return; },
207+
PendingOutboundPayment::InvoiceReceived { .. } |
208+
PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); return; },
200209
});
201210
let payment_hash = self.payment_hash();
202211
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0 };
@@ -230,7 +239,8 @@ impl PendingOutboundPayment {
230239
session_privs.remove(session_priv)
231240
},
232241
PendingOutboundPayment::AwaitingInvoice { .. } |
233-
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false },
242+
PendingOutboundPayment::InvoiceReceived { .. } |
243+
PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); false },
234244
};
235245
if remove_res {
236246
if let PendingOutboundPayment::Retryable {
@@ -259,7 +269,8 @@ impl PendingOutboundPayment {
259269
session_privs.insert(session_priv)
260270
},
261271
PendingOutboundPayment::AwaitingInvoice { .. } |
262-
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false },
272+
PendingOutboundPayment::InvoiceReceived { .. } |
273+
PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); false },
263274
PendingOutboundPayment::Fulfilled { .. } => false,
264275
PendingOutboundPayment::Abandoned { .. } => false,
265276
};
@@ -292,6 +303,7 @@ impl PendingOutboundPayment {
292303
},
293304
PendingOutboundPayment::AwaitingInvoice { .. } => 0,
294305
PendingOutboundPayment::InvoiceReceived { .. } => 0,
306+
PendingOutboundPayment::StaticInvoiceReceived { .. } => 0,
295307
}
296308
}
297309
}
@@ -1195,6 +1207,11 @@ impl OutboundPayments {
11951207
debug_assert!(false);
11961208
return
11971209
},
1210+
PendingOutboundPayment::StaticInvoiceReceived { .. } => {
1211+
log_error!(logger, "Payment already initiating");
1212+
debug_assert!(false);
1213+
return
1214+
},
11981215
PendingOutboundPayment::Fulfilled { .. } => {
11991216
log_error!(logger, "Payment already completed");
12001217
return
@@ -1985,6 +2002,15 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
19852002
(2, retry_strategy, required),
19862003
(4, max_total_routing_fee_msat, option),
19872004
},
2005+
// Added in 0.0.125. Prior versions will drop these outbounds on downgrade, which is safe because
2006+
// no HTLCs are in-flight.
2007+
(9, StaticInvoiceReceived) => {
2008+
(0, payment_hash, required),
2009+
(2, keysend_preimage, required),
2010+
(4, retry_strategy, required),
2011+
(6, payment_release_secret, required),
2012+
(8, route_params, required),
2013+
},
19882014
);
19892015

19902016
#[cfg(test)]

0 commit comments

Comments
 (0)