1
- use std:: sync:: atomic:: Ordering ;
2
1
use std:: sync:: Arc ;
3
2
4
3
use madhouse:: { Command , CommandWrapper } ;
5
- use proptest:: prelude:: { Just , Strategy } ;
6
- use stacks:: chainstate:: stacks:: TenureChangeCause ;
4
+ use proptest:: prelude:: Strategy ;
7
5
use tracing:: info;
8
6
9
7
use super :: context:: { SignerTestContext , SignerTestState } ;
10
- use crate :: tests:: neon_integrations:: get_chain_info;
11
-
12
- /// Command to mine a new Bitcoin block and trigger a tenure change for a specified miner.
13
- /// This command simulates the process of a miner finding a Bitcoin block, submitting a tenure
14
- /// change transaction, and then mining a corresponding Stacks Nakamoto block.
15
- pub struct MinerMineBlockAndTriggerTenureChange {
16
- ctx : Arc < SignerTestContext > ,
17
- miner_index : usize ,
18
- }
19
-
20
- impl MinerMineBlockAndTriggerTenureChange {
21
- pub fn new ( ctx : Arc < SignerTestContext > , miner_index : usize ) -> Self {
22
- Self { ctx, miner_index }
23
- }
24
- }
25
-
26
- impl Command < SignerTestState , SignerTestContext > for MinerMineBlockAndTriggerTenureChange {
27
- fn check ( & self , state : & SignerTestState ) -> bool {
28
- let conf = self . ctx . get_node_config ( self . miner_index ) ;
29
- let burn_height = get_chain_info ( & conf) . burn_block_height ;
30
-
31
- let ( miner_1_submitted_commit_last_burn_height, miner_2_submitted_commit_last_burn_height) = {
32
- let miner_1_height = self
33
- . ctx
34
- . get_counters_for_miner ( 1 )
35
- . naka_submitted_commit_last_burn_height
36
- . load ( Ordering :: SeqCst ) ;
37
- let miner_2_height = self
38
- . ctx
39
- . get_counters_for_miner ( 2 )
40
- . naka_submitted_commit_last_burn_height
41
- . load ( Ordering :: SeqCst ) ;
42
- ( miner_1_height, miner_2_height)
43
- } ;
44
-
45
- let ( current_miner_height, other_miner_height) = match self . miner_index {
46
- 1 => (
47
- miner_1_submitted_commit_last_burn_height,
48
- miner_2_submitted_commit_last_burn_height,
49
- ) ,
50
- 2 => (
51
- miner_2_submitted_commit_last_burn_height,
52
- miner_1_submitted_commit_last_burn_height,
53
- ) ,
54
- _ => panic ! ( "Invalid miner index: {}" , self . miner_index) ,
55
- } ;
56
-
57
- info ! (
58
- "Checking: Miner {} block verification - burn height: {}, current miner: {}, other miner: {}" ,
59
- self . miner_index,
60
- burn_height,
61
- current_miner_height,
62
- other_miner_height
63
- ) ;
64
-
65
- state. is_booted_to_nakamoto
66
- && burn_height == current_miner_height
67
- && burn_height > other_miner_height
68
- }
69
-
70
- fn apply ( & self , state : & mut SignerTestState ) {
71
- info ! ( "Applying: Mining Bitcoin block and tenure change tx" ) ;
72
-
73
- state. last_block_height = Some ( self . ctx . get_peer_stacks_tip_height ( ) ) ;
74
-
75
- let sortdb = self . ctx . get_sortition_db ( self . miner_index ) ;
76
-
77
- self . ctx
78
- . miners
79
- . lock ( )
80
- . unwrap ( )
81
- . mine_bitcoin_block_and_tenure_change_tx ( & sortdb, TenureChangeCause :: BlockFound , 60 )
82
- . expect ( "Failed to mine BTC block" ) ;
83
- }
84
-
85
- fn label ( & self ) -> String {
86
- format ! (
87
- "MINE_BITCOIN_BLOCK_AND_TENURE_CHANGE_MINER_{}" ,
88
- self . miner_index
89
- )
90
- }
91
-
92
- fn build (
93
- ctx : Arc < SignerTestContext > ,
94
- ) -> impl Strategy < Value = CommandWrapper < SignerTestState , SignerTestContext > > {
95
- ( 1usize ..=2usize ) . prop_flat_map ( move |miner_index| {
96
- Just ( CommandWrapper :: new (
97
- MinerMineBlockAndTriggerTenureChange :: new ( ctx. clone ( ) , miner_index) ,
98
- ) )
99
- } )
100
- }
101
- }
102
8
103
9
/// Command to mine a single Bitcoin block in the test environment and wait for its confirmation.
104
10
/// This command simulates the process of mining a new Bitcoin block in the Stacks blockchain
@@ -129,9 +35,11 @@ impl Command<SignerTestState, SignerTestContext> for MinerMineBtcBlocks {
129
35
true
130
36
}
131
37
132
- fn apply ( & self , _state : & mut SignerTestState ) {
38
+ fn apply ( & self , state : & mut SignerTestState ) {
133
39
info ! ( "Applying: Mining {} Bitcoin block(s)" , self . num_blocks) ;
134
40
41
+ state. last_block_height = Some ( self . ctx . get_peer_stacks_tip_height ( ) ) ;
42
+
135
43
// We can use miner 1 sortition db - it's the same for both miners
136
44
let sortdb = self . ctx . get_sortition_db ( 1 ) ;
137
45
@@ -227,4 +135,4 @@ impl Command<SignerTestState, SignerTestContext> for ChainGenerateBtcBlocks {
227
135
} )
228
136
]
229
137
}
230
- }
138
+ }
0 commit comments