diff --git a/params/config.go b/params/config.go index 2ff5581565..1f2289f2a9 100644 --- a/params/config.go +++ b/params/config.go @@ -34,8 +34,8 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/subnet-evm/commontype" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" ) @@ -558,7 +558,7 @@ type Rules struct { // for this rule set. // Note: none of these addresses should conflict with the address space used by // any existing precompiles. - ActivePrecompiles map[common.Address]config.Config + ActivePrecompiles map[common.Address]precompileconfig.Config } // IsPrecompileEnabled returns true if the precompile at [addr] is enabled for this rule set. @@ -594,7 +594,7 @@ func (c *ChainConfig) AvalancheRules(blockNum, blockTimestamp *big.Int) Rules { rules.IsSubnetEVM = c.IsSubnetEVM(blockTimestamp) // Initialize the stateful precompiles that should be enabled at [blockTimestamp]. - rules.ActivePrecompiles = make(map[common.Address]config.Config) + rules.ActivePrecompiles = make(map[common.Address]precompileconfig.Config) for _, module := range modules.RegisteredModules() { if config := c.GetActivePrecompileConfig(module.Address, blockTimestamp); config != nil && !config.IsDisabled() { rules.ActivePrecompiles[module.Address] = config diff --git a/params/precompile_upgrade.go b/params/precompile_upgrade.go index 66dfee0202..16792c6781 100644 --- a/params/precompile_upgrade.go +++ b/params/precompile_upgrade.go @@ -9,9 +9,8 @@ import ( "fmt" "math/big" - "github.com/ava-labs/subnet-evm/precompile/config" - precompileConfig "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" ) @@ -23,7 +22,7 @@ var errNoKey = errors.New("PrecompileUpgrade cannot be empty") // based on the key. Keys are defined in each precompile module, and registered in // precompile/registry/registry.go. type PrecompileUpgrade struct { - config.Config + precompileconfig.Config } // UnmarshalJSON unmarshals the json into the correct precompile config type @@ -59,7 +58,7 @@ func (u *PrecompileUpgrade) UnmarshalJSON(data []byte) error { // MarshalJSON marshal the precompile config into json based on the precompile key. // Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key func (u *PrecompileUpgrade) MarshalJSON() ([]byte, error) { - res := make(map[string]precompileConfig.Config) + res := make(map[string]precompileconfig.Config) res[u.Key()] = u.Config return json.Marshal(res) } @@ -152,7 +151,7 @@ func (c *ChainConfig) verifyPrecompileUpgrades() error { // GetActivePrecompileConfig returns the most recent precompile config corresponding to [address]. // If none have occurred, returns nil. -func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTimestamp *big.Int) config.Config { +func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTimestamp *big.Int) precompileconfig.Config { configs := c.GetActivatingPrecompileConfigs(address, nil, blockTimestamp, c.PrecompileUpgrades) if len(configs) == 0 { return nil @@ -162,13 +161,13 @@ func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTim // GetActivatingPrecompileConfigs returns all upgrades configured to activate during the state transition from a block with timestamp [from] // to a block with timestamp [to]. -func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, from *big.Int, to *big.Int, upgrades []PrecompileUpgrade) []config.Config { +func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, from *big.Int, to *big.Int, upgrades []PrecompileUpgrade) []precompileconfig.Config { // Get key from address. module, ok := modules.GetPrecompileModuleByAddress(address) if !ok { return nil } - configs := make([]config.Config, 0) + configs := make([]precompileconfig.Config, 0) key := module.ConfigKey // First check the embedded [upgrade] for precompiles configured // in the genesis chain config. diff --git a/params/precompiles.go b/params/precompiles.go index 4ad0bf3a8f..fcb7604e5b 100644 --- a/params/precompiles.go +++ b/params/precompiles.go @@ -6,11 +6,11 @@ package params import ( "encoding/json" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" ) -type Precompiles map[string]config.Config +type Precompiles map[string]precompileconfig.Config // UnmarshalJSON parses the JSON-encoded data into the ChainConfigPrecompiles. // ChainConfigPrecompiles is a map of precompile module keys to their diff --git a/precompile/allowlist/allow_list_test.go b/precompile/allowlist/allow_list_test.go index 3a9f4f2dd3..6122a7c818 100644 --- a/precompile/allowlist/allow_list_test.go +++ b/precompile/allowlist/allow_list_test.go @@ -25,7 +25,7 @@ func TestAllowListRun(t *testing.T) { expectedRes []byte expectedErr string - config *Config + config *AllowListConfig assertState func(t *testing.T, state *state.StateDB) } @@ -221,7 +221,7 @@ func TestAllowListRun(t *testing.T) { expectedErr: vmerrs.ErrOutOfGas.Error(), }, "initial config sets admins": { - config: &Config{ + config: &AllowListConfig{ AdminAddresses: []common.Address{noRoleAddr, enabledAddr}, }, suppliedGas: 0, @@ -233,7 +233,7 @@ func TestAllowListRun(t *testing.T) { }, }, "initial config sets enabled": { - config: &Config{ + config: &AllowListConfig{ EnabledAddresses: []common.Address{noRoleAddr, adminAddr}, }, suppliedGas: 0, diff --git a/precompile/allowlist/config.go b/precompile/allowlist/config.go index c11f86afc2..3ab68d374f 100644 --- a/precompile/allowlist/config.go +++ b/precompile/allowlist/config.go @@ -10,15 +10,15 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// Config specifies the initial set of addresses with Admin or Enabled roles. -type Config struct { +// AllowListConfig specifies the initial set of addresses with Admin or Enabled roles. +type AllowListConfig struct { AdminAddresses []common.Address `json:"adminAddresses,omitempty"` // initial admin addresses EnabledAddresses []common.Address `json:"enabledAddresses,omitempty"` // initial enabled addresses } // Configure initializes the address space of [precompileAddr] by initializing the role of each of // the addresses in [AllowListAdmins]. -func (c *Config) Configure(state contract.StateDB, precompileAddr common.Address) error { +func (c *AllowListConfig) Configure(state contract.StateDB, precompileAddr common.Address) error { for _, enabledAddr := range c.EnabledAddresses { SetAllowListRole(state, precompileAddr, enabledAddr, EnabledRole) } @@ -29,7 +29,7 @@ func (c *Config) Configure(state contract.StateDB, precompileAddr common.Address } // Equal returns true iff [other] has the same admins in the same order in its allow list. -func (c *Config) Equal(other *Config) bool { +func (c *AllowListConfig) Equal(other *AllowListConfig) bool { if other == nil { return false } @@ -52,7 +52,7 @@ func areEqualAddressLists(current []common.Address, other []common.Address) bool } // Verify returns an error if there is an overlapping address between admin and enabled roles -func (c *Config) Verify() error { +func (c *AllowListConfig) Verify() error { addressMap := make(map[common.Address]Role) // tracks which addresses we have seen and their role // check for duplicates in enabled list diff --git a/precompile/allowlist/config_test.go b/precompile/allowlist/config_test.go index b9fdb24053..8473115400 100644 --- a/precompile/allowlist/config_test.go +++ b/precompile/allowlist/config_test.go @@ -10,32 +10,32 @@ import ( "github.com/stretchr/testify/require" ) -func TestVerifyAllowlistConfig(t *testing.T) { +func TestVerifyAllowlistAllowList(t *testing.T) { admins := []common.Address{{1}} enableds := []common.Address{{2}} tests := []struct { name string - config Config + config AllowListConfig expectedError string }{ { name: "invalid allow list config in allowlist", - config: Config{admins, admins}, + config: AllowListConfig{admins, admins}, expectedError: "cannot set address", }, { name: "nil member allow list config in allowlist", - config: Config{nil, nil}, + config: AllowListConfig{nil, nil}, expectedError: "", }, { name: "empty member allow list config in allowlist", - config: Config{[]common.Address{}, []common.Address{}}, + config: AllowListConfig{[]common.Address{}, []common.Address{}}, expectedError: "", }, { name: "valid allow list config in allowlist", - config: Config{admins, enableds}, + config: AllowListConfig{admins, enableds}, expectedError: "", }, } @@ -53,37 +53,37 @@ func TestVerifyAllowlistConfig(t *testing.T) { } } -func TestEqualAllowListConfig(t *testing.T) { +func TestEqualAllowListAllowList(t *testing.T) { admins := []common.Address{{1}} enableds := []common.Address{{2}} tests := []struct { name string - config *Config - other *Config + config *AllowListConfig + other *AllowListConfig expected bool }{ { name: "non-nil config and nil other", - config: &Config{admins, enableds}, + config: &AllowListConfig{admins, enableds}, other: nil, expected: false, }, { name: "different admin", - config: &Config{admins, enableds}, - other: &Config{[]common.Address{{3}}, enableds}, + config: &AllowListConfig{admins, enableds}, + other: &AllowListConfig{[]common.Address{{3}}, enableds}, expected: false, }, { name: "different enabled", - config: &Config{admins, enableds}, - other: &Config{admins, []common.Address{{3}}}, + config: &AllowListConfig{admins, enableds}, + other: &AllowListConfig{admins, []common.Address{{3}}}, expected: false, }, { name: "same config", - config: &Config{admins, enableds}, - other: &Config{admins, enableds}, + config: &AllowListConfig{admins, enableds}, + other: &AllowListConfig{admins, enableds}, expected: true, }, } diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index 75f48980a1..66a449fe91 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -9,7 +9,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/subnet-evm/commontype" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -69,10 +69,10 @@ type BlockContext interface { } type Configurator interface { - NewConfig() config.Config + NewConfig() precompileconfig.Config Configure( chainConfig ChainConfig, - precompileConfig config.Config, + precompileconfig precompileconfig.Config, state StateDB, blockContext BlockContext, ) error diff --git a/precompile/contract/utils.go b/precompile/contract/utils.go index 1718eb2dca..f4b7c7db9c 100644 --- a/precompile/contract/utils.go +++ b/precompile/contract/utils.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/ava-labs/subnet-evm/accounts/abi" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/subnet-evm/vmerrs" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -39,7 +39,7 @@ type PrecompileTest struct { // It should be the same precompile config that is used in the // precompile's configurator. // If nil, Configure on the Configurator will not be called. - Config config.Config + Config precompileconfig.Config // BeforeHook is called before the precompile is called. BeforeHook func(t *testing.T, state StateDB) // AfterHook is called after the precompile is called. diff --git a/precompile/contracts/deployerallowlist/config.go b/precompile/contracts/deployerallowlist/config.go index 4f624de1f6..c2d5bf28dd 100644 --- a/precompile/contracts/deployerallowlist/config.go +++ b/precompile/contracts/deployerallowlist/config.go @@ -7,28 +7,28 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/precompile/allowlist" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) -var _ config.Config = &Config{} +var _ precompileconfig.Config = &Config{} // Config contains the configuration for the ContractDeployerAllowList precompile, // consisting of the initial allowlist and the timestamp for the network upgrade. type Config struct { - allowlist.Config - config.Upgrade + allowlist.AllowListConfig + precompileconfig.Upgrade } // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables // ContractDeployerAllowList with [admins] and [enableds] as members of the allowlist. func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address) *Config { return &Config{ - Config: allowlist.Config{ + AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, }, - Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp}, + Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, } } @@ -36,7 +36,7 @@ func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []comm // that disables ContractDeployerAllowList. func NewDisableConfig(blockTimestamp *big.Int) *Config { return &Config{ - Upgrade: config.Upgrade{ + Upgrade: precompileconfig.Upgrade{ BlockTimestamp: blockTimestamp, Disable: true, }, @@ -46,13 +46,13 @@ func NewDisableConfig(blockTimestamp *big.Int) *Config { func (*Config) Key() string { return ConfigKey } // Equal returns true if [cfg] is a [*ContractDeployerAllowListConfig] and it has been configured identical to [c]. -func (c *Config) Equal(cfg config.Config) bool { +func (c *Config) Equal(cfg precompileconfig.Config) bool { // typecast before comparison other, ok := (cfg).(*Config) if !ok { return false } - return c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config) + return c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig) } -func (c *Config) Verify() error { return c.Config.Verify() } +func (c *Config) Verify() error { return c.AllowListConfig.Verify() } diff --git a/precompile/contracts/deployerallowlist/config_test.go b/precompile/contracts/deployerallowlist/config_test.go index 46bba193d6..caa3d8995a 100644 --- a/precompile/contracts/deployerallowlist/config_test.go +++ b/precompile/contracts/deployerallowlist/config_test.go @@ -7,7 +7,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -16,7 +16,7 @@ func TestVerifyContractDeployerConfig(t *testing.T) { admins := []common.Address{{1}} tests := []struct { name string - config config.Config + config precompileconfig.Config ExpectedError string }{ { @@ -44,8 +44,8 @@ func TestEqualContractDeployerAllowListConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config - other config.Config + config precompileconfig.Config + other precompileconfig.Config expected bool }{ { @@ -57,7 +57,7 @@ func TestEqualContractDeployerAllowListConfig(t *testing.T) { { name: "different type", config: NewConfig(big.NewInt(3), admins, enableds), - other: config.NewNoopStatefulPrecompileConfig(), + other: precompileconfig.NewNoopStatefulPrecompileConfig(), expected: false, }, { diff --git a/precompile/contracts/deployerallowlist/module.go b/precompile/contracts/deployerallowlist/module.go index 73bd720bed..623eb27e0f 100644 --- a/precompile/contracts/deployerallowlist/module.go +++ b/precompile/contracts/deployerallowlist/module.go @@ -6,9 +6,9 @@ package deployerallowlist import ( "fmt" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -35,15 +35,15 @@ func init() { } } -func (*configurator) NewConfig() config.Config { +func (*configurator) NewConfig() precompileconfig.Config { return &Config{} } // Configure configures [state] with the given [cfg] config. -func (c *configurator) Configure(_ contract.ChainConfig, cfg config.Config, state contract.StateDB, _ contract.BlockContext) error { +func (c *configurator) Configure(_ contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error { config, ok := cfg.(*Config) if !ok { return fmt.Errorf("incorrect config %T: %v", config, config) } - return config.Config.Configure(state, ContractAddress) + return config.AllowListConfig.Configure(state, ContractAddress) } diff --git a/precompile/contracts/feemanager/config.go b/precompile/contracts/feemanager/config.go index 05d04991f5..9debfa7b1f 100644 --- a/precompile/contracts/feemanager/config.go +++ b/precompile/contracts/feemanager/config.go @@ -8,17 +8,17 @@ import ( "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/precompile/allowlist" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) -var _ config.Config = &Config{} +var _ precompileconfig.Config = &Config{} // Config implements the StatefulPrecompileConfig interface while adding in the // FeeManager specific precompile config. type Config struct { - allowlist.Config // Config for the fee config manager allow list - config.Upgrade + allowlist.AllowListConfig // Config for the fee config manager allow list + precompileconfig.Upgrade InitialFeeConfig *commontype.FeeConfig `json:"initialFeeConfig,omitempty"` // initial fee config to be immediately activated } @@ -27,11 +27,11 @@ type Config struct { // allowlist with [initialConfig] as initial fee config if specified. func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialConfig *commontype.FeeConfig) *Config { return &Config{ - Config: allowlist.Config{ + AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, }, - Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp}, + Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, InitialFeeConfig: initialConfig, } } @@ -40,7 +40,7 @@ func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []comm // that disables FeeManager. func NewDisableConfig(blockTimestamp *big.Int) *Config { return &Config{ - Upgrade: config.Upgrade{ + Upgrade: precompileconfig.Upgrade{ BlockTimestamp: blockTimestamp, Disable: true, }, @@ -50,13 +50,13 @@ func NewDisableConfig(blockTimestamp *big.Int) *Config { func (*Config) Key() string { return ConfigKey } // Equal returns true if [cfg] is a [*FeeManagerConfig] and it has been configured identical to [c]. -func (c *Config) Equal(cfg config.Config) bool { +func (c *Config) Equal(cfg precompileconfig.Config) bool { // typecast before comparison other, ok := (cfg).(*Config) if !ok { return false } - eq := c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config) + eq := c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig) if !eq { return false } @@ -69,7 +69,7 @@ func (c *Config) Equal(cfg config.Config) bool { } func (c *Config) Verify() error { - if err := c.Config.Verify(); err != nil { + if err := c.AllowListConfig.Verify(); err != nil { return err } if c.InitialFeeConfig == nil { diff --git a/precompile/contracts/feemanager/config_test.go b/precompile/contracts/feemanager/config_test.go index 41b1e1ff3d..4b5654d5d9 100644 --- a/precompile/contracts/feemanager/config_test.go +++ b/precompile/contracts/feemanager/config_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/ava-labs/subnet-evm/commontype" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -32,7 +32,7 @@ func TestVerifyFeeManagerConfig(t *testing.T) { invalidFeeConfig.GasLimit = big.NewInt(0) tests := []struct { name string - config config.Config + config precompileconfig.Config ExpectedError string }{ { @@ -70,8 +70,8 @@ func TestEqualFeeManagerConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config - other config.Config + config precompileconfig.Config + other precompileconfig.Config expected bool }{ { @@ -83,7 +83,7 @@ func TestEqualFeeManagerConfig(t *testing.T) { { name: "different type", config: NewConfig(big.NewInt(3), admins, enableds, nil), - other: config.NewNoopStatefulPrecompileConfig(), + other: precompileconfig.NewNoopStatefulPrecompileConfig(), expected: false, }, { diff --git a/precompile/contracts/feemanager/module.go b/precompile/contracts/feemanager/module.go index a725bb3f3d..fa5cf5ccad 100644 --- a/precompile/contracts/feemanager/module.go +++ b/precompile/contracts/feemanager/module.go @@ -6,9 +6,9 @@ package feemanager import ( "fmt" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -35,12 +35,12 @@ func init() { } } -func (*configurator) NewConfig() config.Config { +func (*configurator) NewConfig() precompileconfig.Config { return &Config{} } // Configure configures [state] with the desired admins based on [configIface]. -func (*configurator) Configure(chainConfig contract.ChainConfig, cfg config.Config, state contract.StateDB, blockContext contract.BlockContext) error { +func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.BlockContext) error { config, ok := cfg.(*Config) if !ok { return fmt.Errorf("incorrect config %T: %v", config, config) @@ -57,5 +57,5 @@ func (*configurator) Configure(chainConfig contract.ChainConfig, cfg config.Conf return fmt.Errorf("cannot configure fee config in chain config: %w", err) } } - return config.Config.Configure(state, ContractAddress) + return config.AllowListConfig.Configure(state, ContractAddress) } diff --git a/precompile/contracts/nativeminter/config.go b/precompile/contracts/nativeminter/config.go index 21278e8de6..e2df6bbc82 100644 --- a/precompile/contracts/nativeminter/config.go +++ b/precompile/contracts/nativeminter/config.go @@ -8,19 +8,19 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/precompile/allowlist" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" ) -var _ config.Config = &Config{} +var _ precompileconfig.Config = &Config{} // Config implements the StatefulPrecompileConfig interface while adding in the // ContractNativeMinter specific precompile config. type Config struct { - allowlist.Config - config.Upgrade + allowlist.AllowListConfig + precompileconfig.Upgrade InitialMint map[common.Address]*math.HexOrDecimal256 `json:"initialMint,omitempty"` // addresses to receive the initial mint mapped to the amount to mint } @@ -28,11 +28,11 @@ type Config struct { // ContractNativeMinter with the given [admins] and [enableds] as members of the allowlist. Also mints balances according to [initialMint] when the upgrade activates. func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialMint map[common.Address]*math.HexOrDecimal256) *Config { return &Config{ - Config: allowlist.Config{ + AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, }, - Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp}, + Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, InitialMint: initialMint, } } @@ -41,7 +41,7 @@ func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []comm // that disables ContractNativeMinter. func NewDisableConfig(blockTimestamp *big.Int) *Config { return &Config{ - Upgrade: config.Upgrade{ + Upgrade: precompileconfig.Upgrade{ BlockTimestamp: blockTimestamp, Disable: true, }, @@ -50,13 +50,13 @@ func NewDisableConfig(blockTimestamp *big.Int) *Config { func (*Config) Key() string { return ConfigKey } // Equal returns true if [cfg] is a [*ContractNativeMinterConfig] and it has been configured identical to [c]. -func (c *Config) Equal(cfg config.Config) bool { +func (c *Config) Equal(cfg precompileconfig.Config) bool { // typecast before comparison other, ok := (cfg).(*Config) if !ok { return false } - eq := c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config) + eq := c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig) if !eq { return false } @@ -91,5 +91,5 @@ func (c *Config) Verify() error { return fmt.Errorf("initial mint cannot contain invalid amount %v for address %s", bigIntAmount, addr) } } - return c.Config.Verify() + return c.AllowListConfig.Verify() } diff --git a/precompile/contracts/nativeminter/config_test.go b/precompile/contracts/nativeminter/config_test.go index 08227a9be1..1927a93b9b 100644 --- a/precompile/contracts/nativeminter/config_test.go +++ b/precompile/contracts/nativeminter/config_test.go @@ -7,7 +7,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/stretchr/testify/require" @@ -18,7 +18,7 @@ func TestVerifyContractNativeMinterConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config + config precompileconfig.Config ExpectedError string }{ { @@ -74,8 +74,8 @@ func TestEqualContractNativeMinterConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config - other config.Config + config precompileconfig.Config + other precompileconfig.Config expected bool }{ { @@ -87,7 +87,7 @@ func TestEqualContractNativeMinterConfig(t *testing.T) { { name: "different type", config: NewConfig(big.NewInt(3), admins, enableds, nil), - other: config.NewNoopStatefulPrecompileConfig(), + other: precompileconfig.NewNoopStatefulPrecompileConfig(), expected: false, }, { diff --git a/precompile/contracts/nativeminter/module.go b/precompile/contracts/nativeminter/module.go index 76987071cd..8648c1f119 100644 --- a/precompile/contracts/nativeminter/module.go +++ b/precompile/contracts/nativeminter/module.go @@ -7,9 +7,9 @@ import ( "fmt" "math/big" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -36,12 +36,12 @@ func init() { } } -func (*configurator) NewConfig() config.Config { +func (*configurator) NewConfig() precompileconfig.Config { return &Config{} } // Configure configures [state] with the desired admins based on [cfg]. -func (*configurator) Configure(_ contract.ChainConfig, cfg config.Config, state contract.StateDB, _ contract.BlockContext) error { +func (*configurator) Configure(_ contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error { config, ok := cfg.(*Config) if !ok { return fmt.Errorf("incorrect config %T: %v", config, config) @@ -53,5 +53,5 @@ func (*configurator) Configure(_ contract.ChainConfig, cfg config.Config, state } } - return config.Config.Configure(state, ContractAddress) + return config.AllowListConfig.Configure(state, ContractAddress) } diff --git a/precompile/contracts/rewardmanager/config.go b/precompile/contracts/rewardmanager/config.go index 80adc93429..9b7a8bb238 100644 --- a/precompile/contracts/rewardmanager/config.go +++ b/precompile/contracts/rewardmanager/config.go @@ -10,12 +10,12 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/precompile/allowlist" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) -var _ config.Config = &Config{} +var _ precompileconfig.Config = &Config{} type InitialRewardConfig struct { AllowFeeRecipients bool `json:"allowFeeRecipients"` @@ -57,8 +57,8 @@ func (i *InitialRewardConfig) Configure(state contract.StateDB) error { // Config implements the StatefulPrecompileConfig interface while adding in the // RewardManager specific precompile config. type Config struct { - allowlist.Config - config.Upgrade + allowlist.AllowListConfig + precompileconfig.Upgrade InitialRewardConfig *InitialRewardConfig `json:"initialRewardConfig,omitempty"` } @@ -66,11 +66,11 @@ type Config struct { // RewardManager with the given [admins] and [enableds] as members of the allowlist with [initialConfig] as initial rewards config if specified. func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialConfig *InitialRewardConfig) *Config { return &Config{ - Config: allowlist.Config{ + AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, }, - Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp}, + Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, InitialRewardConfig: initialConfig, } } @@ -79,7 +79,7 @@ func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []comm // that disables RewardManager. func NewDisableConfig(blockTimestamp *big.Int) *Config { return &Config{ - Upgrade: config.Upgrade{ + Upgrade: precompileconfig.Upgrade{ BlockTimestamp: blockTimestamp, Disable: true, }, @@ -94,11 +94,11 @@ func (c *Config) Verify() error { return err } } - return c.Config.Verify() + return c.AllowListConfig.Verify() } // Equal returns true if [cfg] is a [*RewardManagerConfig] and it has been configured identical to [c]. -func (c *Config) Equal(cfg config.Config) bool { +func (c *Config) Equal(cfg precompileconfig.Config) bool { // typecast before comparison other, ok := (cfg).(*Config) if !ok { @@ -114,5 +114,5 @@ func (c *Config) Equal(cfg config.Config) bool { } } - return c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config) + return c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig) } diff --git a/precompile/contracts/rewardmanager/config_test.go b/precompile/contracts/rewardmanager/config_test.go index 249fb85a16..c78dec4c6f 100644 --- a/precompile/contracts/rewardmanager/config_test.go +++ b/precompile/contracts/rewardmanager/config_test.go @@ -7,7 +7,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -17,7 +17,7 @@ func TestVerifyRewardManagerConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config + config precompileconfig.Config ExpectedError string }{ { @@ -53,8 +53,8 @@ func TestEqualRewardManagerConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config - other config.Config + config precompileconfig.Config + other precompileconfig.Config expected bool }{ { @@ -66,7 +66,7 @@ func TestEqualRewardManagerConfig(t *testing.T) { { name: "different type", config: NewConfig(big.NewInt(3), admins, enableds, nil), - other: config.NewNoopStatefulPrecompileConfig(), + other: precompileconfig.NewNoopStatefulPrecompileConfig(), expected: false, }, { diff --git a/precompile/contracts/rewardmanager/module.go b/precompile/contracts/rewardmanager/module.go index 83788648e5..57739af6c8 100644 --- a/precompile/contracts/rewardmanager/module.go +++ b/precompile/contracts/rewardmanager/module.go @@ -6,9 +6,9 @@ package rewardmanager import ( "fmt" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -35,12 +35,12 @@ func init() { } } -func (*configurator) NewConfig() config.Config { +func (*configurator) NewConfig() precompileconfig.Config { return &Config{} } // Configure configures [state] with the initial state for the precompile. -func (*configurator) Configure(chainConfig contract.ChainConfig, cfg config.Config, state contract.StateDB, _ contract.BlockContext) error { +func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error { config, ok := cfg.(*Config) if !ok { return fmt.Errorf("incorrect config %T: %v", config, config) diff --git a/precompile/contracts/txallowlist/config.go b/precompile/contracts/txallowlist/config.go index 93042c46da..c6204b41c5 100644 --- a/precompile/contracts/txallowlist/config.go +++ b/precompile/contracts/txallowlist/config.go @@ -7,28 +7,28 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/precompile/allowlist" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) -var _ config.Config = &Config{} +var _ precompileconfig.Config = &Config{} // Config implements the StatefulPrecompileConfig interface while adding in the // TxAllowList specific precompile config. type Config struct { - allowlist.Config - config.Upgrade + allowlist.AllowListConfig + precompileconfig.Upgrade } // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables // TxAllowList with the given [admins] and [enableds] as members of the allowlist. func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address) *Config { return &Config{ - Config: allowlist.Config{ + AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, }, - Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp}, + Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, } } @@ -36,7 +36,7 @@ func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []comm // that disables TxAllowList. func NewDisableConfig(blockTimestamp *big.Int) *Config { return &Config{ - Upgrade: config.Upgrade{ + Upgrade: precompileconfig.Upgrade{ BlockTimestamp: blockTimestamp, Disable: true, }, @@ -46,11 +46,11 @@ func NewDisableConfig(blockTimestamp *big.Int) *Config { func (c *Config) Key() string { return ConfigKey } // Equal returns true if [cfg] is a [*TxAllowListConfig] and it has been configured identical to [c]. -func (c *Config) Equal(cfg config.Config) bool { +func (c *Config) Equal(cfg precompileconfig.Config) bool { // typecast before comparison other, ok := (cfg).(*Config) if !ok { return false } - return c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config) + return c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig) } diff --git a/precompile/contracts/txallowlist/config_test.go b/precompile/contracts/txallowlist/config_test.go index e6cf062414..54ab46ac34 100644 --- a/precompile/contracts/txallowlist/config_test.go +++ b/precompile/contracts/txallowlist/config_test.go @@ -7,7 +7,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/subnet-evm/precompile/config" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -17,7 +17,7 @@ func TestVerifyTxAllowlistConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config + config precompileconfig.Config ExpectedError string }{ { @@ -60,8 +60,8 @@ func TestEqualTxAllowListConfig(t *testing.T) { enableds := []common.Address{{2}} tests := []struct { name string - config config.Config - other config.Config + config precompileconfig.Config + other precompileconfig.Config expected bool }{ { diff --git a/precompile/contracts/txallowlist/module.go b/precompile/contracts/txallowlist/module.go index 0da9721eb6..b1ae6a096e 100644 --- a/precompile/contracts/txallowlist/module.go +++ b/precompile/contracts/txallowlist/module.go @@ -6,9 +6,9 @@ package txallowlist import ( "fmt" - "github.com/ava-labs/subnet-evm/precompile/config" "github.com/ava-labs/subnet-evm/precompile/contract" "github.com/ava-labs/subnet-evm/precompile/modules" + "github.com/ava-labs/subnet-evm/precompile/precompileconfig" "github.com/ethereum/go-ethereum/common" ) @@ -35,15 +35,15 @@ func init() { } } -func (*configurator) NewConfig() config.Config { +func (*configurator) NewConfig() precompileconfig.Config { return &Config{} } // Configure configures [state] with the initial state for the precompile. -func (*configurator) Configure(chainConfig contract.ChainConfig, cfg config.Config, state contract.StateDB, _ contract.BlockContext) error { +func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error { config, ok := cfg.(*Config) if !ok { return fmt.Errorf("incorrect config %T: %v", config, config) } - return config.Config.Configure(state, ContractAddress) + return config.AllowListConfig.Configure(state, ContractAddress) } diff --git a/precompile/config/config.go b/precompile/precompileconfig/config.go similarity index 97% rename from precompile/config/config.go rename to precompile/precompileconfig/config.go index 63ccf43dad..fcee72fc95 100644 --- a/precompile/config/config.go +++ b/precompile/precompileconfig/config.go @@ -2,7 +2,7 @@ // See the file LICENSE for licensing terms. // Defines the stateless interface for unmarshalling an arbitrary config of a precompile -package config +package precompileconfig import ( "math/big" diff --git a/precompile/config/mock_config.go b/precompile/precompileconfig/mock_config.go similarity index 97% rename from precompile/config/mock_config.go rename to precompile/precompileconfig/mock_config.go index cb1f1f9a91..8abca06f88 100644 --- a/precompile/config/mock_config.go +++ b/precompile/precompileconfig/mock_config.go @@ -2,8 +2,7 @@ // See the file LICENSE for licensing terms. // TODO: replace with gomock - -package config +package precompileconfig import ( "math/big" diff --git a/precompile/config/upgradeable.go b/precompile/precompileconfig/upgradeable.go similarity index 97% rename from precompile/config/upgradeable.go rename to precompile/precompileconfig/upgradeable.go index 66a4381694..3ad8c0498b 100644 --- a/precompile/config/upgradeable.go +++ b/precompile/precompileconfig/upgradeable.go @@ -1,7 +1,7 @@ // (c) 2022 Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package config +package precompileconfig import ( "math/big"