Skip to content

Commit 6789818

Browse files
committed
Delay RAA-after-next processing until PaymentSent is are handled
In 0ad1f4c we fixed a nasty bug where a failure to persist a `ChannelManager` faster than a `ChannelMonitor` could result in the loss of a `PaymentSent` event, eventually resulting in a `PaymentFailed` instead! As noted in that commit, there's still some risk, though its been substantially reduced - if we receive an `update_fulfill_htlc` message for an outbound payment, and persist the initial removal `ChannelMonitorUpdate`, then respond with our own `commitment_signed` + `revoke_and_ack`, followed by receiving our peer's final `revoke_and_ack`, and then persist the `ChannelMonitorUpdate` generated from that, all prior to completing a `ChannelManager` persistence, we'll still forget the HTLC and eventually trigger a `PaymentFailed` rather than the correct `PaymentSent`. Here we fully fix the issue by delaying the final `ChannelMonitorUpdate` persistence until the `PaymentSent` event has been processed and document the fact that a spurious `PaymentFailed` event can still be generated for a sent payment. The original fix in 0ad1f4c is still incredibly useful here, allowing us to avoid blocking the first `ChannelMonitorUpdate` until the event processing completes, as this would cause us to add event-processing delay in our general commitment update latency. Instead, we ultimately race the user handling the `PaymentSent` event with how long it takes our `revoke_and_ack` + `commitment_signed` to make it to our counterparty and receive the response `revoke_and_ack`. This should give the user plenty of time to handle the event before we need to make progress. Sadly, because we change our `ChannelMonitorUpdate` semantics, this change requires a number of test changes, avoiding checking for a post-RAA `ChannelMonitorUpdate` until after we process a `PaymentSent` event. Note that this does not apply to payments we learned the preimage for on-chain - ensuring `PaymentSent` events from such resolutions will be addressed in a future PR. Thus, tests which resolve payments on-chain switch to a direct call to the `expect_payment_sent` function with the claim-expected flag unset.
1 parent 92fd015 commit 6789818

14 files changed

+229
-101
lines changed

lightning-invoice/src/utils.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -1091,22 +1091,7 @@ mod test {
10911091
let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
10921092
expect_payment_claimable!(&nodes[fwd_idx], payment_hash, payment_secret, payment_amt, payment_preimage_opt, route.paths[0].last().unwrap().pubkey);
10931093
do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
1094-
let events = nodes[0].node.get_and_clear_pending_events();
1095-
assert_eq!(events.len(), 2);
1096-
match events[0] {
1097-
Event::PaymentSent { payment_preimage: ref ev_preimage, payment_hash: ref ev_hash, ref fee_paid_msat, .. } => {
1098-
assert_eq!(payment_preimage, *ev_preimage);
1099-
assert_eq!(payment_hash, *ev_hash);
1100-
assert_eq!(fee_paid_msat, &Some(0));
1101-
},
1102-
_ => panic!("Unexpected event")
1103-
}
1104-
match events[1] {
1105-
Event::PaymentPathSuccessful { payment_hash: hash, .. } => {
1106-
assert_eq!(hash, Some(payment_hash));
1107-
},
1108-
_ => panic!("Unexpected event")
1109-
}
1094+
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
11101095
}
11111096

11121097
#[test]

lightning/src/chain/chainmonitor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ mod tests {
788788
use bitcoin::{BlockHeader, TxMerkleNode};
789789
use bitcoin::hashes::Hash;
790790
use crate::{check_added_monitors, check_closed_broadcast, check_closed_event};
791-
use crate::{expect_payment_sent, expect_payment_claimed, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
791+
use crate::{expect_payment_claimed, expect_payment_path_successful, get_event_msg};
792792
use crate::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
793793
use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Watch};
794794
use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
@@ -871,7 +871,7 @@ mod tests {
871871

872872
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
873873
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
874-
expect_payment_sent_without_paths!(nodes[0], payment_preimage_1);
874+
expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false);
875875
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed);
876876
check_added_monitors!(nodes[0], 1);
877877
let (as_first_raa, as_first_update) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id());
@@ -884,7 +884,7 @@ mod tests {
884884
let bs_first_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id());
885885

886886
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]);
887-
expect_payment_sent_without_paths!(nodes[0], payment_preimage_2);
887+
expect_payment_sent(&nodes[0], payment_preimage_2, None, false, false);
888888
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed);
889889
check_added_monitors!(nodes[0], 1);
890890
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa);
@@ -972,7 +972,7 @@ mod tests {
972972
}
973973
}
974974

975-
expect_payment_sent!(nodes[0], payment_preimage);
975+
expect_payment_sent(&nodes[0], payment_preimage, None, true, false);
976976
}
977977

978978
#[test]

lightning/src/ln/chanmon_update_fail_tests.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ fn claim_while_disconnected_monitor_update_fail() {
13711371
MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
13721372
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
13731373
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
1374+
expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false);
13741375
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed);
13751376
check_added_monitors!(nodes[0], 1);
13761377

@@ -1408,7 +1409,7 @@ fn claim_while_disconnected_monitor_update_fail() {
14081409

14091410
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa);
14101411
check_added_monitors!(nodes[0], 1);
1411-
expect_payment_sent!(nodes[0], payment_preimage_1);
1412+
expect_payment_path_successful!(nodes[0]);
14121413

14131414
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
14141415
}
@@ -2140,7 +2141,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
21402141
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_id_2 }]);
21412142

21422143
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]);
2143-
expect_payment_sent_without_paths!(nodes[0], payment_preimage);
2144+
expect_payment_sent(&nodes[0], payment_preimage, None, false, false);
21442145
commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, true, true);
21452146
expect_payment_path_successful!(nodes[0]);
21462147
}
@@ -2376,7 +2377,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
23762377
assert!(updates.update_fee.is_none());
23772378
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
23782379
nodes[1].node.handle_update_fulfill_htlc(&nodes[0].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
2379-
expect_payment_sent_without_paths!(nodes[1], payment_preimage_0);
2380+
expect_payment_sent(&nodes[1], payment_preimage_0, None, false, false);
23802381
assert_eq!(updates.update_add_htlcs.len(), 1);
23812382
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
23822383
updates.commitment_signed
@@ -2393,7 +2394,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
23932394
expect_payment_claimable!(nodes[1], payment_hash_1, payment_secret_1, 100000);
23942395
check_added_monitors!(nodes[1], 1);
23952396

2396-
commitment_signed_dance!(nodes[1], nodes[0], (), false, true, false);
2397+
commitment_signed_dance!(nodes[1], nodes[0], (), false, true, false, false);
23972398

23982399
let events = nodes[1].node.get_and_clear_pending_events();
23992400
assert_eq!(events.len(), 2);
@@ -2493,7 +2494,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24932494
bs_updates = Some(get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()));
24942495
assert_eq!(bs_updates.as_ref().unwrap().update_fulfill_htlcs.len(), 1);
24952496
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]);
2496-
expect_payment_sent_without_paths!(nodes[0], payment_preimage);
2497+
expect_payment_sent(&nodes[0], payment_preimage, None, false, false);
24972498
if htlc_status == HTLCStatusAtDupClaim::Cleared {
24982499
commitment_signed_dance!(nodes[0], nodes[1], &bs_updates.as_ref().unwrap().commitment_signed, false);
24992500
expect_payment_path_successful!(nodes[0]);
@@ -2520,7 +2521,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
25202521
bs_updates = Some(get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()));
25212522
assert_eq!(bs_updates.as_ref().unwrap().update_fulfill_htlcs.len(), 1);
25222523
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]);
2523-
expect_payment_sent_without_paths!(nodes[0], payment_preimage);
2524+
expect_payment_sent(&nodes[0], payment_preimage, None, false, false);
25242525
}
25252526
if htlc_status != HTLCStatusAtDupClaim::Cleared {
25262527
commitment_signed_dance!(nodes[0], nodes[1], &bs_updates.as_ref().unwrap().commitment_signed, false);
@@ -2717,7 +2718,7 @@ fn double_temp_error() {
27172718
assert_eq!(node_id, nodes[0].node.get_our_node_id());
27182719
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_1);
27192720
check_added_monitors!(nodes[0], 0);
2720-
expect_payment_sent_without_paths!(nodes[0], payment_preimage_1);
2721+
expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false);
27212722
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed_b1);
27222723
check_added_monitors!(nodes[0], 1);
27232724
nodes[0].node.process_pending_htlc_forwards();

lightning/src/ln/channel.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
34093409
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
34103410
/// generating an appropriate error *after* the channel state has been updated based on the
34113411
/// revoke_and_ack message.
3412-
pub fn revoke_and_ack<L: Deref>(&mut self, msg: &msgs::RevokeAndACK, logger: &L) -> Result<(Vec<(HTLCSource, PaymentHash)>, Option<&ChannelMonitorUpdate>), ChannelError>
3412+
pub fn revoke_and_ack<L: Deref>(&mut self, msg: &msgs::RevokeAndACK, logger: &L, hold_mon_update: bool)
3413+
-> Result<(Vec<(HTLCSource, PaymentHash)>, Option<&ChannelMonitorUpdate>), ChannelError>
34133414
where L::Target: Logger,
34143415
{
34153416
if (self.channel_state & (ChannelState::ChannelReady as u32)) != (ChannelState::ChannelReady as u32) {
@@ -3606,7 +3607,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36063607
self.monitor_pending_failures.append(&mut revoked_htlcs);
36073608
self.monitor_pending_finalized_fulfills.append(&mut finalized_claimed_htlcs);
36083609
log_debug!(logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply.", log_bytes!(self.channel_id()));
3609-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3610+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36103611
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36113612
update: monitor_update, flown: fly_monitor,
36123613
});
@@ -3623,7 +3624,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36233624
monitor_update.updates.append(&mut additional_update.updates);
36243625

36253626
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3626-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3627+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36273628
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36283629
update: monitor_update, flown: fly_monitor,
36293630
});
@@ -3642,7 +3643,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36423643
log_debug!(logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed.",
36433644
log_bytes!(self.channel_id()), update_fail_htlcs.len() + update_fail_malformed_htlcs.len());
36443645
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3645-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3646+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36463647
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36473648
update: monitor_update, flown: fly_monitor,
36483649
});
@@ -3651,7 +3652,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36513652
} else {
36523653
log_debug!(logger, "Received a valid revoke_and_ack for channel {} with no reply necessary.", log_bytes!(self.channel_id()));
36533654
self.monitor_updating_paused(false, false, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3654-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3655+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36553656
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36563657
update: monitor_update, flown: fly_monitor,
36573658
});

lightning/src/ln/channelmanager.rs

+38-22
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,11 @@ where
863863
///
864864
/// Note that events MUST NOT be removed from pending_events without also holding the
865865
/// `pending_events_processor` lock.
866+
#[cfg(not(any(test, feature = "_test_utils")))]
866867
pending_events: Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
868+
#[cfg(any(test, feature = "_test_utils"))]
869+
pub(crate) pending_events: Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
870+
867871
/// A simple mutex to ensure only one thread can be processing
868872
pending_events_processor: Mutex<()>,
869873
/// See `ChannelManager` struct-level documentation for lock order requirements.
@@ -4121,10 +4125,16 @@ where
41214125
self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
41224126
}
41234127

4124-
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_id: [u8; 32]) {
4128+
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint) {
41254129
match source {
41264130
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
4127-
self.pending_outbound_payments.claim_htlc(payment_id, payment_preimage, session_priv, path, from_onchain, &self.pending_events, &self.logger);
4131+
let ev_completion_action = EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
4132+
channel_funding_outpoint: next_channel_outpoint,
4133+
counterparty_node_id: path[0].pubkey,
4134+
};
4135+
self.pending_outbound_payments.claim_htlc(payment_id, payment_preimage,
4136+
session_priv, path, from_onchain, ev_completion_action, &self.pending_events,
4137+
&self.logger);
41284138
},
41294139
HTLCSource::PreviousHopData(hop_data) => {
41304140
let prev_outpoint = hop_data.outpoint;
@@ -4135,14 +4145,11 @@ where
41354145
Some(claimed_htlc_value - forwarded_htlc_value)
41364146
} else { None };
41374147

4138-
let prev_channel_id = Some(prev_outpoint.to_channel_id());
4139-
let next_channel_id = Some(next_channel_id);
4140-
41414148
Some(MonitorUpdateCompletionAction::EmitEvent { event: events::Event::PaymentForwarded {
41424149
fee_earned_msat,
41434150
claim_from_onchain_tx: from_onchain,
4144-
prev_channel_id,
4145-
next_channel_id,
4151+
prev_channel_id: Some(prev_outpoint.to_channel_id()),
4152+
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
41464153
}})
41474154
} else { None }
41484155
});
@@ -4830,6 +4837,7 @@ where
48304837
}
48314838

48324839
fn internal_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), MsgHandleErrInternal> {
4840+
let funding_txo;
48334841
let (htlc_source, forwarded_htlc_value) = {
48344842
let per_peer_state = self.per_peer_state.read().unwrap();
48354843
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -4841,12 +4849,14 @@ where
48414849
let peer_state = &mut *peer_state_lock;
48424850
match peer_state.channel_by_id.entry(msg.channel_id) {
48434851
hash_map::Entry::Occupied(mut chan) => {
4844-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
4852+
let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
4853+
funding_txo = chan.get().get_funding_txo().expect("We won't accept a fulfill until funded");
4854+
res
48454855
},
48464856
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id))
48474857
}
48484858
};
4849-
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, msg.channel_id);
4859+
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo);
48504860
Ok(())
48514861
}
48524862

@@ -5023,7 +5033,14 @@ where
50235033
match peer_state.channel_by_id.entry(msg.channel_id) {
50245034
hash_map::Entry::Occupied(mut chan) => {
50255035
let funding_txo = chan.get().get_funding_txo();
5026-
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self, chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
5036+
let mon_update_blocked = self.pending_events.lock().unwrap().iter().any(|(_, action)| {
5037+
action == &Some(EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
5038+
channel_funding_outpoint: funding_txo.expect("We won't accept an RAA until funded"),
5039+
counterparty_node_id: *counterparty_node_id,
5040+
})
5041+
});
5042+
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self,
5043+
chan.get_mut().revoke_and_ack(&msg, &self.logger, mon_update_blocked), chan);
50275044
let res = if let Some(monitor_update) = monitor_update_opt {
50285045
let update_res = self.chain_monitor.update_channel(funding_txo.unwrap(), monitor_update);
50295046
let update_id = monitor_update.update_id;
@@ -5202,7 +5219,7 @@ where
52025219
MonitorEvent::HTLCEvent(htlc_update) => {
52035220
if let Some(preimage) = htlc_update.payment_preimage {
52045221
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
5205-
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint.to_channel_id());
5222+
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
52065223
} else {
52075224
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
52085225
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
@@ -7777,7 +7794,13 @@ where
77777794
// generating a `PaymentPathSuccessful` event but regenerating
77787795
// it and the `PaymentSent` on every restart until the
77797796
// `ChannelMonitor` is removed.
7780-
pending_outbounds.claim_htlc(payment_id, preimage, session_priv, path, false, &pending_events, &args.logger);
7797+
let compl_action =
7798+
EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
7799+
channel_funding_outpoint: monitor.get_funding_txo().0,
7800+
counterparty_node_id: path[0].pubkey,
7801+
};
7802+
pending_outbounds.claim_htlc(payment_id, preimage, session_priv,
7803+
path, false, compl_action, &pending_events, &args.logger);
77817804
pending_events_read = pending_events.into_inner().unwrap();
77827805
}
77837806
},
@@ -8172,6 +8195,7 @@ mod tests {
81728195

81738196
let bs_first_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
81748197
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]);
8198+
expect_payment_sent(&nodes[0], payment_preimage, None, false, false);
81758199
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed);
81768200
check_added_monitors!(nodes[0], 1);
81778201
let (as_first_raa, as_first_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id());
@@ -8199,24 +8223,16 @@ mod tests {
81998223
// Note that successful MPP payments will generate a single PaymentSent event upon the first
82008224
// path's success and a PaymentPathSuccessful event for each path's success.
82018225
let events = nodes[0].node.get_and_clear_pending_events();
8202-
assert_eq!(events.len(), 3);
8226+
assert_eq!(events.len(), 2);
82038227
match events[0] {
8204-
Event::PaymentSent { payment_id: ref id, payment_preimage: ref preimage, payment_hash: ref hash, .. } => {
8205-
assert_eq!(Some(payment_id), *id);
8206-
assert_eq!(payment_preimage, *preimage);
8207-
assert_eq!(our_payment_hash, *hash);
8208-
},
8209-
_ => panic!("Unexpected event"),
8210-
}
8211-
match events[1] {
82128228
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
82138229
assert_eq!(payment_id, *actual_payment_id);
82148230
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());
82158231
assert_eq!(route.paths[0], *path);
82168232
},
82178233
_ => panic!("Unexpected event"),
82188234
}
8219-
match events[2] {
8235+
match events[1] {
82208236
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
82218237
assert_eq!(payment_id, *actual_payment_id);
82228238
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());

0 commit comments

Comments
 (0)