@@ -127,6 +127,11 @@ fn test_async_commitment_signature_for_funding_signed() {
127
127
128
128
#[ test]
129
129
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 ) ;
132
+ }
133
+
134
+ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack ( test_case : u8 ) {
130
135
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
131
136
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
132
137
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
@@ -154,23 +159,33 @@ fn test_async_commitment_signature_for_commitment_signed() {
154
159
155
160
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
156
161
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
162
+ dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: GetPerCommitmentPoint ) ;
157
163
dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
158
164
dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
159
165
check_added_monitors ( dst, 1 ) ;
160
166
161
- get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
162
-
163
- // Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
164
- dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
165
- dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
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 ) ;
181
+ 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( ) ) ;
166
183
167
- let events = dst. node . get_and_clear_pending_msg_events ( ) ;
168
- assert_eq ! ( events. len( ) , 1 , "expected one message, got {}" , events. len( ) ) ;
169
- if let MessageSendEvent :: UpdateHTLCs { ref node_id, .. } = events[ 0 ] {
170
- assert_eq ! ( node_id, & src. node. get_our_node_id( ) ) ;
171
- } else {
172
- panic ! ( "expected UpdateHTLCs message, not {:?}" , events[ 0 ] ) ;
173
- } ;
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 ( ) ) ;
188
+ }
174
189
}
175
190
176
191
#[ test]
0 commit comments