10
10
//! Tests for asynchronous signing. These tests verify that the channel state machine behaves
11
11
//! properly with a signer implementation that asynchronously derives signatures.
12
12
13
+ use std:: collections:: HashSet ;
14
+
13
15
use bitcoin:: { Transaction , TxOut , TxIn , Amount } ;
14
16
use bitcoin:: blockdata:: locktime:: absolute:: LockTime ;
15
17
use bitcoin:: transaction:: Version ;
@@ -22,6 +24,7 @@ use crate::ln::{functional_test_utils::*, msgs};
22
24
use crate :: ln:: msgs:: ChannelMessageHandler ;
23
25
use crate :: ln:: channelmanager:: { PaymentId , RAACommitmentOrder , RecipientOnionFields } ;
24
26
use crate :: util:: test_channel_signer:: SignerOp ;
27
+ use crate :: util:: logger:: Logger ;
25
28
26
29
#[ test]
27
30
fn test_async_commitment_signature_for_funding_created ( ) {
@@ -127,11 +130,17 @@ fn test_async_commitment_signature_for_funding_signed() {
127
130
128
131
#[ test]
129
132
fn test_async_commitment_signature_for_commitment_signed ( ) {
130
- do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( 0 ) ;
131
- do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( 1 ) ;
133
+ for i in 0 ..=8 {
134
+ let enable_signer_op_order = vec ! [
135
+ SignerOp :: GetPerCommitmentPoint ,
136
+ SignerOp :: ReleaseCommitmentSecret ,
137
+ SignerOp :: SignCounterpartyCommitment ,
138
+ ] . into_iter ( ) . filter ( |& op| i & ( 1 << op as u8 ) != 0 ) . collect ( ) ;
139
+ do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( enable_signer_op_order) ;
140
+ }
132
141
}
133
142
134
- fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( test_case : u8 ) {
143
+ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( enable_signer_op_order : Vec < SignerOp > ) {
135
144
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
136
145
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
137
146
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
@@ -160,31 +169,33 @@ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(test_
160
169
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
161
170
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
162
171
dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: GetPerCommitmentPoint ) ;
172
+ dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: ReleaseCommitmentSecret ) ;
163
173
dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
164
174
dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
165
175
check_added_monitors ( dst, 1 ) ;
166
176
167
- if test_case == 0 {
168
- // Unblock CS -> no messages should be sent, since we must send RAA first.
169
- dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
170
- dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
171
- let events = dst. node . get_and_clear_pending_msg_events ( ) ;
172
- assert ! ( events. is_empty( ) , "expected no message, got {}" , events. len( ) ) ;
173
-
174
- // Unblock revoke_and_ack -> we should send both RAA + CS.
175
- dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: GetPerCommitmentPoint ) ;
176
- dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
177
- get_revoke_commit_msgs ( & dst, & src. node . get_our_node_id ( ) ) ;
178
- } else if test_case == 1 {
179
- // Unblock revoke_and_ack -> we should send just RAA.
180
- dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: GetPerCommitmentPoint ) ;
177
+ let mut enabled_signer_ops = HashSet :: new ( ) ;
178
+ log_trace ! ( dst. logger, "enable_signer_op_order={:?}" , enable_signer_op_order) ;
179
+ for op in enable_signer_op_order {
180
+ enabled_signer_ops. insert ( op) ;
181
+ dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, op) ;
181
182
dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
182
- get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
183
183
184
- // Unblock commitment signed -> we should send CS.
185
- dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
186
- dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
187
- get_htlc_update_msgs ( dst, & src. node . get_our_node_id ( ) ) ;
184
+ if enabled_signer_ops. contains ( & SignerOp :: GetPerCommitmentPoint ) && enabled_signer_ops. contains ( & SignerOp :: ReleaseCommitmentSecret ) {
185
+ // We are just able to send revoke_and_ack
186
+ if op == SignerOp :: GetPerCommitmentPoint || op == SignerOp :: ReleaseCommitmentSecret {
187
+ get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
188
+ }
189
+ // We either just sent or previously sent revoke_and_ack
190
+ // and now we are able to send commitment_signed
191
+ if op == SignerOp :: SignCounterpartyCommitment {
192
+ get_htlc_update_msgs ( dst, & src. node . get_our_node_id ( ) ) ;
193
+ }
194
+ } else {
195
+ // We can't send either message until RAA is unblocked
196
+ let events = dst. node . get_and_clear_pending_msg_events ( ) ;
197
+ assert ! ( events. is_empty( ) , "expected no message, got {}" , events. len( ) ) ;
198
+ }
188
199
}
189
200
}
190
201
0 commit comments