Skip to content

Commit da5e1b0

Browse files
authored
feat: allow solo mine (#91)
Description --- Allow miners to miner solo while they do not have the entire chain yet
1 parent dddf35b commit da5e1b0

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/sharechain/in_memory.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,16 @@ impl ShareChain for InMemoryShareChain {
430430
let mut excluded_uncles = vec![];
431431
let mut uncles = vec![];
432432
for height in new_height.saturating_sub(3)..new_height {
433-
let older_level = chain_read_lock
434-
.level_at_height(height)
435-
.ok_or(Error::BlockLevelNotFound)?;
436-
let chain_block = older_level.block_in_main_chain().ok_or(Error::BlockNotFound)?;
437-
// Blocks in the main chain can't be uncles
438-
excluded_uncles.push(chain_block.hash);
439-
for uncle in chain_block.uncles.iter() {
440-
excluded_uncles.push(uncle.1);
441-
}
442-
for block in older_level.blocks.iter() {
443-
uncles.push((height, block.0.clone()));
433+
if let Some(older_level) = chain_read_lock.level_at_height(height) {
434+
let chain_block = older_level.block_in_main_chain().ok_or(Error::BlockNotFound)?;
435+
// Blocks in the main chain can't be uncles
436+
excluded_uncles.push(chain_block.hash);
437+
for uncle in chain_block.uncles.iter() {
438+
excluded_uncles.push(uncle.1);
439+
}
440+
for block in older_level.blocks.iter() {
441+
uncles.push((height, block.0.clone()));
442+
}
444443
}
445444
}
446445

0 commit comments

Comments
 (0)