From 83ff97cbfc937f1dd74a035b2db0088c4ceaaef5 Mon Sep 17 00:00:00 2001 From: Nicolas Tallar Date: Wed, 11 Nov 2020 12:50:07 -0300 Subject: [PATCH] [FIX] Return the last blocks when fetching the ommers ancestors from memory --- src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala b/src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala index 30ab9a24d6..ed713ca028 100644 --- a/src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala +++ b/src/main/scala/io/iohk/ethereum/ledger/BlockValidation.scala @@ -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