@@ -47,7 +47,7 @@ use stacks::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions};
47
47
use stacks:: chainstate:: stacks:: boot:: {
48
48
MINERS_NAME , SIGNERS_VOTING_FUNCTION_NAME , SIGNERS_VOTING_NAME ,
49
49
} ;
50
- use stacks:: chainstate:: stacks:: db:: StacksChainState ;
50
+ use stacks:: chainstate:: stacks:: db:: { StacksChainState , StacksHeaderInfo } ;
51
51
use stacks:: chainstate:: stacks:: miner:: {
52
52
BlockBuilder , BlockLimitFunction , TransactionEvent , TransactionResult , TransactionSuccessEvent ,
53
53
} ;
@@ -304,6 +304,30 @@ pub fn get_stackerdb_slot_version(
304
304
} )
305
305
}
306
306
307
+ pub fn get_last_block_in_current_tenure (
308
+ sortdb : & SortitionDB ,
309
+ chainstate : & StacksChainState ,
310
+ ) -> Option < StacksHeaderInfo > {
311
+ let ch = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) )
312
+ . unwrap ( )
313
+ . consensus_hash ;
314
+ let mut tenure_blocks = test_observer:: get_blocks ( ) ;
315
+ tenure_blocks. retain ( |block| {
316
+ let consensus_hash = block. get ( "consensus_hash" ) . unwrap ( ) . as_str ( ) . unwrap ( ) ;
317
+ consensus_hash == format ! ( "0x{ch}" )
318
+ } ) ;
319
+ let last_block = tenure_blocks. last ( ) ?. clone ( ) ;
320
+ let last_block_id = StacksBlockId :: from_hex (
321
+ & last_block
322
+ . get ( "index_block_hash" )
323
+ . unwrap ( )
324
+ . as_str ( )
325
+ . unwrap ( ) [ 2 ..] ,
326
+ )
327
+ . unwrap ( ) ;
328
+ NakamotoChainState :: get_block_header ( chainstate. db ( ) , & last_block_id) . unwrap ( )
329
+ }
330
+
307
331
pub fn add_initial_balances (
308
332
conf : & mut Config ,
309
333
accounts : usize ,
@@ -5023,7 +5047,7 @@ fn forked_tenure_is_ignored() {
5023
5047
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
5024
5048
}
5025
5049
5026
- info ! ( "Tenure B broadcasted but did not process a block. Issue the next bitcon block and unstall block commits." ) ;
5050
+ info ! ( "Tenure B broadcasted but did not process a block. Issue the next bitcoin block and unstall block commits." ) ;
5027
5051
5028
5052
// the block will be stored, not processed, so load it out of staging
5029
5053
let tip_sn = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) )
@@ -5070,16 +5094,17 @@ fn forked_tenure_is_ignored() {
5070
5094
. lock ( )
5071
5095
. expect ( "Mutex poisoned" )
5072
5096
. get_stacks_blocks_processed ( ) ;
5097
+ let block_in_tenure = get_last_block_in_current_tenure ( & sortdb, & chainstate) . is_some ( ) ;
5073
5098
Ok ( commits_count > commits_before
5074
5099
&& blocks_count > blocks_before
5075
- && blocks_processed > blocks_processed_before)
5100
+ && blocks_processed > blocks_processed_before
5101
+ && block_in_tenure)
5076
5102
} )
5077
5103
. unwrap ( ) ;
5078
5104
5079
5105
info ! ( "Tenure C produced a block!" ) ;
5080
- let block_tenure_c = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5081
- . unwrap ( )
5082
- . unwrap ( ) ;
5106
+
5107
+ let block_tenure_c = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5083
5108
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5084
5109
let block_c = blocks. last ( ) . unwrap ( ) ;
5085
5110
info ! ( "Tenure C tip block: {}" , & block_tenure_c. index_block_hash( ) ) ;
@@ -5132,9 +5157,7 @@ fn forked_tenure_is_ignored() {
5132
5157
5133
5158
info ! ( "Tenure C produced a second block!" ) ;
5134
5159
5135
- let block_2_tenure_c = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5136
- . unwrap ( )
5137
- . unwrap ( ) ;
5160
+ let block_2_tenure_c = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5138
5161
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5139
5162
let block_2_c = blocks. last ( ) . unwrap ( ) ;
5140
5163
@@ -5165,9 +5188,7 @@ fn forked_tenure_is_ignored() {
5165
5188
} )
5166
5189
. unwrap ( ) ;
5167
5190
5168
- let block_tenure_d = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5169
- . unwrap ( )
5170
- . unwrap ( ) ;
5191
+ let block_tenure_d = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5171
5192
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5172
5193
let block_d = blocks. last ( ) . unwrap ( ) ;
5173
5194
0 commit comments