Skip to content

Commit 94f5213

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 fe0f634 commit 94f5213

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
@@ -3050,7 +3050,11 @@ pub struct ReconnectArgs<'a, 'b, 'c, 'd> {
30503050
pub node_a: &'a Node<'b, 'c, 'd>,
30513051
pub node_b: &'a Node<'b, 'c, 'd>,
30523052
pub send_channel_ready: (bool, bool),
3053-
pub pending_htlc_adds: (i64, i64),
3053+
pub pending_responding_commitment_signed: (bool, bool),
3054+
/// Indicates that the pending responding commitment signed will be a dup for the recipient,
3055+
/// and no monitor update is expected
3056+
pub pending_responding_commitment_signed_dup_monitor: (bool, bool),
3057+
pub pending_htlc_adds: (usize, usize),
30543058
pub pending_htlc_claims: (usize, usize),
30553059
pub pending_htlc_fails: (usize, usize),
30563060
pub pending_cell_htlc_claims: (usize, usize),
@@ -3064,6 +3068,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30643068
node_a,
30653069
node_b,
30663070
send_channel_ready: (false, false),
3071+
pending_responding_commitment_signed: (false, false),
3072+
pending_responding_commitment_signed_dup_monitor: (false, false),
30673073
pending_htlc_adds: (0, 0),
30683074
pending_htlc_claims: (0, 0),
30693075
pending_htlc_fails: (0, 0),
@@ -3079,7 +3085,8 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
30793085
pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
30803086
let ReconnectArgs {
30813087
node_a, node_b, send_channel_ready, pending_htlc_adds, pending_htlc_claims, pending_htlc_fails,
3082-
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa
3088+
pending_cell_htlc_claims, pending_cell_htlc_fails, pending_raa,
3089+
pending_responding_commitment_signed, pending_responding_commitment_signed_dup_monitor,
30833090
} = args;
30843091
node_a.node.peer_connected(&node_b.node.get_our_node_id(), &msgs::Init {
30853092
features: node_b.node.init_features(), networks: None, remote_network_address: None
@@ -3164,13 +3171,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31643171
} else {
31653172
assert!(chan_msgs.1.is_none());
31663173
}
3167-
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 {
3174+
if pending_htlc_adds.0 != 0 || pending_htlc_claims.0 != 0 || pending_htlc_fails.0 != 0 ||
3175+
pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 ||
3176+
pending_responding_commitment_signed.0
3177+
{
31683178
let commitment_update = chan_msgs.2.unwrap();
3169-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3170-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0 as usize);
3171-
} else {
3172-
assert!(commitment_update.update_add_htlcs.is_empty());
3173-
}
3179+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0);
31743180
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.0 + pending_cell_htlc_claims.0);
31753181
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.0 + pending_cell_htlc_fails.0);
31763182
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3184,7 +3190,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31843190
node_a.node.handle_update_fail_htlc(&node_b.node.get_our_node_id(), &update_fail);
31853191
}
31863192

3187-
if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
3193+
if !pending_responding_commitment_signed.0 {
31883194
commitment_signed_dance!(node_a, node_b, commitment_update.commitment_signed, false);
31893195
} else {
31903196
node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3193,7 +3199,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
31933199
// No commitment_signed so get_event_msg's assert(len == 1) passes
31943200
node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack);
31953201
assert!(node_b.node.get_and_clear_pending_msg_events().is_empty());
3196-
check_added_monitors!(node_b, 1);
3202+
check_added_monitors!(node_b, if pending_responding_commitment_signed_dup_monitor.0 { 0 } else { 1 });
31973203
}
31983204
} else {
31993205
assert!(chan_msgs.2.is_none());
@@ -3223,11 +3229,12 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32233229
} else {
32243230
assert!(chan_msgs.1.is_none());
32253231
}
3226-
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 {
3232+
if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_htlc_fails.1 != 0 ||
3233+
pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 ||
3234+
pending_responding_commitment_signed.1
3235+
{
32273236
let commitment_update = chan_msgs.2.unwrap();
3228-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3229-
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
3230-
}
3237+
assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1);
32313238
assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.1 + pending_cell_htlc_claims.1);
32323239
assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.1 + pending_cell_htlc_fails.1);
32333240
assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
@@ -3241,7 +3248,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32413248
node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
32423249
}
32433250

3244-
if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
3251+
if !pending_responding_commitment_signed.1 {
32453252
commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
32463253
} else {
32473254
node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
@@ -3250,7 +3257,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
32503257
// No commitment_signed so get_event_msg's assert(len == 1) passes
32513258
node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
32523259
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
3253-
check_added_monitors!(node_a, 1);
3260+
check_added_monitors!(node_a, if pending_responding_commitment_signed_dup_monitor.1 { 0 } else { 1 });
32543261
}
32553262
} else {
32563263
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
@@ -3867,13 +3867,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
38673867
} else if messages_delivered == 3 {
38683868
// nodes[0] still wants its RAA + commitment_signed
38693869
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3870-
reconnect_args.pending_htlc_adds.0 = -1;
3870+
reconnect_args.pending_responding_commitment_signed.0 = true;
38713871
reconnect_args.pending_raa.0 = true;
38723872
reconnect_nodes(reconnect_args);
38733873
} else if messages_delivered == 4 {
38743874
// nodes[0] still wants its commitment_signed
38753875
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
3876-
reconnect_args.pending_htlc_adds.0 = -1;
3876+
reconnect_args.pending_responding_commitment_signed.0 = true;
38773877
reconnect_nodes(reconnect_args);
38783878
} else if messages_delivered == 5 {
38793879
// nodes[1] still wants its final RAA
@@ -4001,13 +4001,13 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
40014001
} else if messages_delivered == 2 {
40024002
// nodes[0] still wants its RAA + commitment_signed
40034003
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4004-
reconnect_args.pending_htlc_adds.1 = -1;
4004+
reconnect_args.pending_responding_commitment_signed.1 = true;
40054005
reconnect_args.pending_raa.1 = true;
40064006
reconnect_nodes(reconnect_args);
40074007
} else if messages_delivered == 3 {
40084008
// nodes[0] still wants its commitment_signed
40094009
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
4010-
reconnect_args.pending_htlc_adds.1 = -1;
4010+
reconnect_args.pending_responding_commitment_signed.1 = true;
40114011
reconnect_nodes(reconnect_args);
40124012
} else if messages_delivered == 4 {
40134013
// nodes[1] still wants its final RAA

0 commit comments

Comments
 (0)