Skip to content

Commit 14d5b97

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 monotonic 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 7cc99fb commit 14d5b97

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
@@ -198,6 +198,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
198198
}
199199

200200
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed);
201+
check_added_monitors!(nodes[0], 1);
201202
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
202203
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
203204
}
@@ -784,6 +785,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
784785
send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0));
785786
nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]);
786787
nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg);
788+
check_added_monitors!(nodes[1], 1);
787789
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
788790
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
789791
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@@ -1167,6 +1169,7 @@ fn claim_while_disconnected_monitor_update_fail() {
11671169
let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
11681170
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]);
11691171
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed);
1172+
check_added_monitors!(nodes[1], 1);
11701173
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
11711174
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
11721175
// Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC
@@ -1362,6 +1365,7 @@ fn first_message_on_recv_ordering() {
13621365
// the appropriate HTLC acceptance).
13631366
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
13641367
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
1368+
check_added_monitors!(nodes[1], 1);
13651369
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
13661370
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
13671371

@@ -1639,7 +1643,7 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails:
16391643
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
16401644
if fail_on_generate && !restore_between_fails {
16411645
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented funding_signed from allowing funding broadcast".to_string(), 1);
1642-
check_added_monitors!(nodes[0], 0);
1646+
check_added_monitors!(nodes[0], 1);
16431647
} else {
16441648
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
16451649
check_added_monitors!(nodes[0], 1);

0 commit comments

Comments
 (0)