@@ -20,6 +20,7 @@ use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureR
20
20
use crate :: ln:: functional_test_utils:: * ;
21
21
use crate :: ln:: msgs:: ChannelMessageHandler ;
22
22
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
23
+ use crate :: util:: test_channel_signer:: SignerOp ;
23
24
24
25
#[ test]
25
26
fn test_async_commitment_signature_for_funding_created ( ) {
@@ -43,7 +44,7 @@ fn test_async_commitment_signature_for_funding_created() {
43
44
// But! Let's make node[0]'s signer be unavailable: we should *not* broadcast a funding_created
44
45
// message...
45
46
let ( temporary_channel_id, tx, _) = create_funding_transaction ( & nodes[ 0 ] , & nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 42 ) ;
46
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & temporary_channel_id, false ) ;
47
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
47
48
nodes[ 0 ] . node . funding_transaction_generated ( & temporary_channel_id, & nodes[ 1 ] . node . get_our_node_id ( ) , tx. clone ( ) ) . unwrap ( ) ;
48
49
check_added_monitors ( & nodes[ 0 ] , 0 ) ;
49
50
@@ -57,7 +58,7 @@ fn test_async_commitment_signature_for_funding_created() {
57
58
channels[ 0 ] . channel_id
58
59
} ;
59
60
60
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
61
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
61
62
nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
62
63
63
64
let mut funding_created_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingCreated , nodes[ 1 ] . node. get_our_node_id( ) ) ;
@@ -98,7 +99,7 @@ fn test_async_commitment_signature_for_funding_signed() {
98
99
99
100
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
100
101
// *not* broadcast a `funding_signed`...
101
- nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, false ) ;
102
+ nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
102
103
nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
103
104
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
104
105
@@ -111,7 +112,7 @@ fn test_async_commitment_signature_for_funding_signed() {
111
112
assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
112
113
channels[ 0 ] . channel_id
113
114
} ;
114
- nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
115
+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
115
116
nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
116
117
117
118
expect_channel_pending_event ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
@@ -152,14 +153,14 @@ fn test_async_commitment_signature_for_commitment_signed() {
152
153
153
154
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
154
155
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
155
- dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, false ) ;
156
+ dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
156
157
dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
157
158
check_added_monitors ( dst, 1 ) ;
158
159
159
160
get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
160
161
161
162
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
162
- dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
163
+ dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
163
164
dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
164
165
165
166
let events = dst. node . get_and_clear_pending_msg_events ( ) ;
@@ -215,7 +216,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
215
216
216
217
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
217
218
// *not* broadcast a `funding_signed`...
218
- nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, false ) ;
219
+ nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
219
220
nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
220
221
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
221
222
@@ -230,7 +231,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
230
231
} ;
231
232
232
233
// At this point, we basically expect the channel to open like a normal zero-conf channel.
233
- nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
234
+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
234
235
nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
235
236
236
237
let ( funding_signed, channel_ready_1) = {
@@ -299,7 +300,7 @@ fn test_async_commitment_signature_for_peer_disconnect() {
299
300
300
301
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
301
302
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
302
- dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, false ) ;
303
+ dst. disable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
303
304
dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
304
305
check_added_monitors ( dst, 1 ) ;
305
306
@@ -314,7 +315,7 @@ fn test_async_commitment_signature_for_peer_disconnect() {
314
315
reconnect_nodes ( reconnect_args) ;
315
316
316
317
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
317
- dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
318
+ dst. enable_channel_signer_op ( & src. node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
318
319
dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
319
320
320
321
{
@@ -366,7 +367,6 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
366
367
route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
367
368
let error_message = "Channel force-closed" ;
368
369
369
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, false ) ;
370
370
371
371
if remote_commitment {
372
372
// Make the counterparty broadcast its latest commitment.
@@ -375,6 +375,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
375
375
check_closed_broadcast ( & nodes[ 1 ] , 1 , true ) ;
376
376
check_closed_event ( & nodes[ 1 ] , 1 , ClosureReason :: HolderForceClosed { broadcasted_latest_txn : Some ( true ) } , false , & [ nodes[ 0 ] . node . get_our_node_id ( ) ] , 100_000 ) ;
377
377
} else {
378
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderCommitment ) ;
379
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderHtlcTransaction ) ;
378
380
// We'll connect blocks until the sender has to go onchain to time out the HTLC.
379
381
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
380
382
@@ -383,7 +385,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
383
385
assert ! ( nodes[ 0 ] . chain_monitor. chain_monitor. get_and_clear_pending_events( ) . is_empty( ) ) ;
384
386
385
387
// Mark it as available now, we should see the signed commitment transaction.
386
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
388
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderCommitment ) ;
389
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderHtlcTransaction ) ;
387
390
get_monitor ! ( nodes[ 0 ] , chan_id) . signer_unblocked ( nodes[ 0 ] . tx_broadcaster , nodes[ 0 ] . fee_estimator , & nodes[ 0 ] . logger ) ;
388
391
}
389
392
@@ -409,7 +412,13 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
409
412
410
413
// Mark it as unavailable again to now test the HTLC transaction. We'll mine the commitment such
411
414
// that the HTLC transaction is retried.
412
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, false ) ;
415
+ let sign_htlc_op = if remote_commitment {
416
+ SignerOp :: SignCounterpartyHtlcTransaction
417
+ } else {
418
+ SignerOp :: SignHolderHtlcTransaction
419
+ } ;
420
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderCommitment ) ;
421
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, sign_htlc_op) ;
413
422
mine_transaction ( & nodes[ 0 ] , & commitment_tx) ;
414
423
415
424
check_added_monitors ( & nodes[ 0 ] , 1 ) ;
@@ -426,10 +435,12 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
426
435
if anchors && !remote_commitment {
427
436
handle_bump_htlc_event ( & nodes[ 0 ] , 1 ) ;
428
437
}
429
- assert ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcast( ) . is_empty( ) ) ;
438
+ let txn = nodes[ 0 ] . tx_broadcaster . txn_broadcast ( ) ;
439
+ assert ! ( txn. is_empty( ) , "expected no transaction to be broadcast, got {:?}" , txn) ;
430
440
431
441
// Mark it as available now, we should see the signed HTLC transaction.
432
- nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
442
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignHolderCommitment ) ;
443
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, sign_htlc_op) ;
433
444
get_monitor ! ( nodes[ 0 ] , chan_id) . signer_unblocked ( nodes[ 0 ] . tx_broadcaster , nodes[ 0 ] . fee_estimator , & nodes[ 0 ] . logger ) ;
434
445
435
446
if anchors && !remote_commitment {
@@ -443,9 +454,21 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
443
454
}
444
455
445
456
#[ test]
446
- fn test_async_holder_signatures ( ) {
457
+ fn test_async_holder_signatures_no_anchors ( ) {
447
458
do_test_async_holder_signatures ( false , false ) ;
459
+ }
460
+
461
+ #[ test]
462
+ fn test_async_holder_signatures_remote_commitment_no_anchors ( ) {
448
463
do_test_async_holder_signatures ( false , true ) ;
464
+ }
465
+
466
+ #[ test]
467
+ fn test_async_holder_signatures_anchors ( ) {
449
468
do_test_async_holder_signatures ( true , false ) ;
469
+ }
470
+
471
+ #[ test]
472
+ fn test_async_holder_signatures_remote_commitment_anchors ( ) {
450
473
do_test_async_holder_signatures ( true , true ) ;
451
474
}
0 commit comments