Skip to content

Commit

Permalink
Prevent duplicate PaymentSent events
Browse files Browse the repository at this point in the history
by removing all pending outbound payments associated with the same
MPP payment after the preimage is received
  • Loading branch information
valentinewallace committed Aug 20, 2021
1 parent 98b0be1 commit efabf2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
pending_events.push(events::Event::PaymentSent {
payment_preimage
});
self.pending_outbound_payments.lock().unwrap().retain(|p| {
mpp_id.is_none() || (mpp_id.is_some() && mpp_id != p.1)
});
} else {
log_trace!(self.logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
}
Expand Down Expand Up @@ -5644,20 +5647,13 @@ mod tests {
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa);
check_added_monitors!(nodes[0], 1);

// There's an existing bug that generates a PaymentSent event for each MPP path, so handle that here.
let events = nodes[0].node.get_and_clear_pending_events();
match events[0] {
Event::PaymentSent { payment_preimage: ref preimage } => {
assert_eq!(payment_preimage, *preimage);
},
_ => panic!("Unexpected event"),
}
match events[1] {
Event::PaymentSent { payment_preimage: ref preimage } => {
assert_eq!(payment_preimage, *preimage);
},
_ => panic!("Unexpected event"),
}
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,11 @@ pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, exp

if !skip_last {
last_update_fulfill_dance!(origin_node, expected_route.first().unwrap());
expect_payment_sent!(origin_node, our_payment_preimage);
}
}
if !skip_last {
expect_payment_sent!(origin_node, our_payment_preimage);
}
}

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

0 comments on commit efabf2d

Please sign in to comment.