Skip to content

Commit 041dfb0

Browse files
author
Aurélien Richez
committed
[ETCM-856] fix fork block number handling in tests
1 parent f144be7 commit 041dfb0

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

src/main/resources/conf/testmode.conf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ mantis {
4848
}
4949
}
5050

51-
network.rpc {
52-
apis = "eth,web3,net,personal,mantis,test,iele,debug,qa,checkpointing"
51+
network {
52+
rpc {
53+
apis = "eth,web3,net,personal,mantis,test,iele,debug,qa,checkpointing"
54+
}
55+
automatic-port-forwarding = false
5356
}
57+
5458
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ object TestJsonMethodsImplicits extends JsonMethodsImplicits {
8989
constantinopleForkBlock <- optionalQuantity(blockchainParamsJson \ "constantinopleForkBlock")
9090
istanbulForkBlock <- optionalQuantity(blockchainParamsJson \ "istanbulForkBlock")
9191
} yield BlockchainParams(
92-
eIP150ForkBlock.getOrElse(0),
93-
eIP158ForkBlock.getOrElse(0),
94-
accountStartNonce.getOrElse(0),
95-
allowFutureBlocks,
96-
blockReward.getOrElse(0),
97-
byzantiumForkBlock.getOrElse(0),
98-
homesteadForkBlock.getOrElse(0),
99-
0,
100-
constantinopleForkBlock.getOrElse(0),
101-
istanbulForkBlock.getOrElse(0)
92+
EIP150ForkBlock = eIP150ForkBlock,
93+
EIP158ForkBlock = eIP158ForkBlock,
94+
accountStartNonce = accountStartNonce.getOrElse(0),
95+
allowFutureBlocks = allowFutureBlocks,
96+
blockReward = blockReward.getOrElse(0),
97+
byzantiumForkBlock = byzantiumForkBlock,
98+
homesteadForkBlock = homesteadForkBlock,
99+
maximumExtraDataSize = 0,
100+
constantinopleForkBlock = constantinopleForkBlock,
101+
istanbulForkBlock = istanbulForkBlock
102102
)
103103
}
104104

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ object TestService {
3535
mixHash: ByteString
3636
)
3737
case class BlockchainParams(
38-
EIP150ForkBlock: BigInt,
39-
EIP158ForkBlock: BigInt,
38+
EIP150ForkBlock: Option[BigInt],
39+
EIP158ForkBlock: Option[BigInt],
4040
accountStartNonce: BigInt,
4141
allowFutureBlocks: Boolean,
4242
blockReward: BigInt,
43-
byzantiumForkBlock: BigInt,
44-
homesteadForkBlock: BigInt,
43+
byzantiumForkBlock: Option[BigInt],
44+
homesteadForkBlock: Option[BigInt],
4545
maximumExtraDataSize: BigInt,
46-
constantinopleForkBlock: BigInt,
47-
istanbulForkBlock: BigInt
46+
constantinopleForkBlock: Option[BigInt],
47+
istanbulForkBlock: Option[BigInt]
4848
)
4949

5050
case class ChainParams(
@@ -155,19 +155,44 @@ class TestService(
155155
// load the new genesis
156156
val genesisDataLoader = new GenesisDataLoader(blockchain, newBlockchainConfig)
157157
genesisDataLoader.loadGenesisData(genesisData)
158+
158159
//save account codes to world state
159160
storeGenesisAccountCodes(genesisData.alloc)
160161
storeGenesisAccountStorageData(genesisData.alloc)
161162

162163
// update test ledger with new config
163164
testLedgerWrapper.blockchainConfig = newBlockchainConfig
165+
consensus.blockchainConfig = newBlockchainConfig
164166

165167
accountAddresses = genesisData.alloc.keys.toList
166168
accountRangeOffset = 0
167169

168170
SetChainParamsResponse().rightNow
169171
}
170172

173+
private def buildNewConfig(blockchainParams: BlockchainParams) = {
174+
val byzantiumBlockNumber: BigInt = blockchainParams.byzantiumForkBlock.getOrElse(Int.MaxValue)
175+
val istanbulForkBlockNumber: BigInt = blockchainParams.istanbulForkBlock.getOrElse(Int.MaxValue)
176+
177+
// For block number which are not specified by retesteth, we try to align the number to another fork
178+
testLedgerWrapper.blockchainConfig.copy(
179+
homesteadBlockNumber = blockchainParams.homesteadForkBlock.getOrElse(Int.MaxValue),
180+
eip150BlockNumber = blockchainParams.EIP150ForkBlock.getOrElse(Int.MaxValue),
181+
eip160BlockNumber = byzantiumBlockNumber,
182+
eip161BlockNumber = byzantiumBlockNumber,
183+
byzantiumBlockNumber = byzantiumBlockNumber,
184+
constantinopleBlockNumber = blockchainParams.constantinopleForkBlock.getOrElse(Int.MaxValue),
185+
petersburgBlockNumber = istanbulForkBlockNumber,
186+
aghartaBlockNumber = istanbulForkBlockNumber,
187+
istanbulBlockNumber = istanbulForkBlockNumber,
188+
atlantisBlockNumber = istanbulForkBlockNumber,
189+
phoenixBlockNumber = istanbulForkBlockNumber,
190+
accountStartNonce = UInt256(blockchainParams.accountStartNonce),
191+
networkId = 1,
192+
bootstrapNodes = Set()
193+
)
194+
}
195+
171196
private def storeGenesisAccountCodes(accounts: Map[String, GenesisAccount]): Unit =
172197
accounts
173198
.collect { case (_, GenesisAccount(_, _, Some(code), _, _)) => code }

src/main/scala/io/iohk/ethereum/testmode/TestmodeConsensus.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import io.iohk.ethereum.consensus.pow.validators.ValidatorsExecutor
2020
class TestmodeConsensus(
2121
override val vm: VMImpl,
2222
blockchain: BlockchainImpl,
23-
blockchainConfig: BlockchainConfig,
23+
var blockchainConfig: BlockchainConfig,
2424
consensusConfig: ConsensusConfig,
2525
override val difficultyCalculator: DifficultyCalculator,
2626
var blockTimestamp: Long = 0
@@ -68,14 +68,14 @@ class TestmodeConsensus(
6868

6969
override def validators: Validators = ValidatorsExecutor.apply(blockchainConfig, Protocol.MockedPow)
7070

71-
override val blockPreparator: BlockPreparator = new BlockPreparator(
71+
override def blockPreparator: BlockPreparator = new BlockPreparator(
7272
vm = vm,
7373
signedTxValidator = validators.signedTransactionValidator,
7474
blockchain = blockchain,
7575
blockchainConfig = blockchainConfig
7676
)
7777

78-
override val blockGenerator =
78+
override def blockGenerator =
7979
new NoOmmersBlockGenerator(
8080
blockchain,
8181
blockchainConfig,

0 commit comments

Comments
 (0)