Skip to content

Commit 778d2ae

Browse files
Prevent duplicate PaymentSent events
by removing all pending outbound payments associated with the same MPP payment after the preimage is received
1 parent 8ce4e2f commit 778d2ae

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29782978
pending_events.push(events::Event::PaymentSent {
29792979
payment_preimage
29802980
});
2981+
self.pending_outbound_payments.lock().unwrap().retain(|p| {
2982+
mpp_id.is_none() || (mpp_id.is_some() && mpp_id == p.1)
2983+
});
29812984
} else {
29822985
log_trace!(self.logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
29832986
}
@@ -5491,20 +5494,13 @@ mod tests {
54915494
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa);
54925495
check_added_monitors!(nodes[0], 1);
54935496

5494-
// There's an existing bug that generates a PaymentSent event for each MPP path, so handle that here.
54955497
let events = nodes[0].node.get_and_clear_pending_events();
54965498
match events[0] {
54975499
Event::PaymentSent { payment_preimage: ref preimage } => {
54985500
assert_eq!(payment_preimage, *preimage);
54995501
},
55005502
_ => panic!("Unexpected event"),
55015503
}
5502-
match events[1] {
5503-
Event::PaymentSent { payment_preimage: ref preimage } => {
5504-
assert_eq!(payment_preimage, *preimage);
5505-
},
5506-
_ => panic!("Unexpected event"),
5507-
}
55085504
}
55095505

55105506
#[test]

0 commit comments

Comments
 (0)