Skip to content

Commit

Permalink
[ETCM-987] Fix saving the best block number without adding a mapping …
Browse files Browse the repository at this point in the history
…between block number and block hash (#1090)
  • Loading branch information
Leonor Boga authored Aug 9, 2021
1 parent 1df5b99 commit 1553ff5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object FastSyncItSpecUtils {
FastSync.props(
storagesInstance.storages.fastSyncStateStorage,
storagesInstance.storages.appStateStorage,
storagesInstance.storages.blockNumberMappingStorage,
bl,
blockchainReader,
blockchainWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.iohk.ethereum.blockchain.sync.regular.RegularSync
import io.iohk.ethereum.consensus.Consensus
import io.iohk.ethereum.consensus.validators.Validators
import io.iohk.ethereum.db.storage.AppStateStorage
import io.iohk.ethereum.db.storage.BlockNumberMappingStorage
import io.iohk.ethereum.db.storage.EvmCodeStorage
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.db.storage.NodeStorage
Expand All @@ -28,6 +29,7 @@ class SyncController(
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
appStateStorage: AppStateStorage,
blockNumberMappingStorage: BlockNumberMappingStorage,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
Expand Down Expand Up @@ -96,6 +98,7 @@ class SyncController(
FastSync.props(
fastSyncStateStorage,
appStateStorage,
blockNumberMappingStorage,
blockchain,
blockchainReader,
blockchainWriter,
Expand Down Expand Up @@ -151,6 +154,7 @@ object SyncController {
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
appStateStorage: AppStateStorage,
blockNumberMappingStorage: BlockNumberMappingStorage,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
Expand All @@ -171,6 +175,7 @@ object SyncController {
blockchainReader,
blockchainWriter,
appStateStorage,
blockNumberMappingStorage,
evmCodeStorage,
stateStorage,
nodeStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor.StateSyncFi
import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor.WaitingForNewTargetBlock
import io.iohk.ethereum.consensus.validators.Validators
import io.iohk.ethereum.db.storage.AppStateStorage
import io.iohk.ethereum.db.storage.BlockNumberMappingStorage
import io.iohk.ethereum.db.storage.EvmCodeStorage
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.db.storage.NodeStorage
Expand All @@ -54,6 +55,7 @@ import io.iohk.ethereum.utils.Config.SyncConfig
class FastSync(
val fastSyncStateStorage: FastSyncStateStorage,
val appStateStorage: AppStateStorage,
val blockNumberMappingStorage: BlockNumberMappingStorage,
val blockchain: Blockchain,
val blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
Expand Down Expand Up @@ -1137,11 +1139,14 @@ class FastSync(
val lastStoredBestBlockNumber = appStateStorage.getBestBlockNumber()
if (lastStoredBestBlockNumber < bestReceivedBlock.number) {
blockchain.saveBestKnownBlocks(bestReceivedBlock.number)
appStateStorage.putBestBlockNumber(bestReceivedBlock.number).commit()
// TODO ETCM-1089 move direct calls to storages to blockchain or blockchain writer
appStateStorage
.putBestBlockNumber(bestReceivedBlock.number)
.and(blockNumberMappingStorage.put(bestReceivedBlock.number, bestReceivedBlock.hash))
.commit()
}
syncState = syncState.copy(lastFullBlockNumber = bestReceivedBlock.number.max(lastStoredBestBlockNumber))
}

}
}
}
Expand All @@ -1152,6 +1157,7 @@ object FastSync {
def props(
fastSyncStateStorage: FastSyncStateStorage,
appStateStorage: AppStateStorage,
blockNumberMappingStorage: BlockNumberMappingStorage,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
Expand All @@ -1170,6 +1176,7 @@ object FastSync {
new FastSync(
fastSyncStateStorage,
appStateStorage,
blockNumberMappingStorage,
blockchain,
blockchainReader,
blockchainWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ trait SyncControllerBuilder {
blockchainReader,
blockchainWriter,
storagesInstance.storages.appStateStorage,
storagesInstance.storages.blockNumberMappingStorage,
storagesInstance.storages.evmCodeStorage,
storagesInstance.storages.stateStorage,
storagesInstance.storages.nodeStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class FastSyncSpec
FastSync.props(
fastSyncStateStorage = storagesInstance.storages.fastSyncStateStorage,
appStateStorage = storagesInstance.storages.appStateStorage,
blockNumberMappingStorage = storagesInstance.storages.blockNumberMappingStorage,
blockchain = blockchain,
blockchainReader = blockchainReader,
blockchainWriter = blockchainWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ class SyncControllerSpec
blockchainReader,
blockchainWriter,
storagesInstance.storages.appStateStorage,
storagesInstance.storages.blockNumberMappingStorage,
storagesInstance.storages.evmCodeStorage,
storagesInstance.storages.stateStorage,
storagesInstance.storages.nodeStorage,
Expand Down

0 comments on commit 1553ff5

Please sign in to comment.