Skip to content

Commit 5dd6314

Browse files
author
Aaron Blankstein
authored
Merge pull request #2255 from blockstack/fix/microblock-mining
Do not abort mining a block if the microblock stream failed to load
2 parents 6a8c2f6 + 2d63183 commit 5dd6314

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

src/chainstate/stacks/db/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,12 @@ impl StacksChainState {
12161216
&microblock.block_hash(),
12171217
),
12181218
)? {
1219-
test_debug!("Microblock {} is not processed", &microblock.block_hash());
1219+
debug!("Microblock {} is not processed", &microblock.block_hash());
12201220
return Ok(None);
12211221
}
12221222
}
12231223

1224-
test_debug!(
1224+
debug!(
12251225
"Loaded microblock {}/{}-{} (parent={}, expect_seq={})",
12261226
&parent_consensus_hash,
12271227
&parent_anchored_block_hash,

src/chainstate/stacks/miner.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)