Skip to content

Commit 10491f4

Browse files
committed
f fix tests
1 parent 1e17577 commit 10491f4

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,13 @@ mod tests {
443443

444444
// Confirm the funding transaction.
445445
confirm_transaction(&mut nodes[0], &funding_tx);
446+
let as_funding = get_event_msg!(nodes[0], MessageSendEvent::SendFundingLocked, nodes[1].node.get_our_node_id());
446447
confirm_transaction(&mut nodes[1], &funding_tx);
447-
nodes[0].node.handle_funding_locked(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingLocked, nodes[0].node.get_our_node_id()));
448-
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingLocked, nodes[1].node.get_our_node_id()));
448+
let bs_funding = get_event_msg!(nodes[1], MessageSendEvent::SendFundingLocked, nodes[0].node.get_our_node_id());
449+
nodes[0].node.handle_funding_locked(&nodes[1].node.get_our_node_id(), &bs_funding);
450+
let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
451+
nodes[1].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &as_funding);
452+
let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
449453

450454
assert!(bg_processor.stop().is_ok());
451455

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,10 @@ fn test_monitor_update_fail_reestablish() {
11591159
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish);
11601160

11611161
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish);
1162-
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
1162+
assert_eq!(
1163+
get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id())
1164+
.contents.flags & 2, 0); // The "disabled" bit should be unset as we just reconnected
1165+
11631166
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
11641167
check_added_monitors!(nodes[1], 1);
11651168

@@ -1173,10 +1176,15 @@ fn test_monitor_update_fail_reestablish() {
11731176
assert!(bs_reestablish == get_event_msg!(nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id()));
11741177

11751178
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish);
1179+
assert_eq!(
1180+
get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id())
1181+
.contents.flags & 2, 0); // The "disabled" bit should be unset as we just reconnected
11761182

11771183
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish);
11781184
check_added_monitors!(nodes[1], 0);
1179-
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
1185+
assert_eq!(
1186+
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id())
1187+
.contents.flags & 2, 0); // The "disabled" bit should be unset as we just reconnected
11801188

11811189
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Ok(()));
11821190
let (outpoint, latest_update) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_1.2).unwrap().clone();
@@ -1353,14 +1361,14 @@ fn claim_while_disconnected_monitor_update_fail() {
13531361
let bs_reconnect = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id());
13541362

13551363
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect);
1356-
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
1364+
let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
13571365

13581366
// Now deliver a's reestablish, freeing the claim from the holding cell, but fail the monitor
13591367
// update.
13601368
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
13611369

13621370
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect);
1363-
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
1371+
let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
13641372
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
13651373
check_added_monitors!(nodes[1], 1);
13661374
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@@ -1493,7 +1501,9 @@ fn monitor_failed_no_reestablish_response() {
14931501
let bs_reconnect = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id());
14941502

14951503
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect);
1504+
let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
14961505
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect);
1506+
let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
14971507

14981508
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Ok(()));
14991509
let (outpoint, latest_update) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,19 +2798,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27982798
}
27992799

28002800
let (raa, commitment_update, order, pending_forwards, pending_failures, funding_broadcastable, funding_locked) = channel.get_mut().monitor_updating_restored(&self.logger);
2801-
let channel_update = if funding_locked.is_some() && channel.get().is_usable() {
2801+
let channel_update = if funding_locked.is_some() && channel.get().is_usable() && !channel.get().should_announce() {
2802+
// We only send a channel_update in the case where we are just now sending a
2803+
// funding_locked and the channel is in a usable state. Further, we rely on the
2804+
// normal announcement_signatures process to send a channel_update for public
2805+
// channels, only generating a unicast channel_update if this is a private channel.
28022806
Some(events::MessageSendEvent::SendChannelUpdate {
28032807
node_id: channel.get().get_counterparty_node_id(),
28042808
msg: self.get_channel_update_for_unicast(channel.get()).unwrap(),
28052809
})
28062810
} else { None };
28072811
chan_restoration_res = handle_chan_restoration_locked!(self, channel_lock, channel_state, channel, raa, commitment_update, order, None, pending_forwards, funding_broadcastable, funding_locked);
28082812
if let Some(upd) = channel_update {
2809-
// If we closed the channel due to a failed monitor update in
2810-
// handle_chan_restoration_locked this will send a bogus channel_update immediately
2811-
// after closure, but our direct peer should be fine with that, given they know the
2812-
// channel state as well. Further, we'll broadcast a channel_disabled channel_update
2813-
// in post_handle_chan_restoration below for public channels.
28142813
channel_state.pending_msg_events.push(upd);
28152814
}
28162815
pending_failures
@@ -3428,18 +3427,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34283427
msg,
34293428
});
34303429
} else if chan.get().is_usable() {
3430+
// If the channel is in a usable state (ie the channel is not being shut
3431+
// down), send a unicast channel_update to our counterparty to make sure
3432+
// they have the latest channel parameters.
34313433
channel_update = Some(events::MessageSendEvent::SendChannelUpdate {
34323434
node_id: chan.get().get_counterparty_node_id(),
34333435
msg: self.get_channel_update_for_unicast(chan.get()).unwrap(),
34343436
});
34353437
}
34363438
chan_restoration_res = handle_chan_restoration_locked!(self, channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec::new(), None, funding_locked);
34373439
if let Some(upd) = channel_update {
3438-
// If we closed the channel due to a failed monitor update in
3439-
// handle_chan_restoration_locked this will send a bogus channel_update immediately
3440-
// after closure, but our direct peer should be fine with that, given they know the
3441-
// channel state as well. Further, we'll broadcast a channel_disabled channel_update
3442-
// in post_handle_chan_restoration below for public channels.
34433440
channel_state.pending_msg_events.push(upd);
34443441
}
34453442
htlcs_failed_forward

lightning/src/ln/functional_test_utils.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,18 +1557,20 @@ macro_rules! handle_chan_reestablish_msgs {
15571557
let mut revoke_and_ack = None;
15581558
let mut commitment_update = None;
15591559
let order = if let Some(ev) = msg_events.get(idx) {
1560-
idx += 1;
15611560
match ev {
15621561
&MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
15631562
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15641563
revoke_and_ack = Some(msg.clone());
1564+
idx += 1;
15651565
RAACommitmentOrder::RevokeAndACKFirst
15661566
},
15671567
&MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
15681568
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15691569
commitment_update = Some(updates.clone());
1570+
idx += 1;
15701571
RAACommitmentOrder::CommitmentFirst
15711572
},
1573+
&MessageSendEvent::SendChannelUpdate { .. } => RAACommitmentOrder::CommitmentFirst,
15721574
_ => panic!("Unexpected event"),
15731575
}
15741576
} else {
@@ -1581,16 +1583,24 @@ macro_rules! handle_chan_reestablish_msgs {
15811583
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15821584
assert!(revoke_and_ack.is_none());
15831585
revoke_and_ack = Some(msg.clone());
1586+
idx += 1;
15841587
},
15851588
&MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
15861589
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15871590
assert!(commitment_update.is_none());
15881591
commitment_update = Some(updates.clone());
1592+
idx += 1;
15891593
},
1594+
&MessageSendEvent::SendChannelUpdate { .. } => {},
15901595
_ => panic!("Unexpected event"),
15911596
}
15921597
}
15931598

1599+
if let Some(&MessageSendEvent::SendChannelUpdate { ref node_id, ref msg }) = msg_events.get(idx) {
1600+
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1601+
assert_eq!(msg.contents.flags & 2, 0); // "disabled" flag must not be set as we just reconnected.
1602+
}
1603+
15941604
(funding_locked, revoke_and_ack, commitment_update, order)
15951605
}
15961606
}

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) {
10411041
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_1_2nd_shutdown);
10421042
node_0_2nd_shutdown
10431043
} else {
1044-
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
1044+
let node_0_chan_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
1045+
assert_eq!(node_0_chan_update.contents.flags & 2, 0); // "disabled" flag must not be set as we just reconnected.
10451046
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_1_2nd_shutdown);
10461047
get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id())
10471048
};

0 commit comments

Comments
 (0)