@@ -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 ,
@@ -5042,7 +5066,7 @@ fn forked_tenure_is_ignored() {
5042
5066
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
5043
5067
}
5044
5068
5045
- info ! ( "Tenure B broadcasted but did not process a block. Issue the next bitcon block and unstall block commits." ) ;
5069
+ info ! ( "Tenure B broadcasted but did not process a block. Issue the next bitcoin block and unstall block commits." ) ;
5046
5070
5047
5071
// the block will be stored, not processed, so load it out of staging
5048
5072
let tip_sn = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) )
@@ -5089,16 +5113,17 @@ fn forked_tenure_is_ignored() {
5089
5113
. lock ( )
5090
5114
. expect ( "Mutex poisoned" )
5091
5115
. get_stacks_blocks_processed ( ) ;
5116
+ let block_in_tenure = get_last_block_in_current_tenure ( & sortdb, & chainstate) . is_some ( ) ;
5092
5117
Ok ( commits_count > commits_before
5093
5118
&& blocks_count > blocks_before
5094
- && blocks_processed > blocks_processed_before)
5119
+ && blocks_processed > blocks_processed_before
5120
+ && block_in_tenure)
5095
5121
} )
5096
5122
. unwrap ( ) ;
5097
5123
5098
5124
info ! ( "Tenure C produced a block!" ) ;
5099
- let block_tenure_c = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5100
- . unwrap ( )
5101
- . unwrap ( ) ;
5125
+
5126
+ let block_tenure_c = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5102
5127
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5103
5128
let block_c = blocks. last ( ) . unwrap ( ) ;
5104
5129
info ! ( "Tenure C tip block: {}" , & block_tenure_c. index_block_hash( ) ) ;
@@ -5151,9 +5176,7 @@ fn forked_tenure_is_ignored() {
5151
5176
5152
5177
info ! ( "Tenure C produced a second block!" ) ;
5153
5178
5154
- let block_2_tenure_c = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5155
- . unwrap ( )
5156
- . unwrap ( ) ;
5179
+ let block_2_tenure_c = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5157
5180
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5158
5181
let block_2_c = blocks. last ( ) . unwrap ( ) ;
5159
5182
@@ -5184,9 +5207,7 @@ fn forked_tenure_is_ignored() {
5184
5207
} )
5185
5208
. unwrap ( ) ;
5186
5209
5187
- let block_tenure_d = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
5188
- . unwrap ( )
5189
- . unwrap ( ) ;
5210
+ let block_tenure_d = get_last_block_in_current_tenure ( & sortdb, & chainstate) . unwrap ( ) ;
5190
5211
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
5191
5212
let block_d = blocks. last ( ) . unwrap ( ) ;
5192
5213
0 commit comments