11
11
12
12
//! Further functional tests which test blockchain reorganizations.
13
13
14
- use crate :: events:: bump_transaction:: sync:: WalletSourceSync ;
15
14
use crate :: sign:: { ecdsa:: EcdsaChannelSigner , OutputSpender , SignerProvider , SpendableOutputDescriptor } ;
16
15
use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , ARCHIVAL_DELAY_BLOCKS , LATENCY_GRACE_PERIOD_BLOCKS , COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE , Balance , BalanceSource , ChannelMonitorUpdateStep } ;
17
16
use crate :: chain:: transaction:: OutPoint ;
@@ -465,25 +464,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
465
464
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
466
465
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
467
466
468
- let coinbase_tx = Transaction {
469
- version : Version :: TWO ,
470
- lock_time : LockTime :: ZERO ,
471
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
472
- output : vec ! [
473
- TxOut {
474
- value: Amount :: ONE_BTC ,
475
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
476
- } ,
477
- TxOut {
478
- value: Amount :: ONE_BTC ,
479
- script_pubkey: nodes[ 1 ] . wallet_source. get_change_script( ) . unwrap( ) ,
480
- } ,
481
- ] ,
482
- } ;
483
- if anchors {
484
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
485
- nodes[ 1 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 1 } , coinbase_tx. output [ 1 ] . value ) ;
486
- }
467
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
487
468
488
469
let ( _, _, chan_id, funding_tx) =
489
470
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 1_000_000 ) ;
@@ -872,25 +853,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) {
872
853
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
873
854
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
874
855
875
- let coinbase_tx = Transaction {
876
- version : Version :: TWO ,
877
- lock_time : LockTime :: ZERO ,
878
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
879
- output : vec ! [
880
- TxOut {
881
- value: Amount :: ONE_BTC ,
882
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
883
- } ,
884
- TxOut {
885
- value: Amount :: ONE_BTC ,
886
- script_pubkey: nodes[ 1 ] . wallet_source. get_change_script( ) . unwrap( ) ,
887
- } ,
888
- ] ,
889
- } ;
890
- if anchors {
891
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
892
- nodes[ 1 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 1 } , coinbase_tx. output [ 1 ] . value ) ;
893
- }
856
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
894
857
895
858
// Create a single channel with two pending HTLCs from nodes[0] to nodes[1], one which nodes[1]
896
859
// knows the preimage for, one which it does not.
@@ -1655,25 +1618,7 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
1655
1618
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
1656
1619
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1657
1620
1658
- let coinbase_tx = Transaction {
1659
- version : Version :: TWO ,
1660
- lock_time : LockTime :: ZERO ,
1661
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
1662
- output : vec ! [
1663
- TxOut {
1664
- value: Amount :: ONE_BTC ,
1665
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
1666
- } ,
1667
- TxOut {
1668
- value: Amount :: ONE_BTC ,
1669
- script_pubkey: nodes[ 1 ] . wallet_source. get_change_script( ) . unwrap( ) ,
1670
- } ,
1671
- ] ,
1672
- } ;
1673
- if anchors {
1674
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
1675
- nodes[ 1 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 1 } , coinbase_tx. output [ 1 ] . value ) ;
1676
- }
1621
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
1677
1622
1678
1623
// Create some initial channels
1679
1624
let ( _, _, chan_id, funding_tx) =
@@ -1956,16 +1901,7 @@ fn do_test_revoked_counterparty_aggregated_claims(anchors: bool) {
1956
1901
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
1957
1902
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1958
1903
1959
- let coinbase_tx = Transaction {
1960
- version : Version :: TWO ,
1961
- lock_time : LockTime :: ZERO ,
1962
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
1963
- output : vec ! [ TxOut {
1964
- value: Amount :: ONE_BTC ,
1965
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
1966
- } ] ,
1967
- } ;
1968
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
1904
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
1969
1905
1970
1906
let ( _, _, chan_id, funding_tx) =
1971
1907
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 100_000_000 ) ;
@@ -2246,25 +2182,7 @@ fn do_test_claimable_balance_correct_while_payment_pending(outbound_payment: boo
2246
2182
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
2247
2183
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
2248
2184
2249
- let coinbase_tx = Transaction {
2250
- version : Version :: TWO ,
2251
- lock_time : LockTime :: ZERO ,
2252
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
2253
- output : vec ! [
2254
- TxOut {
2255
- value: Amount :: ONE_BTC ,
2256
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
2257
- } ,
2258
- TxOut {
2259
- value: Amount :: ONE_BTC ,
2260
- script_pubkey: nodes[ 1 ] . wallet_source. get_change_script( ) . unwrap( ) ,
2261
- } ,
2262
- ] ,
2263
- } ;
2264
- if anchors {
2265
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
2266
- nodes[ 1 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 1 } , coinbase_tx. output [ 1 ] . value ) ;
2267
- }
2185
+ provide_anchor_reserves ( & nodes) ;
2268
2186
2269
2187
// Create a channel from A -> B
2270
2188
let ( _, _, chan_ab_id, funding_tx_ab) =
@@ -2411,6 +2329,8 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
2411
2329
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( config. clone ( ) ) , Some ( config) ] ) ;
2412
2330
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2413
2331
2332
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
2333
+
2414
2334
let ( _, _, _, chan_id, funding_tx) = create_chan_between_nodes_with_value (
2415
2335
& nodes[ 0 ] , & nodes[ 1 ] , 1_000_000 , 500_000_000
2416
2336
) ;
@@ -2429,17 +2349,6 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
2429
2349
false , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 1000000 ) ;
2430
2350
check_added_monitors ( & nodes[ 0 ] , 1 ) ;
2431
2351
2432
- let coinbase_tx = Transaction {
2433
- version : Version :: TWO ,
2434
- lock_time : LockTime :: ZERO ,
2435
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
2436
- output : vec ! [ TxOut { // UTXO to attach fees to `htlc_tx` on anchors
2437
- value: Amount :: ONE_BTC ,
2438
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
2439
- } ] ,
2440
- } ;
2441
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
2442
-
2443
2352
// Set up a helper closure we'll use throughout our test. We should only expect retries without
2444
2353
// bumps if fees have not increased after a block has been connected (assuming the height timer
2445
2354
// re-evaluates at every block) or after `ChainMonitor::rebroadcast_pending_claims` is called.
@@ -2543,6 +2452,8 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2543
2452
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( anchors_config. clone ( ) ) , Some ( anchors_config) ] ) ;
2544
2453
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2545
2454
2455
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
2456
+
2546
2457
let ( _, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value (
2547
2458
& nodes, 0 , 1 , 1_000_000 , 500_000_000
2548
2459
) ;
@@ -2618,16 +2529,6 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2618
2529
assert_eq ! ( holder_events. len( ) , 1 ) ;
2619
2530
let ( commitment_tx, anchor_tx) = match holder_events. pop ( ) . unwrap ( ) {
2620
2531
Event :: BumpTransaction ( event) => {
2621
- let coinbase_tx = Transaction {
2622
- version : Version :: TWO ,
2623
- lock_time : LockTime :: ZERO ,
2624
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
2625
- output : vec ! [ TxOut { // UTXO to attach fees to `anchor_tx`
2626
- value: Amount :: ONE_BTC ,
2627
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
2628
- } ] ,
2629
- } ;
2630
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
2631
2532
nodes[ 0 ] . bump_tx_handler . handle_event ( & event) ;
2632
2533
let mut txn = nodes[ 0 ] . tx_broadcaster . unique_txn_broadcast ( ) ;
2633
2534
assert_eq ! ( txn. len( ) , 2 ) ;
@@ -2743,6 +2644,8 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
2743
2644
2744
2645
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2745
2646
2647
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
2648
+
2746
2649
let chan_a = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 20_000_000 ) ;
2747
2650
let chan_b = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 20_000_000 ) ;
2748
2651
@@ -2801,18 +2704,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
2801
2704
assert_eq ! ( events. len( ) , 2 ) ;
2802
2705
let mut revoked_commitment_txs = Vec :: with_capacity ( events. len ( ) ) ;
2803
2706
let mut anchor_txs = Vec :: with_capacity ( events. len ( ) ) ;
2804
- for ( idx, event) in events. into_iter ( ) . enumerate ( ) {
2805
- let utxo_value = Amount :: ONE_BTC * ( idx + 1 ) as u64 ;
2806
- let coinbase_tx = Transaction {
2807
- version : Version :: TWO ,
2808
- lock_time : LockTime :: ZERO ,
2809
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
2810
- output : vec ! [ TxOut { // UTXO to attach fees to `anchor_tx`
2811
- value: utxo_value,
2812
- script_pubkey: nodes[ 1 ] . wallet_source. get_change_script( ) . unwrap( ) ,
2813
- } ] ,
2814
- } ;
2815
- nodes[ 1 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , utxo_value) ;
2707
+ for event in events {
2816
2708
match event {
2817
2709
Event :: BumpTransaction ( event) => nodes[ 1 ] . bump_tx_handler . handle_event ( & event) ,
2818
2710
_ => panic ! ( "Unexpected event" ) ,
@@ -3130,20 +3022,7 @@ fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterp
3130
3022
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
3131
3023
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3132
3024
3133
- let coinbase_tx = Transaction {
3134
- version : Version :: TWO ,
3135
- lock_time : LockTime :: ZERO ,
3136
- input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
3137
- output : vec ! [
3138
- TxOut {
3139
- value: Amount :: ONE_BTC ,
3140
- script_pubkey: nodes[ 0 ] . wallet_source. get_change_script( ) . unwrap( ) ,
3141
- } ,
3142
- ] ,
3143
- } ;
3144
- if anchors {
3145
- nodes[ 0 ] . wallet_source . add_utxo ( bitcoin:: OutPoint { txid : coinbase_tx. compute_txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ) ;
3146
- }
3025
+ let coinbase_tx = provide_anchor_reserves ( & nodes) ;
3147
3026
3148
3027
// Open a channel and route a payment. We'll let it timeout to claim it.
3149
3028
let ( _, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
0 commit comments