Skip to content

Commit 022a5ae

Browse files
author
Nicolás Tallar
authored
[CHORE] BlockchainConfig as a case class (#674)
1 parent d974866 commit 022a5ae

File tree

19 files changed

+711
-732
lines changed

19 files changed

+711
-732
lines changed

src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala

Lines changed: 276 additions & 271 deletions
Large diffs are not rendered by default.

src/ets/scala/io/iohk/ethereum/ets/blockchain/ScenarioSetup.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ object ScenarioSetup {
4343

4444
abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
4545

46+
import BlockchainTestConfig._
47+
4648
// according to: https://github.com/ethereum/tests/issues/480 only "NoProof" value should change our current implementation
4749
def shouldSkipPoW: Boolean = scenario.sealEngine.contains("NoProof")
4850

@@ -101,7 +103,7 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
101103
if (shouldSkipPoW) withSkippedPoWValidationBlockchainConfig(network) else baseBlockchainConfig(network)
102104
}
103105

104-
private def baseBlockchainConfig(network: String): (BlockchainTestConfig, EthashValidators) = network match {
106+
private def baseBlockchainConfig(network: String): (BlockchainConfig, EthashValidators) = network match {
105107
case "EIP150" => (Eip150Config, Validators.eip150Validators)
106108
case "Frontier" => (FrontierConfig, Validators.frontierValidators)
107109
case "Homestead" => (HomesteadConfig, Validators.homesteadValidators)
@@ -119,7 +121,7 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
119121
case _ => (FrontierConfig, Validators.frontierValidators)
120122
}
121123

122-
private def withSkippedPoWValidationBlockchainConfig(network: String): (BlockchainTestConfig, EthashValidators) = network match {
124+
private def withSkippedPoWValidationBlockchainConfig(network: String): (BlockchainConfig, EthashValidators) = network match {
123125
case "EIP150" => (Eip150Config, ValidatorsWithSkippedPoW.eip150Validators)
124126
case "Frontier" => (FrontierConfig, ValidatorsWithSkippedPoW.frontierValidators)
125127
case "Homestead" => (HomesteadConfig, ValidatorsWithSkippedPoW.homesteadValidators)

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.util.concurrent.Executors
55
import io.iohk.ethereum.domain.{ BlockchainImpl, Receipt, UInt256 }
66
import io.iohk.ethereum.ledger._
77
import io.iohk.ethereum.txExecTest.util.FixtureProvider
8-
import io.iohk.ethereum.utils.{ BlockchainConfig, DaoForkConfig, MonetaryPolicyConfig }
8+
import io.iohk.ethereum.utils.{ BlockchainConfig, MonetaryPolicyConfig }
99
import org.scalatest.{ FlatSpec, Matchers }
1010

1111
import scala.concurrent.ExecutionContext
@@ -15,39 +15,39 @@ class ECIP1017Test extends FlatSpec with Matchers {
1515
val EraDuration = 3
1616

1717
trait TestSetup extends ScenarioSetup {
18-
override lazy val blockchainConfig = new BlockchainConfig {
19-
override val monetaryPolicyConfig: MonetaryPolicyConfig =
20-
MonetaryPolicyConfig(EraDuration, 0.2, 5000000000000000000L, 3000000000000000000L)
18+
override lazy val blockchainConfig = BlockchainConfig (
19+
monetaryPolicyConfig =
20+
MonetaryPolicyConfig(EraDuration, 0.2, 5000000000000000000L, 3000000000000000000L),
2121

2222
// unused
23-
override val maxCodeSize: Option[BigInt] = None
24-
override val chainId: Byte = 0x3d.toByte
25-
override val networkId: Int = 1
26-
override val frontierBlockNumber: BigInt = 0
27-
override val homesteadBlockNumber: BigInt = 1150000
28-
override val eip106BlockNumber: BigInt = Long.MaxValue
29-
override val eip150BlockNumber: BigInt = 2500000
30-
override val eip160BlockNumber: BigInt = 3000000
31-
override val eip155BlockNumber: BigInt = 3000000
32-
override val eip161BlockNumber: BigInt = Long.MaxValue
33-
override val byzantiumBlockNumber: BigInt = Long.MaxValue
34-
override val constantinopleBlockNumber: BigInt = Long.MaxValue
35-
override val istanbulBlockNumber: BigInt = Long.MaxValue
36-
override val customGenesisFileOpt: Option[String] = None
37-
override val daoForkConfig: Option[DaoForkConfig] = None
38-
override val difficultyBombPauseBlockNumber: BigInt = Long.MaxValue
39-
override val difficultyBombContinueBlockNumber: BigInt = Long.MaxValue
40-
override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue
41-
override val bootstrapNodes: Set[String] = Set()
42-
override val accountStartNonce: UInt256 = UInt256.Zero
43-
override val ethCompatibleStorage: Boolean = true
23+
maxCodeSize = None,
24+
chainId = 0x3d.toByte,
25+
networkId = 1,
26+
frontierBlockNumber = 0,
27+
homesteadBlockNumber = 1150000,
28+
eip106BlockNumber = Long.MaxValue,
29+
eip150BlockNumber = 2500000,
30+
eip160BlockNumber = 3000000,
31+
eip155BlockNumber = 3000000,
32+
eip161BlockNumber = Long.MaxValue,
33+
byzantiumBlockNumber = Long.MaxValue,
34+
constantinopleBlockNumber = Long.MaxValue,
35+
istanbulBlockNumber = Long.MaxValue,
36+
customGenesisFileOpt = None,
37+
daoForkConfig = None,
38+
difficultyBombPauseBlockNumber = Long.MaxValue,
39+
difficultyBombContinueBlockNumber = Long.MaxValue,
40+
difficultyBombRemovalBlockNumber = Long.MaxValue,
41+
bootstrapNodes = Set(),
42+
accountStartNonce = UInt256.Zero,
43+
ethCompatibleStorage = true,
4444

45-
val gasTieBreaker: Boolean = false
46-
override val atlantisBlockNumber: BigInt = Long.MaxValue
47-
override val aghartaBlockNumber: BigInt = Long.MaxValue
48-
override val phoenixBlockNumber: BigInt = Long.MaxValue
49-
override val petersburgBlockNumber: BigInt = Long.MaxValue
50-
}
45+
gasTieBreaker = false,
46+
atlantisBlockNumber = Long.MaxValue,
47+
aghartaBlockNumber = Long.MaxValue,
48+
phoenixBlockNumber = Long.MaxValue,
49+
petersburgBlockNumber = Long.MaxValue
50+
)
5151
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
5252

5353
val noErrors = a[Right[_, Seq[Receipt]]]

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.util.concurrent.Executors
55
import io.iohk.ethereum.domain.{ BlockchainImpl, Receipt, UInt256 }
66
import io.iohk.ethereum.ledger.{ BlockExecution, BlockQueue, BlockValidation }
77
import io.iohk.ethereum.txExecTest.util.FixtureProvider
8-
import io.iohk.ethereum.utils.{ BlockchainConfig, DaoForkConfig, MonetaryPolicyConfig }
8+
import io.iohk.ethereum.utils.{ BlockchainConfig, MonetaryPolicyConfig }
99
import org.scalatest.{ FlatSpec, Matchers }
1010

1111
import scala.concurrent.ExecutionContext
@@ -14,37 +14,37 @@ import scala.concurrent.ExecutionContext
1414
class ForksTest extends FlatSpec with Matchers {
1515

1616
trait TestSetup extends ScenarioSetup {
17-
override lazy val blockchainConfig = new BlockchainConfig {
18-
override val frontierBlockNumber: BigInt = 0
19-
override val homesteadBlockNumber: BigInt = 3
20-
override val eip150BlockNumber: BigInt = 5
21-
override val eip160BlockNumber: BigInt = 7
22-
override val eip155BlockNumber: BigInt = 0
23-
override val eip106BlockNumber: BigInt = Long.MaxValue
24-
override val chainId: Byte = 0x3d.toByte
25-
override val monetaryPolicyConfig: MonetaryPolicyConfig = MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L)
17+
override lazy val blockchainConfig = BlockchainConfig (
18+
frontierBlockNumber = 0,
19+
homesteadBlockNumber = 3,
20+
eip150BlockNumber = 5,
21+
eip160BlockNumber = 7,
22+
eip155BlockNumber = 0,
23+
eip106BlockNumber = Long.MaxValue,
24+
chainId = 0x3d.toByte,
25+
monetaryPolicyConfig = MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L),
2626

2727
// unused
28-
override val bootstrapNodes: Set[String] = Set()
29-
override val networkId: Int = 1
30-
override val maxCodeSize: Option[BigInt] = None
31-
override val eip161BlockNumber: BigInt = Long.MaxValue
32-
override val customGenesisFileOpt: Option[String] = None
33-
override val difficultyBombPauseBlockNumber: BigInt = Long.MaxValue
34-
override val difficultyBombContinueBlockNumber: BigInt = Long.MaxValue
35-
override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue
36-
override val byzantiumBlockNumber: BigInt = Long.MaxValue
37-
override val constantinopleBlockNumber: BigInt = Long.MaxValue
38-
override val istanbulBlockNumber: BigInt = Long.MaxValue
39-
override val accountStartNonce: UInt256 = UInt256.Zero
40-
override val daoForkConfig: Option[DaoForkConfig] = None
41-
override val gasTieBreaker: Boolean = false
42-
override val ethCompatibleStorage: Boolean = true
43-
override val atlantisBlockNumber: BigInt = Long.MaxValue
44-
override val aghartaBlockNumber: BigInt = Long.MaxValue
45-
override val phoenixBlockNumber: BigInt = Long.MaxValue
46-
override val petersburgBlockNumber: BigInt = Long.MaxValue
47-
}
28+
bootstrapNodes = Set(),
29+
networkId = 1,
30+
maxCodeSize = None,
31+
eip161BlockNumber = Long.MaxValue,
32+
customGenesisFileOpt = None,
33+
difficultyBombPauseBlockNumber = Long.MaxValue,
34+
difficultyBombContinueBlockNumber = Long.MaxValue,
35+
difficultyBombRemovalBlockNumber = Long.MaxValue,
36+
byzantiumBlockNumber = Long.MaxValue,
37+
constantinopleBlockNumber = Long.MaxValue,
38+
istanbulBlockNumber = Long.MaxValue,
39+
accountStartNonce = UInt256.Zero,
40+
daoForkConfig = None,
41+
gasTieBreaker = false,
42+
ethCompatibleStorage = true,
43+
atlantisBlockNumber = Long.MaxValue,
44+
aghartaBlockNumber = Long.MaxValue,
45+
phoenixBlockNumber = Long.MaxValue,
46+
petersburgBlockNumber = Long.MaxValue
47+
)
4848

4949
val noErrors = a[Right[_, Seq[Receipt]]]
5050
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))

src/main/resources/chains/mordor.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
# https://blog.ethereum.org/2016/07/20/hard-fork-completed/
8383
dao = null
8484

85-
8685
# Starting nonce of an empty account. Some networks (like Morden) use different values.
8786
account-start-nonce = "0"
8887

src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ abstract class BlockGeneratorSkeleton(
5151
blockTimestamp: Long,
5252
x: Ommers
5353
): BlockHeader =
54-
BlockHeader(
55-
parentHash = parent.header.hash,
56-
ommersHash = ByteString(kec256(x.toBytes: Array[Byte])),
57-
beneficiary = beneficiary.bytes,
58-
stateRoot = ByteString.empty,
59-
//we are not able to calculate transactionsRoot here because we do not know if they will fail
60-
transactionsRoot = ByteString.empty,
61-
receiptsRoot = ByteString.empty,
62-
logsBloom = ByteString.empty,
63-
difficulty = difficulty.calculateDifficulty(blockNumber, blockTimestamp, parent.header),
64-
number = blockNumber,
65-
gasLimit = calculateGasLimit(parent.header.gasLimit),
66-
gasUsed = 0,
67-
unixTimestamp = blockTimestamp,
68-
extraData = blockchainConfig.daoForkConfig.flatMap(daoForkConfig => daoForkConfig.getExtraData(blockNumber)).getOrElse(headerExtraData),
69-
mixHash = ByteString.empty,
70-
nonce = ByteString.empty
71-
)
54+
BlockHeader(
55+
parentHash = parent.header.hash,
56+
ommersHash = ByteString(kec256(x.toBytes: Array[Byte])),
57+
beneficiary = beneficiary.bytes,
58+
stateRoot = ByteString.empty,
59+
//we are not able to calculate transactionsRoot here because we do not know if they will fail
60+
transactionsRoot = ByteString.empty,
61+
receiptsRoot = ByteString.empty,
62+
logsBloom = ByteString.empty,
63+
difficulty = difficulty.calculateDifficulty(blockNumber, blockTimestamp, parent.header),
64+
number = blockNumber,
65+
gasLimit = calculateGasLimit(parent.header.gasLimit),
66+
gasUsed = 0,
67+
unixTimestamp = blockTimestamp,
68+
extraData = blockchainConfig.daoForkConfig.flatMap(daoForkConfig => daoForkConfig.getExtraData(blockNumber)).getOrElse(headerExtraData),
69+
mixHash = ByteString.empty,
70+
nonce = ByteString.empty
71+
)
7272

7373
protected def prepareHeader(
7474
blockNumber: BigInt, parent: Block,

src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ abstract class BlockHeaderValidatorSkeleton(blockchainConfig: BlockchainConfig)
162162
private def validateNumber(blockHeader: BlockHeader, parentHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
163163
if(blockHeader.number == parentHeader.number + 1) Right(BlockHeaderValid)
164164
else Left(HeaderNumberError)
165+
165166
}
166167

167168

src/main/scala/io/iohk/ethereum/domain/BlockHeader.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ object BlockHeader {
6262

6363
def getEncodedWithoutNonce(blockHeader: BlockHeader): Array[Byte] = {
6464
val rlpEncoded = blockHeader.toRLPEncodable match {
65-
case rlpList: RLPList => RLPList(rlpList.items.dropRight(2): _*)
65+
case rlpList: RLPList =>
66+
RLPList(rlpList.items.dropRight(2): _*)
67+
6668
case _ => throw new Exception("BlockHeader cannot be encoded without nonce and mixHash")
6769
}
6870
rlpEncode(rlpEncoded)

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

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.iohk.ethereum.domain.{Address, Block, BlockchainImpl, UInt256}
99
import io.iohk.ethereum.testmode.{TestLedgerWrapper, TestmodeConsensus}
1010
import io.iohk.ethereum.transactions.PendingTransactionsManager
1111
import io.iohk.ethereum.transactions.PendingTransactionsManager.PendingTransactionsResponse
12-
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, Logger, MonetaryPolicyConfig}
12+
import io.iohk.ethereum.utils.Logger
1313
import org.bouncycastle.util.encoders.Hex
1414

1515
import scala.concurrent.ExecutionContext.Implicits.global
@@ -61,38 +61,14 @@ class TestService(
6161

6262
private var etherbase: Address = consensusConfig.coinbase
6363

64-
// scalastyle:off method.length
6564
def setChainParams(request: SetChainParamsRequest): ServiceResponse[SetChainParamsResponse] = {
66-
val newBlockchainConfig = new BlockchainConfig {
67-
override val frontierBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.frontierBlockNumber
68-
override val homesteadBlockNumber: BigInt = request.chainParams.blockchainParams.homesteadForkBlock
69-
override val eip106BlockNumber: BigInt = testLedgerWrapper.blockchainConfig.eip106BlockNumber
70-
override val eip150BlockNumber: BigInt = request.chainParams.blockchainParams.EIP150ForkBlock
71-
override val eip155BlockNumber: BigInt = testLedgerWrapper.blockchainConfig.eip155BlockNumber
72-
override val eip160BlockNumber: BigInt = testLedgerWrapper.blockchainConfig.eip160BlockNumber
73-
override val eip161BlockNumber: BigInt = testLedgerWrapper.blockchainConfig.eip161BlockNumber
74-
override val byzantiumBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.byzantiumBlockNumber
75-
override val constantinopleBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.constantinopleBlockNumber
76-
override val istanbulBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.istanbulBlockNumber
77-
override val maxCodeSize: Option[BigInt] = testLedgerWrapper.blockchainConfig.maxCodeSize
78-
override val difficultyBombPauseBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.difficultyBombPauseBlockNumber
79-
override val difficultyBombContinueBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.difficultyBombContinueBlockNumber
80-
override val difficultyBombRemovalBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.difficultyBombRemovalBlockNumber
81-
override val customGenesisFileOpt: Option[String] = testLedgerWrapper.blockchainConfig.customGenesisFileOpt
82-
override val daoForkConfig: Option[DaoForkConfig] = testLedgerWrapper.blockchainConfig.daoForkConfig
83-
override val accountStartNonce: UInt256 = UInt256(request.chainParams.blockchainParams.accountStartNonce)
84-
override val chainId: Byte = testLedgerWrapper.blockchainConfig.chainId
85-
override val networkId: Int = 1
86-
override val monetaryPolicyConfig: MonetaryPolicyConfig = testLedgerWrapper.blockchainConfig.monetaryPolicyConfig
87-
override val gasTieBreaker: Boolean = testLedgerWrapper.blockchainConfig.gasTieBreaker
88-
override val ethCompatibleStorage: Boolean = testLedgerWrapper.blockchainConfig.ethCompatibleStorage
89-
override val bootstrapNodes: Set[String] = Set()
90-
override val atlantisBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.atlantisBlockNumber
91-
override val aghartaBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.aghartaBlockNumber
92-
override val phoenixBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.phoenixBlockNumber
93-
override val petersburgBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.petersburgBlockNumber
94-
}
95-
// scalastyle:on method.length
65+
val newBlockchainConfig = testLedgerWrapper.blockchainConfig.copy(
66+
homesteadBlockNumber = request.chainParams.blockchainParams.homesteadForkBlock,
67+
eip150BlockNumber = request.chainParams.blockchainParams.EIP150ForkBlock,
68+
accountStartNonce = UInt256(request.chainParams.blockchainParams.accountStartNonce),
69+
networkId = 1,
70+
bootstrapNodes = Set()
71+
)
9672

9773
val genesisData = GenesisData(
9874
nonce = ByteString(Hex.decode("00")),

0 commit comments

Comments
 (0)