Skip to content

Commit

Permalink
rename fee manager config struct (#427)
Browse files Browse the repository at this point in the history
* rename struct

* rename fee config managers to fee managers

* fix comments
  • Loading branch information
ceyonur authored Jan 12, 2023
1 parent 8868a99 commit 357d9e6
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion commontype/fee_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
//
// The dynamic fee algorithm simply increases fees when the network is operating at a utilization level above the target and decreases fees
// when the network is operating at a utilization level below the target.
// This struct is used by params.Config and precompile.FeeConfigManager
// This struct is used by params.Config and precompile.FeeManager
// any modification of this struct has direct affect on the precompiled contract
// and changes should be carefully handled in the precompiled contract code.
type FeeConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion contract-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $ yarn

`ExampleDeployerList` shows how `ContractDeployerAllowList` precompile can be used in a smart contract. It uses `IAllowList` to interact with `ContractDeployerAllowList` precompile. When the precompile is activated only those allowed can deploy contracts.

`ExampleFeeManager` shows how a contract can change fee configuration with the `FeeConfigManager` precompile.
`ExampleFeeManager` shows how a contract can change fee configuration with the `FeeManager` precompile.

All of these `NativeMinter`, `FeeManager` and `AllowList` contracts should be enabled by a chain config in genesis or as an upgrade. See the example genesis under [Tests](#tests) section.

Expand Down
2 changes: 1 addition & 1 deletion contract-examples/contracts/ExampleFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "./AllowList.sol";
import "./IFeeManager.sol";

// ExampleFeeManager shows how FeeConfigManager precompile can be used in a smart contract
// ExampleFeeManager shows how FeeManager precompile can be used in a smart contract
// All methods of [allowList] can be directly called. There are example calls as tasks in hardhat.config.ts file.
contract ExampleFeeManager is AllowList {
// Precompiled Fee Manager Contract Address
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ func (bc *BlockChain) SubscribeAcceptedTransactionEvent(ch chan<- NewTxsEvent) e
}

// GetFeeConfigAt returns the fee configuration and the last changed block number at [parent].
// If FeeConfigManager is activated at [parent], returns the fee config in the precompile contract state.
// If FeeManager is activated at [parent], returns the fee config in the precompile contract state.
// Otherwise returns the fee config in the chain config.
// Assumes that a valid configuration is stored when the precompile is activated.
func (bc *BlockChain) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error) {
config := bc.Config()
bigTime := new(big.Int).SetUint64(parent.Time)
if !config.IsPrecompileEnabled(precompile.FeeConfigManagerAddress, bigTime) {
if !config.IsPrecompileEnabled(precompile.FeeManagerAddress, bigTime) {
return config.FeeConfig, common.Big0, nil
}

Expand Down
18 changes: 9 additions & 9 deletions core/stateful_precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,14 @@ func TestContractNativeMinterRun(t *testing.T) {
}
}

func TestFeeConfigManagerRun(t *testing.T) {
func TestFeeManagerRun(t *testing.T) {
type test struct {
caller common.Address
preCondition func(t *testing.T, state *state.StateDB)
input func() []byte
suppliedGas uint64
readOnly bool
config *feemanager.FeeConfigManagerConfig
config *feemanager.FeeManagerConfig

expectedRes []byte
expectedErr string
Expand Down Expand Up @@ -772,7 +772,7 @@ func TestFeeConfigManagerRun(t *testing.T) {
suppliedGas: feemanager.SetFeeConfigGasCost,
readOnly: false,
expectedRes: nil,
config: &feemanager.FeeConfigManagerConfig{
config: &feemanager.FeeManagerConfig{
InitialFeeConfig: &testFeeConfig,
},
expectedErr: "cannot be greater than maxBlockGasCost",
Expand Down Expand Up @@ -828,7 +828,7 @@ func TestFeeConfigManagerRun(t *testing.T) {
return feemanager.PackGetFeeConfigInput()
},
suppliedGas: feemanager.GetFeeConfigGasCost,
config: &feemanager.FeeConfigManagerConfig{
config: &feemanager.FeeManagerConfig{
InitialFeeConfig: &testFeeConfig,
},
readOnly: true,
Expand Down Expand Up @@ -923,7 +923,7 @@ func TestFeeConfigManagerRun(t *testing.T) {
readOnly: false,
expectedRes: []byte{},
assertState: func(t *testing.T, state *state.StateDB) {
res := feemanager.GetFeeConfigManagerStatus(state, noRoleAddr)
res := feemanager.GetFeeManagerStatus(state, noRoleAddr)
require.Equal(t, allowlist.AllowListEnabled, res)
},
},
Expand All @@ -946,9 +946,9 @@ func TestFeeConfigManagerRun(t *testing.T) {
require.NoError(t, err)

// Set up the state so that each address has the expected permissions at the start.
feemanager.SetFeeConfigManagerStatus(state, adminAddr, allowlist.AllowListAdmin)
feemanager.SetFeeConfigManagerStatus(state, enabledAddr, allowlist.AllowListEnabled)
feemanager.SetFeeConfigManagerStatus(state, noRoleAddr, allowlist.AllowListNoRole)
feemanager.SetFeeManagerStatus(state, adminAddr, allowlist.AllowListAdmin)
feemanager.SetFeeManagerStatus(state, enabledAddr, allowlist.AllowListEnabled)
feemanager.SetFeeManagerStatus(state, noRoleAddr, allowlist.AllowListNoRole)

if test.preCondition != nil {
test.preCondition(t, state)
Expand All @@ -958,7 +958,7 @@ func TestFeeConfigManagerRun(t *testing.T) {
if test.config != nil {
test.config.Configure(params.TestChainConfig, state, blockContext)
}
ret, remainingGas, err := feemanager.FeeConfigManagerPrecompile.Run(&mockAccessibleState{state: state, blockContext: blockContext, snowContext: snow.DefaultContextTest()}, test.caller, precompile.FeeConfigManagerAddress, test.input(), test.suppliedGas, test.readOnly)
ret, remainingGas, err := feemanager.FeeManagerPrecompile.Run(&mockAccessibleState{state: state, blockContext: blockContext, snowContext: snow.DefaultContextTest()}, test.caller, precompile.FeeManagerAddress, test.input(), test.suppliedGas, test.readOnly)
if len(test.expectedErr) != 0 {
require.ErrorContains(t, err, test.expectedErr)
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/test_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, chainC
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Nonce: gen.TxNonce(addr1),
To: &precompile.FeeConfigManagerAddress,
To: &precompile.FeeManagerAddress,
Gas: 3_000_000,
Value: common.Big0,
GasFeeCap: feeCap,
Expand All @@ -1658,7 +1658,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, chainC
gen.AddTx(signedTx)
},
verifyState: func(sdb *state.StateDB) error {
res := feemanager.GetFeeConfigManagerStatus(sdb, addr1)
res := feemanager.GetFeeManagerStatus(sdb, addr1)
assert.Equal(allowlist.AllowListAdmin, res)

storedConfig := feemanager.GetStoredFeeConfig(sdb)
Expand All @@ -1670,7 +1670,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, chainC
return nil
},
verifyGenesis: func(sdb *state.StateDB) {
res := feemanager.GetFeeConfigManagerStatus(sdb, addr1)
res := feemanager.GetFeeManagerStatus(sdb, addr1)
assert.Equal(allowlist.AllowListAdmin, res)

feeConfig, _, err := blockchain.GetFeeConfigAt(blockchain.Genesis().Header())
Expand Down
4 changes: 2 additions & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,10 +1443,10 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
// when we reset txPool we should explicitly check if fee struct for min base fee has changed
// so that we can correctly drop txs with < minBaseFee from tx pool.
// TODO: this should be checking IsSubnetEVM since we also support minimumFee for SubnetEVM
// without requiring FeeConfigManager is enabled.
// without requiring FeeManager is enabled.
// This is already being set by SetMinFee when gas price updater starts.
// However tests are currently failing if we change this check to IsSubnetEVM.
if pool.chainconfig.IsPrecompileEnabled(precompile.FeeConfigManagerAddress, new(big.Int).SetUint64(newHead.Time)) {
if pool.chainconfig.IsPrecompileEnabled(precompile.FeeManagerAddress, new(big.Int).SetUint64(newHead.Time)) {
feeConfig, _, err := pool.chain.GetFeeConfigAt(newHead)
if err != nil {
log.Error("Failed to get fee config state", "err", err, "root", newHead.Root)
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (oracle *Oracle) suggestDynamicFees(ctx context.Context) (*big.Int, *big.In
feeLastChangedAt *big.Int
feeConfig commontype.FeeConfig
)
if oracle.backend.ChainConfig().IsPrecompileEnabled(precompile.FeeConfigManagerAddress, new(big.Int).SetUint64(head.Time)) {
if oracle.backend.ChainConfig().IsPrecompileEnabled(precompile.FeeManagerAddress, new(big.Int).SetUint64(head.Time)) {
feeConfig, feeLastChangedAt, err = oracle.backend.GetFeeConfigAt(head)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func TestSuggestGasPriceAfterFeeConfigUpdate(t *testing.T) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: chainConfig.ChainID,
Nonce: b.TxNonce(addr),
To: &precompile.FeeConfigManagerAddress,
To: &precompile.FeeManagerAddress,
Gas: chainConfig.FeeConfig.GasLimit.Uint64(),
Value: common.Big0,
GasFeeCap: chainConfig.FeeConfig.MinBaseFee, // give low fee, it should work since we still haven't applied high fees
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (w *worker) commitNewWork() (*types.Block, error) {

bigTimestamp := new(big.Int).SetUint64(timestamp)
var gasLimit uint64
// The fee config manager relies on the state of the parent block to set the fee config
// The fee manager relies on the state of the parent block to set the fee config
// because the fee config may be changed by the current block.
feeConfig, _, err := w.chain.GetFeeConfigAt(parent.Header())
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions params/precompile_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type PrecompileUpgrade struct {
ContractDeployerAllowListConfig *deployerallowlist.ContractDeployerAllowListConfig `json:"contractDeployerAllowListConfig,omitempty"` // Config for the contract deployer allow list precompile
ContractNativeMinterConfig *nativeminter.ContractNativeMinterConfig `json:"contractNativeMinterConfig,omitempty"` // Config for the native minter precompile
TxAllowListConfig *txallowlist.TxAllowListConfig `json:"txAllowListConfig,omitempty"` // Config for the tx allow list precompile
FeeManagerConfig *feemanager.FeeConfigManagerConfig `json:"feeManagerConfig,omitempty"` // Config for the fee manager precompile
FeeManagerConfig *feemanager.FeeManagerConfig `json:"feeManagerConfig,omitempty"` // Config for the fee manager precompile
RewardManagerConfig *rewardmanager.RewardManagerConfig `json:"rewardManagerConfig,omitempty"` // Config for the reward manager precompile
// ADD YOUR PRECOMPILE HERE
// {YourPrecompile}Config *precompile.{YourPrecompile}Config `json:"{yourPrecompile}Config,omitempty"`
Expand All @@ -40,7 +40,7 @@ func (p *PrecompileUpgrade) getByAddress(address common.Address) (precompile.Sta
return p.ContractNativeMinterConfig, p.ContractNativeMinterConfig != nil
case precompile.TxAllowListAddress:
return p.TxAllowListConfig, p.TxAllowListConfig != nil
case precompile.FeeConfigManagerAddress:
case precompile.FeeManagerAddress:
return p.FeeManagerConfig, p.FeeManagerConfig != nil
case precompile.RewardManagerAddress:
return p.RewardManagerConfig, p.RewardManagerConfig != nil
Expand Down Expand Up @@ -184,8 +184,8 @@ func (c *ChainConfig) GetActivePrecompileUpgrade(blockTimestamp *big.Int) Precom
if config := c.GetPrecompileConfig(precompile.TxAllowListAddress, blockTimestamp); config != nil && !config.IsDisabled() {
pu.TxAllowListConfig = config.(*txallowlist.TxAllowListConfig)
}
if config := c.GetPrecompileConfig(precompile.FeeConfigManagerAddress, blockTimestamp); config != nil && !config.IsDisabled() {
pu.FeeManagerConfig = config.(*feemanager.FeeConfigManagerConfig)
if config := c.GetPrecompileConfig(precompile.FeeManagerAddress, blockTimestamp); config != nil && !config.IsDisabled() {
pu.FeeManagerConfig = config.(*feemanager.FeeManagerConfig)
}
if config := c.GetPrecompileConfig(precompile.RewardManagerAddress, blockTimestamp); config != nil && !config.IsDisabled() {
pu.RewardManagerConfig = config.(*rewardmanager.RewardManagerConfig)
Expand Down
12 changes: 6 additions & 6 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2411,13 +2411,13 @@ func TestFeeManagerChangeFee(t *testing.T) {
}

// Check that address 0 is whitelisted and address 1 is not
role := feemanager.GetFeeConfigManagerStatus(genesisState, testEthAddrs[0])
role := feemanager.GetFeeManagerStatus(genesisState, testEthAddrs[0])
if role != allowlist.AllowListAdmin {
t.Fatalf("Expected fee manager list status to be set to admin: %s, but found: %s", precompile.FeeConfigManagerAddress, role)
t.Fatalf("Expected fee manager list status to be set to admin: %s, but found: %s", precompile.FeeManagerAddress, role)
}
role = feemanager.GetFeeConfigManagerStatus(genesisState, testEthAddrs[1])
role = feemanager.GetFeeManagerStatus(genesisState, testEthAddrs[1])
if role != allowlist.AllowListNoRole {
t.Fatalf("Expected fee manager list status to be set to no role: %s, but found: %s", precompile.FeeConfigManagerAddress, role)
t.Fatalf("Expected fee manager list status to be set to no role: %s, but found: %s", precompile.FeeManagerAddress, role)
}
// Contract is initialized but no preconfig is given, reader should return genesis fee config
feeConfig, lastChangedAt, err := vm.blockChain.GetFeeConfigAt(vm.blockChain.Genesis().Header())
Expand All @@ -2435,7 +2435,7 @@ func TestFeeManagerChangeFee(t *testing.T) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: genesis.Config.ChainID,
Nonce: uint64(0),
To: &precompile.FeeConfigManagerAddress,
To: &precompile.FeeManagerAddress,
Gas: testLowFeeConfig.GasLimit.Uint64(),
Value: common.Big0,
GasFeeCap: testLowFeeConfig.MinBaseFee, // give low fee, it should work since we still haven't applied high fees
Expand Down Expand Up @@ -2471,7 +2471,7 @@ func TestFeeManagerChangeFee(t *testing.T) {
tx2 := types.NewTx(&types.DynamicFeeTx{
ChainID: genesis.Config.ChainID,
Nonce: uint64(1),
To: &precompile.FeeConfigManagerAddress,
To: &precompile.FeeManagerAddress,
Gas: genesis.Config.FeeConfig.GasLimit.Uint64(),
Value: common.Big0,
GasFeeCap: testLowFeeConfig.MinBaseFee, // this is too low for applied config, should fail
Expand Down
48 changes: 24 additions & 24 deletions precompile/feemanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// FeeConfigManagerConfig wraps [AllowListConfig] and uses it to implement the StatefulPrecompileConfig
// interface while adding in the FeeConfigManager specific precompile address.
type FeeConfigManagerConfig struct {
allowlist.AllowListConfig // Config for the fee config manager allow list
// FeeManagerConfig wraps [AllowListConfig] and uses it to implement the StatefulPrecompileConfig
// interface while adding in the FeeManager specific precompile address.
type FeeManagerConfig struct {
allowlist.AllowListConfig
precompile.UpgradeableConfig
InitialFeeConfig *commontype.FeeConfig `json:"initialFeeConfig,omitempty"` // initial fee config to be immediately activated
}

// NewFeeManagerConfig returns a config for a network upgrade at [blockTimestamp] that enables
// FeeConfigManager with the given [admins] and [enableds] as members of the allowlist with [initialConfig] as initial fee config if specified.
func NewFeeManagerConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialConfig *commontype.FeeConfig) *FeeConfigManagerConfig {
return &FeeConfigManagerConfig{
// FeeManager with the given [admins] and [enableds] as members of the allowlist with [initialConfig] as initial fee config if specified.
func NewFeeManagerConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialConfig *commontype.FeeConfig) *FeeManagerConfig {
return &FeeManagerConfig{
AllowListConfig: allowlist.AllowListConfig{
AllowListAdmins: admins,
EnabledAddresses: enableds,
Expand All @@ -36,25 +36,25 @@ func NewFeeManagerConfig(blockTimestamp *big.Int, admins []common.Address, enabl
}

// NewDisableFeeManagerConfig returns config for a network upgrade at [blockTimestamp]
// that disables FeeConfigManager.
func NewDisableFeeManagerConfig(blockTimestamp *big.Int) *FeeConfigManagerConfig {
return &FeeConfigManagerConfig{
// that disables FeeManager.
func NewDisableFeeManagerConfig(blockTimestamp *big.Int) *FeeManagerConfig {
return &FeeManagerConfig{
UpgradeableConfig: precompile.UpgradeableConfig{
BlockTimestamp: blockTimestamp,
Disable: true,
},
}
}

// Address returns the address of the fee config manager contract.
func (c *FeeConfigManagerConfig) Address() common.Address {
return precompile.FeeConfigManagerAddress
// Address returns the address of the FeeManager contract.
func (c *FeeManagerConfig) Address() common.Address {
return precompile.FeeManagerAddress
}

// Equal returns true if [s] is a [*FeeConfigManagerConfig] and it has been configured identical to [c].
func (c *FeeConfigManagerConfig) Equal(s precompile.StatefulPrecompileConfig) bool {
// Equal returns true if [s] is a [*FeeManagerConfig] and it has been configured identical to [c].
func (c *FeeManagerConfig) Equal(s precompile.StatefulPrecompileConfig) bool {
// typecast before comparison
other, ok := (s).(*FeeConfigManagerConfig)
other, ok := (s).(*FeeManagerConfig)
if !ok {
return false
}
Expand All @@ -71,8 +71,8 @@ func (c *FeeConfigManagerConfig) Equal(s precompile.StatefulPrecompileConfig) bo
}

// Configure configures [state] with the desired admins based on [c].
func (c *FeeConfigManagerConfig) Configure(chainConfig precompile.ChainConfig, state precompile.StateDB, blockContext precompile.BlockContext) error {
// Store the initial fee config into the state when the fee config manager activates.
func (c *FeeManagerConfig) Configure(chainConfig precompile.ChainConfig, state precompile.StateDB, blockContext precompile.BlockContext) error {
// Store the initial fee config into the state when the fee manager activates.
if c.InitialFeeConfig != nil {
if err := StoreFeeConfig(state, *c.InitialFeeConfig, blockContext); err != nil {
// This should not happen since we already checked this config with Verify()
Expand All @@ -84,15 +84,15 @@ func (c *FeeConfigManagerConfig) Configure(chainConfig precompile.ChainConfig, s
return fmt.Errorf("cannot configure fee config in chain config: %w", err)
}
}
return c.AllowListConfig.Configure(state, precompile.FeeConfigManagerAddress)
return c.AllowListConfig.Configure(state, precompile.FeeManagerAddress)
}

// Contract returns the singleton stateful precompiled contract to be used for the fee manager.
func (c *FeeConfigManagerConfig) Contract() precompile.StatefulPrecompiledContract {
return FeeConfigManagerPrecompile
func (c *FeeManagerConfig) Contract() precompile.StatefulPrecompiledContract {
return FeeManagerPrecompile
}

func (c *FeeConfigManagerConfig) Verify() error {
func (c *FeeManagerConfig) Verify() error {
if err := c.AllowListConfig.Verify(); err != nil {
return err
}
Expand All @@ -103,8 +103,8 @@ func (c *FeeConfigManagerConfig) Verify() error {
return c.InitialFeeConfig.Verify()
}

// String returns a string representation of the FeeConfigManagerConfig.
func (c *FeeConfigManagerConfig) String() string {
// String returns a string representation of the FeeManagerConfig.
func (c *FeeManagerConfig) String() string {
bytes, _ := json.Marshal(c)
return string(bytes)
}
2 changes: 1 addition & 1 deletion precompile/feemanager/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestVerifyFeeManagerConfig(t *testing.T) {
}
}

func TestEqualFeeConfigManagerConfig(t *testing.T) {
func TestEqualFeeManagerConfig(t *testing.T) {
admins := []common.Address{{1}}
enableds := []common.Address{{2}}
tests := []struct {
Expand Down
Loading

0 comments on commit 357d9e6

Please sign in to comment.