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 8ce4e2f commit 778d2ae
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2978,6 +2978,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 @@ -5491,20 +5494,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

0 comments on commit 778d2ae

Please sign in to comment.