@@ -4287,9 +4287,9 @@ mod tests {
4287
4287
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
4288
4288
// broadcasting the right event to other nodes in payment path.
4289
4289
// A --------------------> B ----------------------> C (preimage)
4290
- // A's commitment tx C's commitment tx
4291
- // \ \
4292
- // B's preimage tx C's HTLC Success tx
4290
+ // C's commitment tx
4291
+ // \
4292
+ // C's HTLC Success tx
4293
4293
4294
4294
let nodes = create_network ( 3 ) ;
4295
4295
@@ -4307,6 +4307,7 @@ mod tests {
4307
4307
// Broadcast legit commitment tx from C on B's chain
4308
4308
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
4309
4309
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4310
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4310
4311
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
4311
4312
{
4312
4313
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4332,7 +4333,14 @@ mod tests {
4332
4333
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4333
4334
_ => panic ! ( "Unexpected event" ) ,
4334
4335
}
4335
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4336
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
4337
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4338
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4339
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4340
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4341
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4342
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4343
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4336
4344
4337
4345
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
4338
4346
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -4357,18 +4365,42 @@ mod tests {
4357
4365
} ,
4358
4366
_ => panic ! ( "Unexpected event" ) ,
4359
4367
} ;
4368
+ {
4369
+ 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)
4370
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4371
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4372
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4373
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
4374
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4375
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4376
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4377
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4378
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4379
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4380
+ node_txn. clear ( )
4381
+ }
4360
4382
4361
4383
// Broadcast legit commitment tx from A on B's chain
4362
4384
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
4363
4385
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4386
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4364
4387
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4365
4388
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4366
4389
assert_eq ! ( events. len( ) , 1 ) ;
4367
4390
match events[ 0 ] {
4368
4391
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4369
4392
_ => panic ! ( "Unexpected event" ) ,
4370
4393
}
4371
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4394
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
4395
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4396
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
4397
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4398
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4399
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
4400
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4401
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4402
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4403
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
4372
4404
4373
4405
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
4374
4406
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -4378,6 +4410,17 @@ mod tests {
4378
4410
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4379
4411
_ => panic ! ( "Unexpected event" ) ,
4380
4412
}
4413
+ 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)
4414
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4415
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4416
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
4417
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
4418
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4419
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4420
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4421
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4422
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4423
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4381
4424
}
4382
4425
4383
4426
#[ test]
@@ -4386,7 +4429,7 @@ mod tests {
4386
4429
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
4387
4430
// broadcasting the right event to other nodes in payment path.
4388
4431
// A ------------------> B ----------------------> C (timeout)
4389
- // A 's commitment tx C's commitment tx
4432
+ // B 's commitment tx C's commitment tx
4390
4433
// \ \
4391
4434
// B's HTLC timeout tx B's timeout tx
4392
4435
@@ -4405,6 +4448,7 @@ mod tests {
4405
4448
4406
4449
// Brodacast legit commitment tx from C on B's chain
4407
4450
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4451
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4408
4452
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
4409
4453
{
4410
4454
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4430,23 +4474,36 @@ mod tests {
4430
4474
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4431
4475
_ => panic ! ( "Unexpected event" ) ,
4432
4476
}
4433
- let mut funding_tx_map = HashMap :: new ( ) ;
4434
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
4435
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
4477
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
4478
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
4479
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
4480
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4436
4481
4437
4482
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
4438
4483
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
4439
4484
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4440
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4441
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
4442
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
4443
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4444
-
4445
- let mut commitment_tx_map = HashMap :: new ( ) ;
4446
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
4447
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
4448
-
4449
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
4485
+ let timeout_tx;
4486
+ {
4487
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
4488
+ 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)
4489
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
4490
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
4491
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
4492
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4493
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4494
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4495
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4496
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4497
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4498
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
4499
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
4500
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4501
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4502
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
4503
+ node_txn. clear ( ) ;
4504
+ }
4505
+
4506
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
4450
4507
{
4451
4508
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
4452
4509
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -4468,27 +4525,29 @@ mod tests {
4468
4525
} ,
4469
4526
_ => panic ! ( "Unexpected event" ) ,
4470
4527
} ;
4528
+ 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
4529
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
4471
4530
4472
- // Broadcast legit commitment tx from A on B's chain
4473
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
4474
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4475
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4476
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4477
- assert_eq ! ( events. len( ) , 1 ) ;
4478
- match events[ 0 ] {
4479
- Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4480
- _ => panic ! ( "Unexpected event" ) ,
4481
- }
4482
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4531
+ // Broadcast legit commitment tx from B on A's chain
4532
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4533
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4483
4534
4484
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
4485
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
4535
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4486
4536
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
4487
4537
assert_eq ! ( events. len( ) , 1 ) ;
4488
4538
match events[ 0 ] {
4489
4539
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4490
4540
_ => panic ! ( "Unexpected event" ) ,
4491
4541
}
4542
+ 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
4543
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4544
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4545
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4546
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4547
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4548
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4549
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4550
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4492
4551
}
4493
4552
4494
4553
#[ test]
0 commit comments