File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/main/scala/io/iohk/ethereum/ledger Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -39,15 +39,17 @@ class BlockValidation(
3939 // The in memory blocks aren't connected to the db ones, we don't have n blocks to return so we return none
4040 Nil
4141
42- case Some (block ) =>
42+ case Some (highestBlockInStorage ) =>
4343 // We already have |block +: queuedBlocks|
4444 val remaining = n - queuedBlocks.length - 1
45-
46- val numbers = (block.header.number - remaining) until block.header.number
47- val bestBranch = blockchainReader.getBestBranch()
48- val blocks =
49- (numbers.toList.flatMap(nb => bestBranch.getBlockByNumber(nb)) :+ block) ::: queuedBlocks
50- blocks
45+ val remainingBlocks = Iterator
46+ .iterate(blockchainReader.getBlockByHash(highestBlockInStorage.header.parentHash))(
47+ _.flatMap(p => blockchainReader.getBlockByHash(p.header.parentHash))
48+ )
49+ .take(remaining)
50+ .collect { case Some (block) => block }
51+ .toList
52+ (remainingBlocks :+ highestBlockInStorage) ::: queuedBlocks
5153 }
5254 }
5355 }
You can’t perform that action at this time.
0 commit comments