Skip to content

Commit 811fbab

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 4468def commit 811fbab

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
@@ -3021,7 +3021,11 @@ pub struct ReconnectArgs<'a, 'b, 'c, 'd> {
30213021
pub node_a: &'a Node<'b, 'c, 'd>,
30223022
pub node_b: &'a Node<'b, 'c, 'd>,
30233023
pub send_channel_ready: (bool, bool),
3024-
pub pending_htlc_adds: (i64, i64),
3024+
pub pending_responding_commitment_signed: (bool, bool),
3025+
/// Indicates that the pending responding commitment signed will be a dup for the recipient,
3026+
/// and no monitor update is expected
3027+
pub pending_responding_commitment_signed_dup_monitor: (bool, bool),
3028+
pub pending_htlc_adds: (usize, usize),
30253029
pub pending_htlc_claims: (usize, usize),
30263030
pub pending_htlc_fails: (usize, usize),
30273031
pub pending_cell_htlc_claims: (usize, usize),
@@ -3035,6 +3039,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30353039
node_a,
30363040
node_b,
30373041
send_channel_ready: (false, false),
3042+
pending_responding_commitment_signed: (false, false),
3043+
pending_responding_commitment_signed_dup_monitor: (false, false),
30383044
pending_htlc_adds: (0, 0),
30393045
pending_htlc_claims: (0, 0),
30403046
pending_htlc_fails: (0, 0),
@@ -3050,7 +3056,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30503056
pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
30513057
let ReconnectArgs {
30523058
node_a, node_b, send_channel_ready, pending_htlc_adds, pending_htlc_claims, pending_htlc_fails,
3053-
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa
3059+
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa,
3060+
pending_responding_commitment_signed, pending_responding_commitment_signed_dup_monitor,
30543061
} = args;
30553062
node_a.node.peer_connected(&node_b.node.get_our_node_id(), &msgs::Init {
30563063
features: node_b.node.init_features(), networks: None, remote_network_address: None
@@ -3135,13 +3142,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31353142
} else {
31363143
assert!(chan_msgs.1.is_none());
31373144
}
3138-
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 {
3145+
if pending_htlc_adds.0 != 0 || pending_htlc_claims.0 != 0 || pending_htlc_fails.0 != 0 ||
3146+
pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 ||
3147+
pending_responding_commitment_signed.0
3148+
{
31393149
let commitment_update = chan_msgs.2.unwrap();
3140-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3141-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0 as usize);
3142-
} else {
3143-
assert!(commitment_update.update_add_htlcs.is_empty());
3144-
}
3150+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0);
31453151
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.0 + pending_cell_htlc_claims.0);
31463152
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.0 + pending_cell_htlc_fails.0);
31473153
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3155,7 +3161,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31553161
node_a.node.handle_update_fail_htlc(&node_b.node.get_our_node_id(), &update_fail);
31563162
}
31573163

3158-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3164+
if !pending_responding_commitment_signed.0 {
31593165
commitment_signed_dance!(node_a, node_b, commitment_update.commitment_signed, false);
31603166
} else {
31613167
node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3164,7 +3170,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31643170
// No commitment_signed so get_event_msg's assert(len == 1) passes
31653171
node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack);
31663172
assert!(node_b.node.get_and_clear_pending_msg_events().is_empty());
3167-
check_added_monitors!(node_b, 1);
3173+
check_added_monitors!(node_b, if pending_responding_commitment_signed_dup_monitor.0 { 0 } else { 1 });
31683174
}
31693175
} else {
31703176
assert!(chan_msgs.2.is_none());
@@ -3194,11 +3200,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31943200
} else {
31953201
assert!(chan_msgs.1.is_none());
31963202
}
3197-
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 {
3203+
if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_htlc_fails.1 != 0 ||
3204+
pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 ||
3205+
pending_responding_commitment_signed.1
3206+
{
31983207
let commitment_update = chan_msgs.2.unwrap();
3199-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3200-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
3201-
}
3208+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1);
32023209
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.1 + pending_cell_htlc_claims.1);
32033210
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.1 + pending_cell_htlc_fails.1);
32043211
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3212,7 +3219,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32123219
node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
32133220
}
32143221

3215-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3222+
if !pending_responding_commitment_signed.1 {
32163223
commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
32173224
} else {
32183225
node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3221,7 +3228,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32213228
// No commitment_signed so get_event_msg's assert(len == 1) passes
32223229
node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
32233230
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
3224-
check_added_monitors!(node_a, 1);
3231+
check_added_monitors!(node_a, if pending_responding_commitment_signed_dup_monitor.1 { 0 } else { 1 });
32253232
}
32263233
} else {
32273234
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
@@ -3863,13 +3863,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
38633863
} else if messages_delivered == 3 {
38643864
// nodes[0] still wants its RAA + commitment_signed
38653865
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3866-
reconnect_args.pending_htlc_adds.0 = -1;
3866+
reconnect_args.pending_responding_commitment_signed.0 = true;
38673867
reconnect_args.pending_raa.0 = true;
38683868
reconnect_nodes(reconnect_args);
38693869
} else if messages_delivered == 4 {
38703870
// nodes[0] still wants its commitment_signed
38713871
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3872-
reconnect_args.pending_htlc_adds.0 = -1;
3872+
reconnect_args.pending_responding_commitment_signed.0 = true;
38733873
reconnect_nodes(reconnect_args);
38743874
} else if messages_delivered == 5 {
38753875
// nodes[1] still wants its final RAA
@@ -3997,13 +3997,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
39973997
} else if messages_delivered == 2 {
39983998
// nodes[0] still wants its RAA + commitment_signed
39993999
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4000-
reconnect_args.pending_htlc_adds.1 = -1;
4000+
reconnect_args.pending_responding_commitment_signed.1 = true;
40014001
reconnect_args.pending_raa.1 = true;
40024002
reconnect_nodes(reconnect_args);
40034003
} else if messages_delivered == 3 {
40044004
// nodes[0] still wants its commitment_signed
40054005
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4006-
reconnect_args.pending_htlc_adds.1 = -1;
4006+
reconnect_args.pending_responding_commitment_signed.1 = true;
40074007
reconnect_nodes(reconnect_args);
40084008
} else if messages_delivered == 4 {
40094009
// nodes[1] still wants its final RAA

0 commit comments

Comments
 (0)