Skip to content

Commit

Permalink
params: add BerlinBlock, LondonBlock, ShanghaiTime (#1337)
Browse files Browse the repository at this point in the history
* params: add LondonBlock

* params: add ShanghaiTime

* params: add BerlinBlock

* params: add IsLondon checks to Cancun (similar to upstream)
  • Loading branch information
darioush authored Sep 11, 2024
1 parent 6fd1328 commit 25692e9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
3 changes: 3 additions & 0 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ func TestCreateThenDeletePreByzantium(t *testing.T) {
config.PetersburgBlock = nil
config.IstanbulBlock = nil
config.MuirGlacierBlock = nil
config.BerlinBlock = nil
config.LondonBlock = nil

testCreateThenDelete(t, &config)
}
func TestCreateThenDeletePostByzantium(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func TestVerkleGenesisCommit(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ShanghaiTime: &verkleTime,
CancunTime: &verkleTime,
VerkleTime: &verkleTime,
}
Expand Down
1 change: 1 addition & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func u64(val uint64) *uint64 { return &val }
func TestStateProcessorErrors(t *testing.T) {
cpcfg := *params.TestChainConfig
config := &cpcfg
config.ShanghaiTime = u64(0)
config.CancunTime = u64(0)
config.FeeConfig.MinBaseFee = big.NewInt(params.TestMaxBaseFee)

Expand Down
8 changes: 3 additions & 5 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
"github.com/ava-labs/subnet-evm/internal/blocktest"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/rpc"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -789,15 +788,13 @@ func TestEstimateGas(t *testing.T) {
}

func TestCall(t *testing.T) {
// Enable BLOBHASH opcode in Cancun
cfg := *params.TestChainConfig
cfg.CancunTime = utils.NewUint64(0)
t.Parallel()
// Initialize test accounts
var (
accounts = newAccounts(3)
genesis = &core.Genesis{
Config: &cfg,
Config: params.TestChainConfig,
Timestamp: uint64(upgrade.InitiallyActiveTime.Unix()),
Alloc: types.GenesisAlloc{
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
Expand Down Expand Up @@ -1787,6 +1784,7 @@ func TestRPCGetBlockOrHeader(t *testing.T) {

func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Hash) {
config := *params.TestChainConfig
config.ShanghaiTime = new(uint64)
config.CancunTime = new(uint64)
var (
acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
Expand Down
47 changes: 41 additions & 6 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ShanghaiTime: utils.TimeToNewUint64(upgrade.GetConfig(constants.UnitTestID).DurangoTime),
CancunTime: utils.TimeToNewUint64(upgrade.GetConfig(constants.UnitTestID).EtnaTime),
NetworkUpgrades: getDefaultNetworkUpgrades(upgrade.GetConfig(constants.UnitTestID)), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
Expand All @@ -95,6 +98,8 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
DurangoTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
Expand Down Expand Up @@ -195,11 +200,14 @@ type ChainConfig struct {
PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul)
MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)

// 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)
ShanghaiTime *uint64 `json:"shanghaiTime,omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai)
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)

NetworkUpgrades // Config for timestamps that enable network upgrades. Skip encoding/decoding directly into ChainConfig.

Expand Down Expand Up @@ -317,14 +325,29 @@ func (c *ChainConfig) IsIstanbul(num *big.Int) bool {
return isBlockForked(c.IstanbulBlock, num)
}

// IsCancun returns whether time is either equal to the Cancun fork time or greater.
// IsBerlin returns whether num is either equal to the Berlin fork block or greater.
func (c *ChainConfig) IsBerlin(num *big.Int) bool {
return isBlockForked(c.BerlinBlock, num)
}

// IsLondon returns whether num is either equal to the London fork block or greater.
func (c *ChainConfig) IsLondon(num *big.Int) bool {
return isBlockForked(c.LondonBlock, num)
}

// IsShanghai returns whether time is either equal to the Shanghai fork time or greater.
func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
}

// IsCancun returns whether num is either equal to the Cancun fork time or greater.
func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
return isTimestampForked(c.CancunTime, time)
return c.IsLondon(num) && isTimestampForked(c.CancunTime, time)
}

// IsVerkle returns whether time is either equal to the Verkle fork time or greater.
// IsVerkle returns whether num is either equal to the Verkle fork time or greater.
func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool {
return isTimestampForked(c.VerkleTime, time)
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
Expand Down Expand Up @@ -372,6 +395,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "petersburgBlock", block: c.PetersburgBlock},
{name: "istanbulBlock", block: c.IstanbulBlock},
{name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true},
{name: "berlinBlock", block: c.BerlinBlock},
{name: "londonBlock", block: c.LondonBlock},
{name: "shanghaiTime", timestamp: c.ShanghaiTime},
{name: "cancunTime", timestamp: c.CancunTime, optional: true},
{name: "verkleTime", timestamp: c.VerkleTime, optional: true},
}
Expand Down Expand Up @@ -479,6 +505,15 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkBlockIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, headNumber) {
return newBlockCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock)
}
if isForkBlockIncompatible(c.BerlinBlock, newcfg.BerlinBlock, headNumber) {
return newBlockCompatError("Berlin fork block", c.BerlinBlock, newcfg.BerlinBlock)
}
if isForkBlockIncompatible(c.LondonBlock, newcfg.LondonBlock, headNumber) {
return newBlockCompatError("London fork block", c.LondonBlock, newcfg.LondonBlock)
}
if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) {
return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime)
}
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) {
return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime)
}
Expand Down
9 changes: 9 additions & 0 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type AvalancheContext struct {

// SetEthUpgrades sets the mapped upgrades Avalanche > EVM upgrades) for the chain config.
func (c *ChainConfig) SetEthUpgrades(avalancheUpgrades NetworkUpgrades) {
if avalancheUpgrades.DurangoTimestamp != nil {
c.ShanghaiTime = utils.NewUint64(*avalancheUpgrades.DurangoTimestamp)
}
if avalancheUpgrades.EtnaTimestamp != nil {
c.CancunTime = utils.NewUint64(*avalancheUpgrades.EtnaTimestamp)
}
Expand Down Expand Up @@ -260,6 +263,12 @@ func (c *ChainConfig) SetNetworkUpgradeDefaults() {
if c.MuirGlacierBlock == nil {
c.MuirGlacierBlock = big.NewInt(0)
}
if c.BerlinBlock == nil {
c.BerlinBlock = big.NewInt(0)
}
if c.LondonBlock == nil {
c.LondonBlock = big.NewInt(0)
}

c.NetworkUpgrades.setDefaults(c.SnowCtx.NetworkUpgrades)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ var Forks = map[string]*params.ChainConfig{
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ShanghaiTime: utils.NewUint64(0),
CancunTime: utils.NewUint64(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
Expand Down

0 comments on commit 25692e9

Please sign in to comment.