@@ -4281,9 +4281,9 @@ mod tests {
4281
4281
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
4282
4282
// broadcasting the right event to other nodes in payment path.
4283
4283
// A --------------------> B ----------------------> C (preimage)
4284
- // A's commitment tx C's commitment tx
4285
- // \ \
4286
- // B's preimage tx C's HTLC Success tx
4284
+ // C's commitment tx
4285
+ // \
4286
+ // C's HTLC Success tx
4287
4287
4288
4288
let nodes = create_network ( 3 ) ;
4289
4289
@@ -4301,6 +4301,7 @@ mod tests {
4301
4301
// Broadcast legit commitment tx from C on B's chain
4302
4302
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
4303
4303
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4304
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4304
4305
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
4305
4306
{
4306
4307
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4326,7 +4327,14 @@ mod tests {
4326
4327
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4327
4328
_ => panic ! ( "Unexpected event" ) ,
4328
4329
}
4329
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4330
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
4331
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4332
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4333
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4334
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4335
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4336
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4337
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4330
4338
4331
4339
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
4332
4340
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -4351,18 +4359,42 @@ mod tests {
4351
4359
} ,
4352
4360
_ => panic ! ( "Unexpected event" ) ,
4353
4361
} ;
4362
+ {
4363
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ; ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 1 (timeout tx) * 2 (block-rescan)
4364
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4365
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4366
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4367
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
4368
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4369
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4370
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4371
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4372
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4373
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4374
+ node_txn. clear ( )
4375
+ }
4354
4376
4355
4377
// Broadcast legit commitment tx from A on B's chain
4356
4378
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
4357
4379
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4380
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4358
4381
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4359
4382
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4360
4383
assert_eq ! ( events. len( ) , 1 ) ;
4361
4384
match events[ 0 ] {
4362
4385
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4363
4386
_ => panic ! ( "Unexpected event" ) ,
4364
4387
}
4365
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4388
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
4389
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4390
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
4391
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4392
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4393
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
4394
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4395
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4396
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4397
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
4366
4398
4367
4399
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
4368
4400
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -4372,6 +4404,17 @@ mod tests {
4372
4404
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4373
4405
_ => panic ! ( "Unexpected event" ) ,
4374
4406
}
4407
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 1 (timeout tx) * 2 (block-rescan)
4408
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4409
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4410
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
4411
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
4412
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4413
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4414
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4415
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4416
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4417
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4375
4418
}
4376
4419
4377
4420
#[ test]
@@ -4380,7 +4423,7 @@ mod tests {
4380
4423
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
4381
4424
// broadcasting the right event to other nodes in payment path.
4382
4425
// A ------------------> B ----------------------> C (timeout)
4383
- // A 's commitment tx C's commitment tx
4426
+ // B 's commitment tx C's commitment tx
4384
4427
// \ \
4385
4428
// B's HTLC timeout tx B's timeout tx
4386
4429
@@ -4399,6 +4442,7 @@ mod tests {
4399
4442
4400
4443
// Brodacast legit commitment tx from C on B's chain
4401
4444
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4445
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4402
4446
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
4403
4447
{
4404
4448
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4424,23 +4468,36 @@ mod tests {
4424
4468
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4425
4469
_ => panic ! ( "Unexpected event" ) ,
4426
4470
}
4427
- let mut funding_tx_map = HashMap :: new ( ) ;
4428
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
4429
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
4471
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
4472
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
4473
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
4474
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4430
4475
4431
4476
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
4432
4477
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
4433
4478
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4434
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4435
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
4436
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
4437
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4438
-
4439
- let mut commitment_tx_map = HashMap :: new ( ) ;
4440
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
4441
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
4442
-
4443
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
4479
+ let timeout_tx;
4480
+ {
4481
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
4482
+ assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 6 (HTLC-Timeout tx, commitment tx, timeout tx) * 2 (block-rescan)
4483
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
4484
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
4485
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
4486
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4487
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4488
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4489
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4490
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4491
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4492
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
4493
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
4494
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4495
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4496
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
4497
+ node_txn. clear ( ) ;
4498
+ }
4499
+
4500
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
4444
4501
{
4445
4502
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
4446
4503
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -4462,27 +4519,29 @@ mod tests {
4462
4519
} ,
4463
4520
_ => panic ! ( "Unexpected event" ) ,
4464
4521
} ;
4522
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // Well... here we detect our own htlc_timeout_tx so no tx to be generated
4523
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
4465
4524
4466
- // Broadcast legit commitment tx from A on B's chain
4467
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
4468
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4469
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4470
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4471
- assert_eq ! ( events. len( ) , 1 ) ;
4472
- match events[ 0 ] {
4473
- Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4474
- _ => panic ! ( "Unexpected event" ) ,
4475
- }
4476
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4525
+ // Broadcast legit commitment tx from B on A's chain
4526
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4527
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4477
4528
4478
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
4479
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
4529
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4480
4530
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
4481
4531
assert_eq ! ( events. len( ) , 1 ) ;
4482
4532
match events[ 0 ] {
4483
4533
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4484
4534
_ => panic ! ( "Unexpected event" ) ,
4485
4535
}
4536
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 2 (timeout tx) * 2 block-rescan
4537
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4538
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4539
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4540
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4541
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4542
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4543
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4544
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4486
4545
}
4487
4546
4488
4547
#[ test]
0 commit comments