Skip to content

Commit efabf2d

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 98b0be1 commit efabf2d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31373137
pending_events.push(events::Event::PaymentSent {
31383138
payment_preimage
31393139
});
3140+
self.pending_outbound_payments.lock().unwrap().retain(|p| {
3141+
mpp_id.is_none() || (mpp_id.is_some() && mpp_id != p.1)
3142+
});
31403143
} else {
31413144
log_trace!(self.logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
31423145
}
@@ -5644,20 +5647,13 @@ mod tests {
56445647
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa);
56455648
check_added_monitors!(nodes[0], 1);
56465649

5647-
// There's an existing bug that generates a PaymentSent event for each MPP path, so handle that here.
56485650
let events = nodes[0].node.get_and_clear_pending_events();
56495651
match events[0] {
56505652
Event::PaymentSent { payment_preimage: ref preimage } => {
56515653
assert_eq!(payment_preimage, *preimage);
56525654
},
56535655
_ => panic!("Unexpected event"),
56545656
}
5655-
match events[1] {
5656-
Event::PaymentSent { payment_preimage: ref preimage } => {
5657-
assert_eq!(payment_preimage, *preimage);
5658-
},
5659-
_ => panic!("Unexpected event"),
5660-
}
56615657
}
56625658

56635659
#[test]

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,11 @@ pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, exp
12371237

12381238
if !skip_last {
12391239
last_update_fulfill_dance!(origin_node, expected_route.first().unwrap());
1240-
expect_payment_sent!(origin_node, our_payment_preimage);
12411240
}
12421241
}
1242+
if !skip_last {
1243+
expect_payment_sent!(origin_node, our_payment_preimage);
1244+
}
12431245
}
12441246

12451247
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) {

0 commit comments

Comments
 (0)