Skip to content

Commit 0fd57f5

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 2bd8f46 commit 0fd57f5

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
@@ -200,6 +200,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
200200
}
201201

202202
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed);
203+
check_added_monitors!(nodes[0], 1);
203204
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
204205
nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
205206
}
@@ -788,6 +789,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
788789
send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0));
789790
nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]);
790791
nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg);
792+
check_added_monitors!(nodes[1], 1);
791793
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
792794
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
793795
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
@@ -1171,6 +1173,7 @@ fn claim_while_disconnected_monitor_update_fail() {
11711173
let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
11721174
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]);
11731175
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed);
1176+
check_added_monitors!(nodes[1], 1);
11741177
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
11751178
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
11761179
// Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC
@@ -1366,6 +1369,7 @@ fn first_message_on_recv_ordering() {
13661369
// the appropriate HTLC acceptance).
13671370
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
13681371
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
1372+
check_added_monitors!(nodes[1], 1);
13691373
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
13701374
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
13711375

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

0 commit comments

Comments
 (0)