Skip to content

Commit c81b44b

Browse files
author
Darioush Jalali
authored
Rename configs: alternative (#520)
* alternative renaming for precompile configs * fixes * update naming * rename to AllowListConfig * simplify
1 parent d518651 commit c81b44b

File tree

26 files changed

+135
-137
lines changed

26 files changed

+135
-137
lines changed

params/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434

3535
"github.com/ava-labs/avalanchego/snow"
3636
"github.com/ava-labs/subnet-evm/commontype"
37-
"github.com/ava-labs/subnet-evm/precompile/config"
3837
"github.com/ava-labs/subnet-evm/precompile/modules"
38+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
3939
"github.com/ava-labs/subnet-evm/utils"
4040
"github.com/ethereum/go-ethereum/common"
4141
)
@@ -558,7 +558,7 @@ type Rules struct {
558558
// for this rule set.
559559
// Note: none of these addresses should conflict with the address space used by
560560
// any existing precompiles.
561-
ActivePrecompiles map[common.Address]config.Config
561+
ActivePrecompiles map[common.Address]precompileconfig.Config
562562
}
563563

564564
// 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 {
594594
rules.IsSubnetEVM = c.IsSubnetEVM(blockTimestamp)
595595

596596
// Initialize the stateful precompiles that should be enabled at [blockTimestamp].
597-
rules.ActivePrecompiles = make(map[common.Address]config.Config)
597+
rules.ActivePrecompiles = make(map[common.Address]precompileconfig.Config)
598598
for _, module := range modules.RegisteredModules() {
599599
if config := c.GetActivePrecompileConfig(module.Address, blockTimestamp); config != nil && !config.IsDisabled() {
600600
rules.ActivePrecompiles[module.Address] = config

params/precompile_upgrade.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import (
99
"fmt"
1010
"math/big"
1111

12-
"github.com/ava-labs/subnet-evm/precompile/config"
13-
precompileConfig "github.com/ava-labs/subnet-evm/precompile/config"
1412
"github.com/ava-labs/subnet-evm/precompile/modules"
13+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1514
"github.com/ava-labs/subnet-evm/utils"
1615
"github.com/ethereum/go-ethereum/common"
1716
)
@@ -23,7 +22,7 @@ var errNoKey = errors.New("PrecompileUpgrade cannot be empty")
2322
// based on the key. Keys are defined in each precompile module, and registered in
2423
// precompile/registry/registry.go.
2524
type PrecompileUpgrade struct {
26-
config.Config
25+
precompileconfig.Config
2726
}
2827

2928
// UnmarshalJSON unmarshals the json into the correct precompile config type
@@ -59,7 +58,7 @@ func (u *PrecompileUpgrade) UnmarshalJSON(data []byte) error {
5958
// MarshalJSON marshal the precompile config into json based on the precompile key.
6059
// Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key
6160
func (u *PrecompileUpgrade) MarshalJSON() ([]byte, error) {
62-
res := make(map[string]precompileConfig.Config)
61+
res := make(map[string]precompileconfig.Config)
6362
res[u.Key()] = u.Config
6463
return json.Marshal(res)
6564
}
@@ -152,7 +151,7 @@ func (c *ChainConfig) verifyPrecompileUpgrades() error {
152151

153152
// GetActivePrecompileConfig returns the most recent precompile config corresponding to [address].
154153
// If none have occurred, returns nil.
155-
func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTimestamp *big.Int) config.Config {
154+
func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTimestamp *big.Int) precompileconfig.Config {
156155
configs := c.GetActivatingPrecompileConfigs(address, nil, blockTimestamp, c.PrecompileUpgrades)
157156
if len(configs) == 0 {
158157
return nil
@@ -162,13 +161,13 @@ func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, blockTim
162161

163162
// GetActivatingPrecompileConfigs returns all upgrades configured to activate during the state transition from a block with timestamp [from]
164163
// to a block with timestamp [to].
165-
func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, from *big.Int, to *big.Int, upgrades []PrecompileUpgrade) []config.Config {
164+
func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, from *big.Int, to *big.Int, upgrades []PrecompileUpgrade) []precompileconfig.Config {
166165
// Get key from address.
167166
module, ok := modules.GetPrecompileModuleByAddress(address)
168167
if !ok {
169168
return nil
170169
}
171-
configs := make([]config.Config, 0)
170+
configs := make([]precompileconfig.Config, 0)
172171
key := module.ConfigKey
173172
// First check the embedded [upgrade] for precompiles configured
174173
// in the genesis chain config.

params/precompiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package params
66
import (
77
"encoding/json"
88

9-
"github.com/ava-labs/subnet-evm/precompile/config"
109
"github.com/ava-labs/subnet-evm/precompile/modules"
10+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1111
)
1212

13-
type Precompiles map[string]config.Config
13+
type Precompiles map[string]precompileconfig.Config
1414

1515
// UnmarshalJSON parses the JSON-encoded data into the ChainConfigPrecompiles.
1616
// ChainConfigPrecompiles is a map of precompile module keys to their

precompile/allowlist/allow_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestAllowListRun(t *testing.T) {
2525
expectedRes []byte
2626
expectedErr string
2727

28-
config *Config
28+
config *AllowListConfig
2929

3030
assertState func(t *testing.T, state *state.StateDB)
3131
}
@@ -221,7 +221,7 @@ func TestAllowListRun(t *testing.T) {
221221
expectedErr: vmerrs.ErrOutOfGas.Error(),
222222
},
223223
"initial config sets admins": {
224-
config: &Config{
224+
config: &AllowListConfig{
225225
AdminAddresses: []common.Address{noRoleAddr, enabledAddr},
226226
},
227227
suppliedGas: 0,
@@ -233,7 +233,7 @@ func TestAllowListRun(t *testing.T) {
233233
},
234234
},
235235
"initial config sets enabled": {
236-
config: &Config{
236+
config: &AllowListConfig{
237237
EnabledAddresses: []common.Address{noRoleAddr, adminAddr},
238238
},
239239
suppliedGas: 0,

precompile/allowlist/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
"github.com/ethereum/go-ethereum/common"
1111
)
1212

13-
// Config specifies the initial set of addresses with Admin or Enabled roles.
14-
type Config struct {
13+
// AllowListConfig specifies the initial set of addresses with Admin or Enabled roles.
14+
type AllowListConfig struct {
1515
AdminAddresses []common.Address `json:"adminAddresses,omitempty"` // initial admin addresses
1616
EnabledAddresses []common.Address `json:"enabledAddresses,omitempty"` // initial enabled addresses
1717
}
1818

1919
// Configure initializes the address space of [precompileAddr] by initializing the role of each of
2020
// the addresses in [AllowListAdmins].
21-
func (c *Config) Configure(state contract.StateDB, precompileAddr common.Address) error {
21+
func (c *AllowListConfig) Configure(state contract.StateDB, precompileAddr common.Address) error {
2222
for _, enabledAddr := range c.EnabledAddresses {
2323
SetAllowListRole(state, precompileAddr, enabledAddr, EnabledRole)
2424
}
@@ -29,7 +29,7 @@ func (c *Config) Configure(state contract.StateDB, precompileAddr common.Address
2929
}
3030

3131
// Equal returns true iff [other] has the same admins in the same order in its allow list.
32-
func (c *Config) Equal(other *Config) bool {
32+
func (c *AllowListConfig) Equal(other *AllowListConfig) bool {
3333
if other == nil {
3434
return false
3535
}
@@ -52,7 +52,7 @@ func areEqualAddressLists(current []common.Address, other []common.Address) bool
5252
}
5353

5454
// Verify returns an error if there is an overlapping address between admin and enabled roles
55-
func (c *Config) Verify() error {
55+
func (c *AllowListConfig) Verify() error {
5656
addressMap := make(map[common.Address]Role) // tracks which addresses we have seen and their role
5757

5858
// check for duplicates in enabled list

precompile/allowlist/config_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ import (
1010
"github.com/stretchr/testify/require"
1111
)
1212

13-
func TestVerifyAllowlistConfig(t *testing.T) {
13+
func TestVerifyAllowlistAllowList(t *testing.T) {
1414
admins := []common.Address{{1}}
1515
enableds := []common.Address{{2}}
1616
tests := []struct {
1717
name string
18-
config Config
18+
config AllowListConfig
1919
expectedError string
2020
}{
2121
{
2222
name: "invalid allow list config in allowlist",
23-
config: Config{admins, admins},
23+
config: AllowListConfig{admins, admins},
2424
expectedError: "cannot set address",
2525
},
2626
{
2727
name: "nil member allow list config in allowlist",
28-
config: Config{nil, nil},
28+
config: AllowListConfig{nil, nil},
2929
expectedError: "",
3030
},
3131
{
3232
name: "empty member allow list config in allowlist",
33-
config: Config{[]common.Address{}, []common.Address{}},
33+
config: AllowListConfig{[]common.Address{}, []common.Address{}},
3434
expectedError: "",
3535
},
3636
{
3737
name: "valid allow list config in allowlist",
38-
config: Config{admins, enableds},
38+
config: AllowListConfig{admins, enableds},
3939
expectedError: "",
4040
},
4141
}
@@ -53,37 +53,37 @@ func TestVerifyAllowlistConfig(t *testing.T) {
5353
}
5454
}
5555

56-
func TestEqualAllowListConfig(t *testing.T) {
56+
func TestEqualAllowListAllowList(t *testing.T) {
5757
admins := []common.Address{{1}}
5858
enableds := []common.Address{{2}}
5959
tests := []struct {
6060
name string
61-
config *Config
62-
other *Config
61+
config *AllowListConfig
62+
other *AllowListConfig
6363
expected bool
6464
}{
6565
{
6666
name: "non-nil config and nil other",
67-
config: &Config{admins, enableds},
67+
config: &AllowListConfig{admins, enableds},
6868
other: nil,
6969
expected: false,
7070
},
7171
{
7272
name: "different admin",
73-
config: &Config{admins, enableds},
74-
other: &Config{[]common.Address{{3}}, enableds},
73+
config: &AllowListConfig{admins, enableds},
74+
other: &AllowListConfig{[]common.Address{{3}}, enableds},
7575
expected: false,
7676
},
7777
{
7878
name: "different enabled",
79-
config: &Config{admins, enableds},
80-
other: &Config{admins, []common.Address{{3}}},
79+
config: &AllowListConfig{admins, enableds},
80+
other: &AllowListConfig{admins, []common.Address{{3}}},
8181
expected: false,
8282
},
8383
{
8484
name: "same config",
85-
config: &Config{admins, enableds},
86-
other: &Config{admins, enableds},
85+
config: &AllowListConfig{admins, enableds},
86+
other: &AllowListConfig{admins, enableds},
8787
expected: true,
8888
},
8989
}

precompile/contract/interfaces.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/ava-labs/avalanchego/snow"
1111
"github.com/ava-labs/subnet-evm/commontype"
12-
"github.com/ava-labs/subnet-evm/precompile/config"
12+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1313
"github.com/ethereum/go-ethereum/common"
1414
)
1515

@@ -69,10 +69,10 @@ type BlockContext interface {
6969
}
7070

7171
type Configurator interface {
72-
NewConfig() config.Config
72+
NewConfig() precompileconfig.Config
7373
Configure(
7474
chainConfig ChainConfig,
75-
precompileConfig config.Config,
75+
precompileconfig precompileconfig.Config,
7676
state StateDB,
7777
blockContext BlockContext,
7878
) error

precompile/contract/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/ava-labs/subnet-evm/accounts/abi"
13-
"github.com/ava-labs/subnet-evm/precompile/config"
13+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1414
"github.com/ava-labs/subnet-evm/vmerrs"
1515
"github.com/ethereum/go-ethereum/common"
1616
"github.com/ethereum/go-ethereum/crypto"
@@ -39,7 +39,7 @@ type PrecompileTest struct {
3939
// It should be the same precompile config that is used in the
4040
// precompile's configurator.
4141
// If nil, Configure on the Configurator will not be called.
42-
Config config.Config
42+
Config precompileconfig.Config
4343
// BeforeHook is called before the precompile is called.
4444
BeforeHook func(t *testing.T, state StateDB)
4545
// AfterHook is called after the precompile is called.

precompile/contracts/deployerallowlist/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ import (
77
"math/big"
88

99
"github.com/ava-labs/subnet-evm/precompile/allowlist"
10-
"github.com/ava-labs/subnet-evm/precompile/config"
10+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1111
"github.com/ethereum/go-ethereum/common"
1212
)
1313

14-
var _ config.Config = &Config{}
14+
var _ precompileconfig.Config = &Config{}
1515

1616
// Config contains the configuration for the ContractDeployerAllowList precompile,
1717
// consisting of the initial allowlist and the timestamp for the network upgrade.
1818
type Config struct {
19-
allowlist.Config
20-
config.Upgrade
19+
allowlist.AllowListConfig
20+
precompileconfig.Upgrade
2121
}
2222

2323
// NewConfig returns a config for a network upgrade at [blockTimestamp] that enables
2424
// ContractDeployerAllowList with [admins] and [enableds] as members of the allowlist.
2525
func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address) *Config {
2626
return &Config{
27-
Config: allowlist.Config{
27+
AllowListConfig: allowlist.AllowListConfig{
2828
AdminAddresses: admins,
2929
EnabledAddresses: enableds,
3030
},
31-
Upgrade: config.Upgrade{BlockTimestamp: blockTimestamp},
31+
Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp},
3232
}
3333
}
3434

3535
// NewDisableConfig returns config for a network upgrade at [blockTimestamp]
3636
// that disables ContractDeployerAllowList.
3737
func NewDisableConfig(blockTimestamp *big.Int) *Config {
3838
return &Config{
39-
Upgrade: config.Upgrade{
39+
Upgrade: precompileconfig.Upgrade{
4040
BlockTimestamp: blockTimestamp,
4141
Disable: true,
4242
},
@@ -46,13 +46,13 @@ func NewDisableConfig(blockTimestamp *big.Int) *Config {
4646
func (*Config) Key() string { return ConfigKey }
4747

4848
// Equal returns true if [cfg] is a [*ContractDeployerAllowListConfig] and it has been configured identical to [c].
49-
func (c *Config) Equal(cfg config.Config) bool {
49+
func (c *Config) Equal(cfg precompileconfig.Config) bool {
5050
// typecast before comparison
5151
other, ok := (cfg).(*Config)
5252
if !ok {
5353
return false
5454
}
55-
return c.Upgrade.Equal(&other.Upgrade) && c.Config.Equal(&other.Config)
55+
return c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig)
5656
}
5757

58-
func (c *Config) Verify() error { return c.Config.Verify() }
58+
func (c *Config) Verify() error { return c.AllowListConfig.Verify() }

precompile/contracts/deployerallowlist/config_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"math/big"
88
"testing"
99

10-
"github.com/ava-labs/subnet-evm/precompile/config"
10+
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/stretchr/testify/require"
1313
)
@@ -16,7 +16,7 @@ func TestVerifyContractDeployerConfig(t *testing.T) {
1616
admins := []common.Address{{1}}
1717
tests := []struct {
1818
name string
19-
config config.Config
19+
config precompileconfig.Config
2020
ExpectedError string
2121
}{
2222
{
@@ -44,8 +44,8 @@ func TestEqualContractDeployerAllowListConfig(t *testing.T) {
4444
enableds := []common.Address{{2}}
4545
tests := []struct {
4646
name string
47-
config config.Config
48-
other config.Config
47+
config precompileconfig.Config
48+
other precompileconfig.Config
4949
expected bool
5050
}{
5151
{
@@ -57,7 +57,7 @@ func TestEqualContractDeployerAllowListConfig(t *testing.T) {
5757
{
5858
name: "different type",
5959
config: NewConfig(big.NewInt(3), admins, enableds),
60-
other: config.NewNoopStatefulPrecompileConfig(),
60+
other: precompileconfig.NewNoopStatefulPrecompileConfig(),
6161
expected: false,
6262
},
6363
{

0 commit comments

Comments
 (0)