Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
change params type of basefee and remove default base fee
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Feb 17, 2022
1 parent d483578 commit 1d48659
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 203 deletions.
2 changes: 0 additions & 2 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func (suite *AnteTestSuite) SetupTest() {
feemarketGenesis := feemarkettypes.DefaultGenesisState()
feemarketGenesis.Params.EnableHeight = 1
feemarketGenesis.Params.NoBaseFee = false
bf, _ := sdk.NewIntFromString(feemarketGenesis.Params.BaseFee)
feemarketGenesis.DefaultBaseFee = bf
// Verify feeMarket genesis
err := feemarketGenesis.Validate()
suite.Require().NoError(err)
Expand Down
1 change: 0 additions & 1 deletion docs/api/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ GenesisState defines the feemarket module's genesis state.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#ethermint.feemarket.v1.Params) | | params defines all the paramaters of the module. |
| `default_base_fee` | [string](#string) | | default base fee is the exported value from previous software version. Zero by default. |
| `block_gas` | [uint64](#uint64) | | block gas is the amount of gas used on the last block before the upgrade. Zero by default. |


Expand Down
7 changes: 6 additions & 1 deletion proto/ethermint/feemarket/v1/feemarket.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";
package ethermint.feemarket.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/tharsis/ethermint/x/feemarket/types";

// Params defines the EVM module parameters
Expand All @@ -14,7 +16,10 @@ message Params {
// have.
uint32 elasticity_multiplier = 3;
// base fee for EIP-1559 blocks.
string base_fee = 4;
string base_fee = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// height at which the base fee calculation is enabled.
int64 enable_height = 5;
}
6 changes: 0 additions & 6 deletions proto/ethermint/feemarket/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ option go_package = "github.com/tharsis/ethermint/x/feemarket/types";
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
// default base fee is the exported value from previous software version.
// Zero by default.
string default_base_fee = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// block gas is the amount of gas used on the last block before the upgrade.
// Zero by default.
uint64 block_gas = 3;
Expand Down
3 changes: 0 additions & 3 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
if suite.enableFeemarket {
feemarketGenesis.Params.EnableHeight = 1
feemarketGenesis.Params.NoBaseFee = false
bf, _ := sdk.NewIntFromString(feemarketGenesis.Params.BaseFee)
feemarketGenesis.DefaultBaseFee = bf
} else {
feemarketGenesis.Params.NoBaseFee = true
feemarketGenesis.DefaultBaseFee = sdk.NewInt(0)
}
genesis[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarketGenesis)
if !suite.enableLondonHF {
Expand Down
11 changes: 2 additions & 9 deletions x/feemarket/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ func InitGenesis(

// ExportGenesis exports genesis state of the fee market module
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
baseFee := sdk.ZeroInt()
baseFeeInt := k.GetBaseFee(ctx)
if baseFeeInt != nil {
baseFee = sdk.NewIntFromBigInt(baseFeeInt)
}

return &types.GenesisState{
Params: k.GetParams(ctx),
DefaultBaseFee: baseFee,
BlockGas: k.GetBlockGasUsed(ctx),
Params: k.GetParams(ctx),
BlockGas: k.GetBlockGasUsed(ctx),
}
}
15 changes: 8 additions & 7 deletions x/feemarket/keeper/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ package keeper_test
import (
"fmt"
abci "github.com/tendermint/tendermint/abci/types"
"math/big"
)

func (suite *KeeperTestSuite) TestCalculateBaseFee() {
testCases := []struct {
name string
NoBaseFee bool
malleate func()
expFee string
expFee *big.Int
}{
{
"without BaseFee",
true,
func() {},
"",
nil,
},
{
"with BaseFee - initial EIP-1559 block",
false,
func() {
suite.ctx = suite.ctx.WithBlockHeight(0)
},
suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee,
suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee.BigInt(),
},
{
"with BaseFee - parent block used the same gas as its target",
Expand All @@ -49,7 +50,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() {
params.ElasticityMultiplier = 1
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
},
suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee,
suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee.BigInt(),
},
{
"with BaseFee - parent block used more gas than its target",
Expand All @@ -70,7 +71,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() {
params.ElasticityMultiplier = 1
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
},
"1125000000",
big.NewInt(1125000000),
},
{
"with BaseFee - Parent gas used smaller than parent gas target",
Expand All @@ -91,7 +92,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() {
params.ElasticityMultiplier = 1
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
},
"937500000",
big.NewInt(937500000),
},
}
for _, tc := range testCases {
Expand All @@ -107,7 +108,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() {
if tc.NoBaseFee {
suite.Require().Nil(fee, tc.name)
} else {
suite.Require().Equal(tc.expFee, fee.String(), tc.name)
suite.Require().Equal(tc.expFee, fee, tc.name)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion x/feemarket/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q
}

// BaseFee implements the Query/BaseFee gRPC method
// return empty if base fee is not enable
// return empty if base fee is not enabled
func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types.QueryBaseFeeResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

Expand Down
8 changes: 2 additions & 6 deletions x/feemarket/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
if params.NoBaseFee {
return nil
}
baseFee, valid := new(big.Int).SetString(params.BaseFee, 10)
if !valid {
return nil
}

return baseFee
return params.BaseFee.BigInt()
}

// SetBaseFee set's the base fee in the paramSpace
func (k Keeper) SetBaseFee(ctx sdk.Context, baseFee *big.Int) {
k.paramSpace.Set(ctx, types.ParamStoreKeyBaseFee, baseFee.String())
k.paramSpace.Set(ctx, types.ParamStoreKeyBaseFee, sdk.NewIntFromBigInt(baseFee))
}
2 changes: 1 addition & 1 deletion x/feemarket/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// RandomizedGenState generates a random GenesisState for nft
func RandomizedGenState(simState *module.SimulationState) {
params := types.NewParams(simState.Rand.Uint32()%2 == 0, simState.Rand.Uint32(), simState.Rand.Uint32(), simState.Rand.Int63(), simState.Rand.Int63())
params := types.NewParams(simState.Rand.Uint32()%2 == 0, simState.Rand.Uint32(), simState.Rand.Uint32(), simState.Rand.Uint64(), simState.Rand.Int63())
baseFee := sdk.NewInt(simState.Rand.Int63())
blockGas := simState.Rand.Uint64()
feemarketGenesis := types.NewGenesisState(params, baseFee, blockGas)
Expand Down
77 changes: 39 additions & 38 deletions x/feemarket/types/feemarket.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 4 additions & 14 deletions x/feemarket/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/params"
)

// DefaultGenesisState sets default fee market genesis state.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
// the default base fee should be initialized because the default enable height is zero.
DefaultBaseFee: sdk.NewIntFromUint64(params.InitialBaseFee),
BlockGas: 0,
Params: DefaultParams(),
BlockGas: 0,
}
}

// NewGenesisState creates a new genesis state.
func NewGenesisState(params Params, baseFee sdk.Int, blockGas uint64) *GenesisState {
return &GenesisState{
Params: params,
DefaultBaseFee: baseFee,
BlockGas: blockGas,
Params: params,
BlockGas: blockGas,
}
}

// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
if gs.DefaultBaseFee.IsNegative() {
return fmt.Errorf("base fee cannot be negative: %s", gs.DefaultBaseFee)
}

return gs.Params.Validate()
}
Loading

0 comments on commit 1d48659

Please sign in to comment.