Skip to content

Commit 6b85162

Browse files
committed
f fix tests
1 parent b06cc9c commit 6b85162

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
@@ -1158,7 +1158,10 @@ fn test_monitor_update_fail_reestablish() {
11581158
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish);
11591159

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

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

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

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

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

13541362
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect);
1355-
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
1363+
let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
13561364

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

13611369
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect);
1362-
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
1370+
let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
13631371
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
13641372
check_added_monitors!(nodes[1], 1);
13651373
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@@ -1492,7 +1500,9 @@ fn monitor_failed_no_reestablish_response() {
14921500
let bs_reconnect = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id());
14931501

14941502
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect);
1503+
let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
14951504
nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect);
1505+
let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
14961506

14971507
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Ok(()));
14981508
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
@@ -2797,19 +2797,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27972797
}
27982798

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

lightning/src/ln/functional_test_utils.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,18 +1556,20 @@ macro_rules! handle_chan_reestablish_msgs {
15561556
let mut revoke_and_ack = None;
15571557
let mut commitment_update = None;
15581558
let order = if let Some(ev) = msg_events.get(idx) {
1559-
idx += 1;
15601559
match ev {
15611560
&MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
15621561
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15631562
revoke_and_ack = Some(msg.clone());
1563+
idx += 1;
15641564
RAACommitmentOrder::RevokeAndACKFirst
15651565
},
15661566
&MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
15671567
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15681568
commitment_update = Some(updates.clone());
1569+
idx += 1;
15691570
RAACommitmentOrder::CommitmentFirst
15701571
},
1572+
&MessageSendEvent::SendChannelUpdate { .. } => RAACommitmentOrder::CommitmentFirst,
15711573
_ => panic!("Unexpected event"),
15721574
}
15731575
} else {
@@ -1580,16 +1582,24 @@ macro_rules! handle_chan_reestablish_msgs {
15801582
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15811583
assert!(revoke_and_ack.is_none());
15821584
revoke_and_ack = Some(msg.clone());
1585+
idx += 1;
15831586
},
15841587
&MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
15851588
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
15861589
assert!(commitment_update.is_none());
15871590
commitment_update = Some(updates.clone());
1591+
idx += 1;
15881592
},
1593+
&MessageSendEvent::SendChannelUpdate { .. } => {},
15891594
_ => panic!("Unexpected event"),
15901595
}
15911596
}
15921597

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

lightning/src/ln/functional_tests.rs

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

0 commit comments

Comments
 (0)