aboutsummaryrefslogtreecommitdiff
path: root/params/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'params/config.go')
-rw-r--r--params/config.go88
1 files changed, 84 insertions, 4 deletions
diff --git a/params/config.go b/params/config.go
index e5ec64b..2f59170 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"
@@ -52,7 +53,55 @@ var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{
GoerliGenesisHash: GoerliCheckpointOracle,
}
+// Avalanche ChainIDs
var (
+ // AvalancheMainnetChainID ...
+ AvalancheMainnetChainID = big.NewInt(43114)
+ // AvalancheFujiChainID ...
+ AvalancheFujiChainID = big.NewInt(43113)
+)
+
+// Network upgrade block timestamps
+var (
+ AvalancheMainnetApricotTimestamp = new(big.Int).SetUint64(uint64(time.Date(2021, 1, 7, 5, 00, 0, 0, time.UTC).Unix()))
+ AvalancheFujiApricotTimestamp = new(big.Int).SetUint64(uint64(time.Date(2020, 12, 23, 5, 00, 0, 0, time.UTC).Unix()))
+)
+
+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),
+ ApricotBlockTimestamp: AvalancheMainnetApricotTimestamp,
+ }
+
+ // 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),
+ ApricotBlockTimestamp: AvalancheFujiApricotTimestamp,
+ }
+
// MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{
ChainID: big.NewInt(1),
@@ -239,16 +288,16 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
- AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(EthashConfig), nil}
+ AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, new(EthashConfig), nil}
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus.
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
- AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
+ AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
- TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(EthashConfig), nil}
+ TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int))
)
@@ -323,6 +372,12 @@ 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)
+ // 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:"apricotBlockTimestamp,omitempty"`
+
// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"`
Clique *CliqueConfig `json:"clique,omitempty"`
@@ -358,7 +413,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, 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,
@@ -372,6 +427,7 @@ func (c *ChainConfig) String() string {
c.IstanbulBlock,
c.MuirGlacierBlock,
c.YoloV1Block,
+ c.ApricotBlockTimestamp,
engine,
)
}
@@ -438,6 +494,15 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool {
return isForked(c.EWASMBlock, 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
// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
@@ -477,6 +542,10 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "istanbulBlock", block: c.IstanbulBlock},
{name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true},
{name: "yoloV1Block", block: c.YoloV1Block},
+ // TODO figure out how Apricot fits in here.
+ // Precompiled contracts start from other end so they are compatible
+ // but it may be incompatible (and it was before Apricot as well) due
+ // to how the instruction sets are created
} {
if lastFork.name != "" {
// Next one must be higher number
@@ -610,6 +679,8 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsYoloV1 bool
+ // Avalanche Releases
+ IsApricot bool
}
// Rules ensures c's ChainID is not nil.
@@ -631,3 +702,12 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsYoloV1: c.IsYoloV1(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
+}