Skip to content

Commit 1261b19

Browse files
Don't trigger manager persistence on invalid payment release secret.
If someone sends us an invalid payment_release_secret for an outbound async payment, we should simply ignore it and not persist the entire ChannelManager in response.
1 parent 09c442f commit 1261b19

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,14 +4358,26 @@ where
43584358
&self, payment_id: PaymentId, payment_release_secret: [u8; 32]
43594359
) -> Result<(), Bolt12PaymentError> {
43604360
let best_block_height = self.best_block.read().unwrap().height;
4361-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4362-
self.pending_outbound_payments
4363-
.send_payment_for_static_invoice(
4361+
let mut res = Ok(());
4362+
PersistenceNotifierGuard::optionally_notify(self, || {
4363+
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
43644364
payment_id, payment_release_secret, &self.router, self.list_usable_channels(),
43654365
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer,
43664366
best_block_height, &self.logger, &self.pending_events,
43674367
|args| self.send_payment_along_path(args)
4368-
)
4368+
);
4369+
match outbound_pmts_res {
4370+
Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => {
4371+
res = outbound_pmts_res.map(|_| ());
4372+
NotifyOption::SkipPersistNoEvents
4373+
},
4374+
other_res => {
4375+
res = other_res;
4376+
NotifyOption::DoPersist
4377+
}
4378+
}
4379+
});
4380+
res
43694381
}
43704382

43714383
/// Signals that no further attempts for the given payment should occur. Useful if you have a

0 commit comments

Comments
 (0)