@@ -26,7 +26,6 @@ pub struct ChainExpectNakaBlock {
2626
2727#[ derive( Debug ) ]
2828enum HeightStrategy {
29- FromGlobalHeight ,
3029 FromMinerHeight ,
3130 FromStateHeight ,
3231}
@@ -44,10 +43,6 @@ impl ChainExpectNakaBlock {
4443 }
4544 }
4645
47- pub fn from_global_height ( ctx : Arc < SignerTestContext > , miner_index : usize ) -> Self {
48- Self :: new ( ctx, miner_index, HeightStrategy :: FromGlobalHeight )
49- }
50-
5146 pub fn from_miner_height ( ctx : Arc < SignerTestContext > , miner_index : usize ) -> Self {
5247 Self :: new ( ctx, miner_index, HeightStrategy :: FromMinerHeight )
5348 }
@@ -76,33 +71,6 @@ impl Command<SignerTestState, SignerTestContext> for ChainExpectNakaBlock {
7671
7772 // Calculate expected height based on the strategy
7873 match self . height_strategy {
79- HeightStrategy :: FromGlobalHeight => {
80- // Use global height approach
81- let conf = self . ctx . get_node_config ( self . miner_index ) ;
82- let stacks_height_before = self . ctx . get_peer_stacks_tip_height ( ) ;
83- let expected_height = stacks_height_before + 1 ;
84-
85- let miner_block =
86- wait_for_block_pushed_by_miner_key ( 30 , expected_height, & miner_pk) . expect (
87- & format ! (
88- "Failed to get block for miner {} - Strategy: {:?}" ,
89- self . miner_index, self . height_strategy
90- ) ,
91- ) ;
92-
93- let mined_block_height = miner_block. header . chain_length ;
94-
95- info ! (
96- "Miner {} mined Nakamoto block at height {}" ,
97- self . miner_index, mined_block_height
98- ) ;
99-
100- let info_after = get_chain_info ( & conf) ;
101-
102- assert_eq ! ( info_after. stacks_tip, miner_block. header. block_hash( ) ) ;
103- assert_eq ! ( info_after. stacks_tip_height, mined_block_height) ;
104- assert_eq ! ( mined_block_height, expected_height) ;
105- }
10674 HeightStrategy :: FromMinerHeight => {
10775 // Use miner-specific height approach
10876 let conf = self . ctx . get_node_config ( self . miner_index ) ;
@@ -175,7 +143,7 @@ impl Command<SignerTestState, SignerTestContext> for ChainExpectNakaBlock {
175143 ( 1usize ..=2usize ) . prop_flat_map ( move |miner_index| {
176144 prop_oneof ! [
177145 Just ( CommandWrapper :: new(
178- ChainExpectNakaBlock :: from_global_height ( ctx. clone( ) , miner_index)
146+ ChainExpectNakaBlock :: from_state_height ( ctx. clone( ) , miner_index)
179147 ) ) ,
180148 Just ( CommandWrapper :: new(
181149 ChainExpectNakaBlock :: from_miner_height( ctx. clone( ) , miner_index)
@@ -349,22 +317,23 @@ impl Command<SignerTestState, SignerTestContext> for ChainExpectStacksTenureChan
349317 true
350318 }
351319
352- fn apply ( & self , _state : & mut SignerTestState ) {
320+ fn apply ( & self , state : & mut SignerTestState ) {
353321 let miner_pk = self . ctx . get_miner_public_key ( self . miner_index ) ;
354- // TODO: this is a bug. You cannot gaurantee that the block has not already been processed
355- // by the node causing a potential off by one race condition.
356- // See https://github.com/stacks-network/stacks-core/issues/6221
357- let expected_height = self . ctx . get_peer_stacks_tip_height ( ) + 1 ;
322+ // Cannot use global height as this would result in a race condition. Cannot gaurantee
323+ // that the node has not already processed the stacks block. Must use stored state.
324+ let expected_height = state. last_stacks_block_height . expect (
325+ "Cannot wait for a tenure change block if we haven't set the last_stacks_block_height" ,
326+ ) + 1 ;
358327
359328 info ! (
360- "Applying: Waiting for tenure change block at height {} from miner {}" ,
361- expected_height , self . miner_index
329+ "Applying: Waiting for tenure change block at height {expected_height } from miner {}" ,
330+ self . miner_index
362331 ) ;
363332
364333 let block =
365334 wait_for_block_pushed_by_miner_key ( 30 , expected_height, & miner_pk) . expect ( & format ! (
366- "Failed to get tenure change block for miner {} at height {}" ,
367- self . miner_index, expected_height
335+ "Failed to get tenure change block for miner {} at height {expected_height }" ,
336+ self . miner_index
368337 ) ) ;
369338
370339 // Verify this is a tenure change block
@@ -380,15 +349,14 @@ impl Command<SignerTestState, SignerTestContext> for ChainExpectStacksTenureChan
380349
381350 assert ! (
382351 is_tenure_change_block_found,
383- "Block at height {} from miner {} is not a proper tenure change block. Transactions: {:?}" ,
384- expected_height,
352+ "Block at height {expected_height} from miner {} is not a proper tenure change block. Transactions: {:?}" ,
385353 self . miner_index,
386354 block. txs. iter( ) . map( |tx| & tx. payload) . collect:: <Vec <_>>( )
387355 ) ;
388356
389357 info ! (
390- "Successfully verified tenure change block at height {} from miner {}" ,
391- expected_height , self . miner_index
358+ "Successfully verified tenure change block at height {expected_height } from miner {}" ,
359+ self . miner_index
392360 ) ;
393361 }
394362
0 commit comments