Skip to content

Commit 1fafffd

Browse files
authored
Mutable BlockchainConfig in TestNode (#1038)
1 parent 2e078af commit 1fafffd

File tree

92 files changed

+891
-767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+891
-767
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ import io.iohk.ethereum.blockchain.sync.regular.BlockImporter
2727
import io.iohk.ethereum.blockchain.sync.regular.BlockImporter.NewCheckpoint
2828
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
2929
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
30-
import io.iohk.ethereum.consensus.mining.GetBlockHeaderByHash
31-
import io.iohk.ethereum.consensus.mining.GetNBlocksBack
3230
import io.iohk.ethereum.consensus.pow.validators.OmmersValidator
3331
import io.iohk.ethereum.consensus.pow.validators.StdOmmersValidator
3432
import io.iohk.ethereum.consensus.validators.Validators
3533
import io.iohk.ethereum.crypto
3634
import io.iohk.ethereum.domain._
3735
import io.iohk.ethereum.mpt.MerklePatriciaTrie
36+
import io.iohk.ethereum.utils.BlockchainConfig
3837
import io.iohk.ethereum.utils.Config
3938
import io.iohk.ethereum.utils.Config.SyncConfig
4039

@@ -67,7 +66,8 @@ class BlockImporterItSpec
6766
ommersPoolProbe.ref,
6867
broadcasterProbe.ref,
6968
pendingTransactionsManagerProbe.ref,
70-
supervisor.ref
69+
supervisor.ref,
70+
this
7171
)
7272
)
7373

@@ -180,7 +180,8 @@ class BlockImporterItSpec
180180
ommersPoolProbe.ref,
181181
broadcasterProbe.ref,
182182
pendingTransactionsManagerProbe.ref,
183-
supervisor.ref
183+
supervisor.ref,
184+
this
184185
)
185186
)
186187

@@ -232,15 +233,7 @@ class TestFixture extends TestSetupWithVmAndValidators {
232233
)
233234

234235
override protected lazy val successValidators: Validators = new Mocks.MockValidatorsAlwaysSucceed {
235-
override val ommersValidator: OmmersValidator = (
236-
parentHash: ByteString,
237-
blockNumber: BigInt,
238-
ommers: Seq[BlockHeader],
239-
getBlockHeaderByHash: GetBlockHeaderByHash,
240-
getNBlocksBack: GetNBlocksBack
241-
) =>
242-
new StdOmmersValidator(blockHeaderValidator)
243-
.validate(parentHash, blockNumber, ommers, getBlockHeaderByHash, getNBlocksBack)
236+
override val ommersValidator: OmmersValidator = new StdOmmersValidator(blockHeaderValidator)
244237
}
245238

246239
override lazy val blockImport: BlockImport = mkBlockImport(
@@ -251,14 +244,13 @@ class TestFixture extends TestSetupWithVmAndValidators {
251244
blockchainReader,
252245
blockchainWriter,
253246
storagesInstance.storages.evmCodeStorage,
254-
blockchainConfig,
255247
mining.blockPreparator,
256248
new BlockValidation(mining, blockchainReader, blockQueue)
257249
) {
258250
override def executeAndValidateBlock(
259251
block: Block,
260252
alreadyValidated: Boolean = false
261-
): Either[BlockExecutionError, Seq[Receipt]] =
253+
)(implicit blockchainConfig: BlockchainConfig): Either[BlockExecutionError, Seq[Receipt]] =
262254
Right(BlockResult(emptyWorld).receipts)
263255
}
264256
)
@@ -276,7 +268,8 @@ class TestFixture extends TestSetupWithVmAndValidators {
276268
ommersPoolProbe.ref,
277269
broadcasterProbe.ref,
278270
pendingTransactionsManagerProbe.ref,
279-
supervisor.ref
271+
supervisor.ref,
272+
this
280273
)
281274
)
282275

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import io.iohk.ethereum.network.handshaker.EtcHandshakerConfiguration
6363
import io.iohk.ethereum.network.handshaker.Handshaker
6464
import io.iohk.ethereum.network.rlpx.AuthHandshaker
6565
import io.iohk.ethereum.network.rlpx.RLPxConnectionHandler.RLPxConfiguration
66+
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
6667
import io.iohk.ethereum.nodebuilder.PruningConfigBuilder
6768
import io.iohk.ethereum.security.SecureRandomBuilder
6869
import io.iohk.ethereum.sync.util.SyncCommonItSpec._
@@ -73,7 +74,8 @@ import io.iohk.ethereum.vm.EvmConfig
7374

7475
abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCustomConfig)
7576
extends SecureRandomBuilder
76-
with TestSyncConfig {
77+
with TestSyncConfig
78+
with BlockchainConfigBuilder {
7779
implicit val akkaTimeout: Timeout = Timeout(5.second)
7880

7981
val config = Config.config
@@ -120,7 +122,7 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
120122
override lazy val dataSource: RocksDbDataSource =
121123
RocksDbDataSource(getRockDbTestConfig(tempDir.toAbsolutePath.toString), Namespaces.nsSeq)
122124
}
123-
lazy val blockchainConfig = Config.blockchains.blockchainConfig
125+
implicit override lazy val blockchainConfig: BlockchainConfig = Config.blockchains.blockchainConfig
124126
lazy val discoveryConfig: DiscoveryConfig = DiscoveryConfig(Config.config, blockchainConfig.bootstrapNodes)
125127

126128
/** Default persist interval is 20s, which is too long for tests. As in all tests we treat peer as connected when

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ object FastSyncItSpecUtils {
4545
etcPeerManager,
4646
blacklist,
4747
testSyncConfig,
48-
system.scheduler
48+
system.scheduler,
49+
this
4950
)
5051
)
5152

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ object RegularSyncItSpecUtils {
5555
stateRootHash: ByteString,
5656
receipts: Seq[Receipt],
5757
gasUsed: BigInt
58-
): Either[BlockExecutionError, BlockExecutionSuccess] = Right(BlockExecutionSuccess)
58+
)(implicit blockchainConfig: BlockchainConfig): Either[BlockExecutionError, BlockExecutionSuccess] = Right(
59+
BlockExecutionSuccess
60+
)
5961
}
6062

6163
object ValidatorsExecutorAlwaysSucceed extends ValidatorsExecutorAlwaysSucceed
@@ -74,7 +76,6 @@ object RegularSyncItSpecUtils {
7476
storagesInstance.storages.evmCodeStorage,
7577
bl,
7678
blockchainReader,
77-
blockchainConfig,
7879
fullConfig,
7980
ValidatorsExecutorAlwaysSucceed,
8081
NoAdditionalPoWData
@@ -99,7 +100,6 @@ object RegularSyncItSpecUtils {
99100
blockchainReader,
100101
blockchainWriter,
101102
storagesInstance.storages.evmCodeStorage,
102-
blockchainConfig,
103103
mining.blockPreparator,
104104
blockValidation
105105
)
@@ -154,7 +154,8 @@ object RegularSyncItSpecUtils {
154154
ommersPool,
155155
broadcasterRef,
156156
pendingTransactionsManager,
157-
regularSync
157+
regularSync,
158+
this
158159
)
159160
)
160161

@@ -173,7 +174,8 @@ object RegularSyncItSpecUtils {
173174
testSyncConfig,
174175
ommersPool,
175176
pendingTransactionsManager,
176-
system.scheduler
177+
system.scheduler,
178+
this
177179
)
178180
)
179181

src/it/scala/io/iohk/ethereum/txExecTest/ContractTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class ContractTest extends AnyFlatSpec with Matchers {
2929
blockchainReader,
3030
blockchainWriter,
3131
testBlockchainStorages.evmCodeStorage,
32-
blockchainConfig,
3332
mining.blockPreparator,
3433
blockValidation
3534
)

src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
2323
val EraDuration = 3
2424

2525
trait TestSetup extends ScenarioSetup {
26-
override lazy val blockchainConfig: BlockchainConfig = BlockchainConfig(
26+
implicit override lazy val blockchainConfig: BlockchainConfig = BlockchainConfig(
2727
monetaryPolicyConfig = MonetaryPolicyConfig(EraDuration, 0.2, 5000000000000000000L, 3000000000000000000L),
2828
// unused
2929
maxCodeSize = None,
@@ -91,7 +91,6 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
9191
blockchainReader,
9292
blockchainWriter,
9393
testBlockchainStorages.evmCodeStorage,
94-
blockchainConfig,
9594
mining.blockPreparator,
9695
blockValidation
9796
)

src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import io.iohk.ethereum.utils.MonetaryPolicyConfig
2121
class ForksTest extends AnyFlatSpec with Matchers {
2222

2323
trait TestSetup extends ScenarioSetup {
24-
override lazy val blockchainConfig: BlockchainConfig = BlockchainConfig(
24+
implicit override lazy val blockchainConfig: BlockchainConfig = BlockchainConfig(
2525
forkBlockNumbers = ForkBlockNumbers(
2626
frontierBlockNumber = 0,
2727
homesteadBlockNumber = 3,
@@ -84,7 +84,6 @@ class ForksTest extends AnyFlatSpec with Matchers {
8484
blockchainReader,
8585
blockchainWriter,
8686
testBlockchainStorages.evmCodeStorage,
87-
blockchainConfig,
8887
mining.blockPreparator,
8988
blockValidation
9089
)

src/main/scala/io/iohk/ethereum/blockchain/data/GenesisDataLoader.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import io.iohk.ethereum.utils.Logger
3838
class GenesisDataLoader(
3939
blockchainReader: BlockchainReader,
4040
blockchainWriter: BlockchainWriter,
41-
stateStorage: StateStorage,
42-
blockchainConfig: BlockchainConfig
41+
stateStorage: StateStorage
4342
) extends Logger {
4443

4544
private val bloomLength = 512
@@ -49,9 +48,8 @@ class GenesisDataLoader(
4948
import Account._
5049

5150
private val emptyTrieRootHash = ByteString(crypto.kec256(rlp.encode(Array.emptyByteArray)))
52-
crypto.kec256(ByteString.empty)
5351

54-
def loadGenesisData(): Unit = {
52+
def loadGenesisData()(implicit blockchainConfig: BlockchainConfig): Unit = {
5553
log.debug("Loading genesis data")
5654

5755
val genesisJson = blockchainConfig.customGenesisJsonOpt.getOrElse {
@@ -89,7 +87,7 @@ class GenesisDataLoader(
8987
}
9088
}
9189

92-
private def loadGenesisData(genesisJson: String): Try[Unit] = {
90+
private def loadGenesisData(genesisJson: String)(implicit blockchainConfig: BlockchainConfig): Try[Unit] = {
9391
import org.json4s.native.JsonMethods.parse
9492
implicit val formats: Formats = DefaultFormats + ByteStringJsonSerializer + UInt256JsonSerializer
9593
for {
@@ -98,7 +96,7 @@ class GenesisDataLoader(
9896
} yield ()
9997
}
10098

101-
def loadGenesisData(genesisData: GenesisData): Try[Unit] = {
99+
def loadGenesisData(genesisData: GenesisData)(implicit blockchainConfig: BlockchainConfig): Try[Unit] = {
102100

103101
val storage = stateStorage.getReadOnlyStorage
104102
val initalRootHash = MerklePatriciaTrie.EmptyRootHash
@@ -132,7 +130,9 @@ class GenesisDataLoader(
132130
}
133131
}
134132

135-
private def getGenesisStateRoot(genesisData: GenesisData, initalRootHash: Array[Byte], storage: MptStorage) = {
133+
private def getGenesisStateRoot(genesisData: GenesisData, initalRootHash: Array[Byte], storage: MptStorage)(implicit
134+
blockchainConfig: BlockchainConfig
135+
) = {
136136
import MerklePatriciaTrie.defaultByteArraySerializable
137137

138138
genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) { case (rootHash, ((address, genesisAccount), _)) =>

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import io.iohk.ethereum.domain.BlockchainReader
2020
import io.iohk.ethereum.domain.BlockchainWriter
2121
import io.iohk.ethereum.ledger.BlockImport
2222
import io.iohk.ethereum.ledger.BranchResolution
23+
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
2324
import io.iohk.ethereum.utils.Config.SyncConfig
2425

2526
class SyncController(
@@ -39,6 +40,7 @@ class SyncController(
3940
etcPeerManager: ActorRef,
4041
blacklist: Blacklist,
4142
syncConfig: SyncConfig,
43+
configBuilder: BlockchainConfigBuilder,
4244
externalSchedulerOpt: Option[Scheduler] = None
4345
) extends Actor
4446
with ActorLogging {
@@ -105,7 +107,8 @@ class SyncController(
105107
etcPeerManager,
106108
blacklist,
107109
syncConfig,
108-
scheduler
110+
scheduler,
111+
configBuilder
109112
),
110113
"fast-sync"
111114
)
@@ -131,7 +134,8 @@ class SyncController(
131134
syncConfig,
132135
ommersPool,
133136
pendingTransactionsManager,
134-
scheduler
137+
scheduler,
138+
configBuilder
135139
),
136140
"regular-sync"
137141
)
@@ -159,7 +163,8 @@ object SyncController {
159163
ommersPool: ActorRef,
160164
etcPeerManager: ActorRef,
161165
blacklist: Blacklist,
162-
syncConfig: SyncConfig
166+
syncConfig: SyncConfig,
167+
configBuilder: BlockchainConfigBuilder
163168
): Props =
164169
Props(
165170
new SyncController(
@@ -178,7 +183,8 @@ object SyncController {
178183
ommersPool,
179184
etcPeerManager,
180185
blacklist,
181-
syncConfig
186+
syncConfig,
187+
configBuilder
182188
)
183189
)
184190
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import io.iohk.ethereum.network.Peer
4646
import io.iohk.ethereum.network.p2p.messages.Codes
4747
import io.iohk.ethereum.network.p2p.messages.ETH62._
4848
import io.iohk.ethereum.network.p2p.messages.ETH63._
49+
import io.iohk.ethereum.nodebuilder.BlockchainConfigBuilder
4950
import io.iohk.ethereum.utils.ByteStringUtils
5051
import io.iohk.ethereum.utils.Config.SyncConfig
5152

@@ -64,13 +65,15 @@ class FastSync(
6465
val etcPeerManager: ActorRef,
6566
val blacklist: Blacklist,
6667
val syncConfig: SyncConfig,
67-
implicit val scheduler: Scheduler
68+
implicit val scheduler: Scheduler,
69+
configBuilder: BlockchainConfigBuilder
6870
) extends Actor
6971
with ActorLogging
7072
with PeerListSupportNg
7173
with ReceiptsValidator
7274
with SyncBlocksValidator {
7375

76+
import configBuilder._
7477
import FastSync._
7578
import syncConfig._
7679

@@ -1160,7 +1163,8 @@ object FastSync {
11601163
etcPeerManager: ActorRef,
11611164
blacklist: Blacklist,
11621165
syncConfig: SyncConfig,
1163-
scheduler: Scheduler
1166+
scheduler: Scheduler,
1167+
configBuilder: BlockchainConfigBuilder
11641168
): Props =
11651169
Props(
11661170
new FastSync(
@@ -1177,7 +1181,8 @@ object FastSync {
11771181
etcPeerManager,
11781182
blacklist,
11791183
syncConfig,
1180-
scheduler
1184+
scheduler,
1185+
configBuilder
11811186
)
11821187
)
11831188

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.iohk.ethereum.consensus.validators.Validators
99
import io.iohk.ethereum.domain.BlockBody
1010
import io.iohk.ethereum.domain.BlockHeader
1111
import io.iohk.ethereum.domain.BlockchainReader
12+
import io.iohk.ethereum.utils.BlockchainConfig
1213

1314
trait SyncBlocksValidator { this: ActorLogging =>
1415

@@ -37,7 +38,9 @@ trait SyncBlocksValidator { this: ActorLogging =>
3738
case (invalid, _) => invalid
3839
}
3940

40-
def validateHeaderOnly(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
41+
def validateHeaderOnly(blockHeader: BlockHeader)(implicit
42+
blockchainConfig: BlockchainConfig
43+
): Either[BlockHeaderError, BlockHeaderValid] =
4144
validators.blockHeaderValidator.validateHeaderOnly(blockHeader)
4245

4346
def checkHeadersChain(headers: Seq[BlockHeader]): Boolean =

0 commit comments

Comments
 (0)