@@ -884,6 +884,40 @@ impl StacksBlockBuilder {
884884 Ok ( microblock)
885885 }
886886
887+ fn load_parent_microblocks (
888+ & mut self ,
889+ chainstate : & mut StacksChainState ,
890+ parent_consensus_hash : & ConsensusHash ,
891+ parent_header_hash : & BlockHeaderHash ,
892+ parent_index_hash : & StacksBlockId ,
893+ ) -> Result < Vec < StacksMicroblock > , Error > {
894+ if let Some ( microblock_parent_hash) = self . parent_microblock_hash . as_ref ( ) {
895+ // load up a microblock fork
896+ let microblocks = StacksChainState :: load_microblock_stream_fork (
897+ & chainstate. db ( ) ,
898+ & parent_consensus_hash,
899+ & parent_header_hash,
900+ & microblock_parent_hash,
901+ ) ?
902+ . ok_or ( Error :: NoSuchBlockError ) ?;
903+
904+ Ok ( microblocks)
905+ } else {
906+ // apply all known parent microblocks before beginning our tenure
907+ let ( parent_microblocks, _) =
908+ match StacksChainState :: load_descendant_staging_microblock_stream_with_poison (
909+ & chainstate. db ( ) ,
910+ & parent_index_hash,
911+ 0 ,
912+ u16:: MAX ,
913+ ) ? {
914+ Some ( x) => x,
915+ None => ( vec ! [ ] , None ) ,
916+ } ;
917+ Ok ( parent_microblocks)
918+ }
919+ }
920+
887921 /// Begin mining an epoch's transactions.
888922 /// NOTE: even though we don't yet know the block hash, the Clarity VM ensures that a
889923 /// transaction can't query information about the _current_ block (i.e. information that is not
@@ -932,32 +966,26 @@ impl StacksBlockBuilder {
932966 let parent_index_hash =
933967 StacksBlockHeader :: make_index_block_hash ( & parent_consensus_hash, & parent_header_hash) ;
934968
935- let parent_microblocks =
936- if let Some ( microblock_parent_hash) = self . parent_microblock_hash . as_ref ( ) {
937- // load up a microblock fork
938- let microblocks = StacksChainState :: load_microblock_stream_fork (
939- & chainstate. db ( ) ,
940- & parent_consensus_hash,
941- & parent_header_hash,
942- & microblock_parent_hash,
943- ) ?
944- . ok_or ( Error :: NoSuchBlockError ) ?;
945-
946- microblocks
947- } else {
948- // apply all known parent microblocks before beginning our tenure
949- let ( parent_microblocks, _) =
950- match StacksChainState :: load_descendant_staging_microblock_stream_with_poison (
951- & chainstate. db ( ) ,
952- & parent_index_hash,
953- 0 ,
954- u16:: MAX ,
955- ) ? {
956- Some ( x) => x,
957- None => ( vec ! [ ] , None ) ,
958- } ;
959- parent_microblocks
960- } ;
969+ let parent_microblocks = match self . load_parent_microblocks (
970+ chainstate,
971+ & parent_consensus_hash,
972+ & parent_header_hash,
973+ & parent_index_hash,
974+ ) {
975+ Ok ( x) => x,
976+ Err ( e) => {
977+ warn ! ( "Miner failed to load parent microblock, mining without parent microblock tail" ;
978+ "parent_block_hash" => %parent_header_hash,
979+ "parent_index_hash" => %parent_header_hash,
980+ "parent_consensus_hash" => %parent_header_hash,
981+ "parent_microblock_hash" => match self . parent_microblock_hash. as_ref( ) {
982+ Some ( x) => format!( "Some({})" , x. to_string( ) ) ,
983+ None => "None" . to_string( ) ,
984+ } ,
985+ "error" => ?e) ;
986+ vec ! [ ]
987+ }
988+ } ;
961989
962990 debug ! (
963991 "Descendant of {}/{} confirms {} microblock(s)" ,
0 commit comments