Skip to content

Commit c7e8f27

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 57bebe7 commit c7e8f27

14 files changed

+229
-101
lines changed

lightning-invoice/src/utils.rs

Lines changed: 1 addition & 16 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 8 additions & 7 deletions
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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
34213421
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
34223422
/// generating an appropriate error *after* the channel state has been updated based on the
34233423
/// revoke_and_ack message.
3424-
pub fn revoke_and_ack<L: Deref>(&mut self, msg: &msgs::RevokeAndACK, logger: &L) -> Result<(Vec<(HTLCSource, PaymentHash)>, Option<&ChannelMonitorUpdate>), ChannelError>
3424+
pub fn revoke_and_ack<L: Deref>(&mut self, msg: &msgs::RevokeAndACK, logger: &L, hold_mon_update: bool)
3425+
-> Result<(Vec<(HTLCSource, PaymentHash)>, Option<&ChannelMonitorUpdate>), ChannelError>
34253426
where L::Target: Logger,
34263427
{
34273428
if (self.channel_state & (ChannelState::ChannelReady as u32)) != (ChannelState::ChannelReady as u32) {
@@ -3618,7 +3619,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36183619
self.monitor_pending_failures.append(&mut revoked_htlcs);
36193620
self.monitor_pending_finalized_fulfills.append(&mut finalized_claimed_htlcs);
36203621
log_debug!(logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply.", log_bytes!(self.channel_id()));
3621-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3622+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36223623
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36233624
update: monitor_update, flown: fly_monitor,
36243625
});
@@ -3635,7 +3636,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36353636
monitor_update.updates.append(&mut additional_update.updates);
36363637

36373638
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3638-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3639+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36393640
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36403641
update: monitor_update, flown: fly_monitor,
36413642
});
@@ -3654,7 +3655,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36543655
log_debug!(logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed.",
36553656
log_bytes!(self.channel_id()), update_fail_htlcs.len() + update_fail_malformed_htlcs.len());
36563657
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3657-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3658+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36583659
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36593660
update: monitor_update, flown: fly_monitor,
36603661
});
@@ -3663,7 +3664,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36633664
} else {
36643665
log_debug!(logger, "Received a valid revoke_and_ack for channel {} with no reply necessary.", log_bytes!(self.channel_id()));
36653666
self.monitor_updating_paused(false, false, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3666-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3667+
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown) && !hold_mon_update;
36673668
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
36683669
update: monitor_update, flown: fly_monitor,
36693670
});

lightning/src/ln/channelmanager.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,11 @@ where
918918
///
919919
/// Note that events MUST NOT be removed from pending_events without also holding the
920920
/// `pending_events_processor` lock.
921+
#[cfg(not(any(test, feature = "_test_utils")))]
921922
pending_events: Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
923+
#[cfg(any(test, feature = "_test_utils"))]
924+
pub(crate) pending_events: Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
925+
922926
/// A simple mutex to ensure only one thread can be processing
923927
pending_events_processor: Mutex<()>,
924928
/// See `ChannelManager` struct-level documentation for lock order requirements.
@@ -4180,10 +4184,16 @@ where
41804184
self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
41814185
}
41824186

4183-
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_id: [u8; 32]) {
4187+
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint) {
41844188
match source {
41854189
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
4186-
self.pending_outbound_payments.claim_htlc(payment_id, payment_preimage, session_priv, path, from_onchain, &self.pending_events, &self.logger);
4190+
let ev_completion_action = EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
4191+
channel_funding_outpoint: next_channel_outpoint,
4192+
counterparty_node_id: path[0].pubkey,
4193+
};
4194+
self.pending_outbound_payments.claim_htlc(payment_id, payment_preimage,
4195+
session_priv, path, from_onchain, ev_completion_action, &self.pending_events,
4196+
&self.logger);
41874197
},
41884198
HTLCSource::PreviousHopData(hop_data) => {
41894199
let prev_outpoint = hop_data.outpoint;
@@ -4194,14 +4204,11 @@ where
41944204
Some(claimed_htlc_value - forwarded_htlc_value)
41954205
} else { None };
41964206

4197-
let prev_channel_id = Some(prev_outpoint.to_channel_id());
4198-
let next_channel_id = Some(next_channel_id);
4199-
42004207
Some(MonitorUpdateCompletionAction::EmitEvent { event: events::Event::PaymentForwarded {
42014208
fee_earned_msat,
42024209
claim_from_onchain_tx: from_onchain,
4203-
prev_channel_id,
4204-
next_channel_id,
4210+
prev_channel_id: Some(prev_outpoint.to_channel_id()),
4211+
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
42054212
}})
42064213
} else { None }
42074214
});
@@ -4889,6 +4896,7 @@ where
48894896
}
48904897

48914898
fn internal_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), MsgHandleErrInternal> {
4899+
let funding_txo;
48924900
let (htlc_source, forwarded_htlc_value) = {
48934901
let per_peer_state = self.per_peer_state.read().unwrap();
48944902
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -4900,12 +4908,14 @@ where
49004908
let peer_state = &mut *peer_state_lock;
49014909
match peer_state.channel_by_id.entry(msg.channel_id) {
49024910
hash_map::Entry::Occupied(mut chan) => {
4903-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
4911+
let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
4912+
funding_txo = chan.get().get_funding_txo().expect("We won't accept a fulfill until funded");
4913+
res
49044914
},
49054915
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))
49064916
}
49074917
};
4908-
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, msg.channel_id);
4918+
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo);
49094919
Ok(())
49104920
}
49114921

@@ -5082,7 +5092,14 @@ where
50825092
match peer_state.channel_by_id.entry(msg.channel_id) {
50835093
hash_map::Entry::Occupied(mut chan) => {
50845094
let funding_txo = chan.get().get_funding_txo();
5085-
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self, chan.get_mut().revoke_and_ack(&msg, &self.logger), chan);
5095+
let mon_update_blocked = self.pending_events.lock().unwrap().iter().any(|(_, action)| {
5096+
action == &Some(EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
5097+
channel_funding_outpoint: funding_txo.expect("We won't accept an RAA until funded"),
5098+
counterparty_node_id: *counterparty_node_id,
5099+
})
5100+
});
5101+
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self,
5102+
chan.get_mut().revoke_and_ack(&msg, &self.logger, mon_update_blocked), chan);
50865103
let res = if let Some(monitor_update) = monitor_update_opt {
50875104
let update_res = self.chain_monitor.update_channel(funding_txo.unwrap(), monitor_update);
50885105
let update_id = monitor_update.update_id;
@@ -5261,7 +5278,7 @@ where
52615278
MonitorEvent::HTLCEvent(htlc_update) => {
52625279
if let Some(preimage) = htlc_update.payment_preimage {
52635280
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
5264-
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint.to_channel_id());
5281+
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
52655282
} else {
52665283
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
52675284
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
@@ -7842,7 +7859,13 @@ where
78427859
// generating a `PaymentPathSuccessful` event but regenerating
78437860
// it and the `PaymentSent` on every restart until the
78447861
// `ChannelMonitor` is removed.
7845-
pending_outbounds.claim_htlc(payment_id, preimage, session_priv, path, false, &pending_events, &args.logger);
7862+
let compl_action =
7863+
EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
7864+
channel_funding_outpoint: monitor.get_funding_txo().0,
7865+
counterparty_node_id: path[0].pubkey,
7866+
};
7867+
pending_outbounds.claim_htlc(payment_id, preimage, session_priv,
7868+
path, false, compl_action, &pending_events, &args.logger);
78467869
pending_events_read = pending_events.into_inner().unwrap();
78477870
}
78487871
},
@@ -8237,6 +8260,7 @@ mod tests {
82378260

82388261
let bs_first_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
82398262
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]);
8263+
expect_payment_sent(&nodes[0], payment_preimage, None, false, false);
82408264
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed);
82418265
check_added_monitors!(nodes[0], 1);
82428266
let (as_first_raa, as_first_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id());
@@ -8264,24 +8288,16 @@ mod tests {
82648288
// Note that successful MPP payments will generate a single PaymentSent event upon the first
82658289
// path's success and a PaymentPathSuccessful event for each path's success.
82668290
let events = nodes[0].node.get_and_clear_pending_events();
8267-
assert_eq!(events.len(), 3);
8291+
assert_eq!(events.len(), 2);
82688292
match events[0] {
8269-
Event::PaymentSent { payment_id: ref id, payment_preimage: ref preimage, payment_hash: ref hash, .. } => {
8270-
assert_eq!(Some(payment_id), *id);
8271-
assert_eq!(payment_preimage, *preimage);
8272-
assert_eq!(our_payment_hash, *hash);
8273-
},
8274-
_ => panic!("Unexpected event"),
8275-
}
8276-
match events[1] {
82778293
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
82788294
assert_eq!(payment_id, *actual_payment_id);
82798295
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());
82808296
assert_eq!(route.paths[0], *path);
82818297
},
82828298
_ => panic!("Unexpected event"),
82838299
}
8284-
match events[2] {
8300+
match events[1] {
82858301
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
82868302
assert_eq!(payment_id, *actual_payment_id);
82878303
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());

0 commit comments

Comments
 (0)