@@ -1061,6 +1061,75 @@ impl TestStacksNode {
10611061 Ok ( ( block, size, cost) )
10621062 }
10631063
1064+ /// Insert a staging pre-Nakamoto block and microblocks
1065+ /// then process them as the next ready block
1066+ /// NOTE: Will panic if called with unprocessed staging
1067+ /// blocks already in the queue.
1068+ pub fn process_pre_nakamoto_next_ready_block < ' a > (
1069+ stacks_node : & mut TestStacksNode ,
1070+ sortdb : & mut SortitionDB ,
1071+ miner : & mut TestMiner ,
1072+ tenure_id_consensus_hash : & ConsensusHash ,
1073+ coord : & mut ChainsCoordinator <
1074+ ' a ,
1075+ TestEventObserver ,
1076+ ( ) ,
1077+ OnChainRewardSetProvider < ' a , TestEventObserver > ,
1078+ ( ) ,
1079+ ( ) ,
1080+ BitcoinIndexer ,
1081+ > ,
1082+ block : & StacksBlock ,
1083+ microblocks : & [ StacksMicroblock ] ,
1084+ ) -> Result < Option < StacksEpochReceipt > , ChainstateError > {
1085+ // First append the block to the staging blocks
1086+ {
1087+ let ic = sortdb. index_conn ( ) ;
1088+ let tip = SortitionDB :: get_canonical_burn_chain_tip ( & ic) . unwrap ( ) ;
1089+ stacks_node
1090+ . chainstate
1091+ . preprocess_stacks_epoch ( & ic, & tip, block, microblocks)
1092+ . unwrap ( ) ;
1093+ }
1094+
1095+ let canonical_sortition_tip = coord. canonical_sortition_tip . clone ( ) . expect (
1096+ "FAIL: processing a new Stacks block, but don't have a canonical sortition tip" ,
1097+ ) ;
1098+ let mut sort_tx = sortdb. tx_begin_at_tip ( ) ;
1099+ let res = stacks_node
1100+ . chainstate
1101+ . process_next_staging_block ( & mut sort_tx, coord. dispatcher )
1102+ . map ( |( epoch_receipt, _) | epoch_receipt) ?;
1103+ sort_tx. commit ( ) ?;
1104+ if let Some ( block_receipt) = res. as_ref ( ) {
1105+ let in_sortition_set = coord
1106+ . sortition_db
1107+ . is_stacks_block_in_sortition_set (
1108+ & canonical_sortition_tip,
1109+ & block_receipt. header . anchored_header . block_hash ( ) ,
1110+ )
1111+ . unwrap ( ) ;
1112+ if in_sortition_set {
1113+ let block_hash = block_receipt. header . anchored_header . block_hash ( ) ;
1114+ // Was this block sufficiently confirmed by the prepare phase that it was a PoX
1115+ // anchor block? And if we're in epoch 2.1, does it match the heaviest-confirmed
1116+ // block-commit in the burnchain DB, and is it affirmed by the majority of the
1117+ // network?
1118+ if let Some ( pox_anchor) = coord
1119+ . sortition_db
1120+ . is_stacks_block_pox_anchor ( & block_hash, & canonical_sortition_tip)
1121+ . unwrap ( )
1122+ {
1123+ debug ! ( "Discovered PoX anchor block {block_hash} off of canonical sortition tip {canonical_sortition_tip}" ) ;
1124+ coord
1125+ . process_new_pox_anchor_test ( pox_anchor, & mut HashSet :: new ( ) )
1126+ . unwrap ( ) ;
1127+ }
1128+ }
1129+ }
1130+ Ok ( res)
1131+ }
1132+
10641133 /// Insert a staging Nakamoto block as a pushed block and
10651134 /// then process it as the next ready block
10661135 /// NOTE: Will panic if called with unprocessed staging
0 commit comments