Skip to content

Commit

Permalink
separate avalanche stuff to its own type
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 6, 2024
1 parent 3fb0338 commit 0027803
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 83 deletions.
4 changes: 2 additions & 2 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) {
// Ensure that key1 has some funds in the genesis block.
genesisBalance := big.NewInt(1000000)
gspec := &Genesis{
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig},
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

Expand Down Expand Up @@ -426,7 +426,7 @@ func TestUngracefulAsyncShutdown(t *testing.T) {
// Ensure that key1 has some funds in the genesis block.
genesisBalance := big.NewInt(1000000)
gspec := &Genesis{
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig},
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

Expand Down
18 changes: 11 additions & 7 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func TestStateProcessorErrors(t *testing.T) {
gspec = &Genesis{
Config: &params.ChainConfig{
ChainID: big.NewInt(1),
FeeConfig: params.DefaultFeeConfig,
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
Expand All @@ -268,6 +267,9 @@ func TestStateProcessorErrors(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
ChainConfigExtra: params.ChainConfigExtra{
FeeConfig: params.DefaultFeeConfig,
},
},
Alloc: types.GenesisAlloc{
common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): types.Account{
Expand Down Expand Up @@ -353,7 +355,6 @@ func TestBadTxAllowListBlock(t *testing.T) {

config = &params.ChainConfig{
ChainID: big.NewInt(1),
FeeConfig: params.DefaultFeeConfig,
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
Expand All @@ -363,11 +364,14 @@ func TestBadTxAllowListBlock(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: params.Precompiles{
txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), nil, nil, nil),
ChainConfigExtra: params.ChainConfigExtra{
FeeConfig: params.DefaultFeeConfig,
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: params.Precompiles{
txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), nil, nil, nil),
},
},
}
signer = types.LatestSigner(config)
Expand Down
6 changes: 4 additions & 2 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ func setDefaults(cfg *Config) {
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: new(uint64),
ChainConfigExtra: params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: new(uint64),
},
},
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ func newBackendMock() *backendMock {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(100),
ChainConfigExtra: params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(100),
},
},
CancunTime: &cancunTime,
}
Expand Down
110 changes: 63 additions & 47 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ var (
// SubnetEVMDefaultConfig is the default configuration
// without any network upgrades.
SubnetEVMDefaultChainConfig = &ChainConfig{
ChainID: DefaultChainID,
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
ChainID: DefaultChainID,

HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
Expand All @@ -58,15 +56,16 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: getDefaultNetworkUpgrades(upgrade.GetConfig(constants.MainnetID)), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
ChainConfigExtra: ChainConfigExtra{
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: getDefaultNetworkUpgrades(upgrade.GetConfig(constants.MainnetID)), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
},
}

TestChainConfig = &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),
Expand All @@ -77,16 +76,18 @@ var (
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
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{},
UpgradeConfig: UpgradeConfig{},
ChainConfigExtra: ChainConfigExtra{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: getDefaultNetworkUpgrades(upgrade.GetConfig(constants.UnitTestID)), // This can be changed to correct network (local, test) via VM.
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
},
}

TestPreSubnetEVMChainConfig = &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),
Expand All @@ -96,20 +97,22 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
DurangoTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
ChainConfigExtra: ChainConfigExtra{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
DurangoTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}

TestSubnetEVMChainConfig = &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),
Expand All @@ -119,20 +122,22 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
ChainConfigExtra: ChainConfigExtra{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}

TestDurangoChainConfig = &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),
Expand All @@ -142,20 +147,22 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
ChainConfigExtra: ChainConfigExtra{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
EtnaTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}

TestEtnaChainConfig = &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),
Expand All @@ -165,13 +172,18 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
EtnaTimestamp: utils.NewUint64(0),
ChainConfigExtra: ChainConfigExtra{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
EtnaTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
},
GenesisPrecompiles: Precompiles{},
UpgradeConfig: UpgradeConfig{},
}
TestRules = TestChainConfig.Rules(new(big.Int), 0)
)
Expand Down Expand Up @@ -202,6 +214,10 @@ type ChainConfig struct {
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)

ChainConfigExtra
}

type ChainConfigExtra struct {
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
36 changes: 21 additions & 15 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ func TestCheckCompatible(t *testing.T) {

func TestConfigRules(t *testing.T) {
c := &ChainConfig{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(500),
ChainConfigExtra: ChainConfigExtra{
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(500),
},
},
}

Expand Down Expand Up @@ -238,13 +240,15 @@ func TestConfigUnmarshalJSON(t *testing.T) {

func TestActivePrecompiles(t *testing.T) {
config := ChainConfig{
UpgradeConfig: UpgradeConfig{
PrecompileUpgrades: []PrecompileUpgrade{
{
nativeminter.NewConfig(utils.NewUint64(0), nil, nil, nil, nil), // enable at genesis
},
{
nativeminter.NewDisableConfig(utils.NewUint64(1)), // disable at timestamp 1
ChainConfigExtra: ChainConfigExtra{
UpgradeConfig: UpgradeConfig{
PrecompileUpgrades: []PrecompileUpgrade{
{
nativeminter.NewConfig(utils.NewUint64(0), nil, nil, nil, nil), // enable at genesis
},
{
nativeminter.NewDisableConfig(utils.NewUint64(1)), // disable at timestamp 1
},
},
},
},
Expand All @@ -261,8 +265,6 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) {
config := ChainConfigWithUpgradesJSON{
ChainConfig: ChainConfig{
ChainID: big.NewInt(1),
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
Expand All @@ -272,11 +274,15 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
ChainConfigExtra: ChainConfigExtra{
FeeConfig: DefaultFeeConfig,
AllowFeeRecipients: false,
NetworkUpgrades: NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
},
GenesisPrecompiles: Precompiles{},
},
GenesisPrecompiles: Precompiles{},
},
UpgradeConfig: UpgradeConfig{
PrecompileUpgrades: []PrecompileUpgrade{
Expand Down
22 changes: 14 additions & 8 deletions tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ var Forks = map[string]*params.ChainConfig{
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
ChainConfigExtra: params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
},
},
"Durango": {
Expand All @@ -192,9 +194,11 @@ var Forks = map[string]*params.ChainConfig{
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
ChainConfigExtra: params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
},
},
},
"Cancun": {
Expand All @@ -208,9 +212,11 @@ var Forks = map[string]*params.ChainConfig{
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
CancunTime: utils.NewUint64(0),
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
ChainConfigExtra: params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
DurangoTimestamp: utils.NewUint64(0),
},
},
},
}
Expand Down

0 comments on commit 0027803

Please sign in to comment.