Skip to content
Merged
12 changes: 5 additions & 7 deletions src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockFetcher
import io.iohk.ethereum.blockchain.sync.regular.BlockImporter
import io.iohk.ethereum.blockchain.sync.regular.BlockImporter.NewCheckpoint
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
import io.iohk.ethereum.consensus.Consensus
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.consensus.pow.validators.OmmersValidator
import io.iohk.ethereum.consensus.pow.validators.StdOmmersValidator
Expand Down Expand Up @@ -57,8 +58,7 @@ class BlockImporterItSpec
override val blockImporter = system.actorOf(
BlockImporter.props(
fetcherProbe.ref,
mkBlockImport(validators = successValidators),
blockchain,
mkConsensus(validators = successValidators),
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
Expand Down Expand Up @@ -171,8 +171,7 @@ class BlockImporterItSpec
override val blockImporter = system.actorOf(
BlockImporter.props(
fetcherProbe.ref,
mkBlockImport(validators = successValidators),
blockchain,
mkConsensus(validators = successValidators),
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
Expand Down Expand Up @@ -236,7 +235,7 @@ class TestFixture extends TestSetupWithVmAndValidators {
override val ommersValidator: OmmersValidator = new StdOmmersValidator(blockHeaderValidator)
}

override lazy val blockImport: BlockImport = mkBlockImport(
override lazy val consensus: Consensus = mkConsensus(
validators = successValidators,
blockExecutionOpt = Some(
new BlockExecution(
Expand All @@ -259,8 +258,7 @@ class TestFixture extends TestSetupWithVmAndValidators {
val blockImporter: ActorRef = system.actorOf(
BlockImporter.props(
fetcherProbe.ref,
blockImport,
blockchain,
consensus,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(blockchain, blockchainReader),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockImporter.Start
import io.iohk.ethereum.blockchain.sync.regular.RegularSync
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.NewCheckpoint
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
import io.iohk.ethereum.consensus.Consensus
import io.iohk.ethereum.consensus.ConsensusImpl
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.consensus.mining.FullMiningConfig
import io.iohk.ethereum.consensus.mining.MiningConfig
Expand Down Expand Up @@ -103,8 +105,8 @@ object RegularSyncItSpecUtils {
mining.blockPreparator,
blockValidation
)
lazy val blockImport: BlockImport =
new BlockImport(
lazy val blockImport: Consensus =
new ConsensusImpl(
bl,
blockchainReader,
blockchainWriter,
Expand Down Expand Up @@ -146,7 +148,6 @@ object RegularSyncItSpecUtils {
BlockImporter.props(
fetcher.toClassic,
blockImport,
bl,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(bl, blockchainReader),
Expand All @@ -165,7 +166,6 @@ object RegularSyncItSpecUtils {
etcPeerManager,
peerEventBus,
blockImport,
bl,
blockchainReader,
storagesInstance.storages.stateStorage,
new BranchResolution(bl, blockchainReader),
Expand Down
4 changes: 2 additions & 2 deletions src/it/scala/io/iohk/ethereum/txExecTest/ContractTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ContractTest extends AnyFlatSpec with Matchers {
lazy val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)

//block only with ether transfers
val blockValidation =
override lazy val blockValidation =
new BlockValidation(mining, blockchainReader, BlockQueue(blockchain, blockchainReader, syncConfig))
val blockExecution =
override lazy val blockExecution =
new BlockExecution(
blockchain,
blockchainReader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import akka.actor.Scheduler

import io.iohk.ethereum.blockchain.sync.fast.FastSync
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.EvmCodeStorage
Expand All @@ -18,21 +19,20 @@ 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
import io.iohk.ethereum.ledger.BlockImport
import io.iohk.ethereum.ledger.BranchResolution
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
import io.iohk.ethereum.utils.Config.SyncConfig

class SyncController(
appStateStorage: AppStateStorage,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
appStateStorage: AppStateStorage,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
fastSyncStateStorage: FastSyncStateStorage,
blockImport: BlockImport,
consensus: Consensus,
validators: Validators,
peerEventBus: ActorRef,
pendingTransactionsManager: ActorRef,
Expand Down Expand Up @@ -124,8 +124,7 @@ class SyncController(
peersClient,
etcPeerManager,
peerEventBus,
blockImport,
blockchain,
consensus,
blockchainReader,
stateStorage,
new BranchResolution(blockchain, blockchainReader),
Expand All @@ -148,15 +147,15 @@ class SyncController(
object SyncController {
// scalastyle:off parameter.number
def props(
appStateStorage: AppStateStorage,
blockchain: Blockchain,
blockchainReader: BlockchainReader,
blockchainWriter: BlockchainWriter,
appStateStorage: AppStateStorage,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
nodeStorage: NodeStorage,
syncStateStorage: FastSyncStateStorage,
blockImport: BlockImport,
consensus: Consensus,
validators: Validators,
peerEventBus: ActorRef,
pendingTransactionsManager: ActorRef,
Expand All @@ -168,15 +167,15 @@ object SyncController {
): Props =
Props(
new SyncController(
appStateStorage,
blockchain,
blockchainReader,
blockchainWriter,
appStateStorage,
evmCodeStorage,
stateStorage,
nodeStorage,
syncStateStorage,
blockImport,
consensus,
validators,
peerEventBus,
pendingTransactionsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class FastSync(
SyncStateSchedulerActor
.props(
SyncStateScheduler(
blockchain,
blockchainReader,
evmCodeStorage,
stateStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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
import io.iohk.ethereum.mpt.BranchNode
import io.iohk.ethereum.mpt.ExtensionNode
Expand Down Expand Up @@ -292,7 +291,6 @@ object SyncStateScheduler {
BloomFilter.create[ByteString](ByteStringFunnel, expectedFilterSize)

def apply(
blockchain: Blockchain,
blockchainReader: BlockchainReader,
evmCodeStorage: EvmCodeStorage,
stateStorage: StateStorage,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.iohk.ethereum.blockchain.sync.regular

import io.iohk.ethereum.domain.Block
import io.iohk.ethereum.domain.ChainWeight
import io.iohk.ethereum.ledger.BlockData
import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException

sealed trait BlockImportResult

case class BlockImportedToTop(blockImportData: List[BlockData]) extends BlockImportResult

case object BlockEnqueued extends BlockImportResult

case object DuplicateBlock extends BlockImportResult

case class ChainReorganised(
oldBranch: List[Block],
newBranch: List[Block],
weights: List[ChainWeight]
) extends BlockImportResult

case class BlockImportFailed(error: String) extends BlockImportResult

case class BlockImportFailedDueToMissingNode(reason: MissingNodeException) extends BlockImportResult

case object UnknownParent extends BlockImportResult
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.iohk.ethereum.blockchain.sync.Blacklist.BlacklistReason
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.consensus.Consensus
import io.iohk.ethereum.crypto.kec256
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain._
Expand All @@ -37,8 +38,7 @@ import io.iohk.ethereum.utils.FunctorOps._

class BlockImporter(
fetcher: ActorRef,
blockImport: BlockImport,
blockchain: Blockchain,
consensus: Consensus,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
Expand All @@ -50,6 +50,7 @@ class BlockImporter(
configBuilder: BlockchainConfigBuilder
) extends Actor
with ActorLogging {

import BlockImporter._
import configBuilder._

Expand Down Expand Up @@ -199,8 +200,8 @@ class BlockImporter(
Task.now((importedBlocks, None))
} else {
val restOfBlocks = blocks.tail
blockImport
.importBlock(blocks.head)
consensus
.evaluateBranchBlock(blocks.head)
.flatMap {
case BlockImportedToTop(_) =>
tryImportBlocks(restOfBlocks, blocks.head :: importedBlocks)
Expand Down Expand Up @@ -238,7 +239,7 @@ class BlockImporter(
def doLog(entry: ImportMessages.LogEntry): Unit = log.log(entry._1, entry._2)
importWith(
Task(doLog(importMessages.preImport()))
.flatMap(_ => blockImport.importBlock(block))
.flatMap(_ => consensus.evaluateBranchBlock(block))
.tap((importMessages.messageForImportResult _).andThen(doLog))
.tap {
case BlockImportedToTop(importedBlocksData) =>
Expand Down Expand Up @@ -330,8 +331,7 @@ object BlockImporter {
// scalastyle:off parameter.number
def props(
fetcher: ActorRef,
blockImport: BlockImport,
blockchain: Blockchain,
consensus: Consensus,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
Expand All @@ -345,8 +345,7 @@ object BlockImporter {
Props(
new BlockImporter(
fetcher,
blockImport,
blockchain,
consensus,
blockchainReader,
stateStorage,
branchResolution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import akka.event.Logging._
import akka.util.ByteString

import io.iohk.ethereum.domain.Block
import io.iohk.ethereum.ledger._
import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException
import io.iohk.ethereum.network.PeerId
import io.iohk.ethereum.utils.ByteStringUtils._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockFetcher.InternalLastBlockIm
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.Consensus
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
import io.iohk.ethereum.ledger.BlockImport
import io.iohk.ethereum.ledger.BranchResolution
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
import io.iohk.ethereum.utils.ByteStringUtils
Expand All @@ -34,8 +33,7 @@ class RegularSync(
peersClient: ActorRef,
etcPeerManager: ActorRef,
peerEventBus: ActorRef,
blockImport: BlockImport,
blockchain: Blockchain,
consensus: Consensus,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
Expand Down Expand Up @@ -66,8 +64,7 @@ class RegularSync(
context.actorOf(
BlockImporter.props(
fetcher.toClassic,
blockImport,
blockchain,
consensus,
blockchainReader,
stateStorage,
branchResolution,
Expand Down Expand Up @@ -140,8 +137,7 @@ object RegularSync {
peersClient: ActorRef,
etcPeerManager: ActorRef,
peerEventBus: ActorRef,
blockImport: BlockImport,
blockchain: Blockchain,
consensus: Consensus,
blockchainReader: BlockchainReader,
stateStorage: StateStorage,
branchResolution: BranchResolution,
Expand All @@ -158,8 +154,7 @@ object RegularSync {
peersClient,
etcPeerManager,
peerEventBus,
blockImport,
blockchain,
consensus,
blockchainReader,
stateStorage,
branchResolution,
Expand Down
Loading