Skip to content

Commit 22f0cd9

Browse files
author
Aurélien Richez
committed
avoid trying to fetch parent of genesis
1 parent 2ff9c65 commit 22f0cd9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/main/scala/io/iohk/ethereum/consensus/pow/validators/OmmersValidator.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ trait OmmersValidator {
3030
)(implicit blockchainConfig: BlockchainConfig): Either[OmmersError, OmmersValid] = {
3131

3232
val getBlockHeaderByHash: ByteString => Option[BlockHeader] = blockchainReader.getBlockHeaderByHash
33-
val bestBranch = blockchainReader.getBestBranch()
3433
val getNBlocksBack: (ByteString, Int) => List[Block] =
3534
(tailBlockHash, n) =>
3635
Iterator
3736
.iterate(blockchainReader.getBlockByHash(tailBlockHash))(
38-
_.flatMap(block => blockchainReader.getBlockByHash(block.header.parentHash))
37+
_.filter(_.number > 0) // avoid trying to fetch parent of genesis
38+
.flatMap(block => blockchainReader.getBlockByHash(block.header.parentHash))
3939
)
40-
.take(n)
4140
.collect { case Some(block) => block }
41+
.take(n)
4242
.toList
4343
.reverse
4444

src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class BlockValidation(
4444
val remaining = n - queuedBlocks.length - 1
4545
val remainingBlocks = Iterator
4646
.iterate(blockchainReader.getBlockByHash(highestBlockInStorage.header.parentHash))(
47-
_.flatMap(p => blockchainReader.getBlockByHash(p.header.parentHash))
47+
_.filter(_.number > 0) // avoid trying to fetch parent of genesis
48+
.flatMap(p => blockchainReader.getBlockByHash(p.header.parentHash))
4849
)
4950
.take(remaining)
5051
.collect { case Some(block) => block }

0 commit comments

Comments
 (0)