Skip to content

Commit e9afb00

Browse files
committed
ETCM-987: Latest block not found bug
1 parent 3f6b82f commit e9afb00

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/FastSync.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,14 @@ class FastSync(
567567

568568
// TODO [ETCM-676]: Move to blockchain and make sure it's atomic
569569
private def discardLastBlocks(startBlock: BigInt, blocksToDiscard: Int): Unit = {
570-
(startBlock to ((startBlock - blocksToDiscard).max(1)) by -1).foreach { n =>
570+
// TODO (maybe ETCM-77): Manage last checkpoint number too
571+
appStateStorage.putBestBlockNumber((startBlock - blocksToDiscard - 1).max(0)).commit()
572+
573+
(startBlock to ((startBlock - blocksToDiscard).max(1)) by - 1).foreach { n =>
571574
blockchainReader.getBlockHeaderByNumber(n).foreach { headerToRemove =>
572575
blockchain.removeBlock(headerToRemove.hash, withState = false)
573576
}
574577
}
575-
// TODO (maybe ETCM-77): Manage last checkpoint number too
576-
appStateStorage.putBestBlockNumber((startBlock - blocksToDiscard - 1).max(0)).commit()
577578
}
578579

579580
private def validateHeader(header: BlockHeader, peer: Peer): Either[HeaderProcessingResult, BlockHeader] = {

src/main/scala/io/iohk/ethereum/domain/BlockchainReader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class BlockchainReader(
126126

127127
/** Returns a block hash given a block number
128128
*
129-
* @param number Number of the searchead block
129+
* @param number Number of the searched block
130130
* @return Block hash if found
131131
*/
132132
private def getHashByBlockNumber(number: BigInt): Option[ByteString] =

0 commit comments

Comments
 (0)