Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import io.iohk.ethereum.consensus.pow.validators.StdOmmersValidator
import io.iohk.ethereum.consensus.validators.Validators
import io.iohk.ethereum.crypto
import io.iohk.ethereum.domain._
import io.iohk.ethereum.ledger.BlockResult
import io.iohk.ethereum.mpt.MerklePatriciaTrie
import io.iohk.ethereum.utils.Config
import io.iohk.ethereum.utils.Config.SyncConfig
Expand Down Expand Up @@ -123,6 +122,7 @@ class BlockImporterItSpec
blockImport,
blockchain,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
syncConfig,
ommersPoolProbe.ref,
Expand Down Expand Up @@ -167,6 +167,7 @@ class BlockImporterItSpec
mkBlockImport(validators = successValidators),
blockchain,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
syncConfig,
ommersPoolProbe.ref,
Expand Down Expand Up @@ -280,6 +281,7 @@ class BlockImporterItSpec
mkBlockImport(validators = successValidators),
blockchain,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
syncConfig,
ommersPoolProbe.ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object FastSyncItSpecUtils {
blockchainReader,
blockchainWriter,
storagesInstance.storages.evmCodeStorage,
storagesInstance.storages.stateStorage,
storagesInstance.storages.nodeStorage,
validators,
peerEventBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ object RegularSyncItSpecUtils {
blockImport,
bl,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(bl, blockchainReader),
syncConfig,
ommersPool,
Expand All @@ -164,6 +165,7 @@ object RegularSyncItSpecUtils {
blockImport,
bl,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(bl, blockchainReader),
validators.blockValidator,
blacklist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.iohk.ethereum.db.components.Storages
import io.iohk.ethereum.db.components.Storages.PruningModeComponent
import io.iohk.ethereum.db.storage.AppStateStorage
import io.iohk.ethereum.db.storage.MptStorage
import io.iohk.ethereum.db.storage.NodeStorage.NodeEncoded
import io.iohk.ethereum.db.storage.NodeStorage.NodeHash
import io.iohk.ethereum.db.storage.pruning.ArchivePruning
import io.iohk.ethereum.db.storage.pruning.PruningMode
Expand Down Expand Up @@ -184,8 +183,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
ethCompatibleStorage: Boolean
): StorageProof = EmptyStorageValueProof(StorageProofKey(position))

override def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit = ???

override def removeBlock(hash: ByteString, withState: Boolean = true): Unit = ???

override def getChainWeightByHash(blockhash: ByteString): Option[ChainWeight] = ???
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.iohk.ethereum.db.storage.AppStateStorage
import io.iohk.ethereum.db.storage.EvmCodeStorage
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.db.storage.NodeStorage
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain.Blockchain
import io.iohk.ethereum.domain.BlockchainReader
import io.iohk.ethereum.domain.BlockchainWriter
Expand All @@ -27,6 +28,7 @@ class SyncController(
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
fastSyncStateStorage: FastSyncStateStorage,
blockImport: BlockImport,
Expand Down Expand Up @@ -96,6 +98,7 @@ class SyncController(
blockchainReader,
blockchainWriter,
evmCodeStorage,
stateStorage,
nodeStorage,
validators,
peerEventBus,
Expand All @@ -121,6 +124,7 @@ class SyncController(
blockImport,
blockchain,
blockchainReader,
stateStorage,
new BranchResolution(blockchain, blockchainReader),
validators.blockValidator,
blacklist,
Expand All @@ -145,6 +149,7 @@ object SyncController {
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
syncStateStorage: FastSyncStateStorage,
blockImport: BlockImport,
Expand All @@ -163,6 +168,7 @@ object SyncController {
blockchainReader,
blockchainWriter,
evmCodeStorage,
stateStorage,
nodeStorage,
syncStateStorage,
blockImport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import io.iohk.ethereum.db.storage.AppStateStorage
import io.iohk.ethereum.db.storage.EvmCodeStorage
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.db.storage.NodeStorage
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain._
import io.iohk.ethereum.mpt.MerklePatriciaTrie
import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo
Expand All @@ -56,6 +57,7 @@ class FastSync(
val blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
val validators: Validators,
val peerEventBus: ActorRef,
Expand Down Expand Up @@ -176,6 +178,7 @@ class FastSync(
blockchain,
blockchainReader,
evmCodeStorage,
stateStorage,
nodeStorage,
syncConfig.stateSyncBloomFilterSize
),
Expand Down Expand Up @@ -1150,6 +1153,7 @@ object FastSync {
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
validators: Validators,
peerEventBus: ActorRef,
Expand All @@ -1166,6 +1170,7 @@ object FastSync {
blockchainReader,
blockchainWriter,
evmCodeStorage,
stateStorage,
nodeStorage,
validators,
peerEventBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.iohk.ethereum.blockchain.sync.fast.SyncStateScheduler._
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
import io.iohk.ethereum.db.storage.EvmCodeStorage
import io.iohk.ethereum.db.storage.NodeStorage
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain.Account
import io.iohk.ethereum.domain.Blockchain
import io.iohk.ethereum.domain.BlockchainReader
Expand Down Expand Up @@ -59,9 +60,9 @@ import io.iohk.ethereum.network.p2p.messages.ETH63.MptNodeEncoders.MptNodeDec
* Important part is that nodes retrieved by getMissingNodes, must eventually be provided for scheduler to make progress
*/
class SyncStateScheduler(
blockchain: Blockchain,
blockchainReader: BlockchainReader,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
bloomFilter: LoadableBloomFilter[ByteString]
) {

Expand Down Expand Up @@ -133,7 +134,7 @@ class SyncStateScheduler(
bloomFilter.put(hash)
reqType match {
case _: CodeRequest => evmCodeStorage.put(hash, data).commit()
case _: NodeRequest => blockchain.saveNode(hash, data.toArray, targetBlockNumber)
case _: NodeRequest => stateStorage.saveNode(hash, data.toArray, targetBlockNumber)
}
}
newState
Expand Down Expand Up @@ -294,6 +295,7 @@ object SyncStateScheduler {
blockchain: Blockchain,
blockchainReader: BlockchainReader,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
expectedBloomFilterSize: Int
): SyncStateScheduler = {
Expand All @@ -304,9 +306,9 @@ object SyncStateScheduler {
.takeWhileInclusive(_.isRight)

new SyncStateScheduler(
blockchain,
blockchainReader,
evmCodeStorage,
stateStorage,
LoadableBloomFilter[ByteString](expectedBloomFilterSize, mptStateSavedKeys)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockBroadcast.BlockToBroadcast
import io.iohk.ethereum.blockchain.sync.regular.BlockBroadcasterActor.BroadcastBlocks
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressProtocol
import io.iohk.ethereum.crypto.kec256
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain._
import io.iohk.ethereum.ledger._
import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException
Expand All @@ -38,6 +39,7 @@ class BlockImporter(
blockImport: BlockImport,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
syncConfig: SyncConfig,
ommersPool: ActorRef,
Expand Down Expand Up @@ -116,7 +118,7 @@ class BlockImporter(
state: ImporterState
): Receive = { case BlockFetcher.FetchedStateNode(nodeData) =>
val node = nodeData.values.head
blockchain.saveNode(kec256(node), node.toArray, blocksToRetry.head.number)
stateStorage.saveNode(kec256(node), node.toArray, blocksToRetry.head.number)
importBlocks(blocksToRetry, blockImportType)(state)
}

Expand Down Expand Up @@ -328,6 +330,7 @@ object BlockImporter {
blockImport: BlockImport,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
syncConfig: SyncConfig,
ommersPool: ActorRef,
Expand All @@ -341,6 +344,7 @@ object BlockImporter {
blockImport,
blockchain,
blockchainReader,
stateStorage,
branchResolution,
syncConfig,
ommersPool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.iohk.ethereum.blockchain.sync.regular.RegularSync.NewCheckpoint
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressProtocol
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressState
import io.iohk.ethereum.consensus.validators.BlockValidator
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain.Block
import io.iohk.ethereum.domain.Blockchain
import io.iohk.ethereum.domain.BlockchainReader
Expand All @@ -35,6 +36,7 @@ class RegularSync(
blockImport: BlockImport,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
blockValidator: BlockValidator,
blacklist: Blacklist,
Expand Down Expand Up @@ -65,6 +67,7 @@ class RegularSync(
blockImport,
blockchain,
blockchainReader,
stateStorage,
branchResolution,
syncConfig,
ommersPool,
Expand Down Expand Up @@ -137,6 +140,7 @@ object RegularSync {
blockImport: BlockImport,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
blockValidator: BlockValidator,
blacklist: Blacklist,
Expand All @@ -153,6 +157,7 @@ object RegularSync {
blockImport,
blockchain,
blockchainReader,
stateStorage,
branchResolution,
blockValidator,
blacklist,
Expand Down
7 changes: 0 additions & 7 deletions src/main/scala/io/iohk/ethereum/domain/Blockchain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import cats.syntax.flatMap._
import scala.annotation.tailrec

import io.iohk.ethereum.db.dataSource.DataSourceBatchUpdate
import io.iohk.ethereum.db.storage.NodeStorage.NodeEncoded
import io.iohk.ethereum.db.storage.NodeStorage.NodeHash
import io.iohk.ethereum.db.storage._
import io.iohk.ethereum.domain
import io.iohk.ethereum.jsonrpc.ProofService.StorageProof
Expand Down Expand Up @@ -80,8 +78,6 @@ trait Blockchain {

def saveBestKnownBlocks(bestBlockNumber: BigInt, latestCheckpointNumber: Option[BigInt] = None): Unit

def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit

/** Strict check if given block hash is in chain
* Using any of getXXXByHash is not always accurate - after restart the best block is often lower than before restart
* The result of that is returning data of blocks which we don't consider as a part of the chain anymore
Expand Down Expand Up @@ -203,9 +199,6 @@ class BlockchainImpl(
BestBlockLatestCheckpointNumbers(number, latestCheckpointNumber)
)

def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, blockNumber: BigInt): Unit =
stateStorage.saveNode(nodeHash, nodeEncoded, blockNumber)

private def removeBlockNumberMapping(number: BigInt): DataSourceBatchUpdate =
blockNumberMappingStorage.remove(number)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ trait SyncControllerBuilder {
blockchainReader,
blockchainWriter,
storagesInstance.storages.evmCodeStorage,
storagesInstance.storages.stateStorage,
storagesInstance.storages.nodeStorage,
storagesInstance.storages.fastSyncStateStorage,
blockImport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class FastSyncSpec
blockchainWriter = blockchainWriter,
evmCodeStorage = storagesInstance.storages.evmCodeStorage,
nodeStorage = storagesInstance.storages.nodeStorage,
stateStorage = storagesInstance.storages.stateStorage,
validators = validators,
peerEventBus = peerEventBus.ref,
etcPeerManager = etcPeerManager.ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class StateSyncSpec
blockchain,
blockchainReader,
getNewStorages.storages.evmCodeStorage,
getNewStorages.storages.stateStorage,
getNewStorages.storages.nodeStorage,
syncConfig.stateSyncBloomFilterSize
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ class SyncControllerSpec
blockchainReader,
blockchainWriter,
storagesInstance.storages.evmCodeStorage,
storagesInstance.storages.stateStorage,
storagesInstance.storages.nodeStorage,
storagesInstance.storages.fastSyncStateStorage,
blockImport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class SyncStateSchedulerSpec
freshBlockchain,
freshBlockchainReader,
freshStorage.storages.evmCodeStorage,
freshStorage.storages.stateStorage,
freshStorage.storages.nodeStorage,
bloomFilterSize
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.scalatest.matchers.should.Matchers
import io.iohk.ethereum.BlockHelpers
import io.iohk.ethereum.blockchain.sync._
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain.BlockHeaderImplicits._
import io.iohk.ethereum.domain._
import io.iohk.ethereum.ledger._
Expand Down Expand Up @@ -75,6 +76,8 @@ trait RegularSyncFixtures { self: Matchers with AsyncMockFactory =>
val blacklist: CacheBasedBlacklist = CacheBasedBlacklist.empty(100)
lazy val branchResolution = new BranchResolution(blockchain, blockchainReader)

val stateStorage: StateStorage = stub[StateStorage]

lazy val regularSync: ActorRef = system.actorOf(
RegularSync
.props(
Expand All @@ -84,6 +87,7 @@ trait RegularSyncFixtures { self: Matchers with AsyncMockFactory =>
blockImport,
blockchain,
blockchainReader,
stateStorage,
branchResolution,
validators.blockValidator,
blacklist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class RegularSyncSpec
val failingBlock: Block = testBlocksChunked.head.head
peersClient.setAutoPilot(new PeersClientAutoPilot)
override lazy val branchResolution: BranchResolution = stub[BranchResolution]
(blockchainReader.getBestBlockNumber _).when().returns(0)
(branchResolution.resolveBranch _).when(*).returns(NewBetterBranch(Nil)).repeat(10)
(blockImport
.importBlock(_: Block)(_: Scheduler))
Expand All @@ -483,7 +484,7 @@ class RegularSyncSpec
val nodeData = List(ByteString(failingBlock.header.toBytes: Array[Byte]))
(blockchainReader.getBestBlockNumber _).when().returns(0)
(blockchainReader.getBlockHeaderByNumber _).when(*).returns(Some(BlockHelpers.genesis.header))
(blockchain.saveNode _)
(stateStorage.saveNode _)
.when(*, *, *)
.onCall { (hash, encoded, totalDifficulty) =>
val expectedNode = nodeData.head
Expand Down