From 9e703d3ebe16521846e1bf3db5b76a5e1da1d7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Wed, 26 May 2021 18:46:41 +0200 Subject: [PATCH] [refactor] create dedicated case class for block numbers --- .../ethereum/txExecTest/ECIP1017Test.scala | 43 +++--- .../iohk/ethereum/txExecTest/ForksTest.scala | 41 ++--- .../blocks/BlockGeneratorSkeleton.scala | 2 +- .../ethereum/consensus/pow/PoWConsensus.scala | 2 +- .../EthashDifficultyCalculator.scala | 3 +- .../pow/miners/EthashDAGManager.scala | 3 +- .../consensus/pow/miners/EthashMiner.scala | 2 +- .../EthashBlockHeaderValidator.scala | 5 +- .../validators/PoWBlockHeaderValidator.scala | 2 +- .../BlockHeaderValidatorSkeleton.scala | 6 +- .../std/StdSignedTransactionValidator.scala | 4 +- .../ethereum/jsonrpc/EthMiningService.scala | 3 +- .../ethereum/jsonrpc/PersonalService.scala | 2 +- .../iohk/ethereum/jsonrpc/TestService.scala | 35 +++-- .../ethereum/ledger/BlockPreparator.scala | 10 +- .../ethereum/utils/BlockchainConfig.scala | 85 +++++----- .../ethereum/vm/BlockchainConfigForEvm.scala | 24 +-- .../consensus/blocks/BlockGeneratorSpec.scala | 146 ++++++++++-------- .../pow/miners/KeccakMinerSpec.scala | 3 +- .../EthashBlockHeaderValidatorSpec.scala | 44 +++--- .../PoWBlockHeaderValidatorSpec.scala | 2 +- ...rictedEthashBlockHeaderValidatorSpec.scala | 40 ++--- ...ockWithCheckpointHeaderValidatorSpec.scala | 5 +- .../StdSignedTransactionValidatorSpec.scala | 2 +- .../io/iohk/ethereum/extvm/VMClientSpec.scala | 13 +- .../io/iohk/ethereum/extvm/VMServerSpec.scala | 11 +- .../jsonrpc/PersonalServiceSpec.scala | 51 +++--- .../ethereum/ledger/BlockPreparatorSpec.scala | 6 +- .../ethereum/ledger/BlockRewardSpec.scala | 13 +- .../io/iohk/ethereum/ledger/LedgerSpec.scala | 6 +- .../ethereum/ledger/LedgerTestSetup.scala | 15 +- .../iohk/ethereum/ledger/StxLedgerSpec.scala | 40 ++--- 32 files changed, 361 insertions(+), 308 deletions(-) diff --git a/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala b/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala index d968002f71..9ad1c58a6f 100644 --- a/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala +++ b/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala @@ -1,11 +1,10 @@ package io.iohk.ethereum.txExecTest import java.util.concurrent.Executors - import io.iohk.ethereum.domain.{Address, BlockchainImpl, Receipt, UInt256} import io.iohk.ethereum.ledger._ import io.iohk.ethereum.txExecTest.util.FixtureProvider -import io.iohk.ethereum.utils.{BlockchainConfig, MonetaryPolicyConfig} +import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers @@ -22,16 +21,26 @@ class ECIP1017Test extends AnyFlatSpec with Matchers { maxCodeSize = None, chainId = 0x3d.toByte, networkId = 1, - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, - eip106BlockNumber = Long.MaxValue, - eip150BlockNumber = 2500000, - eip160BlockNumber = 3000000, - eip155BlockNumber = 3000000, - eip161BlockNumber = Long.MaxValue, - byzantiumBlockNumber = Long.MaxValue, - constantinopleBlockNumber = Long.MaxValue, - istanbulBlockNumber = Long.MaxValue, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + eip106BlockNumber = Long.MaxValue, + eip150BlockNumber = 2500000, + eip160BlockNumber = 3000000, + eip155BlockNumber = 3000000, + eip161BlockNumber = Long.MaxValue, + byzantiumBlockNumber = Long.MaxValue, + constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), customGenesisFileOpt = None, customGenesisJsonOpt = None, daoForkConfig = None, @@ -42,15 +51,7 @@ class ECIP1017Test extends AnyFlatSpec with Matchers { accountStartNonce = UInt256.Zero, ethCompatibleStorage = true, gasTieBreaker = false, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, - treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None + treasuryAddress = Address(0) ) val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4)) diff --git a/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala b/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala index e2833fb073..a7a13ac8d3 100644 --- a/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala +++ b/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala @@ -1,11 +1,10 @@ package io.iohk.ethereum.txExecTest import java.util.concurrent.Executors - import io.iohk.ethereum.domain.{Address, BlockchainImpl, Receipt, UInt256} import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation} import io.iohk.ethereum.txExecTest.util.FixtureProvider -import io.iohk.ethereum.utils.{BlockchainConfig, MonetaryPolicyConfig} +import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers @@ -16,40 +15,42 @@ class ForksTest extends AnyFlatSpec with Matchers { trait TestSetup extends ScenarioSetup { override lazy val blockchainConfig = BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 3, - eip150BlockNumber = 5, - eip160BlockNumber = 7, - eip155BlockNumber = 0, - eip106BlockNumber = Long.MaxValue, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 3, + eip150BlockNumber = 5, + eip160BlockNumber = 7, + eip155BlockNumber = 0, + eip106BlockNumber = Long.MaxValue, + eip161BlockNumber = Long.MaxValue, + byzantiumBlockNumber = Long.MaxValue, + constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), chainId = 0x3d.toByte, monetaryPolicyConfig = MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L), // unused bootstrapNodes = Set(), networkId = 1, maxCodeSize = None, - eip161BlockNumber = Long.MaxValue, customGenesisFileOpt = None, customGenesisJsonOpt = None, difficultyBombPauseBlockNumber = Long.MaxValue, difficultyBombContinueBlockNumber = Long.MaxValue, difficultyBombRemovalBlockNumber = Long.MaxValue, - byzantiumBlockNumber = Long.MaxValue, - constantinopleBlockNumber = Long.MaxValue, - istanbulBlockNumber = Long.MaxValue, accountStartNonce = UInt256.Zero, daoForkConfig = None, gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None ) val noErrors = a[Right[_, Seq[Receipt]]] diff --git a/src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala b/src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala index 330d51ab82..f296f1636f 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala @@ -45,7 +45,7 @@ abstract class BlockGeneratorSkeleton( x: Ommers ): BlockHeader = { val extraFields = - if (blockNumber >= blockchainConfig.ecip1097BlockNumber) + if (blockNumber >= blockchainConfig.forkBlockNumbers.ecip1097BlockNumber) HefPostEcip1097(None) else HefEmpty diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/PoWConsensus.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/PoWConsensus.scala index f1d7bb381e..2312154165 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/PoWConsensus.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/PoWConsensus.scala @@ -95,7 +95,7 @@ class PoWConsensus private ( node.ethMiningService, blockCreator, blockchain, - blockchainConfig.ecip1049BlockNumber + blockchainConfig.forkBlockNumbers.ecip1049BlockNumber ), "PoWMinerCoordinator", DispatcherSelector.fromConfig(BlockForgerDispatcherId) diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/difficulty/EthashDifficultyCalculator.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/difficulty/EthashDifficultyCalculator.scala index 48409d097e..06b405bd0b 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/difficulty/EthashDifficultyCalculator.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/difficulty/EthashDifficultyCalculator.scala @@ -6,6 +6,7 @@ import io.iohk.ethereum.utils.BlockchainConfig class EthashDifficultyCalculator(blockchainConfig: BlockchainConfig) extends DifficultyCalculator { import blockchainConfig._ + import blockchainConfig.forkBlockNumbers._ import DifficultyCalculator._ private val ExpDifficultyPeriod: Int = 100000 @@ -19,7 +20,7 @@ class EthashDifficultyCalculator(blockchainConfig: BlockchainConfig) extends Dif val c: BigInt = if (blockNumber < homesteadBlockNumber) { if (blockTimestamp < parentHeader.unixTimestamp + 13) 1 else -1 - } else if (blockNumber >= byzantiumBlockNumber || blockNumber >= blockchainConfig.atlantisBlockNumber) { + } else if (blockNumber >= byzantiumBlockNumber || blockNumber >= atlantisBlockNumber) { val parentUncleFactor = if (parentHeader.ommersHash == BlockHeader.EmptyOmmers) 1 else 2 math.max(parentUncleFactor - (timestampDiff / 9), FrontierTimestampDiffLimit) } else { diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashDAGManager.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashDAGManager.scala index f745221522..404c014a34 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashDAGManager.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashDAGManager.scala @@ -18,7 +18,8 @@ class EthashDAGManager(blockCreator: PoWBlockCreator) extends Logger { (currentEpoch, currentEpochDag, currentEpochDagSize) match { case (_, Some(dag), Some(dagSize)) => (dag, dagSize) case _ => - val seed = EthashUtils.seed(blockNumber, blockCreator.blockchainConfig.ecip1099BlockNumber.toLong) + val seed = + EthashUtils.seed(blockNumber, blockCreator.blockchainConfig.forkBlockNumbers.ecip1099BlockNumber.toLong) val dagSize = EthashUtils.dagSize(epoch) val dagNumHashes = (dagSize / EthashUtils.HASH_BYTES).toInt val dag = diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashMiner.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashMiner.scala index 4c5d06d287..1a194543e6 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashMiner.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/miners/EthashMiner.scala @@ -53,7 +53,7 @@ class EthashMiner( private def doMining(blockNumber: Long, block: Block): (Long, MiningResult) = { val epoch = - EthashUtils.epoch(blockNumber, blockCreator.blockchainConfig.ecip1099BlockNumber.toLong) + EthashUtils.epoch(blockNumber, blockCreator.blockchainConfig.forkBlockNumbers.ecip1099BlockNumber.toLong) val (dag, dagSize) = dagManager.calculateDagSize(blockNumber, epoch) val headerHash = crypto.kec256(BlockHeader.getEncodedWithoutNonce(block.header)) val startTime = System.nanoTime() diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidator.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidator.scala index b37a6f8f1e..26b954cae1 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidator.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidator.scala @@ -41,8 +41,9 @@ class EthashBlockHeaderValidator(blockchainConfig: BlockchainConfig) { } } - val epoch = EthashUtils.epoch(blockHeader.number.toLong, blockchainConfig.ecip1099BlockNumber.toLong) - val seed = EthashUtils.seed(blockHeader.number.toLong, blockchainConfig.ecip1099BlockNumber.toLong) + val epoch = + EthashUtils.epoch(blockHeader.number.toLong, blockchainConfig.forkBlockNumbers.ecip1099BlockNumber.toLong) + val seed = EthashUtils.seed(blockHeader.number.toLong, blockchainConfig.forkBlockNumbers.ecip1099BlockNumber.toLong) val powCacheData = getPowCacheData(epoch, seed) val proofOfWork = hashimotoLight( diff --git a/src/main/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidator.scala b/src/main/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidator.scala index db115632ba..5c2421c469 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidator.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidator.scala @@ -26,7 +26,7 @@ class PoWBlockHeaderValidator(blockchainConfig: BlockchainConfig) else ethashBlockHeaderValidator.validateHeader(blockHeader) private def isKeccak(currentBlockNumber: BigInt): Boolean = - blockchainConfig.ecip1049BlockNumber match { + blockchainConfig.forkBlockNumbers.ecip1049BlockNumber match { case Some(keccakBlock) => currentBlockNumber >= keccakBlock case None => false } diff --git a/src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala b/src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala index 77b92e9d50..e8ef07fac4 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala @@ -192,7 +192,7 @@ abstract class BlockHeaderValidatorSkeleton(blockchainConfig: BlockchainConfig) parentHeader: BlockHeader ): Either[BlockHeaderError, BlockHeaderValid] = { - if (blockHeader.gasLimit > MaxGasLimit && blockHeader.number >= blockchainConfig.eip106BlockNumber) + if (blockHeader.gasLimit > MaxGasLimit && blockHeader.number >= blockchainConfig.forkBlockNumbers.eip106BlockNumber) Left(HeaderGasLimitError) else { val gasLimitDiff = (blockHeader.gasLimit - parentHeader.gasLimit).abs @@ -226,8 +226,8 @@ abstract class BlockHeaderValidatorSkeleton(blockchainConfig: BlockchainConfig) * @return BlockHeader if valid, an [[HeaderExtraFieldsError]] otherwise */ private def validateExtraFields(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] = { - val isECIP1098Activated = blockHeader.number >= blockchainConfig.ecip1098BlockNumber - val isECIP1097Activated = blockHeader.number >= blockchainConfig.ecip1097BlockNumber + val isECIP1098Activated = blockHeader.number >= blockchainConfig.forkBlockNumbers.ecip1098BlockNumber + val isECIP1097Activated = blockHeader.number >= blockchainConfig.forkBlockNumbers.ecip1097BlockNumber blockHeader.extraFields match { case HefPostEcip1097(_) if isECIP1097Activated && isECIP1098Activated => Right(BlockHeaderValid) diff --git a/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala b/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala index 4f985fe794..3da0449424 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala @@ -85,8 +85,8 @@ class StdSignedTransactionValidator(blockchainConfig: BlockchainConfig) extends val r = stx.signature.r val s = stx.signature.s - val beforeHomestead = blockNumber < blockchainConfig.homesteadBlockNumber - val beforeEIP155 = blockNumber < blockchainConfig.eip155BlockNumber + val beforeHomestead = blockNumber < blockchainConfig.forkBlockNumbers.homesteadBlockNumber + val beforeEIP155 = blockNumber < blockchainConfig.forkBlockNumbers.eip155BlockNumber val validR = r > 0 && r < secp256k1n val validS = s > 0 && s < (if (beforeHomestead) secp256k1n else secp256k1n / 2) diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/EthMiningService.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/EthMiningService.scala index 145cc0d3ea..2c896a0796 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/EthMiningService.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/EthMiningService.scala @@ -94,7 +94,8 @@ class EthMiningService( Right( GetWorkResponse( powHeaderHash = ByteString(kec256(BlockHeader.getEncodedWithoutNonce(pb.block.header))), - dagSeed = EthashUtils.seed(pb.block.header.number.toLong, blockchainConfig.ecip1099BlockNumber.toLong), + dagSeed = EthashUtils + .seed(pb.block.header.number.toLong, blockchainConfig.forkBlockNumbers.ecip1099BlockNumber.toLong), target = ByteString((BigInt(2).pow(256) / pb.block.header.difficulty).toByteArray) ) ) diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/PersonalService.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/PersonalService.scala index a318c44341..3a5429e4fe 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/PersonalService.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/PersonalService.scala @@ -207,7 +207,7 @@ class PersonalService( val maybeNextTxNonce = maybeLatestPendingTxNonce.map(_ + 1) orElse maybeCurrentNonce val tx = request.toTransaction(maybeNextTxNonce.getOrElse(blockchainConfig.accountStartNonce)) - val stx = if (blockchain.getBestBlockNumber() >= blockchainConfig.eip155BlockNumber) { + val stx = if (blockchain.getBestBlockNumber() >= blockchainConfig.forkBlockNumbers.eip155BlockNumber) { wallet.signTx(tx, Some(blockchainConfig.chainId)) } else { wallet.signTx(tx, None) diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala index 9b6bf8e7d1..a0db770ddd 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala @@ -13,7 +13,7 @@ import io.iohk.ethereum.ledger._ import io.iohk.ethereum.testmode.{TestLedgerWrapper, TestmodeConsensus} import io.iohk.ethereum.transactions.PendingTransactionsManager import io.iohk.ethereum.transactions.PendingTransactionsManager.PendingTransactionsResponse -import io.iohk.ethereum.utils.{ByteStringUtils, Logger} +import io.iohk.ethereum.utils.{ByteStringUtils, ForkBlockNumbers, Logger} import monix.eval.Task import monix.execution.Scheduler import org.bouncycastle.util.encoders.Hex @@ -170,24 +170,33 @@ class TestService( SetChainParamsResponse().rightNow } + val neverOccuringBlock: Int = Int.MaxValue private def buildNewConfig(blockchainParams: BlockchainParams) = { - val neverOccuringBlock = Int.MaxValue val byzantiumBlockNumber: BigInt = blockchainParams.byzantiumForkBlock.getOrElse(neverOccuringBlock) val istanbulForkBlockNumber: BigInt = blockchainParams.istanbulForkBlock.getOrElse(neverOccuringBlock) // For block number which are not specified by retesteth, we try to align the number to another fork testLedgerWrapper.blockchainConfig.copy( - homesteadBlockNumber = blockchainParams.homesteadForkBlock.getOrElse(neverOccuringBlock), - eip150BlockNumber = blockchainParams.EIP150ForkBlock.getOrElse(neverOccuringBlock), - eip160BlockNumber = byzantiumBlockNumber, - eip161BlockNumber = byzantiumBlockNumber, - byzantiumBlockNumber = byzantiumBlockNumber, - constantinopleBlockNumber = blockchainParams.constantinopleForkBlock.getOrElse(neverOccuringBlock), - petersburgBlockNumber = istanbulForkBlockNumber, - aghartaBlockNumber = istanbulForkBlockNumber, - istanbulBlockNumber = istanbulForkBlockNumber, - atlantisBlockNumber = istanbulForkBlockNumber, - phoenixBlockNumber = istanbulForkBlockNumber, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = blockchainParams.homesteadForkBlock.getOrElse(neverOccuringBlock), + eip106BlockNumber = neverOccuringBlock, + eip150BlockNumber = blockchainParams.EIP150ForkBlock.getOrElse(neverOccuringBlock), + eip155BlockNumber = byzantiumBlockNumber, + eip160BlockNumber = byzantiumBlockNumber, + eip161BlockNumber = byzantiumBlockNumber, + byzantiumBlockNumber = byzantiumBlockNumber, + ecip1049BlockNumber = None, + ecip1097BlockNumber = neverOccuringBlock, + ecip1098BlockNumber = neverOccuringBlock, + constantinopleBlockNumber = blockchainParams.constantinopleForkBlock.getOrElse(neverOccuringBlock), + petersburgBlockNumber = istanbulForkBlockNumber, + aghartaBlockNumber = istanbulForkBlockNumber, + istanbulBlockNumber = istanbulForkBlockNumber, + atlantisBlockNumber = istanbulForkBlockNumber, + phoenixBlockNumber = istanbulForkBlockNumber, + ecip1099BlockNumber = neverOccuringBlock + ), accountStartNonce = UInt256(blockchainParams.accountStartNonce), networkId = 1, bootstrapNodes = Set() diff --git a/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala b/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala index f5c0db6cd6..900be31a5f 100644 --- a/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala +++ b/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala @@ -34,8 +34,8 @@ class BlockPreparator( // in some irrelevant test can throw an exception. private[ledger] lazy val blockRewardCalculator = new BlockRewardCalculator( blockchainConfig.monetaryPolicyConfig, - blockchainConfig.byzantiumBlockNumber, - blockchainConfig.constantinopleBlockNumber + blockchainConfig.forkBlockNumbers.byzantiumBlockNumber, + blockchainConfig.forkBlockNumbers.constantinopleBlockNumber ) /** @@ -98,7 +98,7 @@ class BlockPreparator( } private def treasuryEnabled(blockNo: BigInt): Boolean = - blockNo >= blockchainConfig.ecip1098BlockNumber + blockNo >= blockchainConfig.forkBlockNumbers.ecip1098BlockNumber /** * v0 ≡ Tg (Tx gas limit) * Tp (Tx gas price). See YP equation number (68) @@ -318,8 +318,8 @@ class BlockPreparator( // spec: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md val transactionOutcome = if ( - blockHeader.number >= blockchainConfig.byzantiumBlockNumber || - blockHeader.number >= blockchainConfig.atlantisBlockNumber + blockHeader.number >= blockchainConfig.forkBlockNumbers.byzantiumBlockNumber || + blockHeader.number >= blockchainConfig.forkBlockNumbers.atlantisBlockNumber ) { if (vmError.isDefined) FailureOutcome else SuccessOutcome } else { diff --git a/src/main/scala/io/iohk/ethereum/utils/BlockchainConfig.scala b/src/main/scala/io/iohk/ethereum/utils/BlockchainConfig.scala index 3ef11fe320..f807d63d71 100644 --- a/src/main/scala/io/iohk/ethereum/utils/BlockchainConfig.scala +++ b/src/main/scala/io/iohk/ethereum/utils/BlockchainConfig.scala @@ -11,24 +11,8 @@ import com.typesafe.config.ConfigRenderOptions case class BlockchainConfig( powTargetTime: Option[Long] = None, - frontierBlockNumber: BigInt, - homesteadBlockNumber: BigInt, - eip106BlockNumber: BigInt, - eip150BlockNumber: BigInt, - eip155BlockNumber: BigInt, - eip160BlockNumber: BigInt, - eip161BlockNumber: BigInt, - byzantiumBlockNumber: BigInt, - constantinopleBlockNumber: BigInt, - istanbulBlockNumber: BigInt, - atlantisBlockNumber: BigInt, - aghartaBlockNumber: BigInt, - phoenixBlockNumber: BigInt, - petersburgBlockNumber: BigInt, + forkBlockNumbers: ForkBlockNumbers, treasuryAddress: Address, - ecip1098BlockNumber: BigInt, - ecip1097BlockNumber: BigInt, - ecip1049BlockNumber: Option[BigInt], maxCodeSize: Option[BigInt], difficultyBombPauseBlockNumber: BigInt, difficultyBombContinueBlockNumber: BigInt, @@ -44,12 +28,35 @@ case class BlockchainConfig( ethCompatibleStorage: Boolean, bootstrapNodes: Set[String], checkpointPubKeys: Set[ByteString] = Set.empty, - allowedMinersPublicKeys: Set[ByteString] = Set.empty, - ecip1099BlockNumber: BigInt + allowedMinersPublicKeys: Set[ByteString] = Set.empty ) { val minRequireSignatures: Int = (Math.floor(checkpointPubKeys.size / 2) + 1).toInt + + def withUpdatedForkBlocks(update: (ForkBlockNumbers) => ForkBlockNumbers) = + copy(forkBlockNumbers = update(forkBlockNumbers)) } +case class ForkBlockNumbers( + frontierBlockNumber: BigInt, + homesteadBlockNumber: BigInt, + eip106BlockNumber: BigInt, + eip150BlockNumber: BigInt, + eip155BlockNumber: BigInt, + eip160BlockNumber: BigInt, + eip161BlockNumber: BigInt, + byzantiumBlockNumber: BigInt, + constantinopleBlockNumber: BigInt, + istanbulBlockNumber: BigInt, + atlantisBlockNumber: BigInt, + aghartaBlockNumber: BigInt, + phoenixBlockNumber: BigInt, + petersburgBlockNumber: BigInt, + ecip1098BlockNumber: BigInt, + ecip1097BlockNumber: BigInt, + ecip1049BlockNumber: Option[BigInt], + ecip1099BlockNumber: BigInt +) + object BlockchainConfig { // scalastyle:off method.length @@ -120,24 +127,27 @@ object BlockchainConfig { BlockchainConfig( powTargetTime = powTargetTime, - frontierBlockNumber = frontierBlockNumber, - homesteadBlockNumber = homesteadBlockNumber, - eip106BlockNumber = eip106BlockNumber, - eip150BlockNumber = eip150BlockNumber, - eip155BlockNumber = eip155BlockNumber, - eip160BlockNumber = eip160BlockNumber, - eip161BlockNumber = eip161BlockNumber, - byzantiumBlockNumber = byzantiumBlockNumber, - constantinopleBlockNumber = constantinopleBlockNumber, - istanbulBlockNumber = istanbulBlockNumber, - atlantisBlockNumber = atlantisBlockNumber, - aghartaBlockNumber = aghartaBlockNumber, - phoenixBlockNumber = phoenixBlockNumber, - petersburgBlockNumber = petersburgBlockNumber, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = frontierBlockNumber, + homesteadBlockNumber = homesteadBlockNumber, + eip106BlockNumber = eip106BlockNumber, + eip150BlockNumber = eip150BlockNumber, + eip155BlockNumber = eip155BlockNumber, + eip160BlockNumber = eip160BlockNumber, + eip161BlockNumber = eip161BlockNumber, + byzantiumBlockNumber = byzantiumBlockNumber, + constantinopleBlockNumber = constantinopleBlockNumber, + istanbulBlockNumber = istanbulBlockNumber, + atlantisBlockNumber = atlantisBlockNumber, + aghartaBlockNumber = aghartaBlockNumber, + phoenixBlockNumber = phoenixBlockNumber, + petersburgBlockNumber = petersburgBlockNumber, + ecip1098BlockNumber = ecip1098BlockNumber, + ecip1097BlockNumber = ecip1097BlockNumber, + ecip1049BlockNumber = ecip1049BlockNumber, + ecip1099BlockNumber = ecip1099BlockNumber + ), treasuryAddress = treasuryAddress, - ecip1098BlockNumber = ecip1098BlockNumber, - ecip1097BlockNumber = ecip1097BlockNumber, - ecip1049BlockNumber = ecip1049BlockNumber, maxCodeSize = maxCodeSize, difficultyBombPauseBlockNumber = difficultyBombPauseBlockNumber, difficultyBombContinueBlockNumber = difficultyBombContinueBlockNumber, @@ -153,8 +163,7 @@ object BlockchainConfig { ethCompatibleStorage = ethCompatibleStorage, bootstrapNodes = bootstrapNodes, checkpointPubKeys = checkpointPubKeys, - allowedMinersPublicKeys = allowedMinersPublicKeys, - ecip1099BlockNumber = ecip1099BlockNumber + allowedMinersPublicKeys = allowedMinersPublicKeys ) } // scalastyle:on method.length diff --git a/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala b/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala index de35fee457..20760c262b 100644 --- a/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala +++ b/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala @@ -67,20 +67,20 @@ object BlockchainConfigForEvm { def apply(blockchainConfig: BlockchainConfig): BlockchainConfigForEvm = { import blockchainConfig._ BlockchainConfigForEvm( - frontierBlockNumber = frontierBlockNumber, - homesteadBlockNumber = homesteadBlockNumber, - eip150BlockNumber = eip150BlockNumber, - eip160BlockNumber = eip160BlockNumber, - eip161BlockNumber = eip161BlockNumber, - byzantiumBlockNumber = byzantiumBlockNumber, - constantinopleBlockNumber = constantinopleBlockNumber, - istanbulBlockNumber = istanbulBlockNumber, + frontierBlockNumber = forkBlockNumbers.frontierBlockNumber, + homesteadBlockNumber = forkBlockNumbers.homesteadBlockNumber, + eip150BlockNumber = forkBlockNumbers.eip150BlockNumber, + eip160BlockNumber = forkBlockNumbers.eip160BlockNumber, + eip161BlockNumber = forkBlockNumbers.eip161BlockNumber, + byzantiumBlockNumber = forkBlockNumbers.byzantiumBlockNumber, + constantinopleBlockNumber = forkBlockNumbers.constantinopleBlockNumber, + istanbulBlockNumber = forkBlockNumbers.istanbulBlockNumber, maxCodeSize = maxCodeSize, accountStartNonce = accountStartNonce, - atlantisBlockNumber = atlantisBlockNumber, - aghartaBlockNumber = aghartaBlockNumber, - petersburgBlockNumber = petersburgBlockNumber, - phoenixBlockNumber = phoenixBlockNumber, + atlantisBlockNumber = forkBlockNumbers.atlantisBlockNumber, + aghartaBlockNumber = forkBlockNumbers.aghartaBlockNumber, + petersburgBlockNumber = forkBlockNumbers.petersburgBlockNumber, + phoenixBlockNumber = forkBlockNumbers.phoenixBlockNumber, chainId = chainId ) } diff --git a/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala index cb7618676e..dbd89cf8e6 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala @@ -203,16 +203,9 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "generate block before eip155 and filter out chain specific tx" in new TestSetup { override lazy val blockchainConfig = BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, difficultyBombPauseBlockNumber = 3000000, difficultyBombContinueBlockNumber = 5000000, difficultyBombRemovalBlockNumber = 5900000, - eip155BlockNumber = Long.MaxValue, - eip106BlockNumber = Long.MaxValue, - byzantiumBlockNumber = Long.MaxValue, - constantinopleBlockNumber = Long.MaxValue, - istanbulBlockNumber = Long.MaxValue, chainId = 0x3d.toByte, networkId = 1, customGenesisFileOpt = Some("test-genesis.json"), @@ -221,23 +214,33 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L, 2000000000000000000L), // unused maxCodeSize = None, - eip160BlockNumber = Long.MaxValue, - eip150BlockNumber = Long.MaxValue, - eip161BlockNumber = Long.MaxValue, accountStartNonce = UInt256.Zero, daoForkConfig = None, bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + eip155BlockNumber = Long.MaxValue, + eip106BlockNumber = Long.MaxValue, + byzantiumBlockNumber = Long.MaxValue, + constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, + eip160BlockNumber = Long.MaxValue, + eip150BlockNumber = Long.MaxValue, + eip161BlockNumber = Long.MaxValue, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), + ) override lazy val blockExecution = @@ -277,16 +280,29 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "generate correct block with (without empty accounts) after EIP-161" in new TestSetup { override lazy val blockchainConfig = BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + eip155BlockNumber = Long.MaxValue, + eip106BlockNumber = Long.MaxValue, + byzantiumBlockNumber = Long.MaxValue, + constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, + eip160BlockNumber = Long.MaxValue, + eip150BlockNumber = Long.MaxValue, + eip161BlockNumber = 0, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), difficultyBombPauseBlockNumber = 3000000, difficultyBombContinueBlockNumber = 5000000, difficultyBombRemovalBlockNumber = 5900000, - eip155BlockNumber = Long.MaxValue, - eip106BlockNumber = Long.MaxValue, - byzantiumBlockNumber = Long.MaxValue, - constantinopleBlockNumber = Long.MaxValue, - istanbulBlockNumber = Long.MaxValue, chainId = 0x3d.toByte, networkId = 1, customGenesisFileOpt = Some("test-genesis.json"), @@ -295,23 +311,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L, 2000000000000000000L), // unused maxCodeSize = None, - eip160BlockNumber = Long.MaxValue, - eip150BlockNumber = Long.MaxValue, - eip161BlockNumber = 0, accountStartNonce = UInt256.Zero, daoForkConfig = None, bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, - treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None + treasuryAddress = Address(0) ) override lazy val blockExecution = @@ -512,7 +517,11 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper forAll(table) { case (ecip1098Activated, ecip1097Activated, headerExtraFields) => val testSetup = new TestSetup { override lazy val blockchainConfig = - baseBlockchainConfig.copy(ecip1098BlockNumber = 1000, ecip1097BlockNumber = 2000) + baseBlockchainConfig.withUpdatedForkBlocks( + _.copy( + ecip1098BlockNumber = 1000, + ecip1097BlockNumber = 2000 + )) override lazy val consensusConfig = buildConsensusConfig() } @@ -520,11 +529,11 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper val blockNumber = if (ecip1098Activated && ecip1097Activated) - blockchainConfig.ecip1097BlockNumber * 2 + blockchainConfig.forkBlockNumbers.ecip1097BlockNumber * 2 else if (ecip1098Activated) - (blockchainConfig.ecip1097BlockNumber + blockchainConfig.ecip1098BlockNumber) / 2 + (blockchainConfig.forkBlockNumbers.ecip1097BlockNumber + blockchainConfig.forkBlockNumbers.ecip1098BlockNumber) / 2 else - blockchainConfig.ecip1098BlockNumber / 2 + blockchainConfig.forkBlockNumbers.ecip1098BlockNumber / 2 val parentBlock = bestBlock.get.copy(header = bestBlock.get.header.copy(number = blockNumber - 1)) val generatedBlock = blockGenerator.generateBlock(parentBlock, Nil, Address(testAddress), blockGenerator.emptyX, None).pendingBlock @@ -535,8 +544,9 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "generate a failure if treasury transfer was not made" in { val producer = new TestSetup { - override lazy val blockchainConfig = baseBlockchainConfig.copy( + override lazy val blockchainConfig = baseBlockchainConfig.withUpdatedForkBlocks(_.copy( ecip1098BlockNumber = 20000000, + )).copy( treasuryAddress = treasuryAccount, customGenesisFileOpt = Some("test-genesis-treasury.json") ) @@ -550,8 +560,9 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper } val validator = new TestSetup { - override lazy val blockchainConfig = baseBlockchainConfig.copy( - ecip1098BlockNumber = 1, + override lazy val blockchainConfig = baseBlockchainConfig + .withUpdatedForkBlocks(_.copy(ecip1098BlockNumber = 1)) + .copy( treasuryAddress = treasuryAccount, customGenesisFileOpt = Some("test-genesis-treasury.json") ) @@ -572,8 +583,8 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "generate a failure if treasury transfer was made to a different treasury account" in { val producer = new TestSetup { - override lazy val blockchainConfig = baseBlockchainConfig.copy( - ecip1098BlockNumber = 1, + override lazy val blockchainConfig = baseBlockchainConfig + .withUpdatedForkBlocks(_.copy(ecip1098BlockNumber = 1)).copy( treasuryAddress = maliciousAccount, customGenesisFileOpt = Some("test-genesis-treasury.json") ) @@ -587,8 +598,9 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper } val validator = new TestSetup { - override lazy val blockchainConfig = baseBlockchainConfig.copy( - ecip1098BlockNumber = 1, + override lazy val blockchainConfig = baseBlockchainConfig + .withUpdatedForkBlocks(_.copy(ecip1098BlockNumber = 1)) + .copy( treasuryAddress = treasuryAccount, customGenesisFileOpt = Some("test-genesis-treasury.json") ) @@ -634,16 +646,29 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper SignedTransaction.sign(transaction.copy(gasLimit = 2), keyPair, Some(0x3d.toByte)) val baseBlockchainConfig = BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + eip155BlockNumber = 0, + eip106BlockNumber = Long.MaxValue, + byzantiumBlockNumber = Long.MaxValue, + constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, + eip160BlockNumber = Long.MaxValue, + eip150BlockNumber = Long.MaxValue, + eip161BlockNumber = Long.MaxValue, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), difficultyBombPauseBlockNumber = 3000000, difficultyBombContinueBlockNumber = 5000000, difficultyBombRemovalBlockNumber = 5900000, - eip155BlockNumber = 0, - eip106BlockNumber = Long.MaxValue, - byzantiumBlockNumber = Long.MaxValue, - constantinopleBlockNumber = Long.MaxValue, - istanbulBlockNumber = Long.MaxValue, chainId = 0x3d.toByte, networkId = 1, customGenesisFileOpt = Some("test-genesis.json"), @@ -652,23 +677,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper MonetaryPolicyConfig(5000000, 0.2, 5000000000000000000L, 3000000000000000000L, 2000000000000000000L), // unused maxCodeSize = None, - eip160BlockNumber = Long.MaxValue, - eip150BlockNumber = Long.MaxValue, - eip161BlockNumber = Long.MaxValue, accountStartNonce = UInt256.Zero, daoForkConfig = None, bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None ) override lazy val blockchainConfig = baseBlockchainConfig diff --git a/src/test/scala/io/iohk/ethereum/consensus/pow/miners/KeccakMinerSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/pow/miners/KeccakMinerSpec.scala index cb70d3fff3..8ec589eef7 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/pow/miners/KeccakMinerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/pow/miners/KeccakMinerSpec.scala @@ -45,7 +45,8 @@ class KeccakMinerSpec extends AnyFlatSpec with Matchers { trait TestSetup extends ScalaTestWithActorTestKit with MinerSpecSetup { private implicit val durationTimeout: Duration = Timeouts.miningTimeout - override lazy val blockchainConfig = Config.blockchains.blockchainConfig.copy(ecip1049BlockNumber = Some(0)) + override lazy val blockchainConfig = Config.blockchains.blockchainConfig + .withUpdatedForkBlocks(_.copy(ecip1049BlockNumber = Some(0))) val powBlockHeaderValidator = new PoWBlockHeaderValidator(blockchainConfig) val ethService: EthInfoService = mock[EthInfoService] diff --git a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidatorSpec.scala index db08b6f660..ccbcb2c3f1 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidatorSpec.scala @@ -9,7 +9,7 @@ import io.iohk.ethereum.consensus.validators.BlockHeaderValidator._ import io.iohk.ethereum.consensus.validators.{BlockHeaderError, BlockHeaderValid, BlockHeaderValidatorSkeleton} import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields._ import io.iohk.ethereum.domain.{UInt256, _} -import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig} +import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, ForkBlockNumbers} import io.iohk.ethereum.{Fixtures, ObjectGenerators, SuperSlow} import org.bouncycastle.util.encoders.Hex import org.scalamock.scalatest.MockFactory @@ -191,7 +191,7 @@ class EthashBlockHeaderValidatorSpec it should "mark as valid a post ecip1098 block opt-out with opt out undefined" in new EphemBlockchainTestSetup { val ecip1098BlockNumber = validBlockHeader.number / 2 val blockchainConfigWithECIP1098Enabled: BlockchainConfig = - blockchainConfig.copy(ecip1098BlockNumber = ecip1098BlockNumber) + blockchainConfig.withUpdatedForkBlocks(_.copy(ecip1098BlockNumber = ecip1098BlockNumber)) val blockHeaderValidator = new BlockValidatorWithPowMocked(blockchainConfigWithECIP1098Enabled) val validHeader = validBlockHeader.copy(extraFields = HefEmpty) @@ -376,14 +376,29 @@ class EthashBlockHeaderValidatorSpec import Fixtures.Blocks._ BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + byzantiumBlockNumber = 4370000, + constantinopleBlockNumber = 7280000, + istanbulBlockNumber = 9069000, + eip155BlockNumber = Long.MaxValue, + eip160BlockNumber = Long.MaxValue, + eip161BlockNumber = Long.MaxValue, + eip150BlockNumber = Long.MaxValue, + eip106BlockNumber = 0, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), difficultyBombPauseBlockNumber = 3000000, difficultyBombContinueBlockNumber = 5000000, difficultyBombRemovalBlockNumber = 5900000, - byzantiumBlockNumber = 4370000, - constantinopleBlockNumber = 7280000, - istanbulBlockNumber = 9069000, daoForkConfig = Some(new DaoForkConfig { override val blockExtraData: Option[ByteString] = if (supportsDaoFork) Some(ProDaoForkBlock.header.extraData) else None @@ -396,11 +411,6 @@ class EthashBlockHeaderValidatorSpec }), // unused maxCodeSize = None, - eip155BlockNumber = Long.MaxValue, - eip160BlockNumber = Long.MaxValue, - eip161BlockNumber = Long.MaxValue, - eip150BlockNumber = Long.MaxValue, - eip106BlockNumber = 0, chainId = 0x3d.toByte, networkId = 1, monetaryPolicyConfig = null, @@ -410,15 +420,7 @@ class EthashBlockHeaderValidatorSpec bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, - treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None + treasuryAddress = Address(0) ) } diff --git a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidatorSpec.scala index 127f931208..0b33833596 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/PoWBlockHeaderValidatorSpec.scala @@ -15,7 +15,7 @@ class PoWBlockHeaderValidatorSpec extends AnyFlatSpecLike with Matchers { import PoWBlockHeaderValidatorSpec._ "PoWBlockHeaderValidator" should "call KeccakBlockHeaderValidator when chain is in Keccak" in { - val keccakConfig = blockchainConfig.copy(ecip1049BlockNumber = Some(10)) + val keccakConfig = blockchainConfig.withUpdatedForkBlocks(_.copy(ecip1049BlockNumber = Some(10))) val validatorForKeccak = new PoWBlockHeaderValidator(keccakConfig) validatorForKeccak.validateEvenMore(validKeccakBlockHeader) shouldBe Right(BlockHeaderValid) diff --git a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/RestrictedEthashBlockHeaderValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/RestrictedEthashBlockHeaderValidatorSpec.scala index f1a415247d..e1a48125c5 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/pow/validators/RestrictedEthashBlockHeaderValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/pow/validators/RestrictedEthashBlockHeaderValidatorSpec.scala @@ -8,7 +8,7 @@ import io.iohk.ethereum.crypto import io.iohk.ethereum.crypto.ECDSASignature import io.iohk.ethereum.domain.{Address, BlockHeader, UInt256} import io.iohk.ethereum.security.SecureRandomBuilder -import io.iohk.ethereum.utils.{BlockchainConfig, ByteStringUtils} +import io.iohk.ethereum.utils.{BlockchainConfig, ByteStringUtils, ForkBlockNumbers} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -68,22 +68,32 @@ class RestrictedEthashBlockHeaderValidatorSpec ) def createBlockchainConfig(allowedMiners: Set[ByteString]): BlockchainConfig = { BlockchainConfig( - frontierBlockNumber = 0, - homesteadBlockNumber = 1150000, + forkBlockNumbers = ForkBlockNumbers( + frontierBlockNumber = 0, + homesteadBlockNumber = 1150000, + byzantiumBlockNumber = 4370000, + constantinopleBlockNumber = 7280000, + istanbulBlockNumber = 9069000, + eip155BlockNumber = Long.MaxValue, + eip160BlockNumber = Long.MaxValue, + eip161BlockNumber = Long.MaxValue, + eip150BlockNumber = Long.MaxValue, + eip106BlockNumber = 0, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue, + ecip1098BlockNumber = Long.MaxValue, + ecip1097BlockNumber = Long.MaxValue, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), difficultyBombPauseBlockNumber = 3000000, difficultyBombContinueBlockNumber = 5000000, difficultyBombRemovalBlockNumber = 5900000, - byzantiumBlockNumber = 4370000, - constantinopleBlockNumber = 7280000, - istanbulBlockNumber = 9069000, daoForkConfig = None, // unused maxCodeSize = None, - eip155BlockNumber = Long.MaxValue, - eip160BlockNumber = Long.MaxValue, - eip161BlockNumber = Long.MaxValue, - eip150BlockNumber = Long.MaxValue, - eip106BlockNumber = 0, chainId = 0x3d.toByte, networkId = 1, monetaryPolicyConfig = null, @@ -93,17 +103,9 @@ class RestrictedEthashBlockHeaderValidatorSpec bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue, - ecip1098BlockNumber = Long.MaxValue, treasuryAddress = Address(0), - ecip1097BlockNumber = Long.MaxValue, checkpointPubKeys = Set.empty, allowedMinersPublicKeys = allowedMiners, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None ) } diff --git a/src/test/scala/io/iohk/ethereum/consensus/validators/BlockWithCheckpointHeaderValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/validators/BlockWithCheckpointHeaderValidatorSpec.scala index 1cfd21d350..d096d5b8a4 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/validators/BlockWithCheckpointHeaderValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/validators/BlockWithCheckpointHeaderValidatorSpec.scala @@ -130,7 +130,7 @@ class BlockWithCheckpointHeaderValidatorSpec } it should "return failure if created based on invalid number" in new TestSetup { - forAll(longGen suchThat (num => num != validBlockParentHeader.number + 1 && num >= config.ecip1097BlockNumber)) { + forAll(longGen suchThat (num => num != validBlockParentHeader.number + 1 && num >= config.forkBlockNumbers.ecip1097BlockNumber)) { number => val blockHeader = validBlockHeaderWithCheckpoint.copy(number = number) val validateResult = blockHeaderValidator.validate(blockHeader, validBlockParentHeader) @@ -257,10 +257,11 @@ class BlockWithCheckpointHeaderValidatorSpec "6848a3ab71918f57d3b9116b8e93c6fbc53e8a28dcd63e99c514dceee30fdd9741050fa7646bd196c9512e52f0d03097678c707996fff55587cd467801a1eee1" ) ) - val config: BlockchainConfig = blockchainConfig.copy( + val config: BlockchainConfig = blockchainConfig.withUpdatedForkBlocks(_.copy( ecip1097BlockNumber = validBlockParentHeader.number, ecip1098BlockNumber = validBlockParentHeader.number, eip106BlockNumber = 0, + )).copy( checkpointPubKeys = checkpointPubKeys ) diff --git a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala index 6258beafb7..7b4b0e68b4 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala @@ -247,7 +247,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { signedTransactionValidator.validate( stx.tx, senderAccount = senderAccountAfterHomestead, - blockHeader = blockHeaderAfterHomestead.copy(number = blockchainConfig.eip155BlockNumber), + blockHeader = blockHeaderAfterHomestead.copy(number = blockchainConfig.forkBlockNumbers.eip155BlockNumber), upfrontGasCost = upfrontGasCost, accumGasUsed = accumGasUsed ) match { diff --git a/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala b/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala index dbcc20058b..ea253cfafb 100644 --- a/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala +++ b/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala @@ -4,7 +4,7 @@ import akka.util.ByteString import scalapb.GeneratedMessageCompanion import io.iohk.ethereum.domain.{Account, Address, UInt256} import io.iohk.ethereum.extvm.msg.CallContext.Config -import io.iohk.ethereum.utils.VmConfig +import io.iohk.ethereum.utils.{ForkBlockNumbers, VmConfig} import io.iohk.ethereum.vm.utils.MockVmInput import io.iohk.ethereum.vm._ import org.scalamock.scalatest.MockFactory @@ -151,12 +151,13 @@ class VMClientSpec extends AnyFlatSpec with Matchers with MockFactory { it should "send hello msg" in new TestSetup { val blockchainConfig = io.iohk.ethereum.utils.Config.blockchains.blockchainConfig + val forkBlockNumbers: ForkBlockNumbers = blockchainConfig.forkBlockNumbers val expectedEthereumConfig = msg.EthereumConfig( - frontierBlockNumber = blockchainConfig.frontierBlockNumber, - homesteadBlockNumber = blockchainConfig.homesteadBlockNumber, - eip150BlockNumber = blockchainConfig.eip150BlockNumber, - eip160BlockNumber = blockchainConfig.eip160BlockNumber, - eip161BlockNumber = blockchainConfig.eip161BlockNumber, + frontierBlockNumber = forkBlockNumbers.frontierBlockNumber, + homesteadBlockNumber = forkBlockNumbers.homesteadBlockNumber, + eip150BlockNumber = forkBlockNumbers.eip150BlockNumber, + eip160BlockNumber = forkBlockNumbers.eip160BlockNumber, + eip161BlockNumber = forkBlockNumbers.eip161BlockNumber, maxCodeSize = blockchainConfig.maxCodeSize.get, accountStartNonce = blockchainConfig.accountStartNonce ) diff --git a/src/test/scala/io/iohk/ethereum/extvm/VMServerSpec.scala b/src/test/scala/io/iohk/ethereum/extvm/VMServerSpec.scala index 598878d036..77068debe5 100644 --- a/src/test/scala/io/iohk/ethereum/extvm/VMServerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/extvm/VMServerSpec.scala @@ -100,12 +100,13 @@ class VMServerSpec extends AnyFlatSpec with Matchers with MockFactory { trait TestSetup { val blockchainConfig = io.iohk.ethereum.utils.Config.blockchains.blockchainConfig + val forkBlockNumbers = blockchainConfig.forkBlockNumbers val ethereumConfig = msg.EthereumConfig( - frontierBlockNumber = blockchainConfig.frontierBlockNumber, - homesteadBlockNumber = blockchainConfig.homesteadBlockNumber, - eip150BlockNumber = blockchainConfig.eip150BlockNumber, - eip160BlockNumber = blockchainConfig.eip160BlockNumber, - eip161BlockNumber = blockchainConfig.eip161BlockNumber, + frontierBlockNumber = forkBlockNumbers.frontierBlockNumber, + homesteadBlockNumber = forkBlockNumbers.homesteadBlockNumber, + eip150BlockNumber = forkBlockNumbers.eip150BlockNumber, + eip160BlockNumber = forkBlockNumbers.eip160BlockNumber, + eip161BlockNumber = forkBlockNumbers.eip161BlockNumber, maxCodeSize = ByteString(), accountStartNonce = blockchainConfig.accountStartNonce ) diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala index 31098e5d92..88586a6d36 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala @@ -1,7 +1,6 @@ package io.iohk.ethereum.jsonrpc import java.time.Duration - import akka.actor.ActorSystem import akka.testkit.{TestKit, TestProbe} import akka.util.ByteString @@ -14,7 +13,7 @@ import io.iohk.ethereum.jsonrpc.PersonalService._ import io.iohk.ethereum.keystore.KeyStore.{DecryptionFailed, IOError} import io.iohk.ethereum.keystore.{KeyStore, Wallet} import io.iohk.ethereum.transactions.PendingTransactionsManager._ -import io.iohk.ethereum.utils.{BlockchainConfig, MonetaryPolicyConfig, TxPoolConfig} +import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig, TxPoolConfig} import io.iohk.ethereum.{Fixtures, NormalPatience, Timeouts, WithActorSystemShutDown} import monix.execution.Scheduler.Implicits.global import org.bouncycastle.util.encoders.Hex @@ -112,7 +111,7 @@ class PersonalServiceSpec (blockchain.getBestBlockNumber _).expects().returning(1234) (blockchain.getAccount _).expects(address, BigInt(1234)).returning(Some(Account(nonce, 2 * txValue))) - (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.eip155BlockNumber - 1) + (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.forkBlockNumbers.eip155BlockNumber - 1) val req = SendTransactionWithPassphraseRequest(tx, passphrase) val res = personal.sendTransaction(req).runToFuture @@ -133,7 +132,7 @@ class PersonalServiceSpec (blockchain.getBestBlockNumber _).expects().returning(1234) (blockchain.getAccount _).expects(address, BigInt(1234)).returning(Some(Account(nonce, 2 * txValue))) - (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.eip155BlockNumber - 1) + (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.forkBlockNumbers.eip155BlockNumber - 1) val req = SendTransactionWithPassphraseRequest(tx, passphrase) val res = personal.sendTransaction(req).runToFuture @@ -166,7 +165,7 @@ class PersonalServiceSpec (blockchain.getBestBlockNumber _).expects().returning(1234) (blockchain.getAccount _).expects(address, BigInt(1234)).returning(Some(Account(nonce, 2 * txValue))) - (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.eip155BlockNumber - 1) + (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.forkBlockNumbers.eip155BlockNumber - 1) val req = SendTransactionRequest(tx) val res = personal.sendTransaction(req).runToFuture @@ -325,7 +324,7 @@ class PersonalServiceSpec (blockchain.getBestBlockNumber _).expects().returning(1234) (blockchain.getAccount _).expects(address, BigInt(1234)).returning(Some(Account(nonce, 2 * txValue))) - (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.eip155BlockNumber - 1) + (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.forkBlockNumbers.eip155BlockNumber - 1) val req = SendTransactionWithPassphraseRequest(tx, passphrase) val res = personal.sendTransaction(req).runToFuture @@ -345,7 +344,7 @@ class PersonalServiceSpec (blockchain.getBestBlockNumber _).expects().returning(1234) (blockchain.getAccount _).expects(address, BigInt(1234)).returning(Some(Account(nonce, 2 * txValue))) val forkBlock = new Block(Fixtures.Blocks.Block3125369.header, Fixtures.Blocks.Block3125369.body) - (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.eip155BlockNumber) + (blockchain.getBestBlockNumber _).expects().returning(blockchainConfig.forkBlockNumbers.eip155BlockNumber) val req = SendTransactionWithPassphraseRequest(tx, passphrase) val res = personal.sendTransaction(req).runToFuture @@ -397,20 +396,30 @@ class PersonalServiceSpec val txValue = 128000 val blockchainConfig = BlockchainConfig( - eip155BlockNumber = 12345, chainId = 0x03.toByte, //unused networkId = 1, maxCodeSize = None, - eip161BlockNumber = 0, - frontierBlockNumber = 0, - homesteadBlockNumber = 0, - eip150BlockNumber = 0, - eip160BlockNumber = 0, - eip106BlockNumber = 0, - byzantiumBlockNumber = 0, - constantinopleBlockNumber = 0, - istanbulBlockNumber = 0, + forkBlockNumbers = ForkBlockNumbers( + eip155BlockNumber = 12345, + eip161BlockNumber = 0, + frontierBlockNumber = 0, + homesteadBlockNumber = 0, + eip150BlockNumber = 0, + eip160BlockNumber = 0, + eip106BlockNumber = 0, + byzantiumBlockNumber = 0, + constantinopleBlockNumber = 0, + istanbulBlockNumber = 0, + atlantisBlockNumber = 0, + aghartaBlockNumber = 0, + phoenixBlockNumber = 0, + petersburgBlockNumber = 0, + ecip1098BlockNumber = 0, + ecip1097BlockNumber = 0, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), difficultyBombPauseBlockNumber = 0, difficultyBombContinueBlockNumber = 0, difficultyBombRemovalBlockNumber = Long.MaxValue, @@ -422,15 +431,7 @@ class PersonalServiceSpec bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = 0, - aghartaBlockNumber = 0, - phoenixBlockNumber = 0, - petersburgBlockNumber = 0, - ecip1098BlockNumber = 0, treasuryAddress = Address(0), - ecip1097BlockNumber = 0, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None ) val wallet = Wallet(address, prvKey) diff --git a/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala index cf178b15f1..b4546e5b8c 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala @@ -86,7 +86,7 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope payload = ByteString.empty ) val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) - val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.byzantiumBlockNumber - 1) + val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber - 1) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = consensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) @@ -107,7 +107,7 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope ) val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)).tx val header: BlockHeader = - defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.byzantiumBlockNumber) + defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = consensus.blockPreparator.executeTransactions(Seq(stx), initialWorld, header) @@ -133,7 +133,7 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope ) val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = - defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.byzantiumBlockNumber) + defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = testConsensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) diff --git a/src/test/scala/io/iohk/ethereum/ledger/BlockRewardSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/BlockRewardSpec.scala index e919c2a807..1bca460b14 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/BlockRewardSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/BlockRewardSpec.scala @@ -10,7 +10,7 @@ import io.iohk.ethereum.ledger.BlockPreparator._ import io.iohk.ethereum.ledger.Ledger.VMImpl import io.iohk.ethereum.ledger.BlockRewardCalculatorOps._ import io.iohk.ethereum.mpt.MerklePatriciaTrie -import io.iohk.ethereum.utils.Config +import io.iohk.ethereum.utils.{Config, ForkBlockNumbers} import org.scalamock.scalatest.MockFactory import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers @@ -113,7 +113,7 @@ class BlockRewardSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyC } it should "correctly distribute block reward according to ECIP1098" in new TestSetup { - val blockNoPostTreasury = blockchainConfig.ecip1098BlockNumber + 1 + val blockNoPostTreasury = blockchainConfig.forkBlockNumbers.ecip1098BlockNumber + 1 val blockReward = consensus.blockPreparator.blockRewardCalculator.calculateMiningRewardForBlock(sampleBlockNumber) val blockRewardPostTreasury = consensus.blockPreparator.blockRewardCalculator.calculateMiningRewardForBlock(blockNoPostTreasury) @@ -179,9 +179,12 @@ class BlockRewardSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyC val treasuryAddress = validAccountAddress2 val baseBlockchainConfig = Config.blockchains.blockchainConfig + private val forkBlockNumbers: ForkBlockNumbers = baseBlockchainConfig.forkBlockNumbers override lazy val blockchainConfig = baseBlockchainConfig - .copy(treasuryAddress = treasuryAddress) - .copy(ecip1098BlockNumber = baseBlockchainConfig.byzantiumBlockNumber + 100) + .copy(treasuryAddress = treasuryAddress, + forkBlockNumbers = forkBlockNumbers + .copy(ecip1098BlockNumber = forkBlockNumbers.byzantiumBlockNumber + 100) + ) val minerTwoOmmersReward = BigInt("5312500000000000000") val ommerFiveBlocksDifferenceReward = BigInt("1875000000000000000") @@ -225,7 +228,7 @@ class BlockRewardSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyC } def sampleBlockAfterByzantium(minerAddress: Address, ommerMiners: Seq[Address] = Nil): Block = { - val baseBlockNumber = blockchainConfig.byzantiumBlockNumber + val baseBlockNumber = forkBlockNumbers.byzantiumBlockNumber Block( header = Fixtures.Blocks.Genesis.header.copy(beneficiary = minerAddress.bytes, number = baseBlockNumber), body = Fixtures.Blocks.Genesis.body.copy( diff --git a/src/test/scala/io/iohk/ethereum/ledger/LedgerSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/LedgerSpec.scala index 0ff0d25dee..d9bbca3d4f 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/LedgerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/LedgerSpec.scala @@ -353,7 +353,7 @@ class LedgerSpec extends AnyFlatSpec with ScalaCheckPropertyChecks with Matchers payload = ByteString.empty ) val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) - val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.byzantiumBlockNumber - 1) + val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber - 1) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = consensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) @@ -374,7 +374,7 @@ class LedgerSpec extends AnyFlatSpec with ScalaCheckPropertyChecks with Matchers ) val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)).tx val header: BlockHeader = - defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.byzantiumBlockNumber) + defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = consensus.blockPreparator.executeTransactions(Seq(stx), initialWorld, header) @@ -400,7 +400,7 @@ class LedgerSpec extends AnyFlatSpec with ScalaCheckPropertyChecks with Matchers ) val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = - defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.byzantiumBlockNumber) + defaultBlockHeader.copy(beneficiary = minerAddress.bytes, number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = testConsensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) diff --git a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala index ab320cf839..98c51ca557 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala @@ -48,7 +48,7 @@ trait TestSetup extends SecureRandomBuilder with EphemBlockchainTestSetup { val defaultBlockHeader = Fixtures.Blocks.ValidBlock.header.copy( difficulty = 1000000, - number = blockchainConfig.homesteadBlockNumber + 1, + number = blockchainConfig.forkBlockNumbers.homesteadBlockNumber + 1, gasLimit = 1000000, gasUsed = 0, unixTimestamp = 1486752441 @@ -206,20 +206,21 @@ trait DaoForkTestSetup extends TestSetup with MockFactory { override val refundContract: Option[Address] = Some(Address(4)) } - val proDaoBlockchainConfig: BlockchainConfig = blockchainConfig.copy( + val proDaoBlockchainConfig: BlockchainConfig = blockchainConfig.withUpdatedForkBlocks(_.copy( + eip106BlockNumber = Long.MaxValue, + atlantisBlockNumber = Long.MaxValue, + aghartaBlockNumber = Long.MaxValue, + phoenixBlockNumber = Long.MaxValue, + petersburgBlockNumber = Long.MaxValue + )).copy( chainId = 0x01.toByte, networkId = 1, daoForkConfig = Some(supportDaoForkConfig), customGenesisFileOpt = None, - eip106BlockNumber = Long.MaxValue, maxCodeSize = None, bootstrapNodes = Set(), gasTieBreaker = false, ethCompatibleStorage = true, - atlantisBlockNumber = Long.MaxValue, - aghartaBlockNumber = Long.MaxValue, - phoenixBlockNumber = Long.MaxValue, - petersburgBlockNumber = Long.MaxValue ) val parentBlockHeader = Fixtures.Blocks.DaoParentBlock.header diff --git a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala index 76e304c125..a9df2115d3 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala @@ -106,19 +106,29 @@ class StxLedgerSpec extends AnyFlatSpec with Matchers with Logger { trait ScenarioSetup extends EphemBlockchainTestSetup { override lazy val blockchainConfig: BlockchainConfig = BlockchainConfig( - eip155BlockNumber = 0, + forkBlockNumbers = ForkBlockNumbers( + eip155BlockNumber = 0, + eip161BlockNumber = 0, + frontierBlockNumber = 0, + homesteadBlockNumber = 0, + eip150BlockNumber = 0, + eip160BlockNumber = 0, + eip106BlockNumber = 0, + byzantiumBlockNumber = 0, + constantinopleBlockNumber = 0, + istanbulBlockNumber = 0, + atlantisBlockNumber = 0, + aghartaBlockNumber = 0, + phoenixBlockNumber = 0, + petersburgBlockNumber = 0, + ecip1098BlockNumber = 0, + ecip1097BlockNumber = 0, + ecip1099BlockNumber = Long.MaxValue, + ecip1049BlockNumber = None + ), chainId = 0x03.toByte, networkId = 1, maxCodeSize = None, - eip161BlockNumber = 0, - frontierBlockNumber = 0, - homesteadBlockNumber = 0, - eip150BlockNumber = 0, - eip160BlockNumber = 0, - eip106BlockNumber = 0, - byzantiumBlockNumber = 0, - constantinopleBlockNumber = 0, - istanbulBlockNumber = 0, difficultyBombPauseBlockNumber = 0, difficultyBombContinueBlockNumber = 0, difficultyBombRemovalBlockNumber = Long.MaxValue, @@ -130,15 +140,7 @@ trait ScenarioSetup extends EphemBlockchainTestSetup { gasTieBreaker = false, ethCompatibleStorage = true, bootstrapNodes = Set(), - atlantisBlockNumber = 0, - aghartaBlockNumber = 0, - phoenixBlockNumber = 0, - petersburgBlockNumber = 0, - ecip1098BlockNumber = 0, - treasuryAddress = Address(0), - ecip1097BlockNumber = 0, - ecip1099BlockNumber = Long.MaxValue, - ecip1049BlockNumber = None + treasuryAddress = Address(0) ) override lazy val stxLedger = new StxLedger(blockchain, blockchainConfig, consensus.blockPreparator)