diff options
author | Aaron Buchwald <[email protected]> | 2020-12-15 17:30:03 -0500 |
---|---|---|
committer | Aaron Buchwald <[email protected]> | 2020-12-15 17:30:03 -0500 |
commit | cc2a13f91f95bd377f5c3efb86ebbcc7096f6d97 (patch) | |
tree | 141d6f6a5a6f1d73ea934f2923ec439f6ca1ef69 /params/config.go | |
parent | b892b31f7f9bc9a63eb9774e7fbe0b5cd82891ae (diff) |
Set chain rules based on block times for mainnet/fuji
Diffstat (limited to 'params/config.go')
-rw-r--r-- | params/config.go | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/params/config.go b/params/config.go index 1e14c40..d5db94f 100644 --- a/params/config.go +++ b/params/config.go @@ -20,6 +20,7 @@ import ( "encoding/binary" "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -62,40 +63,38 @@ var ( var ( // AvalancheApricotMainnetChainConfig is the configuration for Avalanche Main Network AvalancheApricotMainnetChainConfig = &ChainConfig{ - ChainID: AvalancheMainnetChainID, - HomesteadBlock: big.NewInt(0), - DAOForkBlock: big.NewInt(0), - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ApricotBlock: big.NewInt(0), // TODO specify correct block height + ChainID: AvalancheMainnetChainID, + HomesteadBlock: big.NewInt(0), + DAOForkBlock: big.NewInt(0), + DAOForkSupport: true, + EIP150Block: big.NewInt(0), + EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), + EIP155Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + ApricotBlockTimestamp: new(big.Int).SetUint64(uint64(time.Date(2021, 1, 7, 5, 00, 0, 0, time.UTC).Unix())), } // AvalancheApricotFujiChainConfig is the configuration for the Fuji Test Network AvalancheApricotFujiChainConfig = &ChainConfig{ - ChainID: AvalancheFujiChainID, - HomesteadBlock: big.NewInt(0), - DAOForkBlock: big.NewInt(0), - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - ApricotBlock: big.NewInt(0), // TODO specify correct block height + ChainID: AvalancheFujiChainID, + HomesteadBlock: big.NewInt(0), + DAOForkBlock: big.NewInt(0), + DAOForkSupport: true, + EIP150Block: big.NewInt(0), + EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), + EIP155Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + ApricotBlockTimestamp: new(big.Int).SetUint64(uint64(time.Date(2020, 12, 23, 5, 00, 0, 0, time.UTC).Unix())), } - // TODO update local network genesis to enable Apricot - // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = &ChainConfig{ ChainID: big.NewInt(1), @@ -366,7 +365,11 @@ type ChainConfig struct { YoloV1Block *big.Int `json:"yoloV1Block,omitempty"` // YOLO v1: https://github.com/ethereum/EIPs/pull/2657 (Ephemeral testnet) EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) - ApricotBlock *big.Int `json:"apricotBlock,omitempty"` // Apricot switch block (nil = no fork, 0 = already activated) + // Avalanche Network Upgrade Block Timestamps: + + // Apricot switch block timestamp (nil = no fork, 0 = already activated) + // Apricot rules go into effect for blocks with a timestamp >= ApricotBlockTimestamp + ApricotBlockTimestamp *big.Int `json:"apricotBlock,omitempty"` // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` @@ -403,7 +406,7 @@ func (c *ChainConfig) String() string { default: engine = "unknown" } - return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, YOLO v1: %v, Apricot: %v, Engine: %v}", + return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, YOLO v1: %v, ApricotTimestamp: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -417,7 +420,7 @@ func (c *ChainConfig) String() string { c.IstanbulBlock, c.MuirGlacierBlock, c.YoloV1Block, - c.ApricotBlock, + c.ApricotBlockTimestamp, engine, ) } @@ -484,9 +487,12 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool { return isForked(c.EWASMBlock, num) } -// IsApricot returns whether num represents a block number after the Apricot fork -func (c *ChainConfig) IsApricot(num *big.Int) bool { - return isForked(c.ApricotBlock, num) +// Avalanche Forks: + +// IsApricot returns whether num represents a block with a timestamp +// after the Apricot fork time. +func (c *ChainConfig) IsApricot(blockTimestamp *big.Int) bool { + return isForked(c.ApricotBlockTimestamp, blockTimestamp) } // TODO review how this works and see if it will work for a live transition @@ -687,6 +693,14 @@ func (c *ChainConfig) Rules(num *big.Int) Rules { IsPetersburg: c.IsPetersburg(num), IsIstanbul: c.IsIstanbul(num), IsYoloV1: c.IsYoloV1(num), - IsApricot: c.IsApricot(num), } } + +// AvalancheRules returns the Avalanche modified rules to support Avalanche +// network upgrades +func (c *ChainConfig) AvalancheRules(blockNum, blockTimestamp *big.Int) Rules { + rules := c.Rules(blockNum) + + rules.IsApricot = c.IsApricot(blockTimestamp) + return rules +} |