Skip to content

Commit d158b95

Browse files
author
Leonor Boga
committed
ETCM-1018 Replace references to BlockImport by Consensus/ConsensusImpl
1 parent 1232fbc commit d158b95

File tree

13 files changed

+87
-133
lines changed

13 files changed

+87
-133
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ package io.iohk.ethereum.ledger
33
import akka.actor.ActorRef
44
import akka.testkit.TestProbe
55
import akka.util.ByteString
6-
76
import cats.data.NonEmptyList
8-
97
import monix.execution.Scheduler
108
import monix.execution.schedulers.SchedulerService
119

1210
import scala.concurrent.duration._
13-
1411
import org.scalamock.scalatest.MockFactory
1512
import org.scalatest.BeforeAndAfterAll
1613
import org.scalatest.concurrent.Eventually
1714
import org.scalatest.flatspec.AnyFlatSpecLike
1815
import org.scalatest.matchers.should.Matchers
19-
2016
import io.iohk.ethereum.Fixtures
2117
import io.iohk.ethereum.Mocks
2218
import io.iohk.ethereum.NormalPatience
@@ -26,6 +22,7 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockFetcher
2622
import io.iohk.ethereum.blockchain.sync.regular.BlockImporter
2723
import io.iohk.ethereum.blockchain.sync.regular.BlockImporter.NewCheckpoint
2824
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
25+
import io.iohk.ethereum.consensus.Consensus
2926
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
3027
import io.iohk.ethereum.consensus.pow.validators.OmmersValidator
3128
import io.iohk.ethereum.consensus.pow.validators.StdOmmersValidator
@@ -57,8 +54,7 @@ class BlockImporterItSpec
5754
override val blockImporter = system.actorOf(
5855
BlockImporter.props(
5956
fetcherProbe.ref,
60-
mkBlockImport(validators = successValidators),
61-
blockchain,
57+
mkConsensus(validators = successValidators),
6258
blockchainReader,
6359
storagesInstance.storages.stateStorage,
6460
new BranchResolution(blockchain, blockchainReader),
@@ -171,8 +167,7 @@ class BlockImporterItSpec
171167
override val blockImporter = system.actorOf(
172168
BlockImporter.props(
173169
fetcherProbe.ref,
174-
mkBlockImport(validators = successValidators),
175-
blockchain,
170+
mkConsensus(validators = successValidators),
176171
blockchainReader,
177172
storagesInstance.storages.stateStorage,
178173
new BranchResolution(blockchain, blockchainReader),
@@ -236,7 +231,7 @@ class TestFixture extends TestSetupWithVmAndValidators {
236231
override val ommersValidator: OmmersValidator = new StdOmmersValidator(blockHeaderValidator)
237232
}
238233

239-
override lazy val blockImport: BlockImport = mkBlockImport(
234+
override lazy val consensus: Consensus = mkConsensus(
240235
validators = successValidators,
241236
blockExecutionOpt = Some(
242237
new BlockExecution(
@@ -259,8 +254,7 @@ class TestFixture extends TestSetupWithVmAndValidators {
259254
val blockImporter: ActorRef = system.actorOf(
260255
BlockImporter.props(
261256
fetcherProbe.ref,
262-
blockImport,
263-
blockchain,
257+
consensus,
264258
blockchainReader,
265259
storagesInstance.storages.stateStorage,
266260
new BranchResolution(blockchain, blockchainReader),

src/it/scala/io/iohk/ethereum/sync/util/RegularSyncItSpecUtils.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import akka.actor.ActorRef
44
import akka.actor.typed
55
import akka.actor.typed.scaladsl.adapter._
66
import akka.util.ByteString
7-
87
import cats.effect.Resource
9-
108
import monix.eval.Task
119
import monix.execution.Scheduler
1210

1311
import scala.concurrent.duration._
14-
1512
import io.iohk.ethereum.Mocks.MockValidatorsAlwaysSucceed
1613
import io.iohk.ethereum.blockchain.sync.PeersClient
1714
import io.iohk.ethereum.blockchain.sync.SyncProtocol
@@ -30,7 +27,7 @@ import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
3027
import io.iohk.ethereum.consensus.mining.FullMiningConfig
3128
import io.iohk.ethereum.consensus.mining.MiningConfig
3229
import io.iohk.ethereum.consensus.mining.Protocol.NoAdditionalPoWData
33-
import io.iohk.ethereum.consensus.pow
30+
import io.iohk.ethereum.consensus.{Consensus, ConsensusImpl, pow}
3431
import io.iohk.ethereum.consensus.pow.EthashConfig
3532
import io.iohk.ethereum.consensus.pow.PoWMining
3633
import io.iohk.ethereum.consensus.pow.validators.ValidatorsExecutor
@@ -103,8 +100,8 @@ object RegularSyncItSpecUtils {
103100
mining.blockPreparator,
104101
blockValidation
105102
)
106-
lazy val blockImport: BlockImport =
107-
new BlockImport(
103+
lazy val blockImport: Consensus =
104+
new ConsensusImpl(
108105
bl,
109106
blockchainReader,
110107
blockchainWriter,
@@ -146,7 +143,6 @@ object RegularSyncItSpecUtils {
146143
BlockImporter.props(
147144
fetcher.toClassic,
148145
blockImport,
149-
bl,
150146
blockchainReader,
151147
storagesInstance.storages.stateStorage,
152148
new BranchResolution(bl, blockchainReader),
@@ -165,7 +161,6 @@ object RegularSyncItSpecUtils {
165161
etcPeerManager,
166162
peerEventBus,
167163
blockImport,
168-
bl,
169164
blockchainReader,
170165
storagesInstance.storages.stateStorage,
171166
new BranchResolution(bl, blockchainReader),

src/main/scala/io/iohk/ethereum/blockchain/sync/SyncController.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import akka.actor.ActorRef
66
import akka.actor.PoisonPill
77
import akka.actor.Props
88
import akka.actor.Scheduler
9-
109
import io.iohk.ethereum.blockchain.sync.fast.FastSync
1110
import io.iohk.ethereum.blockchain.sync.regular.RegularSync
11+
import io.iohk.ethereum.consensus.Consensus
1212
import io.iohk.ethereum.consensus.validators.Validators
1313
import io.iohk.ethereum.db.storage.AppStateStorage
1414
import io.iohk.ethereum.db.storage.EvmCodeStorage
@@ -18,21 +18,20 @@ import io.iohk.ethereum.db.storage.StateStorage
1818
import io.iohk.ethereum.domain.Blockchain
1919
import io.iohk.ethereum.domain.BlockchainReader
2020
import io.iohk.ethereum.domain.BlockchainWriter
21-
import io.iohk.ethereum.ledger.BlockImport
2221
import io.iohk.ethereum.ledger.BranchResolution
2322
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
2423
import io.iohk.ethereum.utils.Config.SyncConfig
2524

2625
class SyncController(
27-
appStateStorage: AppStateStorage,
2826
blockchain: Blockchain,
2927
blockchainReader: BlockchainReader,
3028
blockchainWriter: BlockchainWriter,
29+
appStateStorage: AppStateStorage,
3130
evmCodeStorage: EvmCodeStorage,
3231
stateStorage: StateStorage,
3332
nodeStorage: NodeStorage,
3433
fastSyncStateStorage: FastSyncStateStorage,
35-
blockImport: BlockImport,
34+
consensus: Consensus,
3635
validators: Validators,
3736
peerEventBus: ActorRef,
3837
pendingTransactionsManager: ActorRef,
@@ -124,8 +123,7 @@ class SyncController(
124123
peersClient,
125124
etcPeerManager,
126125
peerEventBus,
127-
blockImport,
128-
blockchain,
126+
consensus,
129127
blockchainReader,
130128
stateStorage,
131129
new BranchResolution(blockchain, blockchainReader),
@@ -148,15 +146,15 @@ class SyncController(
148146
object SyncController {
149147
// scalastyle:off parameter.number
150148
def props(
151-
appStateStorage: AppStateStorage,
152149
blockchain: Blockchain,
153150
blockchainReader: BlockchainReader,
154151
blockchainWriter: BlockchainWriter,
152+
appStateStorage: AppStateStorage,
155153
evmCodeStorage: EvmCodeStorage,
156154
stateStorage: StateStorage,
157155
nodeStorage: NodeStorage,
158156
syncStateStorage: FastSyncStateStorage,
159-
blockImport: BlockImport,
157+
consensus: Consensus,
160158
validators: Validators,
161159
peerEventBus: ActorRef,
162160
pendingTransactionsManager: ActorRef,
@@ -168,15 +166,15 @@ object SyncController {
168166
): Props =
169167
Props(
170168
new SyncController(
171-
appStateStorage,
172169
blockchain,
173170
blockchainReader,
174171
blockchainWriter,
172+
appStateStorage,
175173
evmCodeStorage,
176174
stateStorage,
177175
nodeStorage,
178176
syncStateStorage,
179-
blockImport,
177+
consensus,
180178
validators,
181179
peerEventBus,
182180
pendingTransactionsManager,

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSync.scala

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import akka.actor.Scheduler
1010
import akka.actor.SupervisorStrategy
1111
import akka.actor.typed.scaladsl.adapter._
1212
import akka.actor.typed.{ActorRef => TypedActorRef}
13-
1413
import io.iohk.ethereum.blockchain.sync.Blacklist
1514
import io.iohk.ethereum.blockchain.sync.SyncProtocol
1615
import io.iohk.ethereum.blockchain.sync.SyncProtocol.Status
@@ -19,12 +18,11 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockFetcher.InternalLastBlockIm
1918
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.NewCheckpoint
2019
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressProtocol
2120
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.ProgressState
21+
import io.iohk.ethereum.consensus.Consensus
2222
import io.iohk.ethereum.consensus.validators.BlockValidator
2323
import io.iohk.ethereum.db.storage.StateStorage
2424
import io.iohk.ethereum.domain.Block
25-
import io.iohk.ethereum.domain.Blockchain
2625
import io.iohk.ethereum.domain.BlockchainReader
27-
import io.iohk.ethereum.ledger.BlockImport
2826
import io.iohk.ethereum.ledger.BranchResolution
2927
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
3028
import io.iohk.ethereum.utils.ByteStringUtils
@@ -34,8 +32,7 @@ class RegularSync(
3432
peersClient: ActorRef,
3533
etcPeerManager: ActorRef,
3634
peerEventBus: ActorRef,
37-
blockImport: BlockImport,
38-
blockchain: Blockchain,
35+
consensus: Consensus,
3936
blockchainReader: BlockchainReader,
4037
stateStorage: StateStorage,
4138
branchResolution: BranchResolution,
@@ -66,8 +63,7 @@ class RegularSync(
6663
context.actorOf(
6764
BlockImporter.props(
6865
fetcher.toClassic,
69-
blockImport,
70-
blockchain,
66+
consensus,
7167
blockchainReader,
7268
stateStorage,
7369
branchResolution,
@@ -140,8 +136,7 @@ object RegularSync {
140136
peersClient: ActorRef,
141137
etcPeerManager: ActorRef,
142138
peerEventBus: ActorRef,
143-
blockImport: BlockImport,
144-
blockchain: Blockchain,
139+
consensus: Consensus,
145140
blockchainReader: BlockchainReader,
146141
stateStorage: StateStorage,
147142
branchResolution: BranchResolution,
@@ -158,8 +153,7 @@ object RegularSync {
158153
peersClient,
159154
etcPeerManager,
160155
peerEventBus,
161-
blockImport,
162-
blockchain,
156+
consensus,
163157
blockchainReader,
164158
stateStorage,
165159
branchResolution,

src/main/scala/io/iohk/ethereum/consensus/mining/TestMiningBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait StdTestMiningBuilder
2020
with ActorSystemBuilder
2121
with BlockchainBuilder
2222
with BlockQueueBuilder
23-
with BlockImportBuilder
23+
with ConsensusBuilder
2424
with StorageBuilder
2525
with BlockchainConfigBuilder
2626
with NodeKeyBuilder

src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ package io.iohk.ethereum.jsonrpc
33
import akka.actor.ActorRef
44
import akka.util.ByteString
55
import akka.util.Timeout
6-
76
import monix.eval.Task
87
import monix.execution.Scheduler
98

109
import scala.concurrent.duration._
1110
import scala.util.Failure
1211
import scala.util.Success
1312
import scala.util.Try
14-
1513
import org.bouncycastle.util.encoders.Hex
16-
1714
import io.iohk.ethereum.blockchain.data.GenesisAccount
1815
import io.iohk.ethereum.blockchain.data.GenesisData
1916
import io.iohk.ethereum.blockchain.data.GenesisDataLoader
17+
import io.iohk.ethereum.blockchain.sync.regular.{BlockEnqueued, BlockImportResult, BlockImportedToTop, ChainReorganised}
2018
import io.iohk.ethereum.consensus.blocks._
2119
import io.iohk.ethereum.consensus.mining.MiningConfig
2220
import io.iohk.ethereum.crypto
@@ -34,7 +32,6 @@ import io.iohk.ethereum.domain.BlockchainReader
3432
import io.iohk.ethereum.domain.BlockchainWriter
3533
import io.iohk.ethereum.domain.UInt256
3634
import io.iohk.ethereum.jsonrpc.JsonMethodsImplicits._
37-
import io.iohk.ethereum.ledger._
3835
import io.iohk.ethereum.nodebuilder.TestNode
3936
import io.iohk.ethereum.rlp
4037
import io.iohk.ethereum.rlp.RLPList
@@ -261,8 +258,8 @@ class TestService(
261258
getBlockForMining(blockchainReader.getBestBlock().get)
262259
.flatMap(blockForMining =>
263260
testModeComponentsProvider
264-
.blockImport(preimageCache)
265-
.importBlock(blockForMining.block)
261+
.evaluateBranchBlock(preimageCache)
262+
.evaluateBranchBlock(blockForMining.block)
266263
)
267264
.map { res =>
268265
log.info("Block mining result: " + res)
@@ -301,8 +298,8 @@ class TestService(
301298
Task.now(Left(JsonRpcError(-1, "block validation failed!", None)))
302299
case Success(value) =>
303300
testModeComponentsProvider
304-
.blockImport(preimageCache)
305-
.importBlock(value)
301+
.evaluateBranchBlock(preimageCache)
302+
.evaluateBranchBlock(value)
306303
.flatMap(handleResult(value))
307304
}
308305

0 commit comments

Comments
 (0)