From 6752ced06e5422f97403e0fd301642ce2b9792b9 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 9 Aug 2024 16:59:44 +0300 Subject: [PATCH 01/17] get upgrade configs from context --- go.mod | 2 +- go.sum | 2 ++ params/config.go | 9 ++++----- plugin/evm/vm.go | 17 ++++++++++++++--- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 8adef45ff1..acf0c2a896 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.12 require ( github.com/VictoriaMetrics/fastcache v1.12.1 - github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef + github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1 github.com/cespare/cp v0.1.0 github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index a2b2586ea3..4a169232ba 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef h1:w0N/YXgNoXjDUwdFHGpWYq41uHxvBneHaJ+X0BxSj2w= github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8= +github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1 h1:h/09vEeKWELnlHr2Da2cXawD8Qg/9RyHy5SrODt0kkU= +github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8= 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/params/config.go b/params/config.go index 8688b6e4a8..7e43cc59a5 100644 --- a/params/config.go +++ b/params/config.go @@ -56,13 +56,13 @@ var ( var ( // AvalancheMainnetChainConfig is the configuration for Avalanche Main Network - AvalancheMainnetChainConfig = getChainConfig(constants.MainnetID, AvalancheMainnetChainID) + AvalancheMainnetChainConfig = GetChainConfig(upgrade.GetConfig(constants.MainnetID), AvalancheMainnetChainID) // AvalancheFujiChainConfig is the configuration for the Fuji Test Network - AvalancheFujiChainConfig = getChainConfig(constants.FujiID, AvalancheFujiChainID) + AvalancheFujiChainConfig = GetChainConfig(upgrade.GetConfig(constants.FujiID), AvalancheMainnetChainID) // AvalancheLocalChainConfig is the configuration for the Avalanche Local Network - AvalancheLocalChainConfig = getChainConfig(constants.LocalID, AvalancheLocalChainID) + AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheMainnetChainID) TestChainConfig = &ChainConfig{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, @@ -459,8 +459,7 @@ var ( TestRules = TestChainConfig.Rules(new(big.Int), 0) ) -func getChainConfig(networkID uint32, chainID *big.Int) *ChainConfig { - agoUpgrade := upgrade.GetConfig(networkID) +func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig { return &ChainConfig{ ChainID: chainID, HomesteadBlock: big.NewInt(0), diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index d9a53f14dd..03c853311c 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -449,15 +449,23 @@ func (vm *VM) Initialize( var extDataHashes map[common.Hash]common.Hash // Set the chain config for mainnet/fuji chain IDs - switch { - case g.Config.ChainID.Cmp(params.AvalancheMainnetChainID) == 0: + switch chainCtx.NetworkID { + case avalanchegoConstants.MainnetID: config := *params.AvalancheMainnetChainConfig g.Config = &config extDataHashes = mainnetExtDataHashes - case g.Config.ChainID.Cmp(params.AvalancheFujiChainID) == 0: + case avalanchegoConstants.FujiID: config := *params.AvalancheFujiChainConfig g.Config = &config extDataHashes = fujiExtDataHashes + case avalanchegoConstants.LocalID: + config := *params.AvalancheLocalChainConfig + g.Config = &config + default: + // TODO: This overrides the chain config in the given genesis (in genesisBytes) + // Do we want to do this? + config := params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(g.Config.ChainID)) + g.Config = config } // If the Durango is activated, activate the Warp Precompile at the same time if g.Config.DurangoBlockTimestamp != nil { @@ -465,6 +473,9 @@ func (vm *VM) Initialize( Config: warpPrecompile.NewDefaultConfig(g.Config.DurangoBlockTimestamp), }) } + + js, _ := g.Config.MarshalJSON() + log.Warn("Chain config", "config", js) // Set the Avalanche Context on the ChainConfig g.Config.AvalancheContext = params.AvalancheContext{ SnowCtx: chainCtx, From b595ecc260db02f447218cc9755e9e85d4c6366b Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 9 Aug 2024 17:35:25 +0300 Subject: [PATCH 02/17] fix chainIDs --- params/config.go | 4 ++-- plugin/evm/vm.go | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/params/config.go b/params/config.go index 7e43cc59a5..15d7be8e5b 100644 --- a/params/config.go +++ b/params/config.go @@ -59,10 +59,10 @@ var ( AvalancheMainnetChainConfig = GetChainConfig(upgrade.GetConfig(constants.MainnetID), AvalancheMainnetChainID) // AvalancheFujiChainConfig is the configuration for the Fuji Test Network - AvalancheFujiChainConfig = GetChainConfig(upgrade.GetConfig(constants.FujiID), AvalancheMainnetChainID) + AvalancheFujiChainConfig = GetChainConfig(upgrade.GetConfig(constants.FujiID), AvalancheFujiChainID) // AvalancheLocalChainConfig is the configuration for the Avalanche Local Network - AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheMainnetChainID) + AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheLocalChainID) TestChainConfig = &ChainConfig{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 03c853311c..e29ed1d116 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -474,8 +474,6 @@ func (vm *VM) Initialize( }) } - js, _ := g.Config.MarshalJSON() - log.Warn("Chain config", "config", js) // Set the Avalanche Context on the ChainConfig g.Config.AvalancheContext = params.AvalancheContext{ SnowCtx: chainCtx, From 047d3e5a8f09a91bf3ca5c33f5ac08ebe9eaea1e Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 9 Aug 2024 17:44:49 +0300 Subject: [PATCH 03/17] fix avago version --- go.sum | 2 -- scripts/versions.sh | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.sum b/go.sum index 4a169232ba..edce397dda 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef h1:w0N/YXgNoXjDUwdFHGpWYq41uHxvBneHaJ+X0BxSj2w= -github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8= github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1 h1:h/09vEeKWELnlHr2Da2cXawD8Qg/9RyHy5SrODt0kkU= github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/scripts/versions.sh b/scripts/versions.sh index 7ca0515428..05e1ed7ff6 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -6,4 +6,4 @@ set -euo pipefail # Don't export them as they're used in the context of other calls -AVALANCHE_VERSION=${AVALANCHE_VERSION:-'7e985b530beff5afe03967f5fa94a2eee998cb7a'} +AVALANCHE_VERSION=${AVALANCHE_VERSION:-'da3256302ab1'} From 587cbeab0b4c5c842da42b5a8ee800b91632dd7c Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 9 Aug 2024 18:25:10 +0300 Subject: [PATCH 04/17] commment out override --- plugin/evm/vm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index e29ed1d116..a60d8cfc04 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -464,8 +464,8 @@ func (vm *VM) Initialize( default: // TODO: This overrides the chain config in the given genesis (in genesisBytes) // Do we want to do this? - config := params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(g.Config.ChainID)) - g.Config = config + // config := params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(g.Config.ChainID)) + // g.Config = config } // If the Durango is activated, activate the Warp Precompile at the same time if g.Config.DurangoBlockTimestamp != nil { From cfb3eab1e6addb2b9628a232d3997de6746add81 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 12 Aug 2024 23:29:25 +0300 Subject: [PATCH 05/17] Remove comment out code --- plugin/evm/vm.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index a60d8cfc04..ddde3e4744 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -461,11 +461,6 @@ func (vm *VM) Initialize( case avalanchegoConstants.LocalID: config := *params.AvalancheLocalChainConfig g.Config = &config - default: - // TODO: This overrides the chain config in the given genesis (in genesisBytes) - // Do we want to do this? - // config := params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(g.Config.ChainID)) - // g.Config = config } // If the Durango is activated, activate the Warp Precompile at the same time if g.Config.DurangoBlockTimestamp != nil { From d8f2963ed7ff38728b42ad857d1315e907c9fbc2 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 13 Aug 2024 15:45:01 +0300 Subject: [PATCH 06/17] use network ID rather than chain ID --- plugin/evm/vm.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index ddde3e4744..2ffe3a5e57 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -475,8 +475,8 @@ func (vm *VM) Initialize( } vm.syntacticBlockValidator = NewBlockValidator(extDataHashes) - // Ensure that non-standard commit interval is only allowed for the local network - if g.Config.ChainID.Cmp(params.AvalancheLocalChainID) != 0 { + // Ensure that non-standard commit interval is not allowed for production networks + if avalanchegoConstants.ProductionNetworkIDs.Contains(chainCtx.NetworkID) { if vm.config.CommitInterval != defaultCommitInterval { return fmt.Errorf("cannot start non-local network with commit interval %d", vm.config.CommitInterval) } @@ -623,7 +623,7 @@ func (vm *VM) Initialize( var ( bonusBlockHeights map[uint64]ids.ID ) - if vm.chainID.Cmp(params.AvalancheMainnetChainID) == 0 { + if vm.ctx.NetworkID == avalanchegoConstants.MainnetID { bonusBlockHeights, err = readMainnetBonusBlocks() if err != nil { return fmt.Errorf("failed to read mainnet bonus blocks: %w", err) From 15da144ba67c9990d555eb772d71362b47bd8948 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 13 Aug 2024 23:06:58 +0300 Subject: [PATCH 07/17] refactor params config --- core/state_processor_test.go | 26 +- internal/ethapi/transaction_args_test.go | 28 +- params/config.go | 1108 +++++++---------- params/config_extra.go | 110 +- .../config_extra_test.go | 41 +- params/config_test.go | 4 +- params/network_upgrades.go | 230 +++- params/precompile_upgrade.go | 2 +- plugin/evm/vm.go | 4 +- plugin/evm/vm_test.go | 2 +- tests/init.go | 276 ++-- utils/fork.go | 63 - utils/numbers.go | 29 + 13 files changed, 1007 insertions(+), 916 deletions(-) rename utils/fork_test.go => params/config_extra_test.go (72%) delete mode 100644 utils/fork.go create mode 100644 utils/numbers.go diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 0c27446964..5646604d11 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -255,18 +255,20 @@ func TestStateProcessorErrors(t *testing.T) { 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + }, }, Alloc: GenesisAlloc{ common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): GenesisAccount{ diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index afb2b5e0c5..97d1afc77a 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -238,19 +238,21 @@ type backendMock struct { func newBackendMock() *backendMock { config := ¶ms.ChainConfig{ - ChainID: big.NewInt(42), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: true, - 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), - ApricotPhase3BlockTimestamp: utils.NewUint64(1000), + ChainID: big.NewInt(42), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: true, + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase3BlockTimestamp: utils.NewUint64(1000), + }, } return &backendMock{ current: &types.Header{ diff --git a/params/config.go b/params/config.go index 760fe9a42a..306a995df0 100644 --- a/params/config.go +++ b/params/config.go @@ -40,8 +40,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -const maxJSONLen = 64 * 1024 * 1024 // 64MB - // Avalanche ChainIDs var ( // AvalancheMainnetChainID ... @@ -65,437 +63,434 @@ var ( AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheLocalChainID) TestChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), - EtnaTime: utils.NewUint64(0), + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: utils.NewUint64(0), + EtnaTimestamp: utils.NewUint64(0), + }, } TestLaunchConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: nil, - ApricotPhase2BlockTimestamp: nil, - ApricotPhase3BlockTimestamp: nil, - ApricotPhase4BlockTimestamp: nil, - ApricotPhase5BlockTimestamp: nil, - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: nil, + ApricotPhase2BlockTimestamp: nil, + ApricotPhase3BlockTimestamp: nil, + ApricotPhase4BlockTimestamp: nil, + ApricotPhase5BlockTimestamp: nil, + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase1Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: nil, - ApricotPhase3BlockTimestamp: nil, - ApricotPhase4BlockTimestamp: nil, - ApricotPhase5BlockTimestamp: nil, - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: nil, + ApricotPhase3BlockTimestamp: nil, + ApricotPhase4BlockTimestamp: nil, + ApricotPhase5BlockTimestamp: nil, + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase2Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: nil, - ApricotPhase4BlockTimestamp: nil, - ApricotPhase5BlockTimestamp: nil, - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: nil, + ApricotPhase4BlockTimestamp: nil, + ApricotPhase5BlockTimestamp: nil, + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase3Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: nil, - ApricotPhase5BlockTimestamp: nil, - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: nil, + ApricotPhase5BlockTimestamp: nil, + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase4Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: nil, - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: nil, + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase5Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: nil, - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: nil, + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhasePre6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: nil, - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: nil, + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhase6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: nil, - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: nil, + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestApricotPhasePost6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: nil, - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: nil, + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestBanffChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: nil, - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: nil, + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestCortinaChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: nil, - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: nil, + EtnaTimestamp: nil, + }, } TestDurangoChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), - EtnaTime: nil, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: utils.NewUint64(0), + EtnaTimestamp: nil, + }, } TestEtnaChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{utils.TestSnowContext()}, - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), - ApricotPhase6BlockTimestamp: utils.NewUint64(0), - ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), - EtnaTime: utils.NewUint64(0), + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhasePre6BlockTimestamp: utils.NewUint64(0), + ApricotPhase6BlockTimestamp: utils.NewUint64(0), + ApricotPhasePost6BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: utils.NewUint64(0), + EtnaTimestamp: utils.NewUint64(0), + }, } TestRules = TestChainConfig.Rules(new(big.Int), 0) ) -func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig { - return &ChainConfig{ - ChainID: chainID, - HomesteadBlock: big.NewInt(0), - DAOForkBlock: big.NewInt(0), - DAOForkSupport: true, - 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), - ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time), - ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time), - ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time), - ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time), - ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time), - ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time), - ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time), - ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time), - BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime), - CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime), - DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime), - EtnaTime: utils.TimeToNewUint64(agoUpgrade.EtnaTime), - } -} - // ChainConfig is the core config which determines the blockchain settings. // // 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 { - AvalancheContext `json:"-"` // Avalanche specific context set during VM initialization. Not serialized. - 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) @@ -514,41 +509,14 @@ type ChainConfig struct { 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) - // Avalanche Network Upgrades - ApricotPhase1BlockTimestamp *uint64 `json:"apricotPhase1BlockTimestamp,omitempty"` // Apricot Phase 1 Block Timestamp (nil = no fork, 0 = already activated) - // Apricot Phase 2 Block Timestamp (nil = no fork, 0 = already activated) - // Apricot Phase 2 includes a modified version of the Berlin Hard Fork from Ethereum - ApricotPhase2BlockTimestamp *uint64 `json:"apricotPhase2BlockTimestamp,omitempty"` - // Apricot Phase 3 introduces dynamic fees and a modified version of the London Hard Fork from Ethereum (nil = no fork, 0 = already activated) - ApricotPhase3BlockTimestamp *uint64 `json:"apricotPhase3BlockTimestamp,omitempty"` - // Apricot Phase 4 introduces the notion of a block fee to the dynamic fee algorithm (nil = no fork, 0 = already activated) - ApricotPhase4BlockTimestamp *uint64 `json:"apricotPhase4BlockTimestamp,omitempty"` - // Apricot Phase 5 introduces a batch of atomic transactions with a maximum atomic gas limit per block. (nil = no fork, 0 = already activated) - ApricotPhase5BlockTimestamp *uint64 `json:"apricotPhase5BlockTimestamp,omitempty"` - // Apricot Phase Pre-6 deprecates the NativeAssetCall precompile (soft). (nil = no fork, 0 = already activated) - ApricotPhasePre6BlockTimestamp *uint64 `json:"apricotPhasePre6BlockTimestamp,omitempty"` - // Apricot Phase 6 deprecates the NativeAssetBalance and NativeAssetCall precompiles. (nil = no fork, 0 = already activated) - ApricotPhase6BlockTimestamp *uint64 `json:"apricotPhase6BlockTimestamp,omitempty"` - // Apricot Phase Post-6 deprecates the NativeAssetCall precompile (soft). (nil = no fork, 0 = already activated) - ApricotPhasePost6BlockTimestamp *uint64 `json:"apricotPhasePost6BlockTimestamp,omitempty"` - // Banff restricts import/export transactions to AVAX. (nil = no fork, 0 = already activated) - BanffBlockTimestamp *uint64 `json:"banffBlockTimestamp,omitempty"` - // Cortina increases the block gas limit to 15M. (nil = no fork, 0 = already activated) - CortinaBlockTimestamp *uint64 `json:"cortinaBlockTimestamp,omitempty"` - // Durango activates the Shanghai Execution Spec Upgrade from Ethereum (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md#included-eips) - // and Avalanche Warp Messaging. (nil = no fork, 0 = already activated) - // Note: EIP-4895 is excluded since withdrawals are not relevant to the Avalanche C-Chain or Subnets running the EVM. - DurangoBlockTimestamp *uint64 `json:"durangoBlockTimestamp,omitempty"` - // Etna activates Cancun from Ethereum (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/cancun.md#included-eips) - // and reduces the min base fee. (nil = no fork, 0 = already activated) - // Note: EIP-4844 BlobTxs are not enabled in the mempool and blocks are not - // allowed to contain them. For details see https://github.com/avalanche-foundation/ACPs/pull/131 - EtnaTime *uint64 `json:"etnaTime,omitempty"` - - // Cancun activates the Cancun upgrade from Ethereum. (nil = no fork, 0 = already activated) - CancunTime *uint64 `json:"cancunTime,omitempty"` - // Verkle activates the Verkle upgrade from Ethereum. (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) + // Avalanche Network Upgrades + NetworkUpgrades + + AvalancheContext `json:"-"` // Avalanche specific context set during VM initialization. Not serialized. UpgradeConfig `json:"-"` // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Skip encoding/decoding directly into ChainConfig. } @@ -580,22 +548,11 @@ func (c *ChainConfig) Description() string { } banner += "Hard forks (timestamp based):\n" - banner += fmt.Sprintf(" - Cancun Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(c.CancunTime)) + banner += fmt.Sprintf(" - Cancun Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(c.CancunTime)) banner += "\n" - banner += "Mandatory Avalanche Upgrades (timestamp based):\n" - banner += fmt.Sprintf(" - Apricot Phase 1 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.3.0)\n", ptrToString(c.ApricotPhase1BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase 2 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.4.0)\n", ptrToString(c.ApricotPhase2BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase 3 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.5.0)\n", ptrToString(c.ApricotPhase3BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase 4 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.6.0)\n", ptrToString(c.ApricotPhase4BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase 5 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.7.0)\n", ptrToString(c.ApricotPhase5BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase P6 Timestamp @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0)\n", ptrToString(c.ApricotPhasePre6BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase 6 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0)\n", ptrToString(c.ApricotPhase6BlockTimestamp)) - banner += fmt.Sprintf(" - Apricot Phase Post-6 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0\n", ptrToString(c.ApricotPhasePost6BlockTimestamp)) - banner += fmt.Sprintf(" - Banff Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0)\n", ptrToString(c.BanffBlockTimestamp)) - banner += fmt.Sprintf(" - Cortina Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(c.CortinaBlockTimestamp)) - banner += fmt.Sprintf(" - Durango Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(c.DurangoBlockTimestamp)) - banner += fmt.Sprintf(" - Etna Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(c.EtnaTime)) + banner += "Avalanche Upgrades (timestamp based):\n" + banner += c.NetworkUpgrades.Description() banner += "\n" upgradeConfigBytes, err := json.Marshal(c.UpgradeConfig) @@ -609,155 +566,64 @@ func (c *ChainConfig) Description() string { // IsHomestead returns whether num is either equal to the homestead block or greater. func (c *ChainConfig) IsHomestead(num *big.Int) bool { - return utils.IsBlockForked(c.HomesteadBlock, num) + return isBlockForked(c.HomesteadBlock, num) } // IsDAOFork returns whether num is either equal to the DAO fork block or greater. func (c *ChainConfig) IsDAOFork(num *big.Int) bool { - return utils.IsBlockForked(c.DAOForkBlock, num) + return isBlockForked(c.DAOForkBlock, num) } // IsEIP150 returns whether num is either equal to the EIP150 fork block or greater. func (c *ChainConfig) IsEIP150(num *big.Int) bool { - return utils.IsBlockForked(c.EIP150Block, num) + 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 utils.IsBlockForked(c.EIP155Block, num) + 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 utils.IsBlockForked(c.EIP158Block, num) + 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 utils.IsBlockForked(c.ByzantiumBlock, num) + 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 utils.IsBlockForked(c.ConstantinopleBlock, num) + 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 utils.IsBlockForked(c.MuirGlacierBlock, num) + 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 utils.IsBlockForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && utils.IsBlockForked(c.ConstantinopleBlock, num) + 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 utils.IsBlockForked(c.IstanbulBlock, num) -} - -// Avalanche Upgrades: - -// IsApricotPhase1 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 1 upgrade time. -func (c *ChainConfig) IsApricotPhase1(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase1BlockTimestamp, time) -} - -// IsApricotPhase2 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 2 upgrade time. -func (c *ChainConfig) IsApricotPhase2(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase2BlockTimestamp, time) -} - -// IsApricotPhase3 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 3 upgrade time. -func (c *ChainConfig) IsApricotPhase3(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase3BlockTimestamp, time) -} - -// IsApricotPhase4 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 4 upgrade time. -func (c *ChainConfig) IsApricotPhase4(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase4BlockTimestamp, time) + return isBlockForked(c.IstanbulBlock, num) } -// IsApricotPhase5 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 5 upgrade time. -func (c *ChainConfig) IsApricotPhase5(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase5BlockTimestamp, time) -} - -// IsApricotPhasePre6 returns whether [time] represents a block -// with a timestamp after the Apricot Phase Pre 6 upgrade time. -func (c *ChainConfig) IsApricotPhasePre6(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhasePre6BlockTimestamp, time) -} - -// IsApricotPhase6 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 6 upgrade time. -func (c *ChainConfig) IsApricotPhase6(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhase6BlockTimestamp, time) -} - -// IsApricotPhasePost6 returns whether [time] represents a block -// with a timestamp after the Apricot Phase 6 Post upgrade time. -func (c *ChainConfig) IsApricotPhasePost6(time uint64) bool { - return utils.IsTimestampForked(c.ApricotPhasePost6BlockTimestamp, time) -} - -// IsBanff returns whether [time] represents a block -// with a timestamp after the Banff upgrade time. -func (c *ChainConfig) IsBanff(time uint64) bool { - return utils.IsTimestampForked(c.BanffBlockTimestamp, time) -} - -// IsCortina returns whether [time] represents a block -// with a timestamp after the Cortina upgrade time. -func (c *ChainConfig) IsCortina(time uint64) bool { - return utils.IsTimestampForked(c.CortinaBlockTimestamp, time) -} - -// IsDurango returns whether [time] represents a block -// with a timestamp after the Durango upgrade time. -func (c *ChainConfig) IsDurango(time uint64) bool { - return utils.IsTimestampForked(c.DurangoBlockTimestamp, time) -} - -// IsEtna returns whether [time] represents a block -// with a timestamp after the Etna upgrade time. -func (c *ChainConfig) IsEtna(time uint64) bool { - return utils.IsTimestampForked(c.EtnaTime, time) -} - -// IsCancun returns whether [time] represents a block -// with a timestamp after the Cancun upgrade time. +// 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 utils.IsTimestampForked(c.CancunTime, time) + return isTimestampForked(c.CancunTime, time) } -// IsVerkle returns whether [time] represents a block -// with a timestamp after the Verkle upgrade 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 utils.IsTimestampForked(c.VerkleTime, time) -} - -func (r *Rules) PredicatersExist() bool { - return len(r.Predicaters) > 0 -} - -func (r *Rules) PredicaterExists(addr common.Address) bool { - _, PredicaterExists := r.Predicaters[addr] - return PredicaterExists -} - -// IsPrecompileEnabled returns whether precompile with [address] is enabled at [timestamp]. -func (c *ChainConfig) IsPrecompileEnabled(address common.Address, timestamp uint64) bool { - config := c.getActivePrecompileConfig(address, timestamp) - return config != nil && !config.IsDisabled() + return isTimestampForked(c.VerkleTime, time) } // CheckCompatible checks whether scheduled fork transitions have been imported @@ -785,16 +651,6 @@ func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time u return lasterr } -// Verify verifies chain config and returns error -func (c *ChainConfig) Verify() error { - // Verify the precompile upgrades are internally consistent given the existing chainConfig. - if err := c.verifyPrecompileUpgrades(); err != nil { - return fmt.Errorf("invalid precompile upgrades: %w", err) - } - - return nil -} - type fork struct { name string block *big.Int // some go-ethereum forks use block numbers @@ -816,7 +672,8 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "petersburgBlock", block: c.PetersburgBlock}, {name: "istanbulBlock", block: c.IstanbulBlock}, {name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true}, - {name: "cancunTime", timestamp: c.CancunTime}, + {name: "cancunTime", timestamp: c.CancunTime, optional: true}, + {name: "verkleTime", timestamp: c.VerkleTime, optional: true}, } // Check that forks are enabled in order @@ -881,105 +738,81 @@ func checkForks(forks []fork, blockFork bool) error { lastFork = cur } } - - // TODO(aaronbuchwald) check that avalanche block timestamps are at least possible with the other rule set changes - // additional change: require that block number hard forks are either 0 or nil since they should not - // be enabled at a specific block number. - return nil } -func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, height *big.Int, time uint64) *ConfigCompatError { - if isForkBlockIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, height) { +// 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.DAOForkBlock, newcfg.DAOForkBlock, height) { + if isForkBlockIncompatible(c.DAOForkBlock, newcfg.DAOForkBlock, headNumber) { return newBlockCompatError("DAO fork block", c.DAOForkBlock, newcfg.DAOForkBlock) } - if c.IsDAOFork(height) && c.DAOForkSupport != newcfg.DAOForkSupport { + if c.IsDAOFork(headNumber) && c.DAOForkSupport != newcfg.DAOForkSupport { return newBlockCompatError("DAO fork support flag", c.DAOForkBlock, newcfg.DAOForkBlock) } - if isForkBlockIncompatible(c.EIP150Block, newcfg.EIP150Block, height) { + if isForkBlockIncompatible(c.EIP150Block, newcfg.EIP150Block, headNumber) { return newBlockCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block) } - if isForkBlockIncompatible(c.EIP155Block, newcfg.EIP155Block, height) { + if isForkBlockIncompatible(c.EIP155Block, newcfg.EIP155Block, headNumber) { return newBlockCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block) } - if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, height) { + if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, headNumber) { return newBlockCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) } - if c.IsEIP158(height) && !configBlockEqual(c.ChainID, newcfg.ChainID) { + if c.IsEIP158(headNumber) && !configBlockEqual(c.ChainID, newcfg.ChainID) { return newBlockCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) } - if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, height) { + if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, headNumber) { return newBlockCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock) } - if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, height) { + if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, headNumber) { return newBlockCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) } - if isForkBlockIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, height) { + 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, height) { + if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.PetersburgBlock, headNumber) { return newBlockCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock) } } - if isForkBlockIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, height) { + if isForkBlockIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, headNumber) { return newBlockCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) } - if isForkBlockIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, height) { + if isForkBlockIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, headNumber) { return newBlockCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) } - if isForkTimestampIncompatible(c.ApricotPhase1BlockTimestamp, newcfg.ApricotPhase1BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase1 fork block timestamp", c.ApricotPhase1BlockTimestamp, newcfg.ApricotPhase1BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhase2BlockTimestamp, newcfg.ApricotPhase2BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase2 fork block timestamp", c.ApricotPhase2BlockTimestamp, newcfg.ApricotPhase2BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhase3BlockTimestamp, newcfg.ApricotPhase3BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase3 fork block timestamp", c.ApricotPhase3BlockTimestamp, newcfg.ApricotPhase3BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhase4BlockTimestamp, newcfg.ApricotPhase4BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase4 fork block timestamp", c.ApricotPhase4BlockTimestamp, newcfg.ApricotPhase4BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhase5BlockTimestamp, newcfg.ApricotPhase5BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase5 fork block timestamp", c.ApricotPhase5BlockTimestamp, newcfg.ApricotPhase5BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhasePre6BlockTimestamp, newcfg.ApricotPhasePre6BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhasePre6 fork block timestamp", c.ApricotPhasePre6BlockTimestamp, newcfg.ApricotPhasePre6BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhase6BlockTimestamp, newcfg.ApricotPhase6BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhase6 fork block timestamp", c.ApricotPhase6BlockTimestamp, newcfg.ApricotPhase6BlockTimestamp) - } - if isForkTimestampIncompatible(c.ApricotPhasePost6BlockTimestamp, newcfg.ApricotPhasePost6BlockTimestamp, time) { - return newTimestampCompatError("ApricotPhasePost6 fork block timestamp", c.ApricotPhasePost6BlockTimestamp, newcfg.ApricotPhasePost6BlockTimestamp) - } - if isForkTimestampIncompatible(c.BanffBlockTimestamp, newcfg.BanffBlockTimestamp, time) { - return newTimestampCompatError("Banff fork block timestamp", c.BanffBlockTimestamp, newcfg.BanffBlockTimestamp) - } - if isForkTimestampIncompatible(c.CortinaBlockTimestamp, newcfg.CortinaBlockTimestamp, time) { - return newTimestampCompatError("Cortina fork block timestamp", c.CortinaBlockTimestamp, newcfg.CortinaBlockTimestamp) - } - if isForkTimestampIncompatible(c.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp, time) { - return newTimestampCompatError("Durango fork block timestamp", c.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp) - } - if isForkTimestampIncompatible(c.EtnaTime, newcfg.EtnaTime, time) { - return newTimestampCompatError("Etna fork block timestamp", c.EtnaTime, newcfg.EtnaTime) + if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) { + return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime) } - if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, time) { - return newTimestampCompatError("Cancun fork block timestamp", c.CancunTime, newcfg.CancunTime) - } - if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, time) { - return newTimestampCompatError("Verkle fork block timestamp", c.VerkleTime, newcfg.VerkleTime) + if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) { + return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime) } + // Check avalanche network upgrades + if err := c.CheckNetworkUpgradesCompatible(&newcfg.NetworkUpgrades, headTimestamp); err != nil { + return err + } return nil } -// isForkBlockIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to -// block s2 because head is already past the fork. +// isForkBlockIncompatible returns true if a fork scheduled at block s1 cannot be +// rescheduled to block s2 because head is already past the fork. func isForkBlockIncompatible(s1, s2, head *big.Int) bool { - return (utils.IsBlockForked(s1, head) || utils.IsBlockForked(s2, head)) && !configBlockEqual(s1, s2) + return (isBlockForked(s1, head) || isBlockForked(s2, head)) && !configBlockEqual(s1, s2) +} + +// isBlockForked returns whether a fork scheduled at block s is active at the +// given head block. Whilst this method is the same as isTimestampForked, they +// are explicitly separate for clearer reading. +func isBlockForked(s, head *big.Int) bool { + if s == nil || head == nil { + return false + } + return s.Cmp(head) <= 0 } func configBlockEqual(x, y *big.Int) bool { @@ -995,7 +828,17 @@ func configBlockEqual(x, y *big.Int) bool { // isForkTimestampIncompatible returns true if a fork scheduled at timestamp s1 // cannot be rescheduled to timestamp s2 because head is already past the fork. func isForkTimestampIncompatible(s1, s2 *uint64, head uint64) bool { - return (utils.IsTimestampForked(s1, head) || utils.IsTimestampForked(s2, head)) && !configTimestampEqual(s1, s2) + return (isTimestampForked(s1, head) || isTimestampForked(s2, head)) && !configTimestampEqual(s1, s2) +} + +// isTimestampForked returns whether a fork scheduled at timestamp s is active +// at the given head timestamp. Whilst this method is the same as isBlockForked, +// they are explicitly separate for clearer reading. +func isTimestampForked(s *uint64, head uint64) bool { + if s == nil { + return false + } + return *s <= head } func configTimestampEqual(x, y *uint64) bool { @@ -1077,11 +920,10 @@ func (err *ConfigCompatError) Error() string { return fmt.Sprintf("mismatching %s in database (have timestamp %s, want timestamp %s, rewindto timestamp %d)", err.What, ptrToString(err.StoredTime), ptrToString(err.NewTime), err.RewindToTime) } -func ptrToString(val *uint64) string { - if val == nil { - return "nil" - } - return fmt.Sprintf("%d", *val) +type EthRules struct { + IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool + IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool + IsCancun bool } // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions @@ -1090,10 +932,10 @@ func ptrToString(val *uint64) string { // Rules is a one time interface meaning that it shouldn't be used in between transition // phases. type Rules struct { - ChainID *big.Int - IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool - IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool - IsCancun bool + ChainID *big.Int + + // Rules for Ethereum releases + EthRules // Rules for Avalanche releases AvalancheRules @@ -1111,12 +953,6 @@ type Rules struct { AccepterPrecompiles map[common.Address]precompileconfig.Accepter } -// IsPrecompileEnabled returns true if the precompile at [addr] is enabled for this rule set. -func (r *Rules) IsPrecompileEnabled(addr common.Address) bool { - _, ok := r.ActivePrecompiles[addr] - return ok -} - // Rules ensures c's ChainID is not nil. func (c *ChainConfig) rules(num *big.Int, timestamp uint64) Rules { chainID := c.ChainID @@ -1124,16 +960,18 @@ func (c *ChainConfig) rules(num *big.Int, timestamp uint64) Rules { 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), + ChainID: new(big.Int).Set(chainID), + EthRules: EthRules{ + 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), + }, } } diff --git a/params/config_extra.go b/params/config_extra.go index c752bf1a4f..1b76ccd571 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -6,9 +6,18 @@ package params import ( "encoding/json" "errors" + "fmt" + "math/big" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/coreth/utils" + "github.com/ethereum/go-ethereum/common" +) + +const ( + maxJSONLen = 64 * 1024 * 1024 // 64MB + ) // UpgradeConfig includes the following configs that may be specified in upgradeBytes: @@ -24,6 +33,18 @@ type AvalancheContext struct { SnowCtx *snow.Context } +// SetEthUpgrades enables Etheruem network upgrades using the same time as +// the Avalanche network upgrade that enables them. +// +// TODO: Prior to Cancun, Avalanche upgrades are referenced inline in the +// code in place of their Ethereum counterparts. The original Ethereum names +// should be restored for maintainability. +func (c *ChainConfig) SetEthUpgrades() { + if c.EtnaTimestamp != nil { + c.CancunTime = utils.NewUint64(*c.EtnaTimestamp) + } +} + // 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. @@ -110,6 +131,22 @@ func (cu *ChainConfigWithUpgradesJSON) UnmarshalJSON(input []byte) error { return nil } +// Verify verifies chain config and returns error +func (c *ChainConfig) Verify() error { + // Verify the precompile upgrades are internally consistent given the existing chainConfig. + if err := c.verifyPrecompileUpgrades(); err != nil { + return fmt.Errorf("invalid precompile upgrades: %w", err) + } + + return nil +} + +// IsPrecompileEnabled returns whether precompile with [address] is enabled at [timestamp]. +func (c *ChainConfig) IsPrecompileEnabled(address common.Address, timestamp uint64) bool { + config := c.getActivePrecompileConfig(address, timestamp) + return config != nil && !config.IsDisabled() +} + // ToWithUpgradesJSON converts the ChainConfig to ChainConfigWithUpgradesJSON with upgrades explicitly displayed. // ChainConfig does not include upgrades in its JSON output. // This is a workaround for showing upgrades in the JSON output. @@ -120,14 +157,69 @@ func (c *ChainConfig) ToWithUpgradesJSON() *ChainConfigWithUpgradesJSON { } } -// SetEthUpgrades enables Etheruem network upgrades using the same time as -// the Avalanche network upgrade that enables them. -// -// TODO: Prior to Cancun, Avalanche upgrades are referenced inline in the -// code in place of their Ethereum counterparts. The original Ethereum names -// should be restored for maintainability. -func (c *ChainConfig) SetEthUpgrades() { - if c.EtnaTime != nil { - c.CancunTime = utils.NewUint64(*c.EtnaTime) +func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig { + return &ChainConfig{ + ChainID: chainID, + HomesteadBlock: big.NewInt(0), + DAOForkBlock: big.NewInt(0), + DAOForkSupport: true, + 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), + NetworkUpgrades: NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time), + ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time), + ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time), + ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time), + ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time), + ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time), + ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time), + ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time), + BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime), + CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime), + DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime), + EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime), + }, + } +} + +func (r *Rules) PredicatersExist() bool { + return len(r.Predicaters) > 0 +} + +func (r *Rules) PredicaterExists(addr common.Address) bool { + _, PredicaterExists := r.Predicaters[addr] + return PredicaterExists +} + +// IsPrecompileEnabled returns true if the precompile at [addr] is enabled for this rule set. +func (r *Rules) IsPrecompileEnabled(addr common.Address) bool { + _, ok := r.ActivePrecompiles[addr] + return ok +} + +func ptrToString(val *uint64) string { + if val == nil { + return "nil" + } + return fmt.Sprintf("%d", *val) +} + +// IsForkTransition returns true if [fork] activates during the transition from +// [parent] to [current]. +// Taking [parent] as a pointer allows for us to pass nil when checking forks +// that activate during genesis. +// Note: this works for both block number and timestamp activated forks. +func IsForkTransition(fork *uint64, parent *uint64, current uint64) bool { + var parentForked bool + if parent != nil { + parentForked = isTimestampForked(fork, *parent) } + currentForked := isTimestampForked(fork, current) + return !parentForked && currentForked } diff --git a/utils/fork_test.go b/params/config_extra_test.go similarity index 72% rename from utils/fork_test.go rename to params/config_extra_test.go index ec7870e813..64438b7f07 100644 --- a/utils/fork_test.go +++ b/params/config_extra_test.go @@ -1,11 +1,12 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// (c) 2024 Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package utils +package params import ( "testing" + "github.com/ava-labs/coreth/utils" "github.com/stretchr/testify/assert" ) @@ -28,28 +29,28 @@ func TestIsTimestampForked(t *testing.T) { isForked: false, }, "zero fork at genesis": { - fork: NewUint64(0), + fork: utils.NewUint64(0), block: 0, isForked: true, }, "pre fork timestamp": { - fork: NewUint64(100), + fork: utils.NewUint64(100), block: 50, isForked: false, }, "at fork timestamp": { - fork: NewUint64(100), + fork: utils.NewUint64(100), block: 100, isForked: true, }, "post fork timestamp": { - fork: NewUint64(100), + fork: utils.NewUint64(100), block: 150, isForked: true, }, } { t.Run(name, func(t *testing.T) { - res := IsTimestampForked(test.fork, test.block) + res := isTimestampForked(test.fork, test.block) assert.Equal(t, test.isForked, res) }) } @@ -70,50 +71,50 @@ func TestIsForkTransition(t *testing.T) { transitioned: false, }, "activate at genesis": { - fork: NewUint64(0), + fork: utils.NewUint64(0), parent: nil, current: 0, transitioned: true, }, "nil fork arbitrary transition": { fork: nil, - parent: NewUint64(100), + parent: utils.NewUint64(100), current: 101, transitioned: false, }, "nil fork transition same timestamp": { fork: nil, - parent: NewUint64(100), + parent: utils.NewUint64(100), current: 100, transitioned: false, }, "exact match on current timestamp": { - fork: NewUint64(100), - parent: NewUint64(99), + fork: utils.NewUint64(100), + parent: utils.NewUint64(99), current: 100, transitioned: true, }, "current same as parent does not transition twice": { - fork: NewUint64(100), - parent: NewUint64(101), + fork: utils.NewUint64(100), + parent: utils.NewUint64(101), current: 101, transitioned: false, }, "current, parent, and fork same should not transition twice": { - fork: NewUint64(100), - parent: NewUint64(100), + fork: utils.NewUint64(100), + parent: utils.NewUint64(100), current: 100, transitioned: false, }, "current transitions after fork": { - fork: NewUint64(100), - parent: NewUint64(99), + fork: utils.NewUint64(100), + parent: utils.NewUint64(99), current: 101, transitioned: true, }, "current and parent come after fork": { - fork: NewUint64(100), - parent: NewUint64(101), + fork: utils.NewUint64(100), + parent: utils.NewUint64(101), current: 102, transitioned: false, }, diff --git a/params/config_test.go b/params/config_test.go index a3a37effe6..6123ac5525 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -145,7 +145,9 @@ func TestCheckCompatible(t *testing.T) { func TestConfigRules(t *testing.T) { c := &ChainConfig{ - CortinaBlockTimestamp: utils.NewUint64(500), + NetworkUpgrades: NetworkUpgrades{ + CortinaBlockTimestamp: utils.NewUint64(500), + }, } var stamp uint64 if r := c.Rules(big.NewInt(0), stamp); r.IsCortina { diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 41456c789e..4f443c8979 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -1,25 +1,196 @@ -// (c) 2022, Ava Labs, Inc. All rights reserved. +// (c) 2022, Ava Labs, Inn. All rights reserved. // See the file LICENSE for licensing terms. package params -func (c *ChainConfig) forkOrder() []fork { +import ( + "fmt" + "reflect" +) + +type NetworkUpgrades struct { + ApricotPhase1BlockTimestamp *uint64 `json:"apricotPhase1BlockTimestamp,omitempty"` // Apricot Phase 1 Block Timestamp (nil = no fork, 0 = already activated) + // Apricot Phase 2 Block Timestamp (nil = no fork, 0 = already activated) + // Apricot Phase 2 includes a modified version of the Berlin Hard Fork from Ethereum + ApricotPhase2BlockTimestamp *uint64 `json:"apricotPhase2BlockTimestamp,omitempty"` + // Apricot Phase 3 introduces dynamic fees and a modified version of the London Hard Fork from Ethereum (nil = no fork, 0 = already activated) + ApricotPhase3BlockTimestamp *uint64 `json:"apricotPhase3BlockTimestamp,omitempty"` + // Apricot Phase 4 introduces the notion of a block fee to the dynamic fee algorithm (nil = no fork, 0 = already activated) + ApricotPhase4BlockTimestamp *uint64 `json:"apricotPhase4BlockTimestamp,omitempty"` + // Apricot Phase 5 introduces a batch of atomic transactions with a maximum atomic gas limit per block. (nil = no fork, 0 = already activated) + ApricotPhase5BlockTimestamp *uint64 `json:"apricotPhase5BlockTimestamp,omitempty"` + // Apricot Phase Pre-6 deprecates the NativeAssetCall precompile (soft). (nil = no fork, 0 = already activated) + ApricotPhasePre6BlockTimestamp *uint64 `json:"apricotPhasePre6BlockTimestamp,omitempty"` + // Apricot Phase 6 deprecates the NativeAssetBalance and NativeAssetCall precompiles. (nil = no fork, 0 = already activated) + ApricotPhase6BlockTimestamp *uint64 `json:"apricotPhase6BlockTimestamp,omitempty"` + // Apricot Phase Post-6 deprecates the NativeAssetCall precompile (soft). (nil = no fork, 0 = already activated) + ApricotPhasePost6BlockTimestamp *uint64 `json:"apricotPhasePost6BlockTimestamp,omitempty"` + // Banff restricts import/export transactions to AVAX. (nil = no fork, 0 = already activated) + BanffBlockTimestamp *uint64 `json:"banffBlockTimestamp,omitempty"` + // Cortina increases the block gas limit to 15M. (nil = no fork, 0 = already activated) + CortinaBlockTimestamp *uint64 `json:"cortinaBlockTimestamp,omitempty"` + // Durango activates the Shanghai Execution Spec Upgrade from Ethereum (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md#included-eips) + // and Avalanche Warp Messaging. (nil = no fork, 0 = already activated) + // Note: EIP-4895 is excluded since withdrawals are not relevant to the Avalanche C-Chain or Subnets running the EVM. + DurangoBlockTimestamp *uint64 `json:"durangoBlockTimestamp,omitempty"` + // Etna activates Cancun from Ethereum (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/cancun.md#included-eips) + // and reduces the min base fee. (nil = no fork, 0 = already activated) + // Note: EIP-4844 BlobTxs are not enabled in the mempool and blocks are not + // allowed to contain them. For details see https://github.com/avalanche-foundation/ACPs/pull/131 + EtnaTimestamp *uint64 `json:"etnaTimestamp,omitempty"` +} + +func (n *NetworkUpgrades) Equal(other *NetworkUpgrades) bool { + return reflect.DeepEqual(n, other) +} + +func (n *NetworkUpgrades) CheckNetworkUpgradesCompatible(newcfg *NetworkUpgrades, time uint64) *ConfigCompatError { + if isForkTimestampIncompatible(n.ApricotPhase1BlockTimestamp, newcfg.ApricotPhase1BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase1 fork block timestamp", n.ApricotPhase1BlockTimestamp, newcfg.ApricotPhase1BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhase2BlockTimestamp, newcfg.ApricotPhase2BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase2 fork block timestamp", n.ApricotPhase2BlockTimestamp, newcfg.ApricotPhase2BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhase3BlockTimestamp, newcfg.ApricotPhase3BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase3 fork block timestamp", n.ApricotPhase3BlockTimestamp, newcfg.ApricotPhase3BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhase4BlockTimestamp, newcfg.ApricotPhase4BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase4 fork block timestamp", n.ApricotPhase4BlockTimestamp, newcfg.ApricotPhase4BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhase5BlockTimestamp, newcfg.ApricotPhase5BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase5 fork block timestamp", n.ApricotPhase5BlockTimestamp, newcfg.ApricotPhase5BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhasePre6BlockTimestamp, newcfg.ApricotPhasePre6BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhasePre6 fork block timestamp", n.ApricotPhasePre6BlockTimestamp, newcfg.ApricotPhasePre6BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhase6BlockTimestamp, newcfg.ApricotPhase6BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhase6 fork block timestamp", n.ApricotPhase6BlockTimestamp, newcfg.ApricotPhase6BlockTimestamp) + } + if isForkTimestampIncompatible(n.ApricotPhasePost6BlockTimestamp, newcfg.ApricotPhasePost6BlockTimestamp, time) { + return newTimestampCompatError("ApricotPhasePost6 fork block timestamp", n.ApricotPhasePost6BlockTimestamp, newcfg.ApricotPhasePost6BlockTimestamp) + } + if isForkTimestampIncompatible(n.BanffBlockTimestamp, newcfg.BanffBlockTimestamp, time) { + return newTimestampCompatError("Banff fork block timestamp", n.BanffBlockTimestamp, newcfg.BanffBlockTimestamp) + } + if isForkTimestampIncompatible(n.CortinaBlockTimestamp, newcfg.CortinaBlockTimestamp, time) { + return newTimestampCompatError("Cortina fork block timestamp", n.CortinaBlockTimestamp, newcfg.CortinaBlockTimestamp) + } + if isForkTimestampIncompatible(n.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp, time) { + return newTimestampCompatError("Durango fork block timestamp", n.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp) + } + if isForkTimestampIncompatible(n.EtnaTimestamp, newcfg.EtnaTimestamp, time) { + return newTimestampCompatError("Etna fork block timestamp", n.EtnaTimestamp, newcfg.EtnaTimestamp) + } + + return nil +} + +func (n *NetworkUpgrades) forkOrder() []fork { return []fork{ - {name: "apricotPhase1BlockTimestamp", timestamp: c.ApricotPhase1BlockTimestamp}, - {name: "apricotPhase2BlockTimestamp", timestamp: c.ApricotPhase2BlockTimestamp}, - {name: "apricotPhase3BlockTimestamp", timestamp: c.ApricotPhase3BlockTimestamp}, - {name: "apricotPhase4BlockTimestamp", timestamp: c.ApricotPhase4BlockTimestamp}, - {name: "apricotPhase5BlockTimestamp", timestamp: c.ApricotPhase5BlockTimestamp}, - {name: "apricotPhasePre6BlockTimestamp", timestamp: c.ApricotPhasePre6BlockTimestamp}, - {name: "apricotPhase6BlockTimestamp", timestamp: c.ApricotPhase6BlockTimestamp}, - {name: "apricotPhasePost6BlockTimestamp", timestamp: c.ApricotPhasePost6BlockTimestamp}, - {name: "banffBlockTimestamp", timestamp: c.BanffBlockTimestamp}, - {name: "cortinaBlockTimestamp", timestamp: c.CortinaBlockTimestamp}, - {name: "durangoBlockTimestamp", timestamp: c.DurangoBlockTimestamp}, - {name: "etnaTime", timestamp: c.EtnaTime}, + {name: "apricotPhase1BlockTimestamp", timestamp: n.ApricotPhase1BlockTimestamp}, + {name: "apricotPhase2BlockTimestamp", timestamp: n.ApricotPhase2BlockTimestamp}, + {name: "apricotPhase3BlockTimestamp", timestamp: n.ApricotPhase3BlockTimestamp}, + {name: "apricotPhase4BlockTimestamp", timestamp: n.ApricotPhase4BlockTimestamp}, + {name: "apricotPhase5BlockTimestamp", timestamp: n.ApricotPhase5BlockTimestamp}, + {name: "apricotPhasePre6BlockTimestamp", timestamp: n.ApricotPhasePre6BlockTimestamp}, + {name: "apricotPhase6BlockTimestamp", timestamp: n.ApricotPhase6BlockTimestamp}, + {name: "apricotPhasePost6BlockTimestamp", timestamp: n.ApricotPhasePost6BlockTimestamp}, + {name: "banffBlockTimestamp", timestamp: n.BanffBlockTimestamp}, + {name: "cortinaBlockTimestamp", timestamp: n.CortinaBlockTimestamp}, + {name: "durangoBlockTimestamp", timestamp: n.DurangoBlockTimestamp}, + {name: "etnaTime", timestamp: n.EtnaTimestamp}, } } +// IsApricotPhase1 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 1 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase1(time uint64) bool { + return isTimestampForked(n.ApricotPhase1BlockTimestamp, time) +} + +// IsApricotPhase2 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 2 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase2(time uint64) bool { + return isTimestampForked(n.ApricotPhase2BlockTimestamp, time) +} + +// IsApricotPhase3 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 3 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase3(time uint64) bool { + return isTimestampForked(n.ApricotPhase3BlockTimestamp, time) +} + +// IsApricotPhase4 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 4 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase4(time uint64) bool { + return isTimestampForked(n.ApricotPhase4BlockTimestamp, time) +} + +// IsApricotPhase5 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 5 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase5(time uint64) bool { + return isTimestampForked(n.ApricotPhase5BlockTimestamp, time) +} + +// IsApricotPhasePre6 returns whether [time] represents a block +// with a timestamp after the Apricot Phase Pre 6 upgrade time. +func (n *NetworkUpgrades) IsApricotPhasePre6(time uint64) bool { + return isTimestampForked(n.ApricotPhasePre6BlockTimestamp, time) +} + +// IsApricotPhase6 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 6 upgrade time. +func (n *NetworkUpgrades) IsApricotPhase6(time uint64) bool { + return isTimestampForked(n.ApricotPhase6BlockTimestamp, time) +} + +// IsApricotPhasePost6 returns whether [time] represents a block +// with a timestamp after the Apricot Phase 6 Post upgrade time. +func (n *NetworkUpgrades) IsApricotPhasePost6(time uint64) bool { + return isTimestampForked(n.ApricotPhasePost6BlockTimestamp, time) +} + +// IsBanff returns whether [time] represents a block +// with a timestamp after the Banff upgrade time. +func (n *NetworkUpgrades) IsBanff(time uint64) bool { + return isTimestampForked(n.BanffBlockTimestamp, time) +} + +// IsCortina returns whether [time] represents a block +// with a timestamp after the Cortina upgrade time. +func (n *NetworkUpgrades) IsCortina(time uint64) bool { + return isTimestampForked(n.CortinaBlockTimestamp, time) +} + +// IsDurango returns whether [time] represents a block +// with a timestamp after the Durango upgrade time. +func (n *NetworkUpgrades) IsDurango(time uint64) bool { + return isTimestampForked(n.DurangoBlockTimestamp, time) +} + +// IsEtna returns whether [time] represents a block +// with a timestamp after the Etna upgrade time. +func (n *NetworkUpgrades) IsEtna(time uint64) bool { + return isTimestampForked(n.EtnaTimestamp, time) +} + +func (n *NetworkUpgrades) Description() string { + var banner string + banner += fmt.Sprintf(" - Apricot Phase 1 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.3.0)\n", ptrToString(n.ApricotPhase1BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase 2 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.4.0)\n", ptrToString(n.ApricotPhase2BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase 3 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.5.0)\n", ptrToString(n.ApricotPhase3BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase 4 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.6.0)\n", ptrToString(n.ApricotPhase4BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase 5 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.7.0)\n", ptrToString(n.ApricotPhase5BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase P6 Timestamp @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0)\n", ptrToString(n.ApricotPhasePre6BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase 6 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0)\n", ptrToString(n.ApricotPhase6BlockTimestamp)) + banner += fmt.Sprintf(" - Apricot Phase Post-6 Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.8.0\n", ptrToString(n.ApricotPhasePost6BlockTimestamp)) + banner += fmt.Sprintf(" - Banff Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0)\n", ptrToString(n.BanffBlockTimestamp)) + banner += fmt.Sprintf(" - Cortina Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(n.CortinaBlockTimestamp)) + banner += fmt.Sprintf(" - Durango Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(n.DurangoBlockTimestamp)) + banner += fmt.Sprintf(" - Etna Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(n.EtnaTimestamp)) + return banner +} + type AvalancheRules struct { IsApricotPhase1, IsApricotPhase2, IsApricotPhase3, IsApricotPhase4, IsApricotPhase5 bool IsApricotPhasePre6, IsApricotPhase6, IsApricotPhasePost6 bool @@ -29,20 +200,19 @@ type AvalancheRules struct { IsEtna bool } -func (c *ChainConfig) GetAvalancheRules(timestamp uint64) AvalancheRules { - rules := AvalancheRules{} - rules.IsApricotPhase1 = c.IsApricotPhase1(timestamp) - rules.IsApricotPhase2 = c.IsApricotPhase2(timestamp) - rules.IsApricotPhase3 = c.IsApricotPhase3(timestamp) - rules.IsApricotPhase4 = c.IsApricotPhase4(timestamp) - rules.IsApricotPhase5 = c.IsApricotPhase5(timestamp) - rules.IsApricotPhasePre6 = c.IsApricotPhasePre6(timestamp) - rules.IsApricotPhase6 = c.IsApricotPhase6(timestamp) - rules.IsApricotPhasePost6 = c.IsApricotPhasePost6(timestamp) - rules.IsBanff = c.IsBanff(timestamp) - rules.IsCortina = c.IsCortina(timestamp) - rules.IsDurango = c.IsDurango(timestamp) - rules.IsEtna = c.IsEtna(timestamp) - - return rules +func (n *NetworkUpgrades) GetAvalancheRules(timestamp uint64) AvalancheRules { + return AvalancheRules{ + IsApricotPhase1: n.IsApricotPhase1(timestamp), + IsApricotPhase2: n.IsApricotPhase2(timestamp), + IsApricotPhase3: n.IsApricotPhase3(timestamp), + IsApricotPhase4: n.IsApricotPhase4(timestamp), + IsApricotPhase5: n.IsApricotPhase5(timestamp), + IsApricotPhasePre6: n.IsApricotPhasePre6(timestamp), + IsApricotPhase6: n.IsApricotPhase6(timestamp), + IsApricotPhasePost6: n.IsApricotPhasePost6(timestamp), + IsBanff: n.IsBanff(timestamp), + IsCortina: n.IsCortina(timestamp), + IsDurango: n.IsDurango(timestamp), + IsEtna: n.IsEtna(timestamp), + } } diff --git a/params/precompile_upgrade.go b/params/precompile_upgrade.go index 8130db5d52..4ae5377145 100644 --- a/params/precompile_upgrade.go +++ b/params/precompile_upgrade.go @@ -155,7 +155,7 @@ func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, fro for _, upgrade := range upgrades { if upgrade.Key() == key { // Check if the precompile activates in the specified range. - if utils.IsForkTransition(upgrade.Timestamp(), from, to) { + if IsForkTransition(upgrade.Timestamp(), from, to) { configs = append(configs, upgrade.Config) } } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 20174d553d..0b3b031ddc 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -715,7 +715,7 @@ func (vm *VM) initializeChain(lastAcceptedHash common.Hash) error { // TODO: remove this after Etna is activated func (vm *VM) setMinFeeAtEtna() { now := vm.clock.Time() - if vm.chainConfig.EtnaTime == nil { + if vm.chainConfig.EtnaTimestamp == nil { // If Etna is not set, set the min fee according to the latest upgrade vm.txPool.SetMinFee(big.NewInt(params.ApricotPhase4MinBaseFee)) return @@ -730,7 +730,7 @@ func (vm *VM) setMinFeeAtEtna() { go func() { defer vm.shutdownWg.Done() - wait := utils.Uint64ToTime(vm.chainConfig.EtnaTime).Sub(now) + wait := utils.Uint64ToTime(vm.chainConfig.EtnaTimestamp).Sub(now) t := time.NewTimer(wait) select { case <-t.C: // Wait for Etna to be activated diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 197f584b5d..0d72d2c808 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -119,7 +119,7 @@ var ( activateEtna = func(cfg *params.ChainConfig, etnaTime uint64) *params.ChainConfig { cpy := *cfg - cpy.EtnaTime = &etnaTime + cpy.EtnaTimestamp = &etnaTime return &cpy } diff --git a/tests/init.go b/tests/init.go index a2080e861f..aae979bbe0 100644 --- a/tests/init.go +++ b/tests/init.go @@ -166,151 +166,169 @@ var Forks = map[string]*params.ChainConfig{ IstanbulBlock: big.NewInt(5), }, "ApricotPhase1": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + }, }, "ApricotPhase2": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + }, }, "ApricotPhase3": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + }, }, "ApricotPhase4": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + }, }, "ApricotPhase5": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + }, }, "Banff": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + }, }, "Cortina": { - 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: 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), - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase5BlockTimestamp: utils.NewUint64(0), + BanffBlockTimestamp: utils.NewUint64(0), + CortinaBlockTimestamp: utils.NewUint64(0), + DurangoBlockTimestamp: utils.NewUint64(0), + }, }, } diff --git a/utils/fork.go b/utils/fork.go deleted file mode 100644 index 381e256165..0000000000 --- a/utils/fork.go +++ /dev/null @@ -1,63 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package utils - -import ( - "math/big" - "time" -) - -func NewUint64(val uint64) *uint64 { return &val } - -func TimeToNewUint64(time time.Time) *uint64 { - unix := uint64(time.Unix()) - return NewUint64(unix) -} - -func Uint64ToTime(val *uint64) time.Time { - timestamp := int64(*val) - return time.Unix(timestamp, 0) -} - -// IsBlockForked returns whether a fork scheduled at block s is active at the given head block. -// Note: [s] and [head] can be either a block number or a block timestamp. -func IsBlockForked(s, head *big.Int) bool { - if s == nil || head == nil { - return false - } - return s.Cmp(head) <= 0 -} - -// IsTimestampForked returns whether a fork scheduled at timestamp s is active -// at the given head timestamp. Whilst this method is the same as isBlockForked, -// they are explicitly separate for clearer reading. -func IsTimestampForked(s *uint64, head uint64) bool { - if s == nil { - return false - } - return *s <= head -} - -// IsForkTransition returns true if [fork] activates during the transition from -// [parent] to [current]. -// Taking [parent] as a pointer allows for us to pass nil when checking forks -// that activate during genesis. -// Note: this works for both block number and timestamp activated forks. -func IsForkTransition(fork *uint64, parent *uint64, current uint64) bool { - var parentForked bool - if parent != nil { - parentForked = IsTimestampForked(fork, *parent) - } - currentForked := IsTimestampForked(fork, current) - return !parentForked && currentForked -} - -// Uint64PtrEqual returns true if x and y pointers are equivalent ie. both nil or both -// contain the same value. -func Uint64PtrEqual(x, y *uint64) bool { - if x == nil || y == nil { - return x == y - } - return *x == *y -} diff --git a/utils/numbers.go b/utils/numbers.go new file mode 100644 index 0000000000..a6be2341fb --- /dev/null +++ b/utils/numbers.go @@ -0,0 +1,29 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package utils + +import ( + "time" +) + +func NewUint64(val uint64) *uint64 { return &val } + +func TimeToNewUint64(time time.Time) *uint64 { + unix := uint64(time.Unix()) + return NewUint64(unix) +} + +func Uint64ToTime(val *uint64) time.Time { + timestamp := int64(*val) + return time.Unix(timestamp, 0) +} + +// Uint64PtrEqual returns true if x and y pointers are equivalent ie. both nil or both +// contain the same value. +func Uint64PtrEqual(x, y *uint64) bool { + if x == nil || y == nil { + return x == y + } + return *x == *y +} From 52d0a8a4cf64c914f915dd88874d262b1e6ed49f Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 13 Aug 2024 23:40:40 +0300 Subject: [PATCH 08/17] update avago --- go.mod | 2 +- go.sum | 2 ++ scripts/versions.sh | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index acf0c2a896..6828c0bbb3 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.12 require ( github.com/VictoriaMetrics/fastcache v1.12.1 - github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1 + github.com/ava-labs/avalanchego v1.11.11-0.20240813180138-7520071656af github.com/cespare/cp v0.1.0 github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index edce397dda..7688e92d83 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1 h1:h/09vEeKWELnlHr2Da2cXawD8Qg/9RyHy5SrODt0kkU= github.com/ava-labs/avalanchego v1.11.11-0.20240809105844-da3256302ab1/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8= +github.com/ava-labs/avalanchego v1.11.11-0.20240813180138-7520071656af h1:BpAUJHH+QerXi2dMaHbaOzZHCiQAdqS+75Bqzd1alt8= +github.com/ava-labs/avalanchego v1.11.11-0.20240813180138-7520071656af/go.mod h1:8pnf2At/q0LRq5dvYJYn3CkhKzZNHRd5pjARC9psu+g= 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/scripts/versions.sh b/scripts/versions.sh index 05e1ed7ff6..bbe65fc1a7 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -6,4 +6,4 @@ set -euo pipefail # Don't export them as they're used in the context of other calls -AVALANCHE_VERSION=${AVALANCHE_VERSION:-'da3256302ab1'} +AVALANCHE_VERSION=${AVALANCHE_VERSION:-'7520071656af'} From 163edc7d3653b47c4a1f88c61667b95942d561a5 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 13 Aug 2024 23:43:05 +0300 Subject: [PATCH 09/17] rename --- params/network_upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 4f443c8979..16569a7fc8 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -98,7 +98,7 @@ func (n *NetworkUpgrades) forkOrder() []fork { {name: "banffBlockTimestamp", timestamp: n.BanffBlockTimestamp}, {name: "cortinaBlockTimestamp", timestamp: n.CortinaBlockTimestamp}, {name: "durangoBlockTimestamp", timestamp: n.DurangoBlockTimestamp}, - {name: "etnaTime", timestamp: n.EtnaTimestamp}, + {name: "etnaTimestamp", timestamp: n.EtnaTimestamp}, } } From 0c0659be43fcdafd74ca1e19770959cffe8f717d Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 13 Aug 2024 23:50:35 +0300 Subject: [PATCH 10/17] fix runtime networks --- core/vm/runtime/runtime.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 338c1c53b3..c7bb160064 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -67,22 +67,24 @@ type Config struct { func setDefaults(cfg *Config) { if cfg.ChainConfig == nil { cfg.ChainConfig = ¶ms.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: new(big.Int), - DAOForkBlock: new(big.Int), - DAOForkSupport: false, - 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), - ApricotPhase1BlockTimestamp: new(uint64), - ApricotPhase2BlockTimestamp: new(uint64), - ApricotPhase3BlockTimestamp: new(uint64), - ApricotPhase4BlockTimestamp: new(uint64), + ChainID: big.NewInt(1), + HomesteadBlock: new(big.Int), + DAOForkBlock: new(big.Int), + DAOForkSupport: false, + 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), + NetworkUpgrades: params.NetworkUpgrades{ + ApricotPhase1BlockTimestamp: new(uint64), + ApricotPhase2BlockTimestamp: new(uint64), + ApricotPhase3BlockTimestamp: new(uint64), + ApricotPhase4BlockTimestamp: new(uint64), + }, } } From 330515422495d908148c0df94e62f76be516c916 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 14 Aug 2024 15:14:55 +0300 Subject: [PATCH 11/17] override netowrk upgrades from context --- .../internal/tracetest/calltrace_test.go | 5 ++++- params/config.go | 11 ---------- params/config_extra.go | 15 +------------ params/network_upgrades.go | 22 ++++++++++++++++++- plugin/evm/vm.go | 21 +++++++++++++----- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/eth/tracers/internal/tracetest/calltrace_test.go b/eth/tracers/internal/tracetest/calltrace_test.go index e3f1b1a0cc..582b5979a9 100644 --- a/eth/tracers/internal/tracetest/calltrace_test.go +++ b/eth/tracers/internal/tracetest/calltrace_test.go @@ -34,6 +34,8 @@ import ( "strings" "testing" + "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/coreth/core" "github.com/ava-labs/coreth/core/rawdb" "github.com/ava-labs/coreth/core/types" @@ -275,6 +277,7 @@ func benchTracer(tracerName string, test *callTracerTest, b *testing.B) { func TestInternals(t *testing.T) { var ( + config = params.GetChainConfig(upgrade.GetConfig(constants.MainnetID), params.AvalancheMainnetChainID) to = common.HexToAddress("0x00000000000000000000000000000000deadbeef") origin = common.HexToAddress("0x00000000000000000000000000000000feed") txContext = vm.TxContext{ @@ -388,7 +391,7 @@ func TestInternals(t *testing.T) { }, false, rawdb.HashScheme) defer triedb.Close() - evm := vm.NewEVM(context, txContext, statedb, params.AvalancheMainnetChainConfig, vm.Config{Tracer: tc.tracer}) + evm := vm.NewEVM(context, txContext, statedb, config, vm.Config{Tracer: tc.tracer}) msg := &core.Message{ To: &to, From: origin, diff --git a/params/config.go b/params/config.go index 306a995df0..da47cf8282 100644 --- a/params/config.go +++ b/params/config.go @@ -32,8 +32,6 @@ import ( "fmt" "math/big" - "github.com/ava-labs/avalanchego/upgrade" - "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/coreth/precompile/modules" "github.com/ava-labs/coreth/precompile/precompileconfig" "github.com/ava-labs/coreth/utils" @@ -53,15 +51,6 @@ var ( ) var ( - // AvalancheMainnetChainConfig is the configuration for Avalanche Main Network - AvalancheMainnetChainConfig = GetChainConfig(upgrade.GetConfig(constants.MainnetID), AvalancheMainnetChainID) - - // AvalancheFujiChainConfig is the configuration for the Fuji Test Network - AvalancheFujiChainConfig = GetChainConfig(upgrade.GetConfig(constants.FujiID), AvalancheFujiChainID) - - // AvalancheLocalChainConfig is the configuration for the Avalanche Local Network - AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheLocalChainID) - TestChainConfig = &ChainConfig{ AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), diff --git a/params/config_extra.go b/params/config_extra.go index 1b76ccd571..36fc2c98ba 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -171,20 +171,7 @@ func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig { PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(0), MuirGlacierBlock: big.NewInt(0), - NetworkUpgrades: NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time), - ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time), - ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time), - ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time), - ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time), - ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time), - ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time), - ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time), - BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime), - CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime), - DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime), - EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime), - }, + NetworkUpgrades: getNetworkUpgrades(agoUpgrade), } } diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 16569a7fc8..951dd5a071 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -6,6 +6,9 @@ package params import ( "fmt" "reflect" + + "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/coreth/utils" ) type NetworkUpgrades struct { @@ -187,10 +190,27 @@ func (n *NetworkUpgrades) Description() string { banner += fmt.Sprintf(" - Banff Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0)\n", ptrToString(n.BanffBlockTimestamp)) banner += fmt.Sprintf(" - Cortina Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(n.CortinaBlockTimestamp)) banner += fmt.Sprintf(" - Durango Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(n.DurangoBlockTimestamp)) - banner += fmt.Sprintf(" - Etna Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(n.EtnaTimestamp)) + banner += fmt.Sprintf(" - Etna Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(n.EtnaTimestamp)) return banner } +func getNetworkUpgrades(agoUpgrade upgrade.Config) NetworkUpgrades { + return NetworkUpgrades{ + ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time), + ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time), + ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time), + ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time), + ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time), + ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time), + ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time), + ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time), + BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime), + CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime), + DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime), + EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime), + } +} + type AvalancheRules struct { IsApricotPhase1, IsApricotPhase2, IsApricotPhase3, IsApricotPhase4, IsApricotPhase5 bool IsApricotPhasePre6, IsApricotPhase6, IsApricotPhasePost6 bool diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 0b3b031ddc..9263542acd 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/network/p2p/gossip" + "github.com/ava-labs/avalanchego/upgrade" avalanchegoConstants "github.com/ava-labs/avalanchego/utils/constants" "github.com/prometheus/client_golang/prometheus" @@ -448,20 +449,28 @@ func (vm *VM) Initialize( } var extDataHashes map[common.Hash]common.Hash + var chainID *big.Int + // params.GetChainConfig(chainCtx.NetworkUpgrades) // Set the chain config for mainnet/fuji chain IDs switch chainCtx.NetworkID { case avalanchegoConstants.MainnetID: - config := *params.AvalancheMainnetChainConfig - g.Config = &config + chainID = params.AvalancheMainnetChainID extDataHashes = mainnetExtDataHashes case avalanchegoConstants.FujiID: - config := *params.AvalancheFujiChainConfig - g.Config = &config + chainID = params.AvalancheFujiChainID extDataHashes = fujiExtDataHashes case avalanchegoConstants.LocalID: - config := *params.AvalancheLocalChainConfig - g.Config = &config + chainID = params.AvalancheLocalChainID + default: + chainID = g.Config.ChainID + } + + // if the chainCtx.NetworkUpgrades is not empty, set the chain config + // normally it should not be empty, but some tests may not set it + if chainCtx.NetworkUpgrades != (upgrade.Config{}) { + g.Config = params.GetChainConfig(chainCtx.NetworkUpgrades, chainID) } + // If the Durango is activated, activate the Warp Precompile at the same time if g.Config.DurangoBlockTimestamp != nil { g.Config.PrecompileUpgrades = append(g.Config.PrecompileUpgrades, params.PrecompileUpgrade{ From 060d3b30a1d59bb692c0745b5be6cb3ba14a4f50 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 14 Aug 2024 15:25:31 +0300 Subject: [PATCH 12/17] Update params/network_upgrades.go Signed-off-by: Ceyhun Onur --- params/network_upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 5294d93775..6af886b093 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -1,4 +1,4 @@ -// (c) 2022, Ava Labs, Inn. All rights reserved. +// (c) 2022, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package params From 150640e88918d99c6f1aa5f9ca45f13f9ee1a1a8 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Thu, 15 Aug 2024 18:38:40 +0300 Subject: [PATCH 13/17] remove comment --- plugin/evm/vm.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 2fbd5ba836..f9b559aee4 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -450,7 +450,6 @@ func (vm *VM) Initialize( var extDataHashes map[common.Hash]common.Hash var chainID *big.Int - // params.GetChainConfig(chainCtx.NetworkUpgrades) // Set the chain config for mainnet/fuji chain IDs switch chainCtx.NetworkID { case avalanchegoConstants.MainnetID: From 77af180df82ef80451a9e56c9095d1e0af20b6cd Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Thu, 15 Aug 2024 22:29:59 +0300 Subject: [PATCH 14/17] use chainID copy --- plugin/evm/vm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index f9b559aee4..d1a642add5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -467,7 +467,7 @@ func (vm *VM) Initialize( // if the chainCtx.NetworkUpgrades is not empty, set the chain config // normally it should not be empty, but some tests may not set it if chainCtx.NetworkUpgrades != (upgrade.Config{}) { - g.Config = params.GetChainConfig(chainCtx.NetworkUpgrades, chainID) + g.Config = params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(chainID)) } // If the Durango is activated, activate the Warp Precompile at the same time @@ -502,6 +502,10 @@ func (vm *VM) Initialize( g.Config.SetEthUpgrades() + for _, line := range strings.Split(g.Config.Description(), "\n") { + log.Info(line) + } + vm.ethConfig = ethconfig.NewDefaultConfig() vm.ethConfig.Genesis = g vm.ethConfig.NetworkId = vm.chainID.Uint64() From a96bc921e732223ccea38330ed753e3f9a277e94 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Thu, 15 Aug 2024 22:34:40 +0300 Subject: [PATCH 15/17] bump avago --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8cc4f6b425..88e24bafcf 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.12 require ( github.com/VictoriaMetrics/fastcache v1.12.1 - github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d + github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df github.com/cespare/cp v0.1.0 github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index 2c359f6a24..c9447c5be7 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d h1:LyrKJL9avIIxBY3uTcS2dFtUMBFmI2QpAgG6qYTdA6s= github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM= +github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df h1:Yp9rCHpgEsPFzpx2MXxpb/T+/NbP2NpS1EDwFquffLQ= +github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df/go.mod h1:Kw2GKwTaCkLwq2z3zSVH4V2eiAmq2FohHmN3AIDWjvY= 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= From 2b0e345be33870acb6a4414716db61b37763bc85 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Thu, 15 Aug 2024 22:37:57 +0300 Subject: [PATCH 16/17] remove debug logs --- plugin/evm/vm.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index d1a642add5..cb7cd9f1d6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -502,10 +502,6 @@ func (vm *VM) Initialize( g.Config.SetEthUpgrades() - for _, line := range strings.Split(g.Config.Description(), "\n") { - log.Info(line) - } - vm.ethConfig = ethconfig.NewDefaultConfig() vm.ethConfig.Genesis = g vm.ethConfig.NetworkId = vm.chainID.Uint64() From b28157be64a6676ed436dae3bdb6a12908588aee Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Thu, 15 Aug 2024 22:44:44 +0300 Subject: [PATCH 17/17] update avago version --- scripts/versions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/versions.sh b/scripts/versions.sh index ebfd4dedc9..5bed52626d 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -6,4 +6,4 @@ set -euo pipefail # Don't export them as they're used in the context of other calls -AVALANCHE_VERSION=${AVALANCHE_VERSION:-'ab83fb41528de93c1790301cdd67a07dda9299f0'} +AVALANCHE_VERSION=${AVALANCHE_VERSION:-'1ac532af76df'}