Skip to content

Commit 0d002f7

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 3f15d84 commit 0d002f7

File tree

3 files changed

+196
-37
lines changed

3 files changed

+196
-37
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+133-4
Original file line numberDiff line numberDiff line change
@@ -2989,18 +2989,27 @@ fn test_blocked_chan_preimage_release() {
29892989
check_added_monitors(&nodes[1], 1); // We generate only a preimage monitor update
29902990
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
29912991

2992-
// Finish the CS dance between nodes[0] and nodes[1].
2993-
commitment_signed_dance!(nodes[1], nodes[0], as_htlc_fulfill_updates.commitment_signed, false);
2992+
// Finish the CS dance between nodes[0] and nodes[1]. Note that until the final RAA CS is held
2993+
// until the full set of `ChannelMonitorUpdate`s on the nodes[1] <-> nodes[2] channel are
2994+
// complete, while the preimage that we care about ensuring is on disk did make it there above,
2995+
// the holding logic doesn't care about the type of update, it just cares that there is one.
2996+
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.commitment_signed);
2997+
check_added_monitors(&nodes[1], 1);
2998+
let (a, raa) = do_main_commitment_signed_dance(&nodes[1], &nodes[0], false);
2999+
assert!(a.is_none());
3000+
3001+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa);
29943002
check_added_monitors(&nodes[1], 0);
3003+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
29953004

29963005
let events = nodes[1].node.get_and_clear_pending_events();
29973006
assert_eq!(events.len(), 3);
29983007
if let Event::PaymentSent { .. } = events[0] {} else { panic!(); }
29993008
if let Event::PaymentPathSuccessful { .. } = events[2] {} else { panic!(); }
30003009
if let Event::PaymentForwarded { .. } = events[1] {} else { panic!(); }
30013010

3002-
// The event processing should release the last RAA update.
3003-
check_added_monitors(&nodes[1], 1);
3011+
// The event processing should release the last RAA updates on both channels.
3012+
check_added_monitors(&nodes[1], 2);
30043013

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

lightning/src/ln/channelmanager.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -4424,9 +4424,12 @@ where
44244424
self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
44254425
}
44264426

4427-
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint) {
4427+
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) {
44284428
match source {
44294429
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
4430+
if let Some(pubkey) = next_channel_counterparty_node_id {
4431+
debug_assert_eq!(pubkey, path[0].pubkey);
4432+
}
44304433
let ev_completion_action = EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
44314434
channel_funding_outpoint: next_channel_outpoint,
44324435
counterparty_node_id: path[0].pubkey,
@@ -4453,7 +4456,17 @@ where
44534456
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
44544457
outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
44554458
},
4456-
downstream_counterparty_and_funding_outpoint: None,
4459+
downstream_counterparty_and_funding_outpoint:
4460+
if let Some(node_id) = next_channel_counterparty_node_id {
4461+
Some((node_id, next_channel_outpoint, completed_blocker))
4462+
} else {
4463+
// We can only get `None` here if we are processing a
4464+
// `ChannelMonitor`-originated event, in which case we
4465+
// don't care about ensuring we wake the downstream
4466+
// channel's monitor updating - the channel is already
4467+
// closed.
4468+
None
4469+
},
44574470
})
44584471
} else { None }
44594472
});
@@ -5166,13 +5179,27 @@ where
51665179
match peer_state.channel_by_id.entry(msg.channel_id) {
51675180
hash_map::Entry::Occupied(mut chan) => {
51685181
let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
5182+
if let HTLCSource::PreviousHopData(prev_hop) = &res.0 {
5183+
peer_state.actions_blocking_raa_monitor_updates.entry(msg.channel_id)
5184+
.or_insert_with(Vec::new)
5185+
.push(RAAMonitorUpdateBlockingAction::from_prev_hop_data(&prev_hop));
5186+
}
5187+
// Note that we do not need to push an `actions_blocking_raa_monitor_updates`
5188+
// entry here, even though we *do* need to block the next RAA coming in from
5189+
// generating a monitor update which we let fly. We do this instead in the
5190+
// `claim_funds_internal` by attaching a `ReleaseRAAChannelMonitorUpdate`
5191+
// action to the event generated when we "claim" the sent payment. This is
5192+
// guaranteed to all complete before we process the RAA even though there is no
5193+
// lock held through that point as we aren't allowed to see another P2P message
5194+
// from the counterparty until we return, but `claim_funds_internal` runs
5195+
// first.
51695196
funding_txo = chan.get().get_funding_txo().expect("We won't accept a fulfill until funded");
51705197
res
51715198
},
51725199
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))
51735200
}
51745201
};
5175-
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo);
5202+
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, Some(*counterparty_node_id), funding_txo);
51765203
Ok(())
51775204
}
51785205

@@ -5379,12 +5406,10 @@ where
53795406
match peer_state.channel_by_id.entry(msg.channel_id) {
53805407
hash_map::Entry::Occupied(mut chan) => {
53815408
let funding_txo = chan.get().get_funding_txo();
5382-
let mon_update_blocked = self.pending_events.lock().unwrap().iter().any(|(_, action)| {
5383-
action == &Some(EventCompletionAction::ReleaseRAAChannelMonitorUpdate {
5384-
channel_funding_outpoint: funding_txo.expect("We won't accept an RAA until funded"),
5385-
counterparty_node_id: *counterparty_node_id,
5386-
})
5387-
});
5409+
let mon_update_blocked = self.raa_monitor_updates_held(
5410+
&peer_state.actions_blocking_raa_monitor_updates,
5411+
chan.get().get_funding_txo().expect("We won't accept an RAA until funded"),
5412+
*counterparty_node_id);
53885413
let (htlcs_to_fail, monitor_update_opt) = try_chan_entry!(self,
53895414
chan.get_mut().revoke_and_ack(&msg, &self.logger, mon_update_blocked), chan);
53905415
let res = if let Some(monitor_update) = monitor_update_opt {
@@ -5565,7 +5590,7 @@ where
55655590
MonitorEvent::HTLCEvent(htlc_update) => {
55665591
if let Some(preimage) = htlc_update.payment_preimage {
55675592
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
5568-
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
5593+
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, counterparty_node_id, funding_outpoint);
55695594
} else {
55705595
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
55715596
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };

lightning/src/ln/functional_test_utils.rs

+28-23
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
///
@@ -179,19 +193,19 @@ pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) ->
179193
assert!(depth >= 1);
180194
for i in 1..depth {
181195
let prev_blockhash = block.header.block_hash();
182-
do_connect_block(node, block, skip_intermediaries);
196+
do_connect_block_with_checks(node, block, skip_intermediaries);
183197
block = Block {
184198
header: BlockHeader { version: 0x20000000, prev_blockhash, merkle_root: TxMerkleNode::all_zeros(), time: height + i, bits: 42, nonce: 42 },
185199
txdata: vec![],
186200
};
187201
}
188202
let hash = block.header.block_hash();
189-
do_connect_block(node, block, false);
203+
do_connect_block_with_checks(node, block, false);
190204
hash
191205
}
192206

193207
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block) {
194-
do_connect_block(node, block.clone(), false);
208+
do_connect_block_with_checks(node, block.clone(), false);
195209
}
196210

197211
fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
@@ -201,8 +215,14 @@ fn call_claimable_balances<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>) {
201215
}
202216
}
203217

204-
fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
218+
fn do_connect_block_with_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
219+
call_claimable_balances(node);
220+
do_connect_block_without_checks(node, block, skip_intermediaries);
205221
call_claimable_balances(node);
222+
node.node.test_process_background_events();
223+
}
224+
225+
fn do_connect_block_without_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, skip_intermediaries: bool) {
206226
let height = node.best_block_info().1 + 1;
207227
#[cfg(feature = "std")] {
208228
eprintln!("Connecting block using Block Connection Style: {:?}", *node.connect_style.borrow());
@@ -254,8 +274,6 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
254274
}
255275
}
256276
}
257-
call_claimable_balances(node);
258-
node.node.test_process_background_events();
259277
node.blocks.lock().unwrap().push((block, height));
260278
}
261279

@@ -1605,20 +1623,7 @@ pub fn do_commitment_signed_dance(node_a: &Node<'_, '_, '_>, node_b: &Node<'_, '
16051623
check_added_monitors!(node_a, 1);
16061624

16071625
// If this commitment signed dance was due to a claim, don't check for an RAA monitor update.
1608-
let got_claim = node_a.node.pending_events.lock().unwrap().iter().any(|(ev, action)| {
1609-
let matching_action = if let Some(channelmanager::EventCompletionAction::ReleaseRAAChannelMonitorUpdate
1610-
{ channel_funding_outpoint, counterparty_node_id }) = action
1611-
{
1612-
if channel_funding_outpoint.to_channel_id() == commitment_signed.channel_id {
1613-
assert_eq!(*counterparty_node_id, node_b.node.get_our_node_id());
1614-
true
1615-
} else { false }
1616-
} else { false };
1617-
if matching_action {
1618-
if let Event::PaymentSent { .. } = ev {} else { panic!(); }
1619-
}
1620-
matching_action
1621-
});
1626+
let got_claim = node_a.node.test_raa_monitor_updates_held(node_b.node.get_our_node_id(), commitment_signed.channel_id);
16221627
if fail_backwards { assert!(!got_claim); }
16231628
commitment_signed_dance!(node_a, node_b, (), fail_backwards, true, false, got_claim);
16241629

@@ -2909,7 +2914,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
29092914
}
29102915
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 {
29112916
let commitment_update = chan_msgs.2.unwrap();
2912-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
2917+
if pending_htlc_adds.1 > 0 { // We use -1/-2 to denote a response commitment_signed
29132918
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
29142919
}
29152920
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.1 + pending_cell_htlc_claims.1);
@@ -2925,7 +2930,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
29252930
node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
29262931
}
29272932

2928-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
2933+
if pending_htlc_adds.1 >= 0 { // We use -1/-2 to denote a response commitment_signed
29292934
commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
29302935
} else {
29312936
node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -2934,7 +2939,7 @@ pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a,
29342939
// No commitment_signed so get_event_msg's assert(len == 1) passes
29352940
node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
29362941
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
2937-
check_added_monitors!(node_a, 1);
2942+
check_added_monitors(node_a, if pending_htlc_adds.1 == -1 { 1 } else { 0 });
29382943
}
29392944
} else {
29402945
assert!(chan_msgs.2.is_none());

0 commit comments

Comments
 (0)