@@ -2630,7 +2630,9 @@ fn tenure_extend_after_idle_signers() {
2630
2630
|config| {
2631
2631
config. tenure_idle_timeout = idle_timeout;
2632
2632
} ,
2633
- |_| { } ,
2633
+ |config| {
2634
+ config. miner . tenure_extend_cost_threshold = 0 ;
2635
+ } ,
2634
2636
None ,
2635
2637
None ,
2636
2638
) ;
@@ -2680,7 +2682,9 @@ fn tenure_extend_with_other_transactions() {
2680
2682
|config| {
2681
2683
config. tenure_idle_timeout = idle_timeout;
2682
2684
} ,
2683
- |_| { } ,
2685
+ |config| {
2686
+ config. miner . tenure_extend_cost_threshold = 0 ;
2687
+ } ,
2684
2688
None ,
2685
2689
None ,
2686
2690
) ;
@@ -2787,6 +2791,7 @@ fn tenure_extend_after_idle_miner() {
2787
2791
} ,
2788
2792
|config| {
2789
2793
config. miner . tenure_timeout = miner_idle_timeout;
2794
+ config. miner . tenure_extend_cost_threshold = 0 ;
2790
2795
} ,
2791
2796
None ,
2792
2797
None ,
@@ -2863,6 +2868,7 @@ fn tenure_extend_succeeds_after_rejected_attempt() {
2863
2868
} ,
2864
2869
|config| {
2865
2870
config. miner . tenure_timeout = miner_idle_timeout;
2871
+ config. miner . tenure_extend_cost_threshold = 0 ;
2866
2872
} ,
2867
2873
None ,
2868
2874
None ,
@@ -2951,7 +2957,9 @@ fn stx_transfers_dont_effect_idle_timeout() {
2951
2957
|config| {
2952
2958
config. tenure_idle_timeout = idle_timeout;
2953
2959
} ,
2954
- |_| { } ,
2960
+ |config| {
2961
+ config. miner . tenure_extend_cost_threshold = 0 ;
2962
+ } ,
2955
2963
None ,
2956
2964
None ,
2957
2965
) ;
@@ -3085,6 +3093,7 @@ fn idle_tenure_extend_active_mining() {
3085
3093
|config| {
3086
3094
// accept all proposals in the node
3087
3095
config. connection_options . block_proposal_max_age_secs = u64:: MAX ;
3096
+ config. miner . tenure_extend_cost_threshold = 0 ;
3088
3097
} ,
3089
3098
None ,
3090
3099
None ,
@@ -12592,3 +12601,107 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
12592
12601
run_loop_2_thread. join ( ) . unwrap ( ) ;
12593
12602
signer_test. shutdown ( ) ;
12594
12603
}
12604
+
12605
+ #[ test]
12606
+ #[ ignore]
12607
+ /// This test verifies that a miner will produce a TenureExtend transaction
12608
+ /// only after it has reached the cost threshold.
12609
+ fn tenure_extend_cost_threshold ( ) {
12610
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
12611
+ return ;
12612
+ }
12613
+
12614
+ let deployer_sk = Secp256k1PrivateKey :: random ( ) ;
12615
+ let deployer_addr = tests:: to_addr ( & deployer_sk) ;
12616
+ let num_txs = 10 ;
12617
+ let tx_fee = 10000 ;
12618
+ let deploy_fee = 190200 ;
12619
+
12620
+ info ! ( "------------------------- Test Setup -------------------------" ) ;
12621
+ let num_signers = 5 ;
12622
+ let idle_timeout = Duration :: from_secs ( 10 ) ;
12623
+ let mut signer_test: SignerTest < SpawnedSigner > = SignerTest :: new_with_config_modifications (
12624
+ num_signers,
12625
+ vec ! [ ( deployer_addr, deploy_fee + tx_fee * num_txs) ] ,
12626
+ |config| {
12627
+ config. tenure_idle_timeout = idle_timeout;
12628
+ } ,
12629
+ |config| {
12630
+ config. miner . tenure_extend_cost_threshold = 5 ;
12631
+ } ,
12632
+ None ,
12633
+ None ,
12634
+ ) ;
12635
+ let naka_conf = signer_test. running_nodes . conf . clone ( ) ;
12636
+ let http_origin = format ! ( "http://{}" , & naka_conf. node. rpc_bind) ;
12637
+
12638
+ signer_test. boot_to_epoch_3 ( ) ;
12639
+
12640
+ info ! ( "---- Nakamoto booted, starting test ----" ) ;
12641
+ signer_test. mine_nakamoto_block ( Duration :: from_secs ( 30 ) , true ) ;
12642
+
12643
+ info ! ( "---- Waiting for a tenure extend ----" ) ;
12644
+
12645
+ // Now, wait for a block with a tenure extend
12646
+ wait_for ( idle_timeout. as_secs ( ) + 10 , || {
12647
+ Ok ( last_block_contains_tenure_change_tx (
12648
+ TenureChangeCause :: Extended ,
12649
+ ) )
12650
+ } )
12651
+ . expect_err ( "Received a tenure extend before cost threshold was reached" ) ;
12652
+
12653
+ // Now deploy a contract and call it in order to cross the threshold.
12654
+ let contract_src = format ! (
12655
+ r#"
12656
+ (define-data-var my-var uint u0)
12657
+ (define-public (f) (begin {} (ok 1))) (begin (f))
12658
+ "# ,
12659
+ [ "(var-get my-var)" ; 250 ] . join( " " )
12660
+ ) ;
12661
+
12662
+ // First, lets deploy the contract
12663
+ let mut nonce = 0 ;
12664
+ let contract_tx = make_contract_publish (
12665
+ & deployer_sk,
12666
+ nonce,
12667
+ deploy_fee,
12668
+ naka_conf. burnchain . chain_id ,
12669
+ "small-contract" ,
12670
+ & contract_src,
12671
+ ) ;
12672
+ submit_tx ( & http_origin, & contract_tx) ;
12673
+ nonce += 1 ;
12674
+
12675
+ // Wait for the contract to be included in a block
12676
+ wait_for ( 60 , || {
12677
+ let account = get_account ( & http_origin, & deployer_addr) ;
12678
+ Ok ( account. nonce == nonce)
12679
+ } )
12680
+ . expect ( "Contract not included in block" ) ;
12681
+
12682
+ // Now, lets call the contract a bunch of times to increase the tenure cost
12683
+ for _ in 0 ..num_txs {
12684
+ let call_tx = make_contract_call (
12685
+ & deployer_sk,
12686
+ nonce,
12687
+ tx_fee,
12688
+ naka_conf. burnchain . chain_id ,
12689
+ & deployer_addr,
12690
+ "small-contract" ,
12691
+ "f" ,
12692
+ & [ ] ,
12693
+ ) ;
12694
+ submit_tx ( & http_origin, & call_tx) ;
12695
+ nonce += 1 ;
12696
+ }
12697
+
12698
+ // Now, wait for a block with a tenure extend
12699
+ wait_for ( idle_timeout. as_secs ( ) + 10 , || {
12700
+ Ok ( last_block_contains_tenure_change_tx (
12701
+ TenureChangeCause :: Extended ,
12702
+ ) )
12703
+ } )
12704
+ . expect ( "Timed out waiting for a block with a tenure extend" ) ;
12705
+
12706
+ signer_test. shutdown ( ) ;
12707
+ }
0 commit comments