Skip to content

[FIX] Return the last blocks when fetching the ommers ancestors from memory #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ class BlockValidation(consensus: Consensus, blockchain: Blockchain, blockQueue:
}

private def getNBlocksBackFromChainOrQueue(hash: ByteString, n: Int): List[Block] = {
val queuedBlocks = blockQueue.getBranch(hash, dequeue = false).take(n)
val queuedBlocks = blockQueue.getBranch(hash, dequeue = false).takeRight(n)
if (queuedBlocks.length == n) {
queuedBlocks
} else {
val chainedBlockHash = queuedBlocks.headOption.map(_.header.parentHash).getOrElse(hash)
blockchain.getBlockByHash(chainedBlockHash) match {
case None =>
// The in memory blocks aren't connected to the db ones, we don't have n blocks to return so we return none
Nil

case Some(block) =>
// We already have |block +: queuedBlocks|
val remaining = n - queuedBlocks.length - 1

val numbers = (block.header.number - remaining) until block.header.number
val blocks = (numbers.toList.flatMap(blockchain.getBlockByNumber) :+ block) ::: queuedBlocks
blocks
Expand Down