From cc7d5e660fd6aa6eb3760061fa0e5d49a7353d1e Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Tue, 10 Sep 2024 13:18:44 -0700 Subject: [PATCH] bring in gethparams.ChainConfig (wip) --- accounts/abi/bind/bind_test.go | 2 +- .../precompilebind/precompile_bind_test.go | 2 +- core/blockchain_repair_test.go | 2 +- core/blockchain_test.go | 14 +- core/gen_genesis.go | 10 +- core/genesis.go | 1 - core/genesis_libevm.go | 26 - core/genesis_test.go | 11 +- core/state_processor.go | 3 +- core/state_processor_test.go | 58 +-- core/test_blockchain.go | 2 +- core/txpool/blobpool/blobpool_test.go | 2 +- core/vm/runtime/runtime.go | 28 +- eth/gasprice/gasprice_test.go | 2 +- eth/tracers/api.go | 2 +- eth/tracers/api_extra_test.go | 8 +- ethclient/simulated/backend.go | 2 +- go.mod | 2 +- go.sum | 4 +- internal/ethapi/transaction_args_test.go | 30 +- params/config.go | 448 +++++------------- params/config_extra.go | 67 +-- params/config_libevm.go | 29 +- params/config_test.go | 44 +- params/network_upgrades.go | 2 +- params/network_upgrades_test.go | 2 +- params/precompile_config_test.go | 12 +- params/precompile_upgrade.go | 4 +- params/precompile_upgrade_test.go | 9 +- params/state_upgrade.go | 4 +- params/state_upgrade_test.go | 2 +- tests/init.go | 81 ++-- 32 files changed, 339 insertions(+), 576 deletions(-) delete mode 100644 core/genesis_libevm.go diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go index 9962136472..d14f7acd50 100644 --- a/accounts/abi/bind/bind_test.go +++ b/accounts/abi/bind/bind_test.go @@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) { if out, err := replacer.CombinedOutput(); err != nil { t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) } - replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240909202038-fdd63effd030") + replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240910195743-bc476fea4692") replacer.Dir = pkg if out, err := replacer.CombinedOutput(); err != nil { t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) diff --git a/accounts/abi/bind/precompilebind/precompile_bind_test.go b/accounts/abi/bind/precompilebind/precompile_bind_test.go index 14ea17d682..8295f4b588 100644 --- a/accounts/abi/bind/precompilebind/precompile_bind_test.go +++ b/accounts/abi/bind/precompilebind/precompile_bind_test.go @@ -695,7 +695,7 @@ func TestPrecompileBind(t *testing.T) { if out, err := replacer.CombinedOutput(); err != nil { t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) } - replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240909202038-fdd63effd030") + replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240910195743-bc476fea4692") replacer.Dir = pkg if out, err := replacer.CombinedOutput(); err != nil { t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index 7a5528397d..133dd314a6 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -527,7 +527,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s defer db.Close() // Might double close, should be fine // Initialize a fresh chain - chainConfig := *params.TestChainConfig + chainConfig := params.Copy(params.TestChainConfig) params.GetExtra(&chainConfig).FeeConfig.MinBaseFee = big.NewInt(1) var ( require = require.New(t) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index dec19005f2..dbce963cee 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -313,8 +313,11 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) { // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}}, - Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}}, + Config: params.WithExtra( + ¶ms.ChainConfig{HomesteadBlock: new(big.Int)}, + ¶ms.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}, + ), + Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := createBlockChain(chainDB, pruningConfig, gspec, common.Hash{}) @@ -426,8 +429,11 @@ func TestUngracefulAsyncShutdown(t *testing.T) { // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}}, - Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}}, + Config: params.WithExtra( + ¶ms.ChainConfig{HomesteadBlock: new(big.Int)}, + ¶ms.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}, + ), + Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) diff --git a/core/gen_genesis.go b/core/gen_genesis.go index 008162561e..03f7c6fe42 100644 --- a/core/gen_genesis.go +++ b/core/gen_genesis.go @@ -8,10 +8,10 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/core/types" - "github.com/ava-labs/subnet-evm/params" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/params" ) var _ = (*genesisSpecMarshaling)(nil) @@ -19,7 +19,7 @@ var _ = (*genesisSpecMarshaling)(nil) // MarshalJSON marshals as JSON. func (g Genesis) MarshalJSON() ([]byte, error) { type Genesis struct { - Config *ChainConfig `json:"config"` + Config *params.ChainConfig `json:"config"` Nonce math.HexOrDecimal64 `json:"nonce"` Timestamp math.HexOrDecimal64 `json:"timestamp"` ExtraData hexutil.Bytes `json:"extraData"` @@ -39,7 +39,7 @@ func (g Genesis) MarshalJSON() ([]byte, error) { BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` } var enc Genesis - enc.Config = (*ChainConfig)(g.Config) + enc.Config = g.Config enc.Nonce = math.HexOrDecimal64(g.Nonce) enc.Timestamp = math.HexOrDecimal64(g.Timestamp) enc.ExtraData = g.ExtraData @@ -68,7 +68,7 @@ func (g Genesis) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (g *Genesis) UnmarshalJSON(input []byte) error { type Genesis struct { - Config *ChainConfig `json:"config"` + Config *params.ChainConfig `json:"config"` Nonce *math.HexOrDecimal64 `json:"nonce"` Timestamp *math.HexOrDecimal64 `json:"timestamp"` ExtraData *hexutil.Bytes `json:"extraData"` @@ -92,7 +92,7 @@ func (g *Genesis) UnmarshalJSON(input []byte) error { return err } if dec.Config != nil { - g.Config = (*params.ChainConfig)(dec.Config) + g.Config = dec.Config } if dec.Nonce != nil { g.Nonce = uint64(*dec.Nonce) diff --git a/core/genesis.go b/core/genesis.go index cb90b91802..2394ffcf49 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -92,7 +92,6 @@ type Genesis struct { // field type overrides for gencodec type genesisSpecMarshaling struct { - Config *ChainConfig Nonce math.HexOrDecimal64 Timestamp math.HexOrDecimal64 ExtraData hexutil.Bytes diff --git a/core/genesis_libevm.go b/core/genesis_libevm.go deleted file mode 100644 index 76fe66b8a9..0000000000 --- a/core/genesis_libevm.go +++ /dev/null @@ -1,26 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package core - -import ( - "encoding/json" - - "github.com/ava-labs/subnet-evm/params" - gethparams "github.com/ethereum/go-ethereum/params" -) - -type ChainConfig params.ChainConfig - -func (c *ChainConfig) MarshalJSON() ([]byte, error) { - return json.Marshal((*params.ChainConfig)(c)) -} - -func (c *ChainConfig) UnmarshalJSON(input []byte) error { - var tmp gethparams.ChainConfig - if err := json.Unmarshal(input, &tmp); err != nil { - return err - } - *c = (ChainConfig)(*params.FromChainConfig(&tmp)) - return nil -} diff --git a/core/genesis_test.go b/core/genesis_test.go index 0fd227b05b..dfdd57e705 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -70,7 +70,7 @@ func TestSetupGenesis(t *testing.T) { } func testSetupGenesis(t *testing.T, scheme string) { - preSubnetConfig := *params.TestPreSubnetEVMChainConfig + preSubnetConfig := params.Copy(params.TestPreSubnetEVMChainConfig) params.GetExtra(&preSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(100) var ( customghash = common.HexToHash("0x4a12fe7bf8d40d152d7e9de22337b115186a4662aa3a97217b36146202bbfc66") @@ -84,7 +84,7 @@ func testSetupGenesis(t *testing.T, scheme string) { oldcustomg = customg ) - rollbackpreSubnetConfig := preSubnetConfig + rollbackpreSubnetConfig := params.Copy(&preSubnetConfig) params.GetExtra(&rollbackpreSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(90) oldcustomg.Config = &rollbackpreSubnetConfig @@ -208,7 +208,7 @@ func TestStatefulPrecompilesConfigure(t *testing.T) { for name, test := range map[string]test{ "allow list enabled in genesis": { getConfig: func() *params.ChainConfig { - config := *params.TestChainConfig + config := params.Copy(params.TestChainConfig) params.GetExtra(&config).GenesisPrecompiles = params.Precompiles{ deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr}, nil, nil), } @@ -283,7 +283,7 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) { // header must be bigger than last accepted require.Greater(block.Time, bc.lastAccepted.Time()) - activatedGenesisConfig := *customg.Config + activatedGenesisConfig := params.Copy(customg.Config) contractDeployerConfig := deployerallowlist.NewConfig(utils.NewUint64(51), nil, nil, nil) params.GetExtra(&activatedGenesisConfig).UpgradeConfig.PrecompileUpgrades = []params.PrecompileUpgrade{ { @@ -307,7 +307,7 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) { func TestGenesisWriteUpgradesRegression(t *testing.T) { require := require.New(t) - config := *params.TestChainConfig + config := params.Copy(params.TestChainConfig) genesis := &Genesis{ Config: &config, Alloc: types.GenesisAlloc{ @@ -367,6 +367,7 @@ func TestVerkleGenesisCommit(t *testing.T) { PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(0), MuirGlacierBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), CancunTime: &verkleTime, VerkleTime: &verkleTime, } diff --git a/core/state_processor.go b/core/state_processor.go index 91d042910a..e7001f7600 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -214,8 +214,9 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, // This ensures that the order we call Configure for each precompile is consistent. // This ensures even if precompiles read/write state other than their own they will observe // an identical global state in a deterministic order when they are configured. + extra := params.GetExtra(c) for _, module := range modules.RegisteredModules() { - for _, activatingConfig := range params.GetExtra(c).GetActivatingPrecompileConfigs(module.Address, parentTimestamp, blockTimestamp, params.GetExtra(c).PrecompileUpgrades) { + for _, activatingConfig := range extra.GetActivatingPrecompileConfigs(module.Address, parentTimestamp, blockTimestamp, extra.PrecompileUpgrades) { // If this transition activates the upgrade, configure the stateful precompile. // (or deconfigure it if it is being disabled.) if activatingConfig.IsDisabled() { diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 9874dd1c1a..f53d05e404 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -55,7 +55,7 @@ func u64(val uint64) *uint64 { return &val } // blockchain imports bad blocks, meaning blocks which have valid headers but // contain invalid transactions func TestStateProcessorErrors(t *testing.T) { - cpcfg := *params.TestChainConfig + cpcfg := params.Copy(params.TestChainConfig) config := &cpcfg config.CancunTime = u64(0) params.GetExtra(config).FeeConfig.MinBaseFee = big.NewInt(params.TestMaxBaseFee) @@ -256,21 +256,21 @@ func TestStateProcessorErrors(t *testing.T) { var ( db = rawdb.NewMemoryDatabase() gspec = &Genesis{ - Config: ¶ms.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: params.ChainConfigExtra{ - FeeConfig: params.DefaultFeeConfig, + Config: params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), }, - }, + ¶ms.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}, + ), Alloc: types.GenesisAlloc{ common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): types.Account{ Balance: big.NewInt(1000000000000000000), // 1 ether @@ -353,18 +353,20 @@ func TestBadTxAllowListBlock(t *testing.T) { db = rawdb.NewMemoryDatabase() testAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7") - config = ¶ms.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: params.ChainConfigExtra{ + config = params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + }, + ¶ms.ChainConfigExtra{ FeeConfig: params.DefaultFeeConfig, NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(0), @@ -373,7 +375,7 @@ func TestBadTxAllowListBlock(t *testing.T) { txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), nil, nil, nil), }, }, - } + ) signer = types.LatestSigner(config) testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") diff --git a/core/test_blockchain.go b/core/test_blockchain.go index 8664e41bd3..c48545ef6c 100644 --- a/core/test_blockchain.go +++ b/core/test_blockchain.go @@ -1483,7 +1483,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, gspec // Ensure that key1 has sufficient funds in the genesis block for all of the tests. genesisBalance := new(big.Int).Mul(big.NewInt(1000000), big.NewInt(params.Ether)) - config := *params.TestChainConfig + config := params.Copy(params.TestChainConfig) // Set all of the required config parameters params.GetExtra(&config).GenesisPrecompiles = params.Precompiles{ deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr1}, nil, nil), diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index 92ee854d54..6a4e0c4e2b 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -72,7 +72,7 @@ var testChainConfig *params.ChainConfig func init() { testChainConfig = new(params.ChainConfig) - *testChainConfig = *params.TestChainConfig + *testChainConfig = params.Copy(params.TestChainConfig) params.GetExtra(testChainConfig).FeeConfig.MinBaseFee = new(big.Int).SetUint64(1) testChainConfig.CancunTime = new(uint64) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 01187dbb6b..ce7c2ea360 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -67,23 +67,25 @@ type Config struct { // sets defaults on the config func setDefaults(cfg *Config) { if cfg.ChainConfig == nil { - cfg.ChainConfig = ¶ms.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: new(big.Int), - EIP150Block: new(big.Int), - EIP155Block: new(big.Int), - EIP158Block: new(big.Int), - ByzantiumBlock: new(big.Int), - ConstantinopleBlock: new(big.Int), - PetersburgBlock: new(big.Int), - IstanbulBlock: new(big.Int), - MuirGlacierBlock: new(big.Int), - ChainConfigExtra: params.ChainConfigExtra{ + cfg.ChainConfig = params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: new(big.Int), + EIP150Block: new(big.Int), + EIP155Block: new(big.Int), + EIP158Block: new(big.Int), + ByzantiumBlock: new(big.Int), + ConstantinopleBlock: new(big.Int), + PetersburgBlock: new(big.Int), + IstanbulBlock: new(big.Int), + MuirGlacierBlock: new(big.Int), + }, + ¶ms.ChainConfigExtra{ NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: new(uint64), }, }, - } + ) } if cfg.Difficulty == nil { diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 3f1f32712e..ada261504a 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -390,7 +390,7 @@ func TestSuggestGasPriceAfterFeeConfigUpdate(t *testing.T) { } // create a chain config with fee manager enabled at genesis with [addr] as the admin - chainConfig := *params.TestChainConfig + chainConfig := params.Copy(params.TestChainConfig) params.GetExtra(&chainConfig).GenesisPrecompiles = params.Precompiles{ feemanager.ConfigKey: feemanager.NewConfig(utils.NewUint64(0), []common.Address{addr}, nil, nil, nil), } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 45f86eff73..5b5d0de30f 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -1056,7 +1056,7 @@ func APIs(backend Backend) []rpc.API { // along with a boolean that indicates whether the copy is canonical (equivalent to the original). func overrideConfig(original *params.ChainConfig, override *params.ChainConfig) (*params.ChainConfig, bool) { copy := new(params.ChainConfig) - *copy = *original + *copy = params.Copy(original) canon := true if timestamp := params.GetExtra(override).SubnetEVMTimestamp; timestamp != nil { diff --git a/eth/tracers/api_extra_test.go b/eth/tracers/api_extra_test.go index cbc6495d80..6aedd38a88 100644 --- a/eth/tracers/api_extra_test.go +++ b/eth/tracers/api_extra_test.go @@ -30,7 +30,7 @@ func TestTraceBlockPrecompileActivation(t *testing.T) { // Initialize test accounts accounts := newAccounts(3) - copyConfig := *params.TestChainConfig + copyConfig := params.Copy(params.TestChainConfig) genesis := &core.Genesis{ Config: ©Config, Alloc: types.GenesisAlloc{ @@ -136,7 +136,7 @@ func TestTraceTransactionPrecompileActivation(t *testing.T) { // Initialize test accounts accounts := newAccounts(3) - copyConfig := *params.TestChainConfig + copyConfig := params.Copy(params.TestChainConfig) genesis := &core.Genesis{ Config: ©Config, Alloc: types.GenesisAlloc{ @@ -200,7 +200,7 @@ func TestTraceChainPrecompileActivation(t *testing.T) { // Initialize test accounts // Note: the balances in this test have been increased compared to go-ethereum. accounts := newAccounts(3) - copyConfig := *params.TestChainConfig + copyConfig := params.Copy(params.TestChainConfig) genesis := &core.Genesis{ Config: ©Config, Alloc: types.GenesisAlloc{ @@ -297,7 +297,7 @@ func TestTraceCallWithOverridesStateUpgrade(t *testing.T) { // Initialize test accounts accounts := newAccounts(3) - copyConfig := *params.TestChainConfig + copyConfig := params.Copy(params.TestChainConfig) genesis := &core.Genesis{ Config: ©Config, Alloc: types.GenesisAlloc{ diff --git a/ethclient/simulated/backend.go b/ethclient/simulated/backend.go index ade822572f..3e563f0402 100644 --- a/ethclient/simulated/backend.go +++ b/ethclient/simulated/backend.go @@ -81,7 +81,7 @@ type Backend struct { // // A simulated backend always uses chainID 1337. func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config, ethConf *ethconfig.Config)) *Backend { - chainConfig := *params.TestChainConfig + chainConfig := params.Copy(params.TestChainConfig) chainConfig.ChainID = big.NewInt(1337) // Create the default configurations for the outer node shell and the Ethereum diff --git a/go.mod b/go.mod index b03f203786..83d7b458fc 100644 --- a/go.mod +++ b/go.mod @@ -154,6 +154,6 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum => github.com/ava-labs/go-ethereum v0.0.0-20240909202038-fdd63effd030 +replace github.com/ethereum/go-ethereum => github.com/ava-labs/go-ethereum v0.0.0-20240910195743-bc476fea4692 // replace github.com/ethereum/go-ethereum => ../go-ethereum diff --git a/go.sum b/go.sum index 4f9c937094..c829243028 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/ava-labs/avalanchego v1.11.11 h1:MIQq8xRavRj4ZXHA4G+aMiymig7SOScGOG1S github.com/ava-labs/avalanchego v1.11.11/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 h1:wlhGJbmb7s3bU2QWtxKjscGjfHknQiq+cVhhUjONsB8= github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732/go.mod h1:RkQLaQ961Xe/sUb3ycn4Qi18vPPuEetTqDf2eDcquAs= -github.com/ava-labs/go-ethereum v0.0.0-20240909202038-fdd63effd030 h1:8NsWrzEG9ho9gE4sSLF57BKdu39yUa0RG9lGy7dqkDk= -github.com/ava-labs/go-ethereum v0.0.0-20240909202038-fdd63effd030/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= +github.com/ava-labs/go-ethereum v0.0.0-20240910195743-bc476fea4692 h1:ab//PIDdJWGvXw8JpfoTjF2eYzVuuyVLWBD+7uiYe9Y= +github.com/ava-labs/go-ethereum v0.0.0-20240910195743-bc476fea4692/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index c7afc79439..c4db623dab 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -263,24 +263,26 @@ type backendMock struct { func newBackendMock() *backendMock { var cancunTime uint64 = 600 - config := ¶ms.ChainConfig{ - ChainID: big.NewInt(42), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: params.ChainConfigExtra{ + config := params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(42), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + CancunTime: &cancunTime, + }, + ¶ms.ChainConfigExtra{ NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(100), }, }, - CancunTime: &cancunTime, - } + ) return &backendMock{ current: &types.Header{ Difficulty: big.NewInt(10000000000), diff --git a/params/config.go b/params/config.go index 8820166d39..70db40f300 100644 --- a/params/config.go +++ b/params/config.go @@ -45,39 +45,45 @@ var ( _ = do_init() // XXX: is (temporarily) here because type registeration must proceed the call to .Rules() // SubnetEVMDefaultConfig is the default configuration // without any network upgrades. - SubnetEVMDefaultChainConfig = &ChainConfig{ - ChainID: DefaultChainID, - - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + SubnetEVMDefaultChainConfig = WithExtra( + &ChainConfig{ + ChainID: DefaultChainID, + + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + }, + &ChainConfigExtra{ FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, NetworkUpgrades: getDefaultNetworkUpgrades(upgrade.GetConfig(constants.MainnetID)), // This can be changed to correct network (local, test) via VM. GenesisPrecompiles: Precompiles{}, }, - } + ) - TestChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - CancunTime: utils.TimeToNewUint64(upgrade.GetConfig(constants.UnitTestID).EtnaTime), - ChainConfigExtra: ChainConfigExtra{ + TestChainConfig = WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + CancunTime: utils.TimeToNewUint64(upgrade.GetConfig(constants.UnitTestID).EtnaTime), + }, + &ChainConfigExtra{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, @@ -85,20 +91,24 @@ var ( GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, }, - } + ) - TestPreSubnetEVMChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + TestPreSubnetEVMChainConfig = WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + }, + &ChainConfigExtra{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, @@ -110,20 +120,23 @@ var ( GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, }, - } + ) - TestSubnetEVMChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + TestSubnetEVMChainConfig = WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + }, + &ChainConfigExtra{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, @@ -135,20 +148,22 @@ var ( GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, }, - } + ) - TestDurangoChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + TestDurangoChainConfig = WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + }, + &ChainConfigExtra{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, @@ -160,20 +175,22 @@ var ( GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, }, - } + ) - TestEtnaChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + TestEtnaChainConfig = WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + }, + &ChainConfigExtra{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, @@ -185,7 +202,7 @@ var ( GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, }, - } + ) TestRules = TestChainConfig.Rules(new(big.Int), IsMergeTODO, 0) ) @@ -194,39 +211,25 @@ var ( // ChainConfig is stored in the database on a per block basis. This means // that any network, identified by its genesis block, can have its own // set of configuration options. -type ChainConfig struct { - ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection - - HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead) - - // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) - EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork) - EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block - EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block - - ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) - ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) - PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) - IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) - MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) - - // Fork scheduling was switched from blocks to timestamps here - - CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already activated) - VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle) - - // XXX: Should not be accessed directly except to initialize. Use GetExtra instead. - ChainConfigExtra ChainConfigExtra `json:"-"` -} +type ChainConfig = gethparams.ChainConfig func GetExtra(c *ChainConfig) *ChainConfigExtra { - return &c.ChainConfigExtra + if extra := FromChainConfig(c); extra != nil { + return extra + } + return &ChainConfigExtra{} } func GetRulesExtra(r Rules) *RulesExtra { return FromRules(&r) } +func Copy(c *ChainConfig) ChainConfig { + cpy := *c + extraCpy := *GetExtra(c) + return *WithExtra(&cpy, &extraCpy) +} + type ChainConfigExtra struct { NetworkUpgrades // Config for timestamps that enable network upgrades. Skip encoding/decoding directly into ChainConfig. @@ -239,38 +242,12 @@ type ChainConfigExtra struct { UpgradeConfig `json:"-"` // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Skip encoding/decoding directly into ChainConfig. } -// Description returns a human-readable description of ChainConfig. -func (c *ChainConfig) Description() string { - var banner string - - banner += fmt.Sprintf("Chain ID: %v\n", c.ChainID) - banner += "Consensus: Dummy Consensus Engine\n\n" - - // Create a list of forks with a short description of them. Forks that only - // makes sense for mainnet should be optional at printing to avoid bloating - // the output for testnets and private networks. - banner += "Hard Forks (block based):\n" - banner += fmt.Sprintf(" - Homestead: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)\n", c.HomesteadBlock) - banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)\n", c.EIP150Block) - banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) - banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) - banner += fmt.Sprintf(" - Byzantium: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)\n", c.ByzantiumBlock) - banner += fmt.Sprintf(" - Constantinople: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)\n", c.ConstantinopleBlock) - banner += fmt.Sprintf(" - Petersburg: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)\n", c.PetersburgBlock) - banner += fmt.Sprintf(" - Istanbul: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)\n", c.IstanbulBlock) - if c.MuirGlacierBlock != nil { - banner += fmt.Sprintf(" - Muir Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock) +func (c *ChainConfigExtra) Description() string { + // Handle nil receiver + if c == nil { + return "" } - banner += "Hard forks (timestamp based):\n" - banner += fmt.Sprintf(" - Cancun Timestamp: @%-10v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/cancun.md)\n", ptrToString(c.CancunTime)) - banner += fmt.Sprintf(" - Verkle Timestamp: @%-10v", ptrToString(c.VerkleTime)) - banner += "\n" - - return banner + c.ChainConfigExtra.Description() -} - -func (c *ChainConfigExtra) Description() string { var banner string banner += "Avalanche Upgrades (timestamp based):\n" @@ -303,88 +280,6 @@ func (c *ChainConfigExtra) Description() string { return banner } -// IsHomestead returns whether num is either equal to the homestead block or greater. -func (c *ChainConfig) IsHomestead(num *big.Int) bool { - return isBlockForked(c.HomesteadBlock, num) -} - -// IsEIP150 returns whether num is either equal to the EIP150 fork block or greater. -func (c *ChainConfig) IsEIP150(num *big.Int) bool { - return isBlockForked(c.EIP150Block, num) -} - -// IsEIP155 returns whether num is either equal to the EIP155 fork block or greater. -func (c *ChainConfig) IsEIP155(num *big.Int) bool { - return isBlockForked(c.EIP155Block, num) -} - -// IsEIP158 returns whether num is either equal to the EIP158 fork block or greater. -func (c *ChainConfig) IsEIP158(num *big.Int) bool { - return isBlockForked(c.EIP158Block, num) -} - -// IsByzantium returns whether num is either equal to the Byzantium fork block or greater. -func (c *ChainConfig) IsByzantium(num *big.Int) bool { - return isBlockForked(c.ByzantiumBlock, num) -} - -// IsConstantinople returns whether num is either equal to the Constantinople fork block or greater. -func (c *ChainConfig) IsConstantinople(num *big.Int) bool { - return isBlockForked(c.ConstantinopleBlock, num) -} - -// IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater. -func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool { - return isBlockForked(c.MuirGlacierBlock, num) -} - -// IsPetersburg returns whether num is either -// - equal to or greater than the PetersburgBlock fork block, -// - OR is nil, and Constantinople is active -func (c *ChainConfig) IsPetersburg(num *big.Int) bool { - return isBlockForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isBlockForked(c.ConstantinopleBlock, num) -} - -// IsIstanbul returns whether num is either equal to the Istanbul fork block or greater. -func (c *ChainConfig) IsIstanbul(num *big.Int) bool { - return isBlockForked(c.IstanbulBlock, num) -} - -// IsCancun returns whether time is either equal to the Cancun fork time or greater. -func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { - return isTimestampForked(c.CancunTime, time) -} - -// IsVerkle returns whether time is either equal to the Verkle fork time or greater. -func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool { - return isTimestampForked(c.VerkleTime, time) -} - -// CheckCompatible checks whether scheduled fork transitions have been imported -// with a mismatching chain configuration. -func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError { - var ( - bhead = new(big.Int).SetUint64(height) - btime = time - ) - // Iterate checkCompatible to find the lowest conflict. - var lasterr *ConfigCompatError - for { - err := c.checkCompatible(newcfg, bhead, btime) - if err == nil || (lasterr != nil && err.RewindToBlock == lasterr.RewindToBlock && err.RewindToTime == lasterr.RewindToTime) { - break - } - lasterr = err - - if err.RewindToTime > 0 { - btime = err.RewindToTime - } else { - bhead.SetUint64(err.RewindToBlock) - } - } - return lasterr -} - type fork struct { name string block *big.Int // some go-ethereum forks use block numbers @@ -392,31 +287,12 @@ type fork struct { optional bool // if true, the fork may be nil and next fork is still allowed } -// CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough -// to guarantee that forks can be implemented in a different order than on official networks -func (c *ChainConfig) CheckConfigForkOrder() error { - ethForks := []fork{ - {name: "homesteadBlock", block: c.HomesteadBlock}, - {name: "eip150Block", block: c.EIP150Block}, - {name: "eip155Block", block: c.EIP155Block}, - {name: "eip158Block", block: c.EIP158Block}, - {name: "byzantiumBlock", block: c.ByzantiumBlock}, - {name: "constantinopleBlock", block: c.ConstantinopleBlock}, - {name: "petersburgBlock", block: c.PetersburgBlock}, - {name: "istanbulBlock", block: c.IstanbulBlock}, - {name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true}, - {name: "cancunTime", timestamp: c.CancunTime, optional: true}, - {name: "verkleTime", timestamp: c.VerkleTime, optional: true}, - } - - // Check that forks are enabled in order - if err := checkForks(ethForks, true); err != nil { - return err +func (c *ChainConfigExtra) CheckConfigForkOrder() error { + // Handle nil receiver + if c == nil { + return nil } - return c.ChainConfigExtra.CheckConfigForkOrder() -} -func (c *ChainConfigExtra) CheckConfigForkOrder() error { // Note: In Avalanche, hard forks must take place via block timestamps instead // of block numbers since blocks are produced asynchronously. Therefore, we do not // check that the block timestamps in the same way as for @@ -477,67 +353,24 @@ func checkForks(forks []fork, blockFork bool) error { return nil } -// checkCompatible confirms that [newcfg] is backwards compatible with [c] to upgrade with the given head block height and timestamp. -// This confirms that all Ethereum and Avalanche upgrades are backwards compatible as well as that the precompile config is backwards -// compatible. -func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError { - if isForkBlockIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, headNumber) { - return newBlockCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock) - } - if isForkBlockIncompatible(c.EIP150Block, newcfg.EIP150Block, headNumber) { - return newBlockCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block) - } - if isForkBlockIncompatible(c.EIP155Block, newcfg.EIP155Block, headNumber) { - return newBlockCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block) - } - if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, headNumber) { - return newBlockCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) - } - if c.IsEIP158(headNumber) && !utils.BigNumEqual(c.ChainID, newcfg.ChainID) { - return newBlockCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) - } - if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, headNumber) { - return newBlockCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock) - } - if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, headNumber) { - return newBlockCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) - } - if isForkBlockIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, headNumber) { - // the only case where we allow Petersburg to be set in the past is if it is equal to Constantinople - // mainly to satisfy fork ordering requirements which state that Petersburg fork be set if Constantinople fork is set - if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.PetersburgBlock, headNumber) { - return newBlockCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock) - } - } - if isForkBlockIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, headNumber) { - return newBlockCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) - } - if isForkBlockIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, headNumber) { - return newBlockCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) +func (c *ChainConfigExtra) CheckCompatible(newcfg_ *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError { + if c == nil { + return nil } - if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) { - return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime) - } - if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) { - return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime) - } - - return c.ChainConfigExtra.CheckCompatible(GetExtra(newcfg), headTimestamp) -} + newcfg := GetExtra(newcfg_) -func (c *ChainConfigExtra) CheckCompatible(newcfg *ChainConfigExtra, headTimestamp uint64) *ConfigCompatError { // Check avalanche network upgrades - if err := c.CheckNetworkUpgradesCompatible(&newcfg.NetworkUpgrades, headTimestamp); err != nil { + if err := c.checkNetworkUpgradesCompatible(&newcfg.NetworkUpgrades, headTimestamp); err != nil { return err } // Check that the precompiles on the new config are compatible with the existing precompile config. - if err := c.CheckPrecompilesCompatible(newcfg.PrecompileUpgrades, headTimestamp); err != nil { + if err := c.checkPrecompilesCompatible(newcfg.PrecompileUpgrades, headTimestamp); err != nil { return err } // Check that the state upgrades on the new config are compatible with the existing state upgrade config. - if err := c.CheckStateUpgradesCompatible(newcfg.StateUpgrades, headTimestamp); err != nil { + if err := c.checkStateUpgradesCompatible(newcfg.StateUpgrades, headTimestamp); err != nil { return err } @@ -670,38 +503,3 @@ type RulesExtra struct { params.NOOPHooks // XXX: Embedded to ensure that Rules implements params.RulesHooks } - -// Rules ensures c's ChainID is not nil. -func (c *ChainConfig) rules(num *big.Int, timestamp uint64) Rules { - chainID := c.ChainID - if chainID == nil { - chainID = new(big.Int) - } - return Rules{ - ChainID: new(big.Int).Set(chainID), - IsHomestead: c.IsHomestead(num), - IsEIP150: c.IsEIP150(num), - IsEIP155: c.IsEIP155(num), - IsEIP158: c.IsEIP158(num), - IsByzantium: c.IsByzantium(num), - IsConstantinople: c.IsConstantinople(num), - IsPetersburg: c.IsPetersburg(num), - IsIstanbul: c.IsIstanbul(num), - IsCancun: c.IsCancun(num, timestamp), - IsVerkle: c.IsVerkle(num, timestamp), - } -} - -// Rules returns the Avalanche modified rules to support Avalanche -// network upgrades -func (c *ChainConfig) Rules(blockNum *big.Int, isMerge bool, timestamp uint64) Rules { - // XXX: This just exists to get the callback from libevm to take RulesExtra. - var c_ gethparams.ChainConfig - jsonBytes := []byte(`{}`) - if err := json.Unmarshal(jsonBytes, &c_); err != nil { - panic(err) - } - extra := FromChainConfig(&c_) - *extra = *c - return c_.Rules(blockNum, isMerge, timestamp) -} diff --git a/params/config_extra.go b/params/config_extra.go index 67a12ab07e..eb6a433f23 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -77,18 +77,6 @@ func SetEthUpgrades(c *ChainConfig, avalancheUpgrades NetworkUpgrades) { } } -func (c *ChainConfig) UnmarshalJSON(data []byte) error { - type _ChainConfig ChainConfig - tmp := _ChainConfig{} - if err := json.Unmarshal(data, &tmp); err != nil { - return err - } - - *c = ChainConfig(tmp) - - return json.Unmarshal(data, &c.ChainConfigExtra) -} - // UnmarshalJSON parses the JSON-encoded data and stores the result in the // object pointed to by c. // This is a custom unmarshaler to handle the Precompiles field. @@ -109,38 +97,6 @@ func (c *ChainConfigExtra) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, &c.GenesisPrecompiles) } -// MarshalJSON implements the [json.Marshaler] interface. -func (c ChainConfig) MarshalJSON() ([]byte, error) { - // See UnmarshalJSON() for rationale. - type raw ChainConfig - tmp, err := json.Marshal(raw(c)) - if err != nil { - return nil, err - } - - // Convert to map so we can add the extra fields. - asMap := make(map[string]json.RawMessage) - if err := json.Unmarshal(tmp, &asMap); err != nil { - return nil, err - } - - // Similarly, obtain [c.extra] as a map. - tmp, err = json.Marshal(c.ChainConfigExtra) - if err != nil { - return nil, err - } - extraAsMap := make(map[string]json.RawMessage) - if err := json.Unmarshal(tmp, &extraAsMap); err != nil { - return nil, err - } - - // Merge the two maps and marshal the result. - for k, v := range extraAsMap { - asMap[k] = v - } - return json.Marshal(asMap) -} - // MarshalJSON returns the JSON encoding of c. // This is a custom marshaler to handle the Precompiles field. func (c ChainConfigExtra) MarshalJSON() ([]byte, error) { @@ -181,7 +137,7 @@ type ChainConfigWithUpgradesJSON struct { // ChainConfig struct. func (cu ChainConfigWithUpgradesJSON) MarshalJSON() ([]byte, error) { // embed the ChainConfig struct into the response - chainConfigJSON, err := json.Marshal(cu.ChainConfig) + chainConfigJSON, err := json.Marshal(&cu.ChainConfig) // XXX: Marshal should be defined on value receiver? if err != nil { return nil, err } @@ -308,6 +264,12 @@ func SetNetworkUpgradeDefaults(c *ChainConfig) { if c.MuirGlacierBlock == nil { c.MuirGlacierBlock = big.NewInt(0) } + if c.LondonBlock == nil { + c.LondonBlock = big.NewInt(0) + } + if c.BerlinBlock == nil { + c.BerlinBlock = big.NewInt(0) + } GetExtra(c).NetworkUpgrades.setDefaults(GetExtra(c).SnowCtx.NetworkUpgrades) } @@ -359,3 +321,18 @@ func IsForkTransition(fork *uint64, parent *uint64, current uint64) bool { currentForked := isTimestampForked(fork, current) return !parentForked && currentForked } + +func WithExtra(c *ChainConfig, extra *ChainConfigExtra) *ChainConfig { + // XXX: Hack to initialize the ChainConfigExtra pointer in the ChainConfig. + cpy := *c + jsonBytes, err := json.Marshal(cpy) + if err != nil { + panic(err) + } + if err := json.Unmarshal(jsonBytes, &cpy); err != nil { + panic(err) + } + + *GetExtra(&cpy) = *extra + return &cpy +} diff --git a/params/config_libevm.go b/params/config_libevm.go index b7486614ac..ce1d3cb94f 100644 --- a/params/config_libevm.go +++ b/params/config_libevm.go @@ -13,41 +13,30 @@ import ( ) func do_init() any { - getter = gethparams.RegisterExtras(gethparams.Extras[ChainConfig, RulesExtra]{ + getter = gethparams.RegisterExtras(gethparams.Extras[ChainConfigExtra, RulesExtra]{ NewRules: constructRulesExtra, }) return nil } -var getter gethparams.ExtraPayloadGetter[ChainConfig, RulesExtra] +var getter gethparams.ExtraPayloadGetter[ChainConfigExtra, RulesExtra] // constructRulesExtra acts as an adjunct to the [params.ChainConfig.Rules] // method. Its primary purpose is to construct the extra payload for the // [params.Rules] but it MAY also modify the [params.Rules]. -func constructRulesExtra(c *gethparams.ChainConfig, r *gethparams.Rules, cEx *ChainConfig, blockNum *big.Int, isMerge bool, timestamp uint64) *RulesExtra { - // XXX: Overwrite eth rules with exact avalanche logic for now. - rr := cEx.rules(blockNum, timestamp) - r.ChainID = rr.ChainID - r.IsHomestead = rr.IsHomestead - r.IsEIP150 = rr.IsEIP150 - r.IsEIP155 = rr.IsEIP155 - r.IsEIP158 = rr.IsEIP158 - r.IsByzantium = rr.IsByzantium - r.IsConstantinople = rr.IsConstantinople - r.IsPetersburg = rr.IsPetersburg - r.IsIstanbul = rr.IsIstanbul - r.IsCancun = rr.IsCancun - r.IsVerkle = rr.IsVerkle - +func constructRulesExtra(c *gethparams.ChainConfig, r *gethparams.Rules, cEx *ChainConfigExtra, blockNum *big.Int, isMerge bool, timestamp uint64) *RulesExtra { + if cEx == nil { + return &RulesExtra{} + } var rules RulesExtra - rules.AvalancheRules = cEx.ChainConfigExtra.GetAvalancheRules(timestamp) + rules.AvalancheRules = cEx.GetAvalancheRules(timestamp) // Initialize the stateful precompiles that should be enabled at [blockTimestamp]. rules.ActivePrecompiles = make(map[common.Address]precompileconfig.Config) rules.Predicaters = make(map[common.Address]precompileconfig.Predicater) rules.AccepterPrecompiles = make(map[common.Address]precompileconfig.Accepter) for _, module := range modules.RegisteredModules() { - if config := cEx.ChainConfigExtra.getActivePrecompileConfig(module.Address, timestamp); config != nil && !config.IsDisabled() { + if config := cEx.getActivePrecompileConfig(module.Address, timestamp); config != nil && !config.IsDisabled() { rules.ActivePrecompiles[module.Address] = config if predicater, ok := config.(precompileconfig.Predicater); ok { rules.Predicaters[module.Address] = predicater @@ -62,7 +51,7 @@ func constructRulesExtra(c *gethparams.ChainConfig, r *gethparams.Rules, cEx *Ch } // FromChainConfig returns the extra payload carried by the ChainConfig. -func FromChainConfig(c *gethparams.ChainConfig) *ChainConfig { +func FromChainConfig(c *gethparams.ChainConfig) *ChainConfigExtra { return getter.FromChainConfig(c) } diff --git a/params/config_test.go b/params/config_test.go index 22b349b004..d0141b062a 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -150,13 +150,14 @@ func TestCheckCompatible(t *testing.T) { } func TestConfigRules(t *testing.T) { - c := &ChainConfig{ - ChainConfigExtra: ChainConfigExtra{ + c := WithExtra( + &ChainConfig{}, + &ChainConfigExtra{ NetworkUpgrades: NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(500), }, }, - } + ) var stamp uint64 if r := c.Rules(big.NewInt(0), IsMergeTODO, stamp); GetRulesExtra(r).IsSubnetEVM { @@ -230,7 +231,7 @@ func TestConfigUnmarshalJSON(t *testing.T) { require.True(nativeMinterConfig.Equal(testContractNativeMinterConfig)) // Marshal and unmarshal again and check that the result is the same - marshaled, err := json.Marshal(c) + marshaled, err := json.Marshal(&c) // XXX: Marshal should be defined on value receiver? require.NoError(err) c2 := ChainConfig{} err = json.Unmarshal(marshaled, &c2) @@ -239,8 +240,9 @@ func TestConfigUnmarshalJSON(t *testing.T) { } func TestActivePrecompiles(t *testing.T) { - config := ChainConfig{ - ChainConfigExtra: ChainConfigExtra{ + config := *WithExtra( + &ChainConfig{}, + &ChainConfigExtra{ UpgradeConfig: UpgradeConfig{ PrecompileUpgrades: []PrecompileUpgrade{ { @@ -252,7 +254,7 @@ func TestActivePrecompiles(t *testing.T) { }, }, }, - } + ) rules0 := config.Rules(common.Big0, IsMergeTODO, 0) require.True(t, GetRulesExtra(rules0).IsPrecompileEnabled(nativeminter.Module.Address)) @@ -263,18 +265,20 @@ func TestActivePrecompiles(t *testing.T) { func TestChainConfigMarshalWithUpgrades(t *testing.T) { config := ChainConfigWithUpgradesJSON{ - ChainConfig: ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ChainConfigExtra: ChainConfigExtra{ + ChainConfig: *WithExtra( + &ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + }, + &ChainConfigExtra{ FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, NetworkUpgrades: NetworkUpgrades{ @@ -283,7 +287,7 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { }, GenesisPrecompiles: Precompiles{}, }, - }, + ), UpgradeConfig: UpgradeConfig{ PrecompileUpgrades: []PrecompileUpgrade{ { diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 9b475c19d2..5f4fabbe63 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -32,7 +32,7 @@ func (n *NetworkUpgrades) Equal(other *NetworkUpgrades) bool { return reflect.DeepEqual(n, other) } -func (n *NetworkUpgrades) CheckNetworkUpgradesCompatible(newcfg *NetworkUpgrades, time uint64) *ConfigCompatError { +func (n *NetworkUpgrades) checkNetworkUpgradesCompatible(newcfg *NetworkUpgrades, time uint64) *ConfigCompatError { if isForkTimestampIncompatible(n.SubnetEVMTimestamp, newcfg.SubnetEVMTimestamp, time) { return newTimestampCompatError("SubnetEVM fork block timestamp", n.SubnetEVMTimestamp, newcfg.SubnetEVMTimestamp) } diff --git a/params/network_upgrades_test.go b/params/network_upgrades_test.go index 1a93a2587e..7d8dda9e4c 100644 --- a/params/network_upgrades_test.go +++ b/params/network_upgrades_test.go @@ -161,7 +161,7 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { } for _, test := range testcases { t.Run(test.name, func(t *testing.T) { - err := test.upgrades1.CheckNetworkUpgradesCompatible(test.upgrades2, test.time) + err := test.upgrades1.checkNetworkUpgradesCompatible(test.upgrades2, test.time) if test.expected { require.Nil(t, err) } else { diff --git a/params/precompile_config_test.go b/params/precompile_config_test.go index 1c4325e9bf..8e4dc2f886 100644 --- a/params/precompile_config_test.go +++ b/params/precompile_config_test.go @@ -21,7 +21,7 @@ import ( func TestVerifyWithChainConfig(t *testing.T) { admins := []common.Address{{1}} - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.GenesisPrecompiles = Precompiles{ txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(2), nil, nil, nil), @@ -66,7 +66,7 @@ func TestVerifyWithChainConfig(t *testing.T) { func TestVerifyWithChainConfigAtNilTimestamp(t *testing.T) { admins := []common.Address{{0}} - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.PrecompileUpgrades = []PrecompileUpgrade{ // this does NOT enable the precompile, so it should be upgradeable. @@ -186,7 +186,7 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.PrecompileUpgrades = tt.upgrades @@ -230,7 +230,7 @@ func TestVerifyPrecompiles(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.GenesisPrecompiles = tt.precompiles @@ -246,7 +246,7 @@ func TestVerifyPrecompiles(t *testing.T) { func TestVerifyRequiresSortedTimestamps(t *testing.T) { admins := []common.Address{{1}} - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.PrecompileUpgrades = []PrecompileUpgrade{ { @@ -264,7 +264,7 @@ func TestVerifyRequiresSortedTimestamps(t *testing.T) { func TestGetPrecompileConfig(t *testing.T) { require := require.New(t) - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := GetExtra(&baseConfig) config.GenesisPrecompiles = Precompiles{ deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(10), nil, nil, nil), diff --git a/params/precompile_upgrade.go b/params/precompile_upgrade.go index f12fc02dd0..6dc864798a 100644 --- a/params/precompile_upgrade.go +++ b/params/precompile_upgrade.go @@ -186,14 +186,14 @@ func (c *ChainConfigExtra) GetActivatingPrecompileConfigs(address common.Address return configs } -// CheckPrecompilesCompatible checks if [precompileUpgrades] are compatible with [c] at [headTimestamp]. +// checkPrecompilesCompatible checks if [precompileUpgrades] are compatible with [c] at [headTimestamp]. // Returns a ConfigCompatError if upgrades already activated at [headTimestamp] are missing from // [precompileUpgrades]. Upgrades not already activated may be modified or absent from [precompileUpgrades]. // Returns nil if [precompileUpgrades] is compatible with [c]. // Assumes given timestamp is the last accepted block timestamp. // This ensures that as long as the node has not accepted a block with a different rule set it will allow a // new upgrade to be applied as long as it activates after the last accepted block. -func (c *ChainConfigExtra) CheckPrecompilesCompatible(precompileUpgrades []PrecompileUpgrade, time uint64) *ConfigCompatError { +func (c *ChainConfigExtra) checkPrecompilesCompatible(precompileUpgrades []PrecompileUpgrade, time uint64) *ConfigCompatError { for _, module := range modules.RegisteredModules() { if err := c.checkPrecompileCompatible(module.Address, precompileUpgrades, time); err != nil { return err diff --git a/params/precompile_upgrade_test.go b/params/precompile_upgrade_test.go index 90ac699cfe..6f076ade0f 100644 --- a/params/precompile_upgrade_test.go +++ b/params/precompile_upgrade_test.go @@ -15,7 +15,7 @@ import ( func TestVerifyUpgradeConfig(t *testing.T) { admins := []common.Address{{1}} - chainConfigCpy := *TestChainConfig + chainConfigCpy := Copy(TestChainConfig) chainConfig := GetExtra(&chainConfigCpy) chainConfig.GenesisPrecompiles = Precompiles{ txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), @@ -73,7 +73,7 @@ func TestVerifyUpgradeConfig(t *testing.T) { func TestCheckCompatibleUpgradeConfigs(t *testing.T) { admins := []common.Address{{1}} - chainConfig := *TestChainConfig + chainConfig := Copy(TestChainConfig) GetExtra(&chainConfig).GenesisPrecompiles = Precompiles{ txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(10), admins, nil, nil), @@ -277,10 +277,10 @@ type upgradeCompatibilityTest struct { func (tt *upgradeCompatibilityTest) run(t *testing.T, chainConfig ChainConfig) { // apply all the upgrade bytes specified in order for i, upgrade := range tt.configs { - newCfg := chainConfig + newCfg := Copy(&chainConfig) GetExtra(&newCfg).UpgradeConfig = *upgrade - err := chainConfig.checkCompatible(&newCfg, nil, tt.startTimestamps[i]) + err := chainConfig.CheckCompatible(&newCfg, 0, tt.startTimestamps[i]) // if this is not the final upgradeBytes, continue applying // the next upgradeBytes. (only check the result on the last apply) @@ -293,6 +293,7 @@ func (tt *upgradeCompatibilityTest) run(t *testing.T, chainConfig ChainConfig) { } if tt.expectedErrorString != "" { + require.NotNil(t, err) require.ErrorContains(t, err, tt.expectedErrorString) } else { require.Nil(t, err) diff --git a/params/state_upgrade.go b/params/state_upgrade.go index 10a44a2b1b..b72a8da58b 100644 --- a/params/state_upgrade.go +++ b/params/state_upgrade.go @@ -68,8 +68,8 @@ func (c *ChainConfigExtra) GetActivatingStateUpgrades(from *uint64, to uint64, u return activating } -// CheckStateUpgradesCompatible checks if [stateUpgrades] are compatible with [c] at [headTimestamp]. -func (c *ChainConfigExtra) CheckStateUpgradesCompatible(stateUpgrades []StateUpgrade, lastTimestamp uint64) *ConfigCompatError { +// checkStateUpgradesCompatible checks if [stateUpgrades] are compatible with [c] at [headTimestamp]. +func (c *ChainConfigExtra) checkStateUpgradesCompatible(stateUpgrades []StateUpgrade, lastTimestamp uint64) *ConfigCompatError { // All active upgrades (from nil to [lastTimestamp]) must match. activeUpgrades := c.GetActivatingStateUpgrades(nil, lastTimestamp, c.StateUpgrades) newUpgrades := c.GetActivatingStateUpgrades(nil, lastTimestamp, stateUpgrades) diff --git a/params/state_upgrade_test.go b/params/state_upgrade_test.go index f844fb2ca1..ebb019faaa 100644 --- a/params/state_upgrade_test.go +++ b/params/state_upgrade_test.go @@ -59,7 +59,7 @@ func TestVerifyStateUpgrades(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - baseConfig := *TestChainConfig + baseConfig := Copy(TestChainConfig) config := &baseConfig GetExtra(config).StateUpgrades = tt.upgrades diff --git a/tests/init.go b/tests/init.go index 5232eb82f7..1541ee865e 100644 --- a/tests/init.go +++ b/tests/init.go @@ -168,57 +168,64 @@ var Forks = map[string]*params.ChainConfig{ IstanbulBlock: big.NewInt(0), MuirGlacierBlock: big.NewInt(0), }, - "SubnetEVM": { - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - ChainConfigExtra: params.ChainConfigExtra{ + "SubnetEVM": params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + }, + ¶ms.ChainConfigExtra{ NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(0), }, }, - }, - "Durango": { - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - ChainConfigExtra: params.ChainConfigExtra{ + ), + "Durango": params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + }, + ¶ms.ChainConfigExtra{ NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(0), DurangoTimestamp: utils.NewUint64(0), }, }, - }, - "Cancun": { - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - CancunTime: utils.NewUint64(0), - ChainConfigExtra: params.ChainConfigExtra{ + ), + "Cancun": params.WithExtra( + ¶ms.ChainConfig{ + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + CancunTime: utils.NewUint64(0), + }, + ¶ms.ChainConfigExtra{ NetworkUpgrades: params.NetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(0), DurangoTimestamp: utils.NewUint64(0), }, }, - }, + ), } // AvailableForks returns the set of defined fork names