@@ -2606,6 +2606,17 @@ mod tests {
2606
2606
( chan_announcement. 1 , chan_announcement. 2 , chan_announcement. 3 , chan_announcement. 4 )
2607
2607
}
2608
2608
2609
+ macro_rules! check_spends {
2610
+ ( $tx: expr, $spends_tx: expr) => {
2611
+ {
2612
+ let mut funding_tx_map = HashMap :: new( ) ;
2613
+ let spends_tx = $spends_tx;
2614
+ funding_tx_map. insert( spends_tx. txid( ) , spends_tx) ;
2615
+ $tx. verify( & funding_tx_map) . unwrap( ) ;
2616
+ }
2617
+ }
2618
+ }
2619
+
2609
2620
fn close_channel ( outbound_node : & Node , inbound_node : & Node , channel_id : & [ u8 ; 32 ] , funding_tx : Transaction , close_inbound_first : bool ) -> ( msgs:: ChannelUpdate , msgs:: ChannelUpdate ) {
2610
2621
let ( node_a, broadcaster_a) = if close_inbound_first { ( & inbound_node. node , & inbound_node. tx_broadcaster ) } else { ( & outbound_node. node , & outbound_node. tx_broadcaster ) } ;
2611
2622
let ( node_b, broadcaster_b) = if close_inbound_first { ( & outbound_node. node , & outbound_node. tx_broadcaster ) } else { ( & inbound_node. node , & inbound_node. tx_broadcaster ) } ;
@@ -2649,9 +2660,7 @@ mod tests {
2649
2660
tx_a = broadcaster_a. txn_broadcasted . lock ( ) . unwrap ( ) . remove ( 0 ) ;
2650
2661
}
2651
2662
assert_eq ! ( tx_a, tx_b) ;
2652
- let mut funding_tx_map = HashMap :: new ( ) ;
2653
- funding_tx_map. insert ( funding_tx. txid ( ) , funding_tx) ;
2654
- tx_a. verify ( & funding_tx_map) . unwrap ( ) ;
2663
+ check_spends ! ( tx_a, funding_tx) ;
2655
2664
2656
2665
let events_2 = node_a. get_and_clear_pending_events ( ) ;
2657
2666
assert_eq ! ( events_2. len( ) , 1 ) ;
@@ -3189,9 +3198,7 @@ mod tests {
3189
3198
let mut res = Vec :: with_capacity ( 2 ) ;
3190
3199
node_txn. retain ( |tx| {
3191
3200
if tx. input . len ( ) == 1 && tx. input [ 0 ] . previous_output . txid == chan. 3 . txid ( ) {
3192
- let mut funding_tx_map = HashMap :: new ( ) ;
3193
- funding_tx_map. insert ( chan. 3 . txid ( ) , chan. 3 . clone ( ) ) ;
3194
- tx. verify ( & funding_tx_map) . unwrap ( ) ;
3201
+ check_spends ! ( tx, chan. 3 . clone( ) ) ;
3195
3202
if commitment_tx. is_none ( ) {
3196
3203
res. push ( tx. clone ( ) ) ;
3197
3204
}
@@ -3207,9 +3214,7 @@ mod tests {
3207
3214
if has_htlc_tx != HTLCType :: NONE {
3208
3215
node_txn. retain ( |tx| {
3209
3216
if tx. input . len ( ) == 1 && tx. input [ 0 ] . previous_output . txid == res[ 0 ] . txid ( ) {
3210
- let mut funding_tx_map = HashMap :: new ( ) ;
3211
- funding_tx_map. insert ( res[ 0 ] . txid ( ) , res[ 0 ] . clone ( ) ) ;
3212
- tx. verify ( & funding_tx_map) . unwrap ( ) ;
3217
+ check_spends ! ( tx, res[ 0 ] . clone( ) ) ;
3213
3218
if has_htlc_tx == HTLCType :: TIMEOUT {
3214
3219
assert ! ( tx. lock_time != 0 ) ;
3215
3220
} else {
@@ -3233,9 +3238,7 @@ mod tests {
3233
3238
assert_eq ! ( node_txn. len( ) , 1 ) ;
3234
3239
node_txn. retain ( |tx| {
3235
3240
if tx. input . len ( ) == 1 && tx. input [ 0 ] . previous_output . txid == revoked_tx. txid ( ) {
3236
- let mut funding_tx_map = HashMap :: new ( ) ;
3237
- funding_tx_map. insert ( revoked_tx. txid ( ) , revoked_tx. clone ( ) ) ;
3238
- tx. verify ( & funding_tx_map) . unwrap ( ) ;
3241
+ check_spends ! ( tx, revoked_tx. clone( ) ) ;
3239
3242
false
3240
3243
} else { true }
3241
3244
} ) ;
@@ -3251,10 +3254,7 @@ mod tests {
3251
3254
3252
3255
for tx in prev_txn {
3253
3256
if node_txn[ 0 ] . input [ 0 ] . previous_output . txid == tx. txid ( ) {
3254
- let mut funding_tx_map = HashMap :: new ( ) ;
3255
- funding_tx_map. insert ( tx. txid ( ) , tx. clone ( ) ) ;
3256
- node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3257
-
3257
+ check_spends ! ( node_txn[ 0 ] , tx. clone( ) ) ;
3258
3258
assert ! ( node_txn[ 0 ] . input[ 0 ] . witness[ 2 ] . len( ) > 106 ) ; // must spend an htlc output
3259
3259
assert_eq ! ( tx. input. len( ) , 1 ) ; // must spend a commitment tx
3260
3260
@@ -3441,9 +3441,7 @@ mod tests {
3441
3441
assert_eq ! ( node_txn. pop( ) . unwrap( ) , node_txn[ 0 ] ) ; // An outpoint registration will result in a 2nd block_connected
3442
3442
assert_eq ! ( node_txn[ 0 ] . input. len( ) , 2 ) ; // We should claim the revoked output and the HTLC output
3443
3443
3444
- let mut funding_tx_map = HashMap :: new ( ) ;
3445
- funding_tx_map. insert ( revoked_local_txn[ 0 ] . txid ( ) , revoked_local_txn[ 0 ] . clone ( ) ) ;
3446
- node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3444
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
3447
3445
node_txn. swap_remove ( 0 ) ;
3448
3446
}
3449
3447
test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , HTLCType :: NONE ) ;
@@ -3481,13 +3479,8 @@ mod tests {
3481
3479
3482
3480
assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
3483
3481
3484
- let mut revoked_tx_map = HashMap :: new ( ) ;
3485
- revoked_tx_map. insert ( revoked_local_txn[ 0 ] . txid ( ) , revoked_local_txn[ 0 ] . clone ( ) ) ;
3486
- node_txn[ 0 ] . verify ( & revoked_tx_map) . unwrap ( ) ;
3487
-
3488
- revoked_tx_map. clear ( ) ;
3489
- revoked_tx_map. insert ( chan_1. 3 . txid ( ) , chan_1. 3 . clone ( ) ) ;
3490
- node_txn[ 1 ] . verify ( & revoked_tx_map) . unwrap ( ) ;
3482
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
3483
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
3491
3484
3492
3485
// Inform nodes[0] that a watchtower cheated on its behalf, so it will force-close the chan
3493
3486
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
@@ -3516,6 +3509,7 @@ mod tests {
3516
3509
assert_eq ! ( revoked_local_txn[ 1 ] . input. len( ) , 1 ) ;
3517
3510
assert_eq ! ( revoked_local_txn[ 1 ] . input[ 0 ] . previous_output. txid, revoked_local_txn[ 0 ] . txid( ) ) ;
3518
3511
assert_eq ! ( revoked_local_txn[ 1 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ; // HTLC-Timeout
3512
+ check_spends ! ( revoked_local_txn[ 1 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
3519
3513
3520
3514
//Revoke the old state
3521
3515
claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_1) ;
@@ -3529,11 +3523,9 @@ mod tests {
3529
3523
let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3530
3524
assert_eq ! ( node_txn. len( ) , 4 ) ;
3531
3525
3532
- let mut revoked_tx_map = HashMap :: new ( ) ;
3533
- revoked_tx_map. insert ( revoked_local_txn[ 0 ] . txid ( ) , revoked_local_txn[ 0 ] . clone ( ) ) ;
3534
-
3535
3526
assert_eq ! ( node_txn[ 0 ] . input. len( ) , 3 ) ; // Claim the revoked output + both revoked HTLC outputs
3536
- node_txn[ 0 ] . verify ( & revoked_tx_map) . unwrap ( ) ;
3527
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
3528
+
3537
3529
assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ; // justice tx is duplicated due to block re-scanning
3538
3530
3539
3531
let mut witness_lens = BTreeSet :: new ( ) ;
@@ -3617,10 +3609,8 @@ mod tests {
3617
3609
assert_eq ! ( * witness_lens. iter( ) . skip( 1 ) . next( ) . unwrap( ) , 133 ) ; // revoked offered HTLC
3618
3610
assert_eq ! ( * witness_lens. iter( ) . skip( 2 ) . next( ) . unwrap( ) , 138 ) ; // revoked received HTLC
3619
3611
3620
- let mut funding_tx_map = HashMap :: new ( ) ;
3621
- funding_tx_map. insert ( chan_1. 3 . txid ( ) , chan_1. 3 . clone ( ) ) ;
3622
- node_txn[ 3 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3623
3612
assert_eq ! ( node_txn[ 3 ] . input. len( ) , 1 ) ;
3613
+ check_spends ! ( node_txn[ 3 ] , chan_1. 3 . clone( ) ) ;
3624
3614
3625
3615
assert_eq ! ( node_txn[ 4 ] . input. len( ) , 1 ) ;
3626
3616
let witness_script = node_txn[ 4 ] . input [ 0 ] . witness . last ( ) . unwrap ( ) ;
@@ -3790,9 +3780,8 @@ mod tests {
3790
3780
assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . previous_output. txid, tx. txid( ) ) ;
3791
3781
assert_eq ! ( node_txn[ 0 ] . lock_time, 0 ) ; // Must be an HTLC-Success
3792
3782
assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. len( ) , 5 ) ; // Must be an HTLC-Success
3793
- let mut funding_tx_map = HashMap :: new ( ) ;
3794
- funding_tx_map. insert ( tx. txid ( ) , tx) ;
3795
- node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3783
+
3784
+ check_spends ! ( node_txn[ 0 ] , tx) ;
3796
3785
}
3797
3786
3798
3787
#[ test]
0 commit comments