Skip to content

Commit b20e374

Browse files
Don't trigger manager persistence on unexpected release_htlc message.
If someone sends us an unexpected or duplicate release_held_htlc onion message, we should simply ignore it and not persist the entire ChannelManager in response.
1 parent 5a07741 commit b20e374

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
@@ -4392,14 +4392,26 @@ where
43924392
&self, payment_id: PaymentId, payment_release_secret: [u8; 32]
43934393
) -> Result<(), Bolt12PaymentError> {
43944394
let best_block_height = self.best_block.read().unwrap().height;
4395-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4396-
self.pending_outbound_payments
4397-
.send_payment_for_static_invoice(
4395+
let mut res = Ok(());
4396+
PersistenceNotifierGuard::optionally_notify(self, || {
4397+
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
43984398
payment_id, payment_release_secret, &self.router, self.list_usable_channels(),
43994399
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
44004400
&self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
44014401
|args| self.send_payment_along_path(args)
4402-
)
4402+
);
4403+
match outbound_pmts_res {
4404+
Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => {
4405+
res = outbound_pmts_res.map(|_| ());
4406+
NotifyOption::SkipPersistNoEvents
4407+
},
4408+
other_res => {
4409+
res = other_res;
4410+
NotifyOption::DoPersist
4411+
}
4412+
}
4413+
});
4414+
res
44034415
}
44044416

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

0 commit comments

Comments
 (0)