Skip to content

Commit ac35287

Browse files
committed
Add PendingOutboundPayment::InvoiceReceived
When a BOLT 12 invoice has been received, a payment attempt is made and any errors result in abandoning the PendingOutboundPayment. This results in generating at PaymentFailed event, which has a PaymentHash. Thus, when receiving an invoice, transition from AwaitingInvoice to a new InvoiceReceived state, the latter of which contains a PaymentHash such the abandon_payment helper can still be used.
1 parent 53e2ee9 commit ac35287

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ pub enum ChannelShutdownState {
16831683
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
16841684
#[derive(Debug, PartialEq)]
16851685
pub enum RecentPaymentDetails {
1686-
/// When an invoice was requested but not yet received, and thus a payment has not been sent.
1686+
/// When an invoice was requested and thus a payment has not yet been sent.
16871687
AwaitingInvoice {
16881688
/// Identifier for the payment to ensure idempotency.
16891689
payment_id: PaymentId,
@@ -2423,6 +2423,10 @@ where
24232423
PendingOutboundPayment::AwaitingInvoice { .. } => {
24242424
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
24252425
},
2426+
// InvoiceReceived is an intermediate state and doesn't need to be exposed
2427+
PendingOutboundPayment::InvoiceReceived { .. } => {
2428+
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
2429+
},
24262430
PendingOutboundPayment::Retryable { payment_hash, total_msat, .. } => {
24272431
Some(RecentPaymentDetails::Pending {
24282432
payment_hash: *payment_hash,
@@ -8361,6 +8365,7 @@ where
83618365
}
83628366
}
83638367
PendingOutboundPayment::AwaitingInvoice { .. } => {},
8368+
PendingOutboundPayment::InvoiceReceived { .. } => {},
83648369
PendingOutboundPayment::Fulfilled { .. } => {},
83658370
PendingOutboundPayment::Abandoned { .. } => {},
83668371
}

lightning/src/ln/outbound_payment.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pub(crate) enum PendingOutboundPayment {
5353
AwaitingInvoice {
5454
timer_ticks_without_response: u8,
5555
},
56+
InvoiceReceived {
57+
payment_hash: PaymentHash,
58+
},
5659
Retryable {
5760
retry_strategy: Option<Retry>,
5861
attempts: PaymentAttempts,
@@ -152,6 +155,7 @@ impl PendingOutboundPayment {
152155
match self {
153156
PendingOutboundPayment::Legacy { .. } => None,
154157
PendingOutboundPayment::AwaitingInvoice { .. } => None,
158+
PendingOutboundPayment::InvoiceReceived { payment_hash } => Some(*payment_hash),
155159
PendingOutboundPayment::Retryable { payment_hash, .. } => Some(*payment_hash),
156160
PendingOutboundPayment::Fulfilled { payment_hash, .. } => *payment_hash,
157161
PendingOutboundPayment::Abandoned { payment_hash, .. } => Some(*payment_hash),
@@ -165,10 +169,8 @@ impl PendingOutboundPayment {
165169
PendingOutboundPayment::Retryable { session_privs, .. } |
166170
PendingOutboundPayment::Fulfilled { session_privs, .. } |
167171
PendingOutboundPayment::Abandoned { session_privs, .. } => session_privs,
168-
PendingOutboundPayment::AwaitingInvoice { .. } => {
169-
debug_assert!(false);
170-
return;
171-
},
172+
PendingOutboundPayment::AwaitingInvoice { .. } |
173+
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); return; },
172174
});
173175
let payment_hash = self.payment_hash();
174176
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0 };
@@ -183,6 +185,12 @@ impl PendingOutboundPayment {
183185
payment_hash: *payment_hash,
184186
reason: Some(reason)
185187
};
188+
} else if let PendingOutboundPayment::InvoiceReceived { payment_hash } = self {
189+
*self = PendingOutboundPayment::Abandoned {
190+
session_privs: HashSet::new(),
191+
payment_hash: *payment_hash,
192+
reason: Some(reason)
193+
};
186194
}
187195
}
188196

@@ -196,6 +204,7 @@ impl PendingOutboundPayment {
196204
session_privs.remove(session_priv)
197205
},
198206
PendingOutboundPayment::AwaitingInvoice { .. } => false,
207+
PendingOutboundPayment::InvoiceReceived { .. } => false,
199208
};
200209
if remove_res {
201210
if let PendingOutboundPayment::Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
@@ -216,6 +225,7 @@ impl PendingOutboundPayment {
216225
session_privs.insert(session_priv)
217226
}
218227
PendingOutboundPayment::AwaitingInvoice { .. } => false,
228+
PendingOutboundPayment::InvoiceReceived { .. } => false,
219229
PendingOutboundPayment::Fulfilled { .. } => false,
220230
PendingOutboundPayment::Abandoned { .. } => false,
221231
};
@@ -239,6 +249,7 @@ impl PendingOutboundPayment {
239249
session_privs.len()
240250
},
241251
PendingOutboundPayment::AwaitingInvoice { .. } => 0,
252+
PendingOutboundPayment::InvoiceReceived { .. } => 0,
242253
}
243254
}
244255
}
@@ -874,7 +885,9 @@ impl OutboundPayments {
874885
log_error!(logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102");
875886
return
876887
},
877-
PendingOutboundPayment::AwaitingInvoice { .. } => {
888+
PendingOutboundPayment::AwaitingInvoice { .. } |
889+
PendingOutboundPayment::InvoiceReceived { .. } =>
890+
{
878891
log_error!(logger, "Payment not yet sent");
879892
return
880893
},
@@ -1567,6 +1580,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
15671580
(5, AwaitingInvoice) => {
15681581
(0, timer_ticks_without_response, required),
15691582
},
1583+
(7, InvoiceReceived) => {
1584+
(0, payment_hash, required),
1585+
},
15701586
);
15711587

15721588
#[cfg(test)]

0 commit comments

Comments
 (0)