Skip to content

Commit 08780c1

Browse files
committed
[ETCM-27] Update and check ETS tests
1 parent e223485 commit 08780c1

File tree

9 files changed

+68
-25
lines changed

9 files changed

+68
-25
lines changed

src/ets/resources/ets

Submodule ets updated from 253e998 to 66a55cd

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package io.iohk.ethereum.ets.blockchain
22

33
import java.util.concurrent.Executors
4-
54
import akka.actor.ActorSystem
65
import io.iohk.ethereum.domain.Block
76
import io.iohk.ethereum.ets.common.TestOptions
87
import io.iohk.ethereum.extvm.ExtVMInterface
98
import io.iohk.ethereum.ledger.Ledger.VMImpl
109
import io.iohk.ethereum.nodebuilder.VmSetup
11-
import io.iohk.ethereum.utils.{ Config, Logger, VmConfig}
10+
import io.iohk.ethereum.utils.{Config, Logger, VmConfig}
1211
import org.scalatest._
13-
1412
import scala.concurrent.duration.Duration
1513
import scala.concurrent.{Await, ExecutionContext, Future}
1614

@@ -23,7 +21,9 @@ object BlockchainSuite {
2321
class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with Logger {
2422
import BlockchainSuite.testContext
2523

26-
val unsupportedNetworks: Set[String] = Set()
24+
val unsupportedNetworks: Set[String] = Set(
25+
"Berlin"
26+
)
2727
val supportedNetworks = Set(
2828
"EIP150",
2929
"Frontier",
@@ -35,7 +35,9 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
3535
"Byzantium",
3636
"EIP158ToByzantiumAt5",
3737
"Constantinople",
38-
"ByzantiumToConstantinopleAt5"
38+
"ByzantiumToConstantinopleFixAt5",
39+
"ConstantinopleFix",
40+
"Istanbul"
3941
)
4042
// Map of ignored tests, empty set of ignored names means cancellation of whole group
4143
val ignoredTests: Map[String, Set[String]] = Map()
@@ -107,12 +109,13 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
107109

108110
val lastBlock = getBestBlock
109111

110-
val expectedWorldStateHash = finalWorld.stateRootHash
112+
val expectedWorldStateHash =
113+
scenario.postStateHash.orElse(finalWorld.map(_.stateRootHash)).getOrElse(throw new IllegalStateException("postState or PostStateHash not defined"))
111114

112115
lastBlock shouldBe defined
113116

114-
val expectedState = getExpectedState
115-
val resultState = getResultState
117+
val expectedState = getExpectedState.toList.flatten
118+
val resultState = getResultState.toList.flatten
116119

117120
lastBlock.get.header.hash shouldEqual scenario.lastblockhash
118121
resultState should contain theSameElementsAs expectedState

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ trait BlockchainTestConfig extends BlockchainConfig {
1919
val eip161BlockNumber: BigInt = Long.MaxValue
2020
val byzantiumBlockNumber: BigInt = Long.MaxValue
2121
val constantinopleBlockNumber: BigInt = Long.MaxValue
22+
val petersburgBlockNumber: BigInt = Long.MaxValue
2223
val istanbulBlockNumber: BigInt = Long.MaxValue
2324
// unused
2425
override val maxCodeSize: Option[BigInt] = None
2526
override val difficultyBombPauseBlockNumber: BigInt = 3000000
2627
override val difficultyBombContinueBlockNumber: BigInt = 5000000
2728
override val difficultyBombRemovalBlockNumber: BigInt = 5900000
28-
override val chainId: Byte = 0x3d.toByte
29+
override val chainId: Byte = 0x1.toByte
2930
override val networkId: Int = 1
3031
override val customGenesisFileOpt: Option[String] = Some("test-genesis.json")
3132
override val monetaryPolicyConfig: MonetaryPolicyConfig =
@@ -40,7 +41,6 @@ trait BlockchainTestConfig extends BlockchainConfig {
4041
override val atlantisBlockNumber: BigInt = Long.MaxValue
4142
override val aghartaBlockNumber: BigInt = Long.MaxValue
4243
override val phoenixBlockNumber: BigInt = Long.MaxValue
43-
override val petersburgBlockNumber: BigInt = Long.MaxValue
4444
}
4545

4646
object FrontierConfig extends BlockchainTestConfig {
@@ -229,6 +229,35 @@ object ConstantinopleConfig extends BlockchainTestConfig {
229229
override val monetaryPolicyConfig: MonetaryPolicyConfig =
230230
MonetaryPolicyConfig(5000000, 0.2, BigInt("5000000000000000000"), BigInt("3000000000000000000"), BigInt("2000000000000000000"))
231231
}
232+
object ConstantinopleFixConfig extends BlockchainTestConfig {
233+
override val frontierBlockNumber: BigInt = -1
234+
override val homesteadBlockNumber: BigInt = -1
235+
override val eip150BlockNumber: BigInt = -1
236+
override val eip155BlockNumber: BigInt = -1
237+
override val eip160BlockNumber: BigInt = -1
238+
override val eip161BlockNumber: BigInt = -1
239+
override val maxCodeSize: Option[BigInt] = Some(24576)
240+
override val byzantiumBlockNumber: BigInt = -1
241+
override val constantinopleBlockNumber: BigInt = -1
242+
override val petersburgBlockNumber: BigInt = 0
243+
override val monetaryPolicyConfig: MonetaryPolicyConfig =
244+
MonetaryPolicyConfig(5000000, 0.2, BigInt("5000000000000000000"), BigInt("3000000000000000000"), BigInt("2000000000000000000"))
245+
}
246+
object IstanbulConfig extends BlockchainTestConfig {
247+
override val frontierBlockNumber: BigInt = -1
248+
override val homesteadBlockNumber: BigInt = -1
249+
override val eip150BlockNumber: BigInt = -1
250+
override val eip155BlockNumber: BigInt = -1
251+
override val eip160BlockNumber: BigInt = -1
252+
override val eip161BlockNumber: BigInt = -1
253+
override val maxCodeSize: Option[BigInt] = Some(24576)
254+
override val byzantiumBlockNumber: BigInt = -1
255+
override val constantinopleBlockNumber: BigInt = -1
256+
override val petersburgBlockNumber: BigInt = -1
257+
override val istanbulBlockNumber: BigInt = 0
258+
override val monetaryPolicyConfig: MonetaryPolicyConfig =
259+
MonetaryPolicyConfig(5000000, 0.2, BigInt("5000000000000000000"), BigInt("3000000000000000000"), BigInt("2000000000000000000"))
260+
}
232261
object Eip158ToByzantiumAt5Config extends BlockchainTestConfig {
233262
override val frontierBlockNumber: BigInt = -1
234263
override val homesteadBlockNumber: BigInt = -1
@@ -267,6 +296,8 @@ object Validators {
267296
val eip158Validators = EthashValidators(Eip158Config)
268297
val byzantiumValidators = EthashValidators(ByzantiumConfig)
269298
val constantinopleValidators = EthashValidators(ConstantinopleConfig)
299+
val constantinopleFixValidators = EthashValidators(ConstantinopleFixConfig)
300+
val istanbulValidators = EthashValidators(IstanbulConfig)
270301
val eip158ToByzantiumValidators = EthashValidators(Eip158ToByzantiumAt5Config)
271302
val byzantiumToConstantinopleAt5 = EthashValidators(ByzantiumToConstantinopleAt5)
272303
}
@@ -283,6 +314,8 @@ object ValidatorsWithSkippedPoW {
283314
val eip158Validators = EthashValidators(Eip158Config, new EthashTestBlockHeaderValidator(Eip158Config))
284315
val byzantiumValidators = EthashValidators(ByzantiumConfig, new EthashTestBlockHeaderValidator(ByzantiumConfig))
285316
val constantinopleValidators = EthashValidators(ConstantinopleConfig, new EthashTestBlockHeaderValidator(ConstantinopleConfig))
317+
val constantinopleFixValidators = EthashValidators(ConstantinopleFixConfig, new EthashTestBlockHeaderValidator(ConstantinopleFixConfig))
318+
val istanbulValidators = EthashValidators(IstanbulConfig, new EthashTestBlockHeaderValidator(IstanbulConfig))
286319
val eip158ToByzantiumValidators = EthashValidators(Eip158ToByzantiumAt5Config, new EthashTestBlockHeaderValidator(Eip158ToByzantiumAt5Config))
287320
val byzantiumToConstantinopleAt5 = EthashValidators(ByzantiumToConstantinopleAt5, new EthashTestBlockHeaderValidator(ByzantiumToConstantinopleAt5))
288321
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
6060
val ledger =
6161
new LedgerImpl(
6262
blockchain,
63-
new BlockQueue(blockchain, 10, 10), blockchainConfig, consensus, ScenarioSetup.testContext)
63+
new BlockQueue(blockchain, 50, 50), blockchainConfig, consensus, ScenarioSetup.testContext)
6464

6565
def loadGenesis(): Block = {
6666
val genesisBlock = scenario.genesisRLP match {
@@ -82,20 +82,20 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
8282

8383
val initialWorld: InMemoryWorldStateProxy = InMemoryWorldStateProxy.persistState(getWorldState(scenario.pre))
8484

85-
val finalWorld: InMemoryWorldStateProxy = InMemoryWorldStateProxy.persistState(getWorldState(scenario.postState))
85+
val finalWorld: Option[InMemoryWorldStateProxy] = scenario.postState.map(postState => InMemoryWorldStateProxy.persistState(getWorldState(postState)))
8686

8787
def getBestBlock: Option[Block] = {
8888
val bestBlockNumber = blockchain.getBestBlockNumber()
8989
blockchain.getBlockByNumber(bestBlockNumber)
9090
}
9191

92-
def getExpectedState: List[(Address, Option[Account])] = {
93-
scenario.postState.map((addAcc) => addAcc._1 -> finalWorld.getAccount(addAcc._1)).toList
92+
def getExpectedState: Option[List[(Address, Option[Account])]] = {
93+
finalWorld.map(w => scenario.postState.get.map(addAcc => addAcc._1 -> w.getAccount(addAcc._1)).toList)
9494
}
9595

96-
def getResultState: List[(Address, Option[Account])] = {
96+
def getResultState: Option[List[(Address, Option[Account])]] = {
9797
val bestBlockNumber = blockchain.getBestBlockNumber()
98-
scenario.postState.map(addAcc => addAcc._1 -> blockchain.getAccount(addAcc._1, bestBlockNumber)).toList
98+
scenario.postState.map(_.map(addAcc => addAcc._1 -> blockchain.getAccount(addAcc._1, bestBlockNumber)).toList)
9999
}
100100

101101
private def buildBlockchainConfig(network: String, shouldSkipPoW: Boolean): (BlockchainConfig, EthashValidators) = {
@@ -113,7 +113,9 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
113113
case "Byzantium" => (ByzantiumConfig, Validators.byzantiumValidators)
114114
case "Constantinople" => (ConstantinopleConfig, Validators.constantinopleValidators)
115115
case "EIP158ToByzantiumAt5" => (Eip158ToByzantiumAt5Config, Validators.eip158ToByzantiumValidators)
116-
case "ByzantiumToConstantinopleAt5" => (ByzantiumToConstantinopleAt5, Validators.byzantiumToConstantinopleAt5)
116+
case "ByzantiumToConstantinopleFixAt5" => (ByzantiumToConstantinopleAt5, Validators.byzantiumToConstantinopleAt5)
117+
case "ConstantinopleFix" => (ConstantinopleFixConfig, Validators.constantinopleValidators)
118+
case "Istanbul" => (IstanbulConfig, Validators.istanbulValidators)
117119
// Some default config, test will fail or be canceled
118120
case _ => (FrontierConfig, Validators.frontierValidators)
119121
}
@@ -129,7 +131,9 @@ abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
129131
case "Byzantium" => (ByzantiumConfig, ValidatorsWithSkippedPoW.byzantiumValidators)
130132
case "Constantinople" => (ConstantinopleConfig, ValidatorsWithSkippedPoW.constantinopleValidators)
131133
case "EIP158ToByzantiumAt5" => (Eip158ToByzantiumAt5Config, ValidatorsWithSkippedPoW.eip158ToByzantiumValidators)
132-
case "ByzantiumToConstantinopleAt5" => (ByzantiumToConstantinopleAt5, ValidatorsWithSkippedPoW.byzantiumToConstantinopleAt5)
134+
case "ByzantiumToConstantinopleFixAt5" => (ByzantiumToConstantinopleAt5, ValidatorsWithSkippedPoW.byzantiumToConstantinopleAt5)
135+
case "ConstantinopleFix" => (ConstantinopleFixConfig, ValidatorsWithSkippedPoW.constantinopleFixValidators)
136+
case "Istanbul" => (IstanbulConfig, ValidatorsWithSkippedPoW.istanbulValidators)
133137
// Some default config, test will fail or be canceled
134138
case _ => (FrontierConfig, ValidatorsWithSkippedPoW.frontierValidators)
135139
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ case class BlockchainScenario(
1010
genesisRLP: Option[ByteString],
1111
lastblockhash: ByteString,
1212
network: String,
13-
postState: Map[Address, AccountState],
13+
postState: Option[Map[Address, AccountState]],
14+
postStateHash: Option[ByteString],
1415
pre: Map[Address, AccountState],
1516
sealEngine: Option[String]
1617
)

src/main/resources/application.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,17 @@ mantis {
366366
# depth in ethereum (https://www.reddit.com/r/ethereum/comments/4eplsv/how_many_confirms_is_considered_safe_in_ethereum/)
367367
branch-resolution-request-size = 12
368368

369+
# TODO investigate proper value to handle ETC reorgs correctly
369370
# threshold for storing non-main-chain blocks in queue.
370371
# if: current_best_block_number - block_number > max-queued-block-number-behind
371372
# then: the block will not be queued (such already queued blocks will be removed)
372-
max-queued-block-number-behind = 10
373+
max-queued-block-number-behind = 100
373374

375+
# TODO investigate proper value to handle ETC reorgs correctly
374376
# threshold for storing non-main-chain blocks in queue.
375377
# if: block_number - current_best_block_number > max-queued-block-number-ahead
376378
# then: the block will not be queued (such already queued blocks will be removed)
377-
max-queued-block-number-ahead = 10
379+
max-queued-block-number-ahead = 100
378380

379381
# Maximum number of blocks, after which block hash from NewBlockHashes packet is considered ancient
380382
# and peer sending it is blacklisted

src/main/scala/io/iohk/ethereum/ledger/BlockExecution.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.iohk.ethereum.ledger
22

33
import io.iohk.ethereum.domain._
44
import io.iohk.ethereum.ledger.Ledger.BlockResult
5-
import io.iohk.ethereum.utils.{ BlockchainConfig, DaoForkConfig, Logger }
5+
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, Logger}
66
import io.iohk.ethereum.vm.EvmConfig
77

88
import scala.annotation.tailrec

src/main/scala/io/iohk/ethereum/ledger/BlockImport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class BlockImport(
215215
*/
216216
private def removeBlocksUntil(parent: ByteString, fromNumber: BigInt): List[BlockData] = {
217217
blockchain.getBlockByNumber(fromNumber) match {
218-
case Some(block) if block.header.hash == parent =>
218+
case Some(block) if block.header.hash == parent || fromNumber == 0 =>
219219
Nil
220220

221221
case Some(block) =>

src/test/scala/io/iohk/ethereum/ledger/BlockQueueSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class BlockQueueSpec extends FlatSpec with Matchers with MockFactory {
151151
}
152152

153153
trait TestConfig {
154-
val syncConfig = SyncConfig(Config.config)
154+
val syncConfig = SyncConfig(Config.config).copy(maxQueuedBlockNumberAhead = 10, maxQueuedBlockNumberBehind = 10)
155155
val blockchain = mock[BlockchainImpl]
156156
val blockQueue = BlockQueue(blockchain, syncConfig)
157157

0 commit comments

Comments
 (0)