Skip to content

Commit 1adf114

Browse files
author
Nicolás Tallar
authored
[FIX] Return the last blocks when fetching the ommers ancestors from memory (#790)
1 parent ccc0c91 commit 1adf114

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ class BlockValidation(consensus: Consensus, blockchain: Blockchain, blockQueue:
2020
}
2121

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

3233
case Some(block) =>
34+
// We already have |block +: queuedBlocks|
3335
val remaining = n - queuedBlocks.length - 1
36+
3437
val numbers = (block.header.number - remaining) until block.header.number
3538
val blocks = (numbers.toList.flatMap(blockchain.getBlockByNumber) :+ block) ::: queuedBlocks
3639
blocks

0 commit comments

Comments
 (0)