Skip to content

Commit

Permalink
Merge branch 'master' into docker-img-build
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur authored Mar 19, 2024
2 parents 30dd4d4 + eeb2cd5 commit a4615e5
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 265 deletions.
11 changes: 10 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package core

import (
"encoding/json"
"fmt"
"math/big"

Expand Down Expand Up @@ -197,7 +198,15 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64,
// since Suicide will be committed after the reconfiguration.
statedb.Finalise(true)
} else {
log.Info("Activating new precompile", "name", module.ConfigKey, "config", activatingConfig)
var printIntf interface{}
marshalled, err := json.Marshal(activatingConfig)
if err == nil {
printIntf = string(marshalled)
} else {
printIntf = activatingConfig
}

log.Info("Activating new precompile", "name", module.ConfigKey, "config", printIntf)
// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
// that it is marked as non-empty and will not be cleaned up when the statedb is finalized.
statedb.SetNonce(module.Address, 1)
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestBadTxAllowListBlock(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
MandatoryNetworkUpgrades: params.MandatoryNetworkUpgrades{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: params.Precompiles{
Expand Down
2 changes: 1 addition & 1 deletion core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func setDefaults(cfg *Config) {
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
MandatoryNetworkUpgrades: params.MandatoryNetworkUpgrades{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: new(uint64),
},
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
github.com/go-cmd/cmd v1.4.1
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.6.0
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
Expand Down Expand Up @@ -82,6 +81,7 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func newBackendMock() *backendMock {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
MandatoryNetworkUpgrades: params.MandatoryNetworkUpgrades{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(1000),
},
}
Expand Down
152 changes: 83 additions & 69 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ var (
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,

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),
MandatoryNetworkUpgrades: GetMandatoryNetworkUpgrades(constants.MainnetID), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
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: getDefaultNetworkUpgrades(constants.MainnetID), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
}

TestChainConfig = &ChainConfig{
Expand All @@ -105,7 +105,7 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
},
Expand All @@ -127,30 +127,30 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}

TestPreSubnetEVMConfig = &ChainConfig{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
ChainID: big.NewInt(1),
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
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),
MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
ChainID: big.NewInt(1),
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
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: NetworkUpgrades{},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}

TestRules = TestChainConfig.Rules(new(big.Int), 0)
Expand Down Expand Up @@ -186,8 +186,10 @@ 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)

MandatoryNetworkUpgrades // Config for timestamps that enable mandatory network upgrades. Skip encoding/decoding directly into ChainConfig.
OptionalNetworkUpgrades // Config for optional timestamps that enable network upgrades
// Cancun activates the Cancun upgrade from Ethereum. (nil = no fork, 0 = already activated)
CancunTime *uint64 `json:"cancunTime,omitempty"`

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

AvalancheContext `json:"-"` // Avalanche specific context set during VM initialization. Not serialized.

Expand Down Expand Up @@ -224,19 +226,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 += "Mandatory Avalanche Upgrades (timestamp based):\n"
banner += "Avalanche Upgrades (timestamp based):\n"
banner += fmt.Sprintf(" - SubnetEVM Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(c.SubnetEVMTimestamp))
banner += fmt.Sprintf(" - Durango Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(c.DurangoTimestamp))
banner += "\n"

// Add Subnet-EVM custom fields
optionalNetworkUpgradeBytes, err := json.Marshal(c.OptionalNetworkUpgrades)
if err != nil {
optionalNetworkUpgradeBytes = []byte("cannot marshal OptionalNetworkUpgrades")
}
banner += fmt.Sprintf("Optional Network Upgrades: %s", string(optionalNetworkUpgradeBytes))
banner += "\n"

precompileUpgradeBytes, err := json.Marshal(c.GenesisPrecompiles)
if err != nil {
precompileUpgradeBytes = []byte("cannot marshal PrecompileUpgrade")
Expand All @@ -263,6 +257,42 @@ func (c *ChainConfig) Description() string {
return banner
}

func (c *ChainConfig) SetNetworkUpgradeDefaults() {
if c.HomesteadBlock == nil {
c.HomesteadBlock = big.NewInt(0)
}
if c.EIP150Block == nil {
c.EIP150Block = big.NewInt(0)
}
if c.EIP155Block == nil {
c.EIP155Block = big.NewInt(0)
}
if c.EIP158Block == nil {
c.EIP158Block = big.NewInt(0)
}
if c.ByzantiumBlock == nil {
c.ByzantiumBlock = big.NewInt(0)
}
if c.ConstantinopleBlock == nil {
c.ConstantinopleBlock = big.NewInt(0)
}
if c.PetersburgBlock == nil {
c.PetersburgBlock = big.NewInt(0)
}
if c.IstanbulBlock == nil {
c.IstanbulBlock = big.NewInt(0)
}
if c.MuirGlacierBlock == nil {
c.MuirGlacierBlock = big.NewInt(0)
}

c.NetworkUpgrades.setDefaults(c.SnowCtx.NetworkID)

// if c.CancunTime == nil {
// c.CancunTime = c.EUpgrade
// }
}

// 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)
Expand Down Expand Up @@ -316,6 +346,7 @@ func (c *ChainConfig) IsSubnetEVM(time uint64) bool {
return utils.IsTimestampForked(c.SubnetEVMTimestamp, time)
}

// TODO: move avalanche hardforks to network_upgrades.go
// IsDurango returns whether [time] represents a block
// with a timestamp after the Durango upgrade time.
func (c *ChainConfig) IsDurango(time uint64) bool {
Expand Down Expand Up @@ -384,6 +415,11 @@ func (c *ChainConfig) Verify() error {
return fmt.Errorf("invalid state upgrades: %w", err)
}

// Verify the network upgrades are internally consistent given the existing chainConfig.
if err := c.VerifyNetworkUpgrades(c.SnowCtx.NetworkID); err != nil {
return fmt.Errorf("invalid network upgrades: %w", err)
}

return nil
}

Expand Down Expand Up @@ -422,12 +458,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
// Note: we do not add the optional stateful precompile configs in here because they are optional
// and independent, such that the ordering they are enabled does not impact the correctness of the
// chain config.
if err := checkForks(c.mandatoryForkOrder(), false); err != nil {
return err
}

// Check optional forks are enabled in order
if err := checkForks(c.optionalForkOrder(), false); err != nil {
if err := checkForks(c.forkOrder(), false); err != nil {
return err
}

Expand All @@ -446,12 +477,12 @@ func checkForks(forks []fork, blockFork bool) error {
// Next one must be higher number
if lastFork.timestamp == nil && cur.timestamp != nil {
return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v",
lastFork.name, cur.name, cur.timestamp)
lastFork.name, cur.name, *cur.timestamp)
}
if lastFork.timestamp != nil && cur.timestamp != nil {
if *lastFork.timestamp > *cur.timestamp {
return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v",
lastFork.name, lastFork.timestamp, cur.name, cur.timestamp)
lastFork.name, *lastFork.timestamp, cur.name, *cur.timestamp)
}
}
}
Expand Down Expand Up @@ -502,20 +533,12 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, height *big.Int, time
return newBlockCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock)
}

// Check avalanhe network upgrades
if err := c.CheckMandatoryCompatible(&newcfg.MandatoryNetworkUpgrades, time); err != nil {
return err
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, time) {
return newTimestampCompatError("Cancun fork block timestamp", c.CancunTime, c.CancunTime)
}

// Check subnet-evm specific activations
newOptionalNetworkUpgrades := newcfg.getOptionalNetworkUpgrades()
if c.UpgradeConfig.OptionalNetworkUpgrades != nil && newcfg.UpgradeConfig.OptionalNetworkUpgrades == nil {
// Note: if the current OptionalNetworkUpgrades are set via UpgradeConfig, then a new config
// without OptionalNetworkUpgrades will be treated as having specified an empty set of network
// upgrades (ie., treated as the user intends to cancel scheduled forks)
newOptionalNetworkUpgrades = &OptionalNetworkUpgrades{}
}
if err := c.getOptionalNetworkUpgrades().CheckOptionalCompatible(newOptionalNetworkUpgrades, time); err != nil {
// Check avalanche network upgrades
if err := c.CheckNetworkUpgradesCompatible(&newcfg.NetworkUpgrades, time); err != nil {
return err
}

Expand Down Expand Up @@ -733,12 +756,3 @@ func (c *ChainConfig) GetFeeConfig() commontype.FeeConfig {
func (c *ChainConfig) AllowedFeeRecipients() bool {
return c.AllowFeeRecipients
}

// getOptionalNetworkUpgrades returns OptionalNetworkUpgrades from upgrade config if set there,
// otherwise it falls back to the genesis chain config.
func (c *ChainConfig) getOptionalNetworkUpgrades() *OptionalNetworkUpgrades {
if upgradeConfigOverride := c.UpgradeConfig.OptionalNetworkUpgrades; upgradeConfigOverride != nil {
return upgradeConfigOverride
}
return &c.OptionalNetworkUpgrades
}
6 changes: 2 additions & 4 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
// - Timestamps that enable avalanche network upgrades,
// - Enabling or disabling precompiles as network upgrades.
type UpgradeConfig struct {
// Config for optional timestamps that enable network upgrades.
// Note: if OptionalUpgrades is specified in the JSON all previously activated
// forks must be present or upgradeBytes will be rejected.
OptionalNetworkUpgrades *OptionalNetworkUpgrades `json:"networkUpgrades,omitempty"`
// Config for timestamps that enable network upgrades.
NetworkUpgradeOverrides *NetworkUpgrades `json:"networkUpgradeOverrides,omitempty"`

// Config for modifying state as a network upgrade.
StateUpgrades []StateUpgrade `json:"stateUpgrades,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestCheckCompatible(t *testing.T) {

func TestConfigRules(t *testing.T) {
c := &ChainConfig{
MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(500),
},
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
},
Expand Down
Loading

0 comments on commit a4615e5

Please sign in to comment.