@@ -4260,9 +4260,9 @@ mod tests {
4260
4260
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
4261
4261
// broadcasting the right event to other nodes in payment path.
4262
4262
// A --------------------> B ----------------------> C (preimage)
4263
- // A's commitment tx C's commitment tx
4264
- // \ \
4265
- // B's preimage tx C's HTLC Success tx
4263
+ // C's commitment tx
4264
+ // \
4265
+ // C's HTLC Success tx
4266
4266
4267
4267
let nodes = create_network ( 3 ) ;
4268
4268
@@ -4280,6 +4280,7 @@ mod tests {
4280
4280
// Broadcast legit commitment tx from C on B's chain
4281
4281
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
4282
4282
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4283
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4283
4284
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
4284
4285
{
4285
4286
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4305,7 +4306,14 @@ mod tests {
4305
4306
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4306
4307
_ => panic ! ( "Unexpected event" ) ,
4307
4308
}
4308
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4309
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
4310
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4311
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4312
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4313
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4314
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4315
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4316
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4309
4317
4310
4318
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
4311
4319
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -4330,18 +4338,42 @@ mod tests {
4330
4338
} ,
4331
4339
_ => panic ! ( "Unexpected event" ) ,
4332
4340
} ;
4341
+ {
4342
+ 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)
4343
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4344
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4345
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4346
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
4347
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4348
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4349
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4350
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4351
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4352
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4353
+ node_txn. clear ( )
4354
+ }
4333
4355
4334
4356
// Broadcast legit commitment tx from A on B's chain
4335
4357
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
4336
4358
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4359
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4337
4360
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4338
4361
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4339
4362
assert_eq ! ( events. len( ) , 1 ) ;
4340
4363
match events[ 0 ] {
4341
4364
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4342
4365
_ => panic ! ( "Unexpected event" ) ,
4343
4366
}
4344
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4367
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
4368
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
4369
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
4370
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4371
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4372
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
4373
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4374
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4375
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4376
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
4345
4377
4346
4378
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
4347
4379
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -4351,6 +4383,17 @@ mod tests {
4351
4383
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4352
4384
_ => panic ! ( "Unexpected event" ) ,
4353
4385
}
4386
+ 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)
4387
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4388
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4389
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
4390
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
4391
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4392
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
4393
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4394
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4395
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4396
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4354
4397
}
4355
4398
4356
4399
#[ test]
@@ -4359,7 +4402,7 @@ mod tests {
4359
4402
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
4360
4403
// broadcasting the right event to other nodes in payment path.
4361
4404
// A ------------------> B ----------------------> C (timeout)
4362
- // A 's commitment tx C's commitment tx
4405
+ // B 's commitment tx C's commitment tx
4363
4406
// \ \
4364
4407
// B's HTLC timeout tx B's timeout tx
4365
4408
@@ -4378,6 +4421,7 @@ mod tests {
4378
4421
4379
4422
// Brodacast legit commitment tx from C on B's chain
4380
4423
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4424
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
4381
4425
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
4382
4426
{
4383
4427
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -4403,23 +4447,36 @@ mod tests {
4403
4447
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4404
4448
_ => panic ! ( "Unexpected event" ) ,
4405
4449
}
4406
- let mut funding_tx_map = HashMap :: new ( ) ;
4407
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
4408
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
4450
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
4451
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
4452
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
4453
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4409
4454
4410
4455
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
4411
4456
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
4412
4457
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4413
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4414
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
4415
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
4416
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4417
-
4418
- let mut commitment_tx_map = HashMap :: new ( ) ;
4419
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
4420
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
4421
-
4422
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
4458
+ let timeout_tx;
4459
+ {
4460
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
4461
+ 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)
4462
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
4463
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
4464
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
4465
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4466
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4467
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
4468
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4469
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4470
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4471
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
4472
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
4473
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
4474
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
4475
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
4476
+ node_txn. clear ( ) ;
4477
+ }
4478
+
4479
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
4423
4480
{
4424
4481
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
4425
4482
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -4441,27 +4498,29 @@ mod tests {
4441
4498
} ,
4442
4499
_ => panic ! ( "Unexpected event" ) ,
4443
4500
} ;
4501
+ 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
4502
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
4444
4503
4445
- // Broadcast legit commitment tx from A on B's chain
4446
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
4447
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4448
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
4449
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4450
- assert_eq ! ( events. len( ) , 1 ) ;
4451
- match events[ 0 ] {
4452
- Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4453
- _ => panic ! ( "Unexpected event" ) ,
4454
- }
4455
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
4504
+ // Broadcast legit commitment tx from B on A's chain
4505
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4506
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
4456
4507
4457
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
4458
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
4508
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
4459
4509
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
4460
4510
assert_eq ! ( events. len( ) , 1 ) ;
4461
4511
match events[ 0 ] {
4462
4512
Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4463
4513
_ => panic ! ( "Unexpected event" ) ,
4464
4514
}
4515
+ 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
4516
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
4517
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
4518
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
4519
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
4520
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
4521
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
4522
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
4523
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4465
4524
}
4466
4525
4467
4526
#[ test]
0 commit comments