Skip to content

Commit e37a400

Browse files
committed
Clean up test handling of resending responding commitment_signed
When we need to rebroadcast a `commitment_signed` on reconnect in response to a previous update (ie not one which contains any updates) we previously hacked in support for it by passing a `-1` for the number of expected update_add_htlcs. This is a mess, and with the introduction of `ReconnectArgs` we can now clean it up easily with a new bool.
1 parent 4835b16 commit e37a400

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,11 @@ pub struct ReconnectArgs<'a, 'b, 'c, 'd> {
30303030
pub node_a: &'a Node<'b, 'c, 'd>,
30313031
pub node_b: &'a Node<'b, 'c, 'd>,
30323032
pub send_channel_ready: (bool, bool),
3033-
pub pending_htlc_adds: (i64, i64),
3033+
pub pending_responding_commitment_signed: (bool, bool),
3034+
/// Indicates that the pending responding commitment signed will be a dup for the recipient,
3035+
/// and no monitor update is expected
3036+
pub pending_responding_commitment_signed_dup_monitor: (bool, bool),
3037+
pub pending_htlc_adds: (usize, usize),
30343038
pub pending_htlc_claims: (usize, usize),
30353039
pub pending_htlc_fails: (usize, usize),
30363040
pub pending_cell_htlc_claims: (usize, usize),
@@ -3044,6 +3048,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30443048
node_a,
30453049
node_b,
30463050
send_channel_ready: (false, false),
3051+
pending_responding_commitment_signed: (false, false),
3052+
pending_responding_commitment_signed_dup_monitor: (false, false),
30473053
pending_htlc_adds: (0, 0),
30483054
pending_htlc_claims: (0, 0),
30493055
pending_htlc_fails: (0, 0),
@@ -3059,7 +3065,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30593065
pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
30603066
let ReconnectArgs {
30613067
node_a, node_b, send_channel_ready, pending_htlc_adds, pending_htlc_claims, pending_htlc_fails,
3062-
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa
3068+
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa,
3069+
pending_responding_commitment_signed, pending_responding_commitment_signed_dup_monitor,
30633070
} = args;
30643071
node_a.node.peer_connected(&node_b.node.get_our_node_id(), &msgs::Init {
30653072
features: node_b.node.init_features(), networks: None, remote_network_address: None
@@ -3144,13 +3151,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31443151
} else {
31453152
assert!(chan_msgs.1.is_none());
31463153
}
3147-
if pending_htlc_adds.0 != 0 || pending_htlc_claims.0 != 0 || pending_htlc_fails.0 != 0 || pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 {
3154+
if pending_htlc_adds.0 != 0 || pending_htlc_claims.0 != 0 || pending_htlc_fails.0 != 0 ||
3155+
pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 ||
3156+
pending_responding_commitment_signed.0
3157+
{
31483158
let commitment_update = chan_msgs.2.unwrap();
3149-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3150-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0 as usize);
3151-
} else {
3152-
assert!(commitment_update.update_add_htlcs.is_empty());
3153-
}
3159+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0);
31543160
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.0 + pending_cell_htlc_claims.0);
31553161
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.0 + pending_cell_htlc_fails.0);
31563162
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3164,7 +3170,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31643170
node_a.node.handle_update_fail_htlc(&node_b.node.get_our_node_id(), &update_fail);
31653171
}
31663172

3167-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3173+
if !pending_responding_commitment_signed.0 {
31683174
commitment_signed_dance!(node_a, node_b, commitment_update.commitment_signed, false);
31693175
} else {
31703176
node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3173,7 +3179,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31733179
// No commitment_signed so get_event_msg's assert(len == 1) passes
31743180
node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack);
31753181
assert!(node_b.node.get_and_clear_pending_msg_events().is_empty());
3176-
check_added_monitors!(node_b, 1);
3182+
check_added_monitors!(node_b, if pending_responding_commitment_signed_dup_monitor.0 { 0 } else { 1 });
31773183
}
31783184
} else {
31793185
assert!(chan_msgs.2.is_none());
@@ -3203,11 +3209,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32033209
} else {
32043210
assert!(chan_msgs.1.is_none());
32053211
}
3206-
if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_htlc_fails.1 != 0 || pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 {
3212+
if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_htlc_fails.1 != 0 ||
3213+
pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 ||
3214+
pending_responding_commitment_signed.1
3215+
{
32073216
let commitment_update = chan_msgs.2.unwrap();
3208-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3209-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
3210-
}
3217+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1);
32113218
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.1 + pending_cell_htlc_claims.1);
32123219
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.1 + pending_cell_htlc_fails.1);
32133220
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3221,7 +3228,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32213228
node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
32223229
}
32233230

3224-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3231+
if !pending_responding_commitment_signed.1 {
32253232
commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
32263233
} else {
32273234
node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3230,7 +3237,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32303237
// No commitment_signed so get_event_msg's assert(len == 1) passes
32313238
node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
32323239
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
3233-
check_added_monitors!(node_a, 1);
3240+
check_added_monitors!(node_a, if pending_responding_commitment_signed_dup_monitor.1 { 0 } else { 1 });
32343241
}
32353242
} else {
32363243
assert!(chan_msgs.2.is_none());

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,13 +3880,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
38803880
} else if messages_delivered == 3 {
38813881
// nodes[0] still wants its RAA + commitment_signed
38823882
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3883-
reconnect_args.pending_htlc_adds.0 = -1;
3883+
reconnect_args.pending_responding_commitment_signed.0 = true;
38843884
reconnect_args.pending_raa.0 = true;
38853885
reconnect_nodes(reconnect_args);
38863886
} else if messages_delivered == 4 {
38873887
// nodes[0] still wants its commitment_signed
38883888
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3889-
reconnect_args.pending_htlc_adds.0 = -1;
3889+
reconnect_args.pending_responding_commitment_signed.0 = true;
38903890
reconnect_nodes(reconnect_args);
38913891
} else if messages_delivered == 5 {
38923892
// nodes[1] still wants its final RAA
@@ -4014,13 +4014,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
40144014
} else if messages_delivered == 2 {
40154015
// nodes[0] still wants its RAA + commitment_signed
40164016
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4017-
reconnect_args.pending_htlc_adds.1 = -1;
4017+
reconnect_args.pending_responding_commitment_signed.1 = true;
40184018
reconnect_args.pending_raa.1 = true;
40194019
reconnect_nodes(reconnect_args);
40204020
} else if messages_delivered == 3 {
40214021
// nodes[0] still wants its commitment_signed
40224022
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4023-
reconnect_args.pending_htlc_adds.1 = -1;
4023+
reconnect_args.pending_responding_commitment_signed.1 = true;
40244024
reconnect_nodes(reconnect_args);
40254025
} else if messages_delivered == 4 {
40264026
// nodes[1] still wants its final RAA

0 commit comments

Comments
 (0)