Skip to content

Commit 271f210

Browse files
committed
Use ChannelMonitorUpdates in commitment signing fns in Channel
This is a rather big step towards using the new ChannelMonitorUpdate flow, using it in the various commitment signing and commitment update message processing functions in Channel. Becase they all often call each other, they all have to be updated as a group, resulting in the somewhat large diff in this commit. In order to keep the update_ids strictly increasing by one for ease of use on the user end, we have to play some games with the latest_monitor_update_id field, though its generally still pretty readable, and the pattern of "get an update_id at the start, and use the one we got at the start when returning, irrespective of what other calls into the Channel during that time did" is relatively straightforward.
1 parent 5dacd2c commit 271f210

File tree

4 files changed

+278
-83
lines changed

4 files changed

+278
-83
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
201201
}
202202

203203
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed);
204+
check_added_monitors!(nodes[0], 1);
204205
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
205206
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
206207
}
@@ -791,6 +792,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
791792
send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0));
792793
nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]);
793794
nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg);
795+
check_added_monitors!(nodes[1], 1);
794796
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
795797
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
796798
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@@ -1177,6 +1179,7 @@ fn claim_while_disconnected_monitor_update_fail() {
11771179
let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
11781180
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]);
11791181
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed);
1182+
check_added_monitors!(nodes[1], 1);
11801183
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
11811184
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
11821185
// Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC
@@ -1374,6 +1377,7 @@ fn first_message_on_recv_ordering() {
13741377
// the appropriate HTLC acceptance).
13751378
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
13761379
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
1380+
check_added_monitors!(nodes[1], 1);
13771381
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
13781382
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
13791383

@@ -1655,7 +1659,7 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails:
16551659
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
16561660
if fail_on_generate && !restore_between_fails {
16571661
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented funding_signed from allowing funding broadcast".to_string(), 1);
1658-
check_added_monitors!(nodes[0], 0);
1662+
check_added_monitors!(nodes[0], 1);
16591663
} else {
16601664
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
16611665
check_added_monitors!(nodes[0], 1);

0 commit comments

Comments
 (0)