Skip to content

Commit 416def4

Browse files
committed
Block the mon update removing a preimage until upstream mon writes
When we forward a payment and receive an `update_fulfill_htlc` message from the downstream channel, we immediately claim the HTLC on the upstream channel, before even doing a `commitment_signed` dance on the downstream channel. This implies that our `ChannelMonitorUpdate`s "go out" in the right order - first we ensure we'll get our money by writing the preimage down, then we write the update that resolves giving money on the downstream node. This is safe as long as `ChannelMonitorUpdate`s complete in the order in which they are generated, but of course looking forward we want to support asynchronous updates, which may complete in any order. Thus, here, we enforce the correct ordering by blocking the downstream `ChannelMonitorUpdate` until the upstream one completes. Like the `PaymentSent` event handling we do so only for the `revoke_and_ack` `ChannelMonitorUpdate`, ensuring the preimage-containing upstream update has a full RTT to complete before we actually manage to slow anything down.
1 parent 66ad55f commit 416def4

File tree

3 files changed

+196
-37
lines changed

3 files changed

+196
-37
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,18 +3011,27 @@ fn test_blocked_chan_preimage_release() {
30113011
check_added_monitors(&nodes[1], 1); // We generate only a preimage monitor update
30123012
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
30133013

3014-
// Finish the CS dance between nodes[0] and nodes[1].
3015-
commitment_signed_dance!(nodes[1], nodes[0], as_htlc_fulfill_updates.commitment_signed, false);
3014+
// Finish the CS dance between nodes[0] and nodes[1]. Note that until the final RAA CS is held
3015+
// until the full set of `ChannelMonitorUpdate`s on the nodes[1] <-> nodes[2] channel are
3016+
// complete, while the preimage that we care about ensuring is on disk did make it there above,
3017+
// the holding logic doesn't care about the type of update, it just cares that there is one.
3018+
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.commitment_signed);
3019+
check_added_monitors(&nodes[1], 1);
3020+
let (a, raa) = do_main_commitment_signed_dance(&nodes[1], &nodes[0], false);
3021+
assert!(a.is_none());
3022+
3023+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa);
30163024
check_added_monitors(&nodes[1], 0);
3025+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
30173026

30183027
let events = nodes[1].node.get_and_clear_pending_events();
30193028
assert_eq!(events.len(), 3);
30203029
if let Event::PaymentSent { .. } = events[0] {} else { panic!(); }
30213030
if let Event::PaymentPathSuccessful { .. } = events[2] {} else { panic!(); }
30223031
if let Event::PaymentForwarded { .. } = events[1] {} else { panic!(); }
30233032

3024-
// The event processing should release the last RAA update.
3025-
check_added_monitors(&nodes[1], 1);
3033+
// The event processing should release the last RAA updates on both channels.
3034+
check_added_monitors(&nodes[1], 2);
30263035

30273036
// When we fetch the next update the message getter will generate the next update for nodes[2],
30283037
// generating a further monitor update.
@@ -3033,3 +3042,123 @@ fn test_blocked_chan_preimage_release() {
30333042
commitment_signed_dance!(nodes[2], nodes[1], bs_htlc_fulfill_updates.commitment_signed, false);
30343043
expect_payment_sent(&nodes[2], payment_preimage_2, None, true, true);
30353044
}
3045+
3046+
fn do_test_inverted_mon_completion_order(complete_bc_commitment_dance: bool) {
3047+
// When we forward a payment and receive an `update_fulfill_htlc` message from the downstream
3048+
// channel, we immediately claim the HTLC on the upstream channel, before even doing a
3049+
// `commitment_signed` dance on the downstream channel. This implies that our
3050+
// `ChannelMonitorUpdate`s "go out" in the right order - first we ensure we'll get our money,
3051+
// then we write the update that resolves giving money on the downstream node. This is safe as
3052+
// long as `ChannelMonitorUpdate`s complete in the order in which they are generated, but of
3053+
// course this may not be the case. For asynchronous update writes, we have to ensure monitor
3054+
// updates can block each other, preventing the inversion all together.
3055+
let chanmon_cfgs = create_chanmon_cfgs(3);
3056+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
3057+
3058+
let persister;
3059+
let new_chain_monitor;
3060+
let nodes_1_deserialized;
3061+
3062+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
3063+
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
3064+
3065+
let chan_id_ab = create_announced_chan_between_nodes(&nodes, 0, 1).2;
3066+
let chan_id_bc = create_announced_chan_between_nodes(&nodes, 1, 2).2;
3067+
3068+
// Route a payment from A, through B, to C, then claim it on C. Once we pass B the
3069+
// `update_fulfill_htlc` we have a monitor update for both of B's channels. We complete the one
3070+
// on the B<->C channel but leave the A<->B monitor update pending, then reload B.
3071+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100_000);
3072+
3073+
let mon_ab = get_monitor!(nodes[1], chan_id_ab).encode();
3074+
3075+
nodes[2].node.claim_funds(payment_preimage);
3076+
check_added_monitors(&nodes[2], 1);
3077+
expect_payment_claimed!(nodes[2], payment_hash, 100_000);
3078+
3079+
chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
3080+
let cs_updates = get_htlc_update_msgs(&nodes[2], &nodes[1].node.get_our_node_id());
3081+
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]);
3082+
3083+
// B generates a new monitor update for the A <-> B channel, but doesn't send the new messages
3084+
// for it since the monitor update is marked in-progress.
3085+
check_added_monitors(&nodes[1], 1);
3086+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
3087+
3088+
// Now step the Commitment Signed Dance between B and C forward a bit (or fully), ensuring we
3089+
// won't get the preimage when the nodes reconnect, at which point we have to ensure we get it
3090+
// from the ChannelMonitor.
3091+
nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed);
3092+
check_added_monitors(&nodes[1], 1);
3093+
if complete_bc_commitment_dance {
3094+
let (bs_revoke_and_ack, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[2].node.get_our_node_id());
3095+
nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack);
3096+
check_added_monitors(&nodes[2], 1);
3097+
nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment_signed);
3098+
check_added_monitors(&nodes[2], 1);
3099+
let cs_raa = get_event_msg!(nodes[2], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id());
3100+
3101+
// At this point node B still hasn't persisted the `ChannelMonitorUpdate` with the
3102+
// preimage in the A <-> B channel, which will prevent it from persisting the
3103+
// `ChannelMonitorUpdate` here to avoid "losing" the preimage.
3104+
nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &cs_raa);
3105+
check_added_monitors(&nodes[1], 0);
3106+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
3107+
}
3108+
3109+
// Now reload node B
3110+
let manager_b = nodes[1].node.encode();
3111+
3112+
let mon_bc = get_monitor!(nodes[1], chan_id_bc).encode();
3113+
reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, new_chain_monitor, nodes_1_deserialized);
3114+
3115+
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
3116+
nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id());
3117+
3118+
// If we used the latest ChannelManager to reload from, we should have both channels still
3119+
// live. The B <-> C channel's final RAA ChannelMonitorUpdate must still be blocked as
3120+
// before - the ChannelMonitorUpdate for the A <-> B channel hasn't completed.
3121+
// When we call `timer_tick_occurred` we will get that monitor update back, which we'll
3122+
// complete after reconnecting to our peers.
3123+
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
3124+
nodes[1].node.timer_tick_occurred();
3125+
check_added_monitors(&nodes[1], 1);
3126+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
3127+
3128+
// Now reconnect B to both A and C. If the B <-> C commitment signed dance wasn't run to
3129+
// the end go ahead and do that, though the -2 in `reconnect_nodes` indicates that we
3130+
// expect to *not* receive the final RAA ChannelMonitorUpdate.
3131+
if complete_bc_commitment_dance {
3132+
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
3133+
} else {
3134+
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, -2), (0, 0), (0, 0), (0, 0), (0, 0), (false, true));
3135+
}
3136+
3137+
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
3138+
3139+
// (Finally) complete the A <-> B ChannelMonitorUpdate, ensuring the preimage is durably on
3140+
// disk in the proper ChannelMonitor, unblocking the B <-> C ChannelMonitor updating
3141+
// process.
3142+
let (outpoint, _, ab_update_id) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id_ab).unwrap().clone();
3143+
nodes[1].chain_monitor.chain_monitor.channel_monitor_updated(outpoint, ab_update_id).unwrap();
3144+
3145+
// When we fetch B's HTLC update messages here (now that the ChannelMonitorUpdate has
3146+
// completed), it will also release the final RAA ChannelMonitorUpdate on the B <-> C
3147+
// channel.
3148+
let bs_updates = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id());
3149+
check_added_monitors(&nodes[1], 1);
3150+
3151+
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]);
3152+
do_commitment_signed_dance(&nodes[0], &nodes[1], &bs_updates.commitment_signed, false, false);
3153+
3154+
expect_payment_forwarded!(nodes[1], &nodes[0], &nodes[2], Some(1_000), false, false);
3155+
3156+
// Finally, check that the payment was, ultimately, seen as sent by node A.
3157+
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
3158+
}
3159+
3160+
#[test]
3161+
fn test_inverted_mon_completion_order() {
3162+
do_test_inverted_mon_completion_order(true);
3163+
do_test_inverted_mon_completion_order(false);
3164+
}

lightning/src/ln/channelmanager.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4548,9 +4548,12 @@ where
45484548
self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
45494549
}
45504550

4551-
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint) {
4551+
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_counterparty_node_id: Option<PublicKey>, next_channel_outpoint: OutPoint) {
45524552
match source {
45534553
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
4554+
if let Some(pubkey) = next_channel_counterparty_node_id {
4555+
debug_assert_eq!(pubkey, path.hops[0].pubkey);
4556+
}
45544557
let ev_completion_action = EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
45554558
channel_funding_outpoint: next_channel_outpoint,
45564559
counterparty_node_id: path.hops[0].pubkey,
@@ -4576,7 +4579,17 @@ where
45764579
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
45774580
outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
45784581
},
4579-
downstream_counterparty_and_funding_outpoint: None,
4582+
downstream_counterparty_and_funding_outpoint:
4583+
if let Some(node_id) = next_channel_counterparty_node_id {
4584+
Some((node_id, next_channel_outpoint, completed_blocker))
4585+
} else {
4586+
// We can only get `None` here if we are processing a
4587+
// `ChannelMonitor`-originated event, in which case we
4588+
// don't care about ensuring we wake the downstream
4589+
// channel's monitor updating - the channel is already
4590+
// closed.
4591+
None
4592+
},
45804593
})
45814594
} else { None }
45824595
});
@@ -5289,13 +5302,27 @@ where
52895302
match peer_state.channel_by_id.entry(msg.channel_id) {
52905303
hash_map::Entry::Occupied(mut chan) => {
52915304
let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
5305+
if let HTLCSource::PreviousHopData(prev_hop) = &res.0 {
5306+
peer_state.actions_blocking_raa_monitor_updates.entry(msg.channel_id)
5307+
.or_insert_with(Vec::new)
5308+
.push(RAAMonitorUpdateBlockingAction::from_prev_hop_data(&prev_hop));
5309+
}
5310+
// Note that we do not need to push an `actions_blocking_raa_monitor_updates`
5311+
// entry here, even though we *do* need to block the next RAA coming in from
5312+
// generating a monitor update which we let fly. We do this instead in the
5313+
// `claim_funds_internal` by attaching a `ReleaseRAAChannelMonitorUpdate`
5314+
// action to the event generated when we "claim" the sent payment. This is
5315+
// guaranteed to all complete before we process the RAA even though there is no
5316+
// lock held through that point as we aren't allowed to see another P2P message
5317+
// from the counterparty until we return, but `claim_funds_internal` runs
5318+
// first.
52925319
funding_txo = chan.get().get_funding_txo().expect("We won't accept a fulfill until funded");
52935320
res
52945321
},
52955322
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))
52965323
}
52975324
};
5298-
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo);
5325+
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, Some(*counterparty_node_id), funding_txo);
52995326
Ok(())
53005327
}
53015328

@@ -5490,12 +5517,10 @@ where
54905517
match peer_state.channel_by_id.entry(msg.channel_id) {
54915518
hash_map::Entry::Occupied(mut chan) => {
54925519
let funding_txo = chan.get().get_funding_txo();
5493-
let mon_update_blocked = self.pending_events.lock().unwrap().iter().any(|(_, action)| {
5494-
action == &Some(EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
5495-
channel_funding_outpoint: funding_txo.expect("We won't accept an RAA until funded"),
5496-
counterparty_node_id: *counterparty_node_id,
5497-
})
5498-
});
5520+
let mon_update_blocked = self.raa_monitor_updates_held(
5521+
&peer_state.actions_blocking_raa_monitor_updates,
5522+
chan.get().get_funding_txo().expect("We won't accept an RAA until funded"),
5523+
*counterparty_node_id);
54995524
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self,
55005525
chan.get_mut().revoke_and_ack(&msg, &self.logger, mon_update_blocked), chan);
55015526
let res = if let Some(monitor_update) = monitor_update_opt {
@@ -5676,7 +5701,7 @@ where
56765701
MonitorEvent::HTLCEvent(htlc_update) => {
56775702
if let Some(preimage) = htlc_update.payment_preimage {
56785703
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
5679-
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
5704+
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, counterparty_node_id, funding_outpoint);
56805705
} else {
56815706
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
56825707
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };

lightning/src/ln/functional_test_utils.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ pub fn mine_transactions<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn: &[&Tra
7474
let height = node.best_block_info().1 + 1;
7575
confirm_transactions_at(node, txn, height);
7676
}
77+
/// Mine a single block containing the given transaction without extra checks which may impact
78+
/// ChannelManager state.
79+
pub fn mine_transaction_without_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
80+
let height = node.best_block_info().1 + 1;
81+
let mut block = Block {
82+
header: BlockHeader { version: 0x20000000, prev_blockhash: node.best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: height, bits: 42, nonce: 42 },
83+
txdata: Vec::new(),
84+
};
85+
for _ in 0..*node.network_chan_count.borrow() { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
86+
block.txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
87+
}
88+
block.txdata.push((*tx).clone());
89+
do_connect_block_without_checks(node, block, false);
90+
}
7791
/// Mine the given transaction at the given height, mining blocks as required to build to that
7892
/// height
7993
///
@@ -212,16 +226,16 @@ pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) ->
212226
assert!(depth >= 1);
213227
for i in 1..depth {
214228
let prev_blockhash = block.header.block_hash();
215-
do_connect_block(node, block, skip_intermediaries);
229+
do_connect_block_with_checks(node, block, skip_intermediaries);
216230
block = create_dummy_block(prev_blockhash, height + i, Vec::new());
217231
}
218232
let hash = block.header.block_hash();
219-
do_connect_block(node, block, false);
233+
do_connect_block_with_checks(node, block, false);
220234
hash
221235
}
222236

223237
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block) {
224-
do_connect_block(node, block.clone(), false);
238+
do_connect_block_with_checks(node, block.clone(), false);
225239
}
226240

227241
fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
@@ -231,8 +245,14 @@ fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
231245
}
232246
}
233247

234-
fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
248+
fn do_connect_block_with_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
249+
call_claimable_balances(node);
250+
do_connect_block_without_checks(node, block, skip_intermediaries);
235251
call_claimable_balances(node);
252+
node.node.test_process_background_events();
253+
}
254+
255+
fn do_connect_block_without_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
236256
let height = node.best_block_info().1 + 1;
237257
#[cfg(feature = "std")] {
238258
eprintln!("Connecting block using Block Connection Style: {:?}", *node.connect_style.borrow());
@@ -287,8 +307,6 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
287307
}
288308
}
289309
}
290-
call_claimable_balances(node);
291-
node.node.test_process_background_events();
292310
}
293311

294312
pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32) {
@@ -1684,20 +1702,7 @@ pub fn do_commitment_signed_dance(node_a: &Node<'_, '_, '_>, node_b: &Node<'_, '
16841702
check_added_monitors!(node_a, 1);
16851703

16861704
// If this commitment signed dance was due to a claim, don't check for an RAA monitor update.
1687-
let got_claim = node_a.node.pending_events.lock().unwrap().iter().any(|(ev, action)| {
1688-
let matching_action = if let Some(channelmanager::EventCompletionAction::ReleaseRAAChannelMonitorUpdate
1689-
{ channel_funding_outpoint, counterparty_node_id }) = action
1690-
{
1691-
if channel_funding_outpoint.to_channel_id() == commitment_signed.channel_id {
1692-
assert_eq!(*counterparty_node_id, node_b.node.get_our_node_id());
1693-
true
1694-
} else { false }
1695-
} else { false };
1696-
if matching_action {
1697-
if let Event::PaymentSent { .. } = ev {} else { panic!(); }
1698-
}
1699-
matching_action
1700-
});
1705+
let got_claim = node_a.node.test_raa_monitor_updates_held(node_b.node.get_our_node_id(), commitment_signed.channel_id);
17011706
if fail_backwards { assert!(!got_claim); }
17021707
commitment_signed_dance!(node_a, node_b, (), fail_backwards, true, false, got_claim);
17031708

@@ -3004,7 +3009,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
30043009
}
30053010
if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_htlc_fails.1 != 0 || pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 {
30063011
let commitment_update = chan_msgs.2.unwrap();
3007-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3012+
if pending_htlc_adds.1 > 0 { // We use -1/-2 to denote a response commitment_signed
30083013
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
30093014
}
30103015
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.1 + pending_cell_htlc_claims.1);
@@ -3020,7 +3025,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
30203025
node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
30213026
}
30223027

3023-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3028+
if pending_htlc_adds.1 >= 0 { // We use -1/-2 to denote a response commitment_signed
30243029
commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
30253030
} else {
30263031
node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3029,7 +3034,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
30293034
// No commitment_signed so get_event_msg's assert(len == 1) passes
30303035
node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
30313036
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
3032-
check_added_monitors!(node_a, 1);
3037+
check_added_monitors(node_a, if pending_htlc_adds.1 == -1 { 1 } else { 0 });
30333038
}
30343039
} else {
30353040
assert!(chan_msgs.2.is_none());

0 commit comments

Comments
 (0)