Skip to content

Commit 5d2e474

Browse files
committed
Test channel reestablish during splice lifecycle
This test captures all the new spec requirements introduced for a splice to the channel reestablish flow.
1 parent 7d92927 commit 5d2e474

File tree

3 files changed

+376
-46
lines changed

3 files changed

+376
-46
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ fn do_test_async_raa_peer_disconnect(
596596
}
597597

598598
// Expect the RAA
599-
let (_, revoke_and_ack, commitment_signed, resend_order, _) =
599+
let (_, revoke_and_ack, commitment_signed, resend_order, _, _) =
600600
handle_chan_reestablish_msgs!(dst, src);
601601
if test_case == UnblockSignerAcrossDisconnectCase::AtEnd {
602602
assert!(revoke_and_ack.is_none());
@@ -612,14 +612,15 @@ fn do_test_async_raa_peer_disconnect(
612612
dst.node.signer_unblocked(Some((src_node_id, chan_id)));
613613

614614
if test_case == UnblockSignerAcrossDisconnectCase::AtEnd {
615-
let (_, revoke_and_ack, commitment_signed, resend_order, _) =
615+
let (_, revoke_and_ack, commitment_signed, resend_order, _, _) =
616616
handle_chan_reestablish_msgs!(dst, src);
617617
assert!(revoke_and_ack.is_some());
618618
assert!(commitment_signed.is_some());
619619
assert!(resend_order == RAACommitmentOrder::RevokeAndACKFirst);
620620
} else {
621621
// Make sure we don't double send the RAA.
622-
let (_, revoke_and_ack, commitment_signed, _, _) = handle_chan_reestablish_msgs!(dst, src);
622+
let (_, revoke_and_ack, commitment_signed, _, _, _) =
623+
handle_chan_reestablish_msgs!(dst, src);
623624
assert!(revoke_and_ack.is_none());
624625
assert!(commitment_signed.is_none());
625626
}
@@ -745,7 +746,7 @@ fn do_test_async_commitment_signature_peer_disconnect(
745746
}
746747

747748
// Expect the RAA
748-
let (_, revoke_and_ack, commitment_signed, _, _) = handle_chan_reestablish_msgs!(dst, src);
749+
let (_, revoke_and_ack, commitment_signed, _, _, _) = handle_chan_reestablish_msgs!(dst, src);
749750
assert!(revoke_and_ack.is_some());
750751
if test_case == UnblockSignerAcrossDisconnectCase::AtEnd {
751752
assert!(commitment_signed.is_none());
@@ -758,11 +759,11 @@ fn do_test_async_commitment_signature_peer_disconnect(
758759
dst.node.signer_unblocked(Some((src_node_id, chan_id)));
759760

760761
if test_case == UnblockSignerAcrossDisconnectCase::AtEnd {
761-
let (_, _, commitment_signed, _, _) = handle_chan_reestablish_msgs!(dst, src);
762+
let (_, _, commitment_signed, _, _, _) = handle_chan_reestablish_msgs!(dst, src);
762763
assert!(commitment_signed.is_some());
763764
} else {
764765
// Make sure we don't double send the CS.
765-
let (_, _, commitment_signed, _, _) = handle_chan_reestablish_msgs!(dst, src);
766+
let (_, _, commitment_signed, _, _, _) = handle_chan_reestablish_msgs!(dst, src);
766767
assert!(commitment_signed.is_none());
767768
}
768769
}
@@ -878,6 +879,7 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) {
878879
assert!(as_resp.1.is_none());
879880
assert!(as_resp.2.is_none());
880881
assert!(as_resp.4.is_none());
882+
assert!(as_resp.5.is_none());
881883

882884
if monitor_update_failure {
883885
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
@@ -898,6 +900,7 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) {
898900
assert!(as_resp.1.is_none());
899901
assert!(as_resp.2.is_none());
900902
assert!(as_resp.4.is_none());
903+
assert!(as_resp.5.is_none());
901904

902905
nodes[0].enable_channel_signer_op(&node_b_id, &chan_id, SignerOp::SignCounterpartyCommitment);
903906
nodes[0].node.signer_unblocked(Some((node_b_id, chan_id)));
@@ -917,6 +920,9 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) {
917920
assert!(as_resp.4.is_none());
918921
assert!(bs_resp.4.is_none());
919922

923+
assert!(as_resp.5.is_none());
924+
assert!(bs_resp.5.is_none());
925+
920926
// Now that everything is restored, get the CS + RAA and handle them.
921927
nodes[1]
922928
.node

lightning/src/ln/functional_test_utils.rs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,6 +4862,15 @@ macro_rules! handle_chan_reestablish_msgs {
48624862
}
48634863
}
48644864

4865+
let mut tx_signatures = None;
4866+
if let Some(&MessageSendEvent::SendTxSignatures { ref node_id, ref msg }) =
4867+
msg_events.get(idx)
4868+
{
4869+
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
4870+
tx_signatures = Some(msg.clone());
4871+
idx += 1;
4872+
}
4873+
48654874
if let Some(&MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg }) =
48664875
msg_events.get(idx)
48674876
{
@@ -4880,7 +4889,7 @@ macro_rules! handle_chan_reestablish_msgs {
48804889

48814890
assert_eq!(msg_events.len(), idx, "{msg_events:?}");
48824891

4883-
(channel_ready, revoke_and_ack, commitment_update, order, announcement_sigs)
4892+
(channel_ready, revoke_and_ack, commitment_update, order, announcement_sigs, tx_signatures)
48844893
}};
48854894
}
48864895

@@ -4889,6 +4898,9 @@ pub struct ReconnectArgs<'a, 'b, 'c, 'd> {
48894898
pub node_b: &'a Node<'b, 'c, 'd>,
48904899
pub send_channel_ready: (bool, bool),
48914900
pub send_announcement_sigs: (bool, bool),
4901+
pub send_interactive_tx_commit_sig: (bool, bool),
4902+
pub send_interactive_tx_sigs: (bool, bool),
4903+
pub expect_renegotiated_funding_locked_monitor_update: (bool, bool),
48924904
pub pending_responding_commitment_signed: (bool, bool),
48934905
/// Indicates that the pending responding commitment signed will be a dup for the recipient,
48944906
/// and no monitor update is expected
@@ -4908,6 +4920,9 @@ impl<'a, 'b, 'c, 'd> ReconnectArgs<'a, 'b, 'c, 'd> {
49084920
node_b,
49094921
send_channel_ready: (false, false),
49104922
send_announcement_sigs: (false, false),
4923+
send_interactive_tx_commit_sig: (false, false),
4924+
send_interactive_tx_sigs: (false, false),
4925+
expect_renegotiated_funding_locked_monitor_update: (false, false),
49114926
pending_responding_commitment_signed: (false, false),
49124927
pending_responding_commitment_signed_dup_monitor: (false, false),
49134928
pending_htlc_adds: (0, 0),
@@ -4928,6 +4943,9 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
49284943
node_b,
49294944
send_channel_ready,
49304945
send_announcement_sigs,
4946+
send_interactive_tx_commit_sig,
4947+
send_interactive_tx_sigs,
4948+
expect_renegotiated_funding_locked_monitor_update,
49314949
pending_htlc_adds,
49324950
pending_htlc_claims,
49334951
pending_htlc_fails,
@@ -4978,7 +4996,11 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
49784996
node_b.node.handle_channel_reestablish(node_a_id, &msg);
49794997
resp_1.push(handle_chan_reestablish_msgs!(node_b, node_a));
49804998
}
4981-
if pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 {
4999+
5000+
if pending_cell_htlc_claims.0 != 0
5001+
|| pending_cell_htlc_fails.0 != 0
5002+
|| expect_renegotiated_funding_locked_monitor_update.1
5003+
{
49825004
check_added_monitors!(node_b, 1);
49835005
} else {
49845006
check_added_monitors!(node_b, 0);
@@ -4989,7 +5011,10 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
49895011
node_a.node.handle_channel_reestablish(node_b_id, &msg);
49905012
resp_2.push(handle_chan_reestablish_msgs!(node_a, node_b));
49915013
}
4992-
if pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 {
5014+
if pending_cell_htlc_claims.1 != 0
5015+
|| pending_cell_htlc_fails.1 != 0
5016+
|| expect_renegotiated_funding_locked_monitor_update.0
5017+
{
49935018
check_added_monitors!(node_a, 1);
49945019
} else {
49955020
check_added_monitors!(node_a, 0);
@@ -5036,6 +5061,21 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
50365061
} else {
50375062
assert!(chan_msgs.4.is_none());
50385063
}
5064+
if send_interactive_tx_commit_sig.0 {
5065+
assert!(chan_msgs.1.is_none());
5066+
let commitment_update = chan_msgs.2.take().unwrap();
5067+
assert_eq!(commitment_update.commitment_signed.len(), 1);
5068+
node_a.node.handle_commitment_signed_batch_test(
5069+
node_b_id,
5070+
&commitment_update.commitment_signed,
5071+
)
5072+
}
5073+
if send_interactive_tx_sigs.0 {
5074+
let tx_signatures = chan_msgs.5.take().unwrap();
5075+
node_a.node.handle_tx_signatures(node_b_id, &tx_signatures);
5076+
} else {
5077+
assert!(chan_msgs.5.is_none());
5078+
}
50395079
if pending_raa.0 {
50405080
assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst);
50415081
node_a.node.handle_revoke_and_ack(node_b_id, &chan_msgs.1.unwrap());
@@ -5127,6 +5167,21 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) {
51275167
} else {
51285168
assert!(chan_msgs.4.is_none());
51295169
}
5170+
if send_interactive_tx_commit_sig.1 {
5171+
assert!(chan_msgs.1.is_none());
5172+
let commitment_update = chan_msgs.2.take().unwrap();
5173+
assert_eq!(commitment_update.commitment_signed.len(), 1);
5174+
node_b.node.handle_commitment_signed_batch_test(
5175+
node_a_id,
5176+
&commitment_update.commitment_signed,
5177+
)
5178+
}
5179+
if send_interactive_tx_sigs.1 {
5180+
let tx_signatures = chan_msgs.5.take().unwrap();
5181+
node_b.node.handle_tx_signatures(node_a_id, &tx_signatures);
5182+
} else {
5183+
assert!(chan_msgs.5.is_none());
5184+
}
51305185
if pending_raa.1 {
51315186
assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst);
51325187
node_b.node.handle_revoke_and_ack(node_a_id, &chan_msgs.1.unwrap());

0 commit comments

Comments
 (0)