Skip to content

Commit b516930

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 cbeaeb7 commit b516930

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
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: 24 additions & 14 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

@@ -195,10 +203,8 @@ impl PendingOutboundPayment {
195203
PendingOutboundPayment::Abandoned { session_privs, .. } => {
196204
session_privs.remove(session_priv)
197205
},
198-
PendingOutboundPayment::AwaitingInvoice { .. } => {
199-
debug_assert!(false);
200-
false
201-
},
206+
PendingOutboundPayment::AwaitingInvoice { .. } |
207+
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false },
202208
};
203209
if remove_res {
204210
if let PendingOutboundPayment::Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
@@ -217,11 +223,9 @@ impl PendingOutboundPayment {
217223
PendingOutboundPayment::Legacy { session_privs } |
218224
PendingOutboundPayment::Retryable { session_privs, .. } => {
219225
session_privs.insert(session_priv)
220-
}
221-
PendingOutboundPayment::AwaitingInvoice { .. } => {
222-
debug_assert!(false);
223-
false
224-
},
226+
},
227+
PendingOutboundPayment::AwaitingInvoice { .. } |
228+
PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false },
225229
PendingOutboundPayment::Fulfilled { .. } => false,
226230
PendingOutboundPayment::Abandoned { .. } => false,
227231
};
@@ -245,6 +249,7 @@ impl PendingOutboundPayment {
245249
session_privs.len()
246250
},
247251
PendingOutboundPayment::AwaitingInvoice { .. } => 0,
252+
PendingOutboundPayment::InvoiceReceived { .. } => 0,
248253
}
249254
}
250255
}
@@ -880,7 +885,9 @@ impl OutboundPayments {
880885
log_error!(logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102");
881886
return
882887
},
883-
PendingOutboundPayment::AwaitingInvoice { .. } => {
888+
PendingOutboundPayment::AwaitingInvoice { .. } |
889+
PendingOutboundPayment::InvoiceReceived { .. } =>
890+
{
884891
log_error!(logger, "Payment not yet sent");
885892
return
886893
},
@@ -1573,6 +1580,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
15731580
(5, AwaitingInvoice) => {
15741581
(0, timer_ticks_without_response, required),
15751582
},
1583+
(7, InvoiceReceived) => {
1584+
(0, payment_hash, required),
1585+
},
15761586
);
15771587

15781588
#[cfg(test)]

0 commit comments

Comments
 (0)