diff --git a/.github/workflows/deploy-contract.yml b/.github/workflows/deploy-contract.yml index cfbb67e7a5..db9da8113c 100644 --- a/.github/workflows/deploy-contract.yml +++ b/.github/workflows/deploy-contract.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v2.4.0 - name: Use Node.js - uses: actions/setup-node@v2.5.1 + uses: actions/setup-node@v3 with: node-version: '12.x' - name: Install dependencies diff --git a/.mergify.yml b/.mergify.yml index d1c5c6997a..749cc4a724 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -14,7 +14,6 @@ pull_request_rules: name: default merge: method: squash - strict: true commit_message: title+body - name: backport patches to v0.9.x branch conditions: diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e94a0d9b..794def139f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + + +# List of Modules + +Here are the modules required in Ethermint : + +- [EVM](evm/spec/README.md) - Implement the EVM as a Cosmos SDK module. +- [Fee Market](feemarket/spec/README.md) - Define a global variable fee for Cosmos transactions based on EIP-1559. \ No newline at end of file diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index 073fcdaf15..4a69d07ee7 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -91,10 +91,8 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { if suite.enableFeemarket { feemarketGenesis.Params.EnableHeight = 1 feemarketGenesis.Params.NoBaseFee = false - feemarketGenesis.BaseFee = sdk.NewInt(feemarketGenesis.Params.InitialBaseFee) } else { feemarketGenesis.Params.NoBaseFee = true - feemarketGenesis.BaseFee = sdk.NewInt(0) } genesis[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarketGenesis) if !suite.enableLondonHF { diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index f2cb09d02e..39014b015f 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -371,7 +371,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace // access list preparaion is moved from ante handler to here, because it's needed when `ApplyMessage` is called // under contexts where ante handlers are not run, for example `eth_call` and `eth_estimateGas`. - if rules := cfg.ChainConfig.Rules(big.NewInt(ctx.BlockHeight())); rules.IsBerlin { + if rules := cfg.ChainConfig.Rules(big.NewInt(ctx.BlockHeight()), cfg.ChainConfig.MergeForkBlock != nil); rules.IsBerlin { stateDB.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList()) } diff --git a/x/evm/types/tracer.go b/x/evm/types/tracer.go index a033895d0c..7e59662389 100644 --- a/x/evm/types/tracer.go +++ b/x/evm/types/tracer.go @@ -31,7 +31,7 @@ func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height switch tracer { case TracerAccessList: - preCompiles := vm.ActivePrecompiles(cfg.Rules(big.NewInt(height))) + preCompiles := vm.ActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeForkBlock != nil)) return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles) case TracerJSON: return logger.NewJSONLogger(logCfg, os.Stderr) diff --git a/x/feemarket/genesis.go b/x/feemarket/genesis.go index 8fd95d9b96..d2d8e95c11 100644 --- a/x/feemarket/genesis.go +++ b/x/feemarket/genesis.go @@ -15,7 +15,6 @@ func InitGenesis( data types.GenesisState, ) []abci.ValidatorUpdate { k.SetParams(ctx, data.Params) - k.SetBaseFee(ctx, data.BaseFee.BigInt()) k.SetBlockGasUsed(ctx, data.BlockGas) return []abci.ValidatorUpdate{} @@ -23,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), - BaseFee: baseFee, BlockGas: k.GetBlockGasUsed(ctx), } } diff --git a/x/feemarket/keeper/eip1559.go b/x/feemarket/keeper/eip1559.go index 93fd055aa8..cba9121b14 100644 --- a/x/feemarket/keeper/eip1559.go +++ b/x/feemarket/keeper/eip1559.go @@ -25,13 +25,13 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { // If the current block is the first EIP-1559 block, return the InitialBaseFee. if ctx.BlockHeight() == params.EnableHeight { - return new(big.Int).SetInt64(params.InitialBaseFee) + return params.BaseFee.BigInt() } // get the block gas used and the base fee values for the parent block. - parentBaseFee := k.GetBaseFee(ctx) + parentBaseFee := params.BaseFee.BigInt() if parentBaseFee == nil { - parentBaseFee = new(big.Int).SetInt64(params.InitialBaseFee) + return nil } parentGasUsed := k.GetBlockGasUsed(ctx) @@ -43,7 +43,7 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { parentGasTargetBig := new(big.Int).Div(gasLimit, new(big.Int).SetUint64(uint64(params.ElasticityMultiplier))) if !parentGasTargetBig.IsUint64() { - return new(big.Int).SetInt64(params.InitialBaseFee) + return nil } parentGasTarget := parentGasTargetBig.Uint64() diff --git a/x/feemarket/keeper/eip1559_test.go b/x/feemarket/keeper/eip1559_test.go index 1ab5a78ffa..b4da37e18e 100644 --- a/x/feemarket/keeper/eip1559_test.go +++ b/x/feemarket/keeper/eip1559_test.go @@ -2,9 +2,8 @@ package keeper_test import ( "fmt" - "math/big" - abci "github.com/tendermint/tendermint/abci/types" + "math/big" ) func (suite *KeeperTestSuite) TestCalculateBaseFee() { @@ -26,7 +25,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() { func() { suite.ctx = suite.ctx.WithBlockHeight(0) }, - big.NewInt(suite.app.FeeMarketKeeper.GetParams(suite.ctx).InitialBaseFee), + suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee.BigInt(), }, { "with BaseFee - parent block used the same gas as its target", @@ -51,7 +50,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() { params.ElasticityMultiplier = 1 suite.app.FeeMarketKeeper.SetParams(suite.ctx, params) }, - big.NewInt(suite.app.FeeMarketKeeper.GetParams(suite.ctx).InitialBaseFee), + suite.app.FeeMarketKeeper.GetParams(suite.ctx).BaseFee.BigInt(), }, { "with BaseFee - parent block used more gas than its target", diff --git a/x/feemarket/keeper/keeper.go b/x/feemarket/keeper/keeper.go index 0f90aa8370..cdbcf02778 100644 --- a/x/feemarket/keeper/keeper.go +++ b/x/feemarket/keeper/keeper.go @@ -1,8 +1,6 @@ package keeper import ( - "math/big" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -65,27 +63,3 @@ func (k Keeper) SetBlockGasUsed(ctx sdk.Context, gas uint64) { gasBz := sdk.Uint64ToBigEndian(gas) store.Set(types.KeyPrefixBlockGasUsed, gasBz) } - -// ---------------------------------------------------------------------------- -// Parent Base Fee -// Required by EIP1559 base fee calculation. -// ---------------------------------------------------------------------------- - -// GetBaseFee returns the last base fee value from the store. -// returns nil if base fee is not enabled. -func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixBaseFee) - if len(bz) == 0 { - return nil - } - - return new(big.Int).SetBytes(bz) -} - -// SetBaseFee set the last base fee value to the store. -// CONTRACT: this should be only called during EndBlock. -func (k Keeper) SetBaseFee(ctx sdk.Context, baseFee *big.Int) { - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixBaseFee, baseFee.Bytes()) -} diff --git a/x/feemarket/keeper/params.go b/x/feemarket/keeper/params.go index caa5e69f1f..5e7f2c62b0 100644 --- a/x/feemarket/keeper/params.go +++ b/x/feemarket/keeper/params.go @@ -1,8 +1,9 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "math/big" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tharsis/ethermint/x/feemarket/types" ) @@ -16,3 +17,24 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } + +// ---------------------------------------------------------------------------- +// Parent Base Fee +// Required by EIP1559 base fee calculation. +// ---------------------------------------------------------------------------- + +// GetBaseFee get's the base fee from the paramSpace +// return nil if base fee is not enabled +func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int { + params := k.GetParams(ctx) + if params.NoBaseFee { + return nil + } + + 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, sdk.NewIntFromBigInt(baseFee)) +} diff --git a/x/feemarket/simulation/genesis.go b/x/feemarket/simulation/genesis.go index b99b43149f..b5b5c0ec7f 100644 --- a/x/feemarket/simulation/genesis.go +++ b/x/feemarket/simulation/genesis.go @@ -6,16 +6,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tharsis/ethermint/x/feemarket/types" ) // 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()) - baseFee := sdk.NewInt(simState.Rand.Int63()) + params := types.NewParams(simState.Rand.Uint32()%2 == 0, simState.Rand.Uint32(), simState.Rand.Uint32(), simState.Rand.Uint64(), simState.Rand.Int63()) blockGas := simState.Rand.Uint64() - feemarketGenesis := types.NewGenesisState(params, baseFee, blockGas) + feemarketGenesis := types.NewGenesisState(params, blockGas) bz, err := json.MarshalIndent(feemarketGenesis, "", " ") if err != nil { diff --git a/x/feemarket/spec/01_concepts.md b/x/feemarket/spec/01_concepts.md new file mode 100644 index 0000000000..99d0e91ad8 --- /dev/null +++ b/x/feemarket/spec/01_concepts.md @@ -0,0 +1,35 @@ + + +# Concepts + +## Base fee + +The base fee is a global base fee defined at the consensus level. It is adjusted for each block based on the total gas used in the previous block and gas target (block gas limit divided by elasticity multiplier) + +- it increases when blocks are above the gas target +- it decreases when blocks are below the gas target + +Unlike the Cosmos SDK local `minimal-gas-prices`, this value is stored as a module parameter which provides a reliable value for validators to agree upon. + +## Tip + +In EIP-1559, the `tip` is a value that can be added to the `baseFee` in order to incentive transaction prioritization. + +The transaction fee in Ethereum is calculated using the following the formula : + +`transaction fee = (baseFee + tip) * gas units (limit)` + +In Cosmos SDK there is no notion of prioritization, thus the tip for an EIP-1559 transaction in Ethermint should be zero (`MaxPriorityFeePerGas` JSON-RPC endpoint returns `0`) + + + +## EIP-1559 + +A transaction pricing mechanism introduced in Ethereum that includes fixed-per-block network fee that is burned and dynamically expands/contracts block sizes to deal with transient congestion. + +Transactions specify a maximum fee per gas they are willing to pay total (aka: max fee), which covers both the priority fee and the block's network fee per gas (aka: base fee) + +Reference: [EIP1559](https://eips.ethereum.org/EIPS/eip-1559) + diff --git a/x/feemarket/spec/02_state.md b/x/feemarket/spec/02_state.md new file mode 100644 index 0000000000..9720c0a4d5 --- /dev/null +++ b/x/feemarket/spec/02_state.md @@ -0,0 +1,14 @@ + + +# State + +The x/feemarket module keeps in the state variable needed to the fee calculation: + +Only BlockGasUsed in previous block needs to be tracked in state for the next base fee calculation. + + +| | Description | Key | Value | Store | +| ----------- | ------------------------------ | ---------------| ------------------- | --------- | +| BlockGasUsed | gas used in the block | `[]byte{1}` | `[]byte{gas_used}` | KV | diff --git a/x/feemarket/spec/03_begin_block.md b/x/feemarket/spec/03_begin_block.md new file mode 100644 index 0000000000..3db8ea5c79 --- /dev/null +++ b/x/feemarket/spec/03_begin_block.md @@ -0,0 +1,54 @@ + + +# Begin block + +The base fee is calculated at the beginning of each block. + +## Base Fee + +### Disabling base fee + +We introduce two parameters : `NoBaseFee`and `EnableHeight` + +`NoBaseFee` controls the feemarket base fee value. If set to true, no calculation is done and the base fee returned by the keeper is zero. + +`EnableHeight` controls the height we start the calculation. +- If `NoBaseFee = false` and `height < EnableHeight`, the base fee value will be equal to `base_fee` defined in the genesis and the `BeginBlock` will return without further computation. +- If `NoBaseFee = false` and `height >= EnableHeight`, the base fee is dynamically calculated upon each block at `BeginBlock`. + +Those parameters allow us to introduce a static base fee or activate the base fee at a later stage. + +### Enabling base fee + +To enable EIP1559 with the EVM, the following parameters should be set : + +- NoBaseFee should be false +- EnableHeight should be set to a positive integer >= upgrade height. It defines at which height the chain starts the base fee adjustment +- LondonBlock evm's param should be set to a positive integer >= upgrade height. It defines at which height the chain start to accept EIP1559 transactions + + +### Calculation + +The base fee is initialized at `EnableHeight` to the `InitialBaseFee` value defined in the genesis file. + +The base fee is after adjusted according to the total gas used in the previous block. + +```golang +parent_gas_target = parent_gas_limit / ELASTICITY_MULTIPLIER + +if EnableHeight == block.number + base_fee = INITIAL_BASE_FEE +else if parent_gas_used == parent_gas_target: + base_fee = parent_base_fee +else if parent_gas_used > parent_gas_target: + gas_used_delta = parent_gas_used - parent_gas_target + base_fee_delta = max(parent_base_fee * gas_used_delta / parent_gas_target / BASE_FEE_MAX_CHANGE_DENOMINATOR, 1) + base_fee = parent_base_fee + base_fee_delta +else: + gas_used_delta = parent_gas_target - parent_gas_used + base_fee_delta = parent_base_fee * gas_used_delta / parent_gas_target / BASE_FEE_MAX_CHANGE_DENOMINATOR + base_fee = parent_base_fee - base_fee_delta + +``` \ No newline at end of file diff --git a/x/feemarket/spec/04_end_block.md b/x/feemarket/spec/04_end_block.md new file mode 100644 index 0000000000..efef3573c9 --- /dev/null +++ b/x/feemarket/spec/04_end_block.md @@ -0,0 +1,13 @@ + + +# End block + +The block_gas_used value is updated at the end of each block. + +## Block Gas Used + +The total gas used by current block is stored in the KVStore at `EndBlock`. + +It is initialized to `block_gas` defined in the genesis. \ No newline at end of file diff --git a/x/feemarket/spec/05_keeper.md b/x/feemarket/spec/05_keeper.md new file mode 100644 index 0000000000..9fdc86894c --- /dev/null +++ b/x/feemarket/spec/05_keeper.md @@ -0,0 +1,15 @@ + + +# Keeper + +The feemarket module provides this exported keeper that can be passed to other modules that need to get access to the base fee value + +```go + +type Keeper interface { + GetBaseFee(ctx sdk.Context) *big.Int +} + +``` \ No newline at end of file diff --git a/x/feemarket/spec/06_events.md b/x/feemarket/spec/06_events.md new file mode 100644 index 0000000000..2dbdc3e1d9 --- /dev/null +++ b/x/feemarket/spec/06_events.md @@ -0,0 +1,19 @@ + + +# Events + +The `x/feemarket` module emits the following events: + +## BeginBlocker + +| Type | Attribute Key | Attribute Value | +| ---------- | --------------- | --------------- | +| fee_market | base_fee | {baseGasPrices} | + +## EndBlocker + +| Type | Attribute Key | Attribute Value | +| ---------- | --------------- | --------------- | +| block_gas | height | {blockHeight} | +| block_gas | amount | {blockGasUsed} | diff --git a/x/feemarket/spec/07_params.md b/x/feemarket/spec/07_params.md new file mode 100644 index 0000000000..2a1c4cbaaa --- /dev/null +++ b/x/feemarket/spec/07_params.md @@ -0,0 +1,14 @@ + + +# Parameters + +The `x/feemarket` module contains the following parameters: + +| Key | Type | Default Values | Description | +| ----------------------------- | ------ | ----------- |------------- | +| NoBaseFee | bool | false | control the base fee adjustment | +| BaseFeeChangeDenominator | uint32 | 8 | bounds the amount the base fee that can change between blocks | +| ElasticityMultiplier | uint32 | 2 | bounds the threshold which the base fee will increase or decrease depending on the total gas used in the previous block| +| BaseFee | uint32 | 1000000000 | base fee for EIP-1559 blocks | +| EnableHeight | uint32 | 0 | height which enable fee adjustment | \ No newline at end of file diff --git a/x/feemarket/spec/08_client.md b/x/feemarket/spec/08_client.md new file mode 100644 index 0000000000..f42270c897 --- /dev/null +++ b/x/feemarket/spec/08_client.md @@ -0,0 +1,92 @@ + + +# Client + +## CLI + +A user can query and interact with the `feemarket` module using the CLI. + +### Queries + +The `query` commands allow users to query `feemarket` state. + +```go +ethermintd query feemarket --help +``` + +#### Base Fee + +The `base-fee` command allows users to query the block base fee by height. + +``` +ethermintd query feemarket base-fee [height] [flags] +``` + +Example: + +``` +ethermintd query feemarket base-fee 5... +``` + +Example Output: + +``` +base_fee: "512908936" +``` + +#### Block Gas + +The `block-gas` command allows users to query the block gas by height. + +``` +ethermintd query feemarket block-gas [height] [flags] +``` + +Example: + +``` +ethermintd query feemarket block-gas 5... +``` + +Example Output: + +``` +gas: "21000" +``` + +#### Params + +The `params` command allows users to query the module params. + +``` +ethermintd query params subspace [subspace] [key] [flags] +``` + +Example: + +``` +ethermintd query params subspace feemarket ElasticityMultiplier ... +``` + +Example Output: + +``` +key: ElasticityMultiplier +subspace: feemarket +value: "2" +``` + + +## gRPC + +### Queries + +| Verb | Method | Description | +| ------ | ---------------------------------------------------- | -------------------------------------------------------------------------- | +| `gRPC` | `ethermint.feemarket.v1.Query/Params` | Get the module params | +| `gRPC` | `ethermint.feemarket.v1.Query/BaseFee` | Get the block base fee | +| `gRPC` | `ethermint.feemarket.v1.Query/BlockGas` | Get the block gas used | +| `GET` | `/feemarket/evm/v1/params` | Get the module params | +| `GET` | `/feemarket/evm/v1/base_fee` | Get the block base fee | +| `GET` | `/feemarket/evm/v1/block_gas` | Get the block gas used | diff --git a/x/feemarket/spec/09_future_improvements.md b/x/feemarket/spec/09_future_improvements.md new file mode 100644 index 0000000000..ca73f9ccab --- /dev/null +++ b/x/feemarket/spec/09_future_improvements.md @@ -0,0 +1,7 @@ + + +# Future Improvements + +- The feemarket module has been designed mainly to support EIP-1559 on EVM-based chain on cosmos, supporting non-EVM chain could be done as a future improvements. + diff --git a/x/feemarket/spec/README.md b/x/feemarket/spec/README.md new file mode 100644 index 0000000000..5d4de798aa --- /dev/null +++ b/x/feemarket/spec/README.md @@ -0,0 +1,34 @@ + + +# Feemarket + +## Abstract + +This document specifies the feemarket module which allows to define a global transaction fee for the network. + +This module has been designed to support EIP1559 in cosmos-sdk. + +The `MempoolFeeDecorator` in `x/auth` module needs to be overrided to check the `baseFee` along with the `minimal-gas-prices` allowing to implement a global fee mechanism which vary depending on the network activity. + +For more reference to EIP1559: + +https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md + + + +## Contents + +1. **[Concepts](01_concepts.md)** +2. **[State](02_state.md)** +3. **[Begin Block](03_begin_block.md)** +4. **[End Block](04_end_block.md)** +5. **[Keeper](05_keeper.md)** +6. **[Events](06_events.md)** +7. **[Params](07_params.md)** +8. **[Client](08_client.md)** +9. **[Future Improvements](09_future_improvements.md)** \ No newline at end of file diff --git a/x/feemarket/types/feemarket.pb.go b/x/feemarket/types/feemarket.pb.go index 0ec4ef3b21..a445ff5439 100644 --- a/x/feemarket/types/feemarket.pb.go +++ b/x/feemarket/types/feemarket.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -32,10 +34,10 @@ type Params struct { // elasticity multiplier bounds the maximum gas limit an EIP-1559 block may // have. ElasticityMultiplier uint32 `protobuf:"varint,3,opt,name=elasticity_multiplier,json=elasticityMultiplier,proto3" json:"elasticity_multiplier,omitempty"` - // initial base fee for EIP-1559 blocks. - InitialBaseFee int64 `protobuf:"varint,4,opt,name=initial_base_fee,json=initialBaseFee,proto3" json:"initial_base_fee,omitempty"` // height at which the base fee calculation is enabled. EnableHeight int64 `protobuf:"varint,5,opt,name=enable_height,json=enableHeight,proto3" json:"enable_height,omitempty"` + // base fee for EIP-1559 blocks. + BaseFee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=base_fee,json=baseFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"base_fee"` } func (m *Params) Reset() { *m = Params{} } @@ -92,13 +94,6 @@ func (m *Params) GetElasticityMultiplier() uint32 { return 0 } -func (m *Params) GetInitialBaseFee() int64 { - if m != nil { - return m.InitialBaseFee - } - return 0 -} - func (m *Params) GetEnableHeight() int64 { if m != nil { return m.EnableHeight @@ -115,25 +110,29 @@ func init() { } var fileDescriptor_4feb8b20cf98e6e1 = []byte{ - // 286 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0x03, 0x31, - 0x10, 0x86, 0x1b, 0xab, 0x45, 0xa3, 0x15, 0x59, 0x54, 0x16, 0x84, 0x50, 0x14, 0x64, 0x4f, 0xbb, - 0x94, 0x9e, 0xbd, 0x54, 0x91, 0x5e, 0x04, 0xe9, 0xd1, 0x4b, 0xc8, 0xd6, 0x69, 0x33, 0xb8, 0x49, - 0x4a, 0x32, 0x2d, 0xf6, 0x2d, 0x7c, 0x2c, 0x8f, 0x3d, 0x7a, 0x94, 0xf6, 0xe8, 0x4b, 0x08, 0x5b, - 0xdb, 0x78, 0x9c, 0xff, 0xfb, 0x06, 0x7e, 0x7e, 0x7e, 0x0b, 0xa4, 0xc1, 0x1b, 0xb4, 0x54, 0x8c, - 0x01, 0x8c, 0xf2, 0x6f, 0x40, 0xc5, 0xbc, 0x1b, 0x8f, 0x7c, 0xea, 0x1d, 0xb9, 0xe4, 0x72, 0xe7, - 0xe5, 0x11, 0xcd, 0xbb, 0xd7, 0x3f, 0x8c, 0xb7, 0x9e, 0x95, 0x57, 0x26, 0x24, 0x82, 0x1f, 0x5b, - 0x27, 0x4b, 0x15, 0x40, 0x8e, 0x01, 0x52, 0xd6, 0x61, 0xd9, 0xe1, 0xf0, 0xc8, 0xba, 0xbe, 0x0a, - 0xf0, 0x08, 0x90, 0xdc, 0xf1, 0xab, 0x2d, 0x94, 0x23, 0xad, 0xec, 0x04, 0xe4, 0x2b, 0x58, 0x67, - 0xd0, 0x2a, 0x72, 0x3e, 0xdd, 0xeb, 0xb0, 0xac, 0x3d, 0x4c, 0xcb, 0x8d, 0x7d, 0x5f, 0x0b, 0x0f, - 0x91, 0x27, 0x3d, 0x7e, 0x01, 0x95, 0x0a, 0x84, 0x23, 0xa4, 0x85, 0x34, 0xb3, 0x8a, 0x70, 0x5a, - 0x21, 0xf8, 0xb4, 0x59, 0x3f, 0x9e, 0x47, 0xf8, 0xb4, 0x63, 0x49, 0xc6, 0xcf, 0xd0, 0x22, 0xa1, - 0xaa, 0x62, 0xb1, 0xfd, 0x0e, 0xcb, 0x9a, 0xc3, 0xd3, 0xbf, 0x7c, 0xdb, 0xee, 0x86, 0xb7, 0xc1, - 0xaa, 0xb2, 0x02, 0xa9, 0x01, 0x27, 0x9a, 0xd2, 0x83, 0x5a, 0x3b, 0xd9, 0x84, 0x83, 0x3a, 0xeb, - 0x0f, 0x3e, 0x57, 0x82, 0x2d, 0x57, 0x82, 0x7d, 0xaf, 0x04, 0xfb, 0x58, 0x8b, 0xc6, 0x72, 0x2d, - 0x1a, 0x5f, 0x6b, 0xd1, 0x78, 0xc9, 0x27, 0x48, 0x7a, 0x56, 0xe6, 0x23, 0x67, 0x0a, 0xd2, 0xca, - 0x07, 0x0c, 0x45, 0x9c, 0xf6, 0xfd, 0xdf, 0xb8, 0xb4, 0x98, 0x42, 0x28, 0x5b, 0xf5, 0xac, 0xbd, - 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x56, 0x3a, 0xd4, 0xaa, 0x80, 0x01, 0x00, 0x00, + // 343 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x6a, 0xea, 0x40, + 0x14, 0x87, 0x33, 0xfe, 0xbb, 0x9a, 0x7b, 0x05, 0x09, 0xde, 0x4b, 0xb8, 0x85, 0x18, 0x5a, 0x90, + 0x6c, 0x9a, 0x20, 0xae, 0xbb, 0xb1, 0xa5, 0x68, 0xa1, 0x50, 0xb2, 0xec, 0x26, 0x4c, 0xe2, 0x31, + 0x19, 0x4c, 0x66, 0x64, 0xe6, 0x28, 0xf5, 0x2d, 0xfa, 0x10, 0x7d, 0x18, 0x97, 0x2e, 0x4b, 0x17, + 0x52, 0xf4, 0x45, 0x4a, 0xa3, 0x4d, 0x5c, 0xcd, 0xcc, 0xf9, 0xbe, 0xe1, 0x1c, 0xce, 0x4f, 0xef, + 0x03, 0x26, 0x20, 0x33, 0xc6, 0xd1, 0x9b, 0x01, 0x64, 0x54, 0xce, 0x01, 0xbd, 0xd5, 0xa0, 0x7c, + 0xb8, 0x0b, 0x29, 0x50, 0x18, 0xff, 0x0a, 0xcf, 0x2d, 0xd1, 0x6a, 0xf0, 0xbf, 0x1b, 0x8b, 0x58, + 0xe4, 0x8a, 0xf7, 0x7d, 0x3b, 0xda, 0x97, 0x6f, 0x15, 0xbd, 0xf1, 0x44, 0x25, 0xcd, 0x94, 0x61, + 0xe9, 0xbf, 0xb9, 0x08, 0x42, 0xaa, 0x20, 0x98, 0x01, 0x98, 0xc4, 0x26, 0x4e, 0xd3, 0x6f, 0x71, + 0x31, 0xa2, 0x0a, 0xee, 0x01, 0x8c, 0x1b, 0xfd, 0xe2, 0x07, 0x06, 0x51, 0x42, 0x79, 0x0c, 0xc1, + 0x14, 0xb8, 0xc8, 0x18, 0xa7, 0x28, 0xa4, 0x59, 0xb1, 0x89, 0xd3, 0xf6, 0xcd, 0xf0, 0x68, 0xdf, + 0xe6, 0xc2, 0x5d, 0xc9, 0x8d, 0xa1, 0xfe, 0x17, 0x52, 0xaa, 0x90, 0x45, 0x0c, 0xd7, 0x41, 0xb6, + 0x4c, 0x91, 0x2d, 0x52, 0x06, 0xd2, 0xac, 0xe6, 0x1f, 0xbb, 0x25, 0x7c, 0x2c, 0x98, 0x71, 0xa5, + 0xb7, 0x81, 0xd3, 0x30, 0x85, 0x20, 0x01, 0x16, 0x27, 0x68, 0xd6, 0x6d, 0xe2, 0x54, 0xfd, 0x3f, + 0xc7, 0xe2, 0x38, 0xaf, 0x19, 0x13, 0xbd, 0x59, 0x4c, 0xdd, 0xb0, 0x89, 0xd3, 0x1a, 0xb9, 0x9b, + 0x5d, 0x4f, 0xfb, 0xd8, 0xf5, 0xfa, 0x31, 0xc3, 0x64, 0x19, 0xba, 0x91, 0xc8, 0xbc, 0x48, 0xa8, + 0x4c, 0xa8, 0xd3, 0x71, 0xad, 0xa6, 0x73, 0x0f, 0xd7, 0x0b, 0x50, 0xee, 0x84, 0xa3, 0xff, 0xeb, + 0x34, 0xf5, 0x43, 0xad, 0x59, 0xeb, 0xd4, 0xfd, 0x0e, 0xe3, 0x0c, 0x19, 0x4d, 0x8b, 0x65, 0x8c, + 0xc6, 0x9b, 0xbd, 0x45, 0xb6, 0x7b, 0x8b, 0x7c, 0xee, 0x2d, 0xf2, 0x7a, 0xb0, 0xb4, 0xed, 0xc1, + 0xd2, 0xde, 0x0f, 0x96, 0xf6, 0xec, 0x9e, 0xb5, 0xc0, 0x84, 0x4a, 0xc5, 0x94, 0x57, 0x26, 0xf5, + 0x72, 0x96, 0x55, 0xde, 0x2e, 0x6c, 0xe4, 0x7b, 0x1f, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0xee, + 0xfc, 0x5c, 0x06, 0xcf, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -156,16 +155,21 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.BaseFee.Size() + i -= size + if _, err := m.BaseFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintFeemarket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 if m.EnableHeight != 0 { i = encodeVarintFeemarket(dAtA, i, uint64(m.EnableHeight)) i-- dAtA[i] = 0x28 } - if m.InitialBaseFee != 0 { - i = encodeVarintFeemarket(dAtA, i, uint64(m.InitialBaseFee)) - i-- - dAtA[i] = 0x20 - } if m.ElasticityMultiplier != 0 { i = encodeVarintFeemarket(dAtA, i, uint64(m.ElasticityMultiplier)) i-- @@ -215,12 +219,11 @@ func (m *Params) Size() (n int) { if m.ElasticityMultiplier != 0 { n += 1 + sovFeemarket(uint64(m.ElasticityMultiplier)) } - if m.InitialBaseFee != 0 { - n += 1 + sovFeemarket(uint64(m.InitialBaseFee)) - } if m.EnableHeight != 0 { n += 1 + sovFeemarket(uint64(m.EnableHeight)) } + l = m.BaseFee.Size() + n += 1 + l + sovFeemarket(uint64(l)) return n } @@ -317,11 +320,11 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } - case 4: + case 5: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field InitialBaseFee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field EnableHeight", wireType) } - m.InitialBaseFee = 0 + m.EnableHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFeemarket @@ -331,16 +334,16 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.InitialBaseFee |= int64(b&0x7F) << shift + m.EnableHeight |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EnableHeight", wireType) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseFee", wireType) } - m.EnableHeight = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFeemarket @@ -350,11 +353,26 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.EnableHeight |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFeemarket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFeemarket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BaseFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipFeemarket(dAtA[iNdEx:]) diff --git a/x/feemarket/types/genesis.go b/x/feemarket/types/genesis.go index b92f5b92ad..4fc7011339 100644 --- a/x/feemarket/types/genesis.go +++ b/x/feemarket/types/genesis.go @@ -1,27 +1,17 @@ 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. - BaseFee: sdk.NewIntFromUint64(params.InitialBaseFee), + Params: DefaultParams(), BlockGas: 0, } } // NewGenesisState creates a new genesis state. -func NewGenesisState(params Params, baseFee sdk.Int, blockGas uint64) *GenesisState { +func NewGenesisState(params Params, blockGas uint64) *GenesisState { return &GenesisState{ Params: params, - BaseFee: baseFee, BlockGas: blockGas, } } @@ -29,9 +19,5 @@ func NewGenesisState(params Params, baseFee sdk.Int, blockGas uint64) *GenesisSt // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - if gs.BaseFee.IsNegative() { - return fmt.Errorf("base fee cannot be negative: %s", gs.BaseFee) - } - return gs.Params.Validate() } diff --git a/x/feemarket/types/genesis.pb.go b/x/feemarket/types/genesis.pb.go index e3be5d55d4..94e66f48d3 100644 --- a/x/feemarket/types/genesis.pb.go +++ b/x/feemarket/types/genesis.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -28,9 +27,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { // params defines all the paramaters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - // base fee is the exported value from previous software version. - // Zero by default. - BaseFee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=base_fee,json=baseFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"base_fee"` // block gas is the amount of gas used on the last block before the upgrade. // Zero by default. BlockGas uint64 `protobuf:"varint,3,opt,name=block_gas,json=blockGas,proto3" json:"block_gas,omitempty"` @@ -92,25 +88,23 @@ func init() { } var fileDescriptor_6241c21661288629 = []byte{ - // 286 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0x31, 0x4b, 0xc3, 0x40, - 0x14, 0xc7, 0x73, 0x5a, 0x6a, 0x1b, 0x9d, 0x82, 0x48, 0xa9, 0x70, 0x0d, 0x22, 0x25, 0x8b, 0x77, - 0x54, 0x57, 0xa7, 0x0c, 0xd6, 0x6e, 0x12, 0x37, 0x97, 0x72, 0x89, 0xaf, 0x49, 0x88, 0xc9, 0x85, - 0x7b, 0x67, 0xd1, 0x6f, 0xe1, 0x87, 0xf1, 0x43, 0x74, 0xec, 0x28, 0x0e, 0x45, 0x92, 0x2f, 0x22, - 0xb9, 0x96, 0xb6, 0x83, 0x4e, 0x77, 0xbc, 0xf7, 0xfb, 0xbf, 0x1f, 0xfc, 0xed, 0x4b, 0xd0, 0x09, - 0xa8, 0x3c, 0x2d, 0x34, 0x9f, 0x01, 0xe4, 0x42, 0x65, 0xa0, 0xf9, 0x7c, 0xc4, 0x63, 0x28, 0x00, - 0x53, 0x64, 0xa5, 0x92, 0x5a, 0x3a, 0x67, 0x5b, 0x8a, 0x6d, 0x29, 0x36, 0x1f, 0xf5, 0x4f, 0x63, - 0x19, 0x4b, 0x83, 0xf0, 0xe6, 0xb7, 0xa6, 0xfb, 0xc3, 0x7f, 0x6e, 0xee, 0xa2, 0x86, 0xbb, 0xf8, - 0x24, 0xf6, 0xc9, 0x78, 0xed, 0x79, 0xd4, 0x42, 0x83, 0x73, 0x6b, 0xb7, 0x4b, 0xa1, 0x44, 0x8e, - 0x3d, 0xe2, 0x12, 0xef, 0xf8, 0x9a, 0xb2, 0xbf, 0xbd, 0xec, 0xc1, 0x50, 0x7e, 0x6b, 0xb1, 0x1a, - 0x58, 0xc1, 0x26, 0xe3, 0x4c, 0xec, 0x4e, 0x28, 0x10, 0xa6, 0x33, 0x80, 0xde, 0x81, 0x4b, 0xbc, - 0xae, 0xcf, 0x9a, 0xfd, 0xf7, 0x6a, 0x30, 0x8c, 0x53, 0x9d, 0xbc, 0x86, 0x2c, 0x92, 0x39, 0x8f, - 0x24, 0xe6, 0x12, 0x37, 0xcf, 0x15, 0x3e, 0x67, 0x5c, 0xbf, 0x97, 0x80, 0x6c, 0x52, 0xe8, 0xe0, - 0xa8, 0xc9, 0xdf, 0x01, 0x38, 0xe7, 0x76, 0x37, 0x7c, 0x91, 0x51, 0x36, 0x8d, 0x05, 0xf6, 0x0e, - 0x5d, 0xe2, 0xb5, 0x82, 0x8e, 0x19, 0x8c, 0x05, 0xfa, 0xf7, 0x8b, 0x8a, 0x92, 0x65, 0x45, 0xc9, - 0x4f, 0x45, 0xc9, 0x47, 0x4d, 0xad, 0x65, 0x4d, 0xad, 0xaf, 0x9a, 0x5a, 0x4f, 0x6c, 0xcf, 0xa3, - 0x13, 0xa1, 0x30, 0x45, 0xbe, 0xeb, 0xe2, 0x6d, 0xaf, 0x0d, 0xe3, 0x0c, 0xdb, 0xa6, 0x87, 0x9b, - 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xbf, 0x7e, 0x16, 0x85, 0x01, 0x00, 0x00, + // 246 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0x2d, 0xc9, 0x48, + 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4f, 0x4b, 0x4d, 0xcd, 0x4d, 0x2c, 0xca, 0x4e, 0x2d, 0xd1, + 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x83, 0xab, 0xd2, 0x83, 0xab, 0xd2, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0xa5, 0xd4, 0x70, 0x98, 0x89, 0xd0, 0x0a, 0x56, 0xa7, + 0x54, 0xc9, 0xc5, 0xe3, 0x0e, 0xb1, 0x26, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, 0x86, 0x8b, 0xad, + 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x4e, 0x0f, 0xbb, + 0xb5, 0x7a, 0x01, 0x60, 0x55, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0xf5, 0x08, 0x49, + 0x73, 0x71, 0x26, 0xe5, 0xe4, 0x27, 0x67, 0xc7, 0xa7, 0x27, 0x16, 0x4b, 0x30, 0x2b, 0x30, 0x6a, + 0xb0, 0x04, 0x71, 0x80, 0x05, 0xdc, 0x13, 0x8b, 0xbd, 0x58, 0x38, 0x98, 0x04, 0x98, 0x83, 0x38, + 0x92, 0x12, 0x8b, 0x53, 0xe3, 0xd3, 0x52, 0x53, 0x9d, 0x3c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, + 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, + 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x2f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, + 0xbf, 0x24, 0x23, 0xb1, 0xa8, 0x38, 0xb3, 0x58, 0x1f, 0xe1, 0x9f, 0x0a, 0x24, 0x1f, 0x95, 0x54, + 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xfd, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x3c, 0x4e, + 0x2a, 0x68, 0x49, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -138,16 +132,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x18 } - { - size := m.BaseFee.Size() - i -= size - if _, err := m.BaseFee.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -180,8 +164,6 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - l = m.BaseFee.Size() - n += 1 + l + sovGenesis(uint64(l)) if m.BlockGas != 0 { n += 1 + sovGenesis(uint64(m.BlockGas)) } @@ -256,40 +238,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseFee", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.BaseFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field BlockGas", wireType) diff --git a/x/feemarket/types/genesis_test.go b/x/feemarket/types/genesis_test.go index 6c77d412a6..843f70fca5 100644 --- a/x/feemarket/types/genesis_test.go +++ b/x/feemarket/types/genesis_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" ) @@ -30,7 +29,6 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { "valid genesis", &GenesisState{ DefaultParams(), - sdk.ZeroInt(), uint64(1), }, true, @@ -39,7 +37,6 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { "valid New genesis", NewGenesisState( DefaultParams(), - sdk.ZeroInt(), uint64(1), ), true, @@ -48,16 +45,6 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { "empty genesis", &GenesisState{ Params: Params{}, - BaseFee: sdk.ZeroInt(), - BlockGas: 0, - }, - false, - }, - { - "base fee is negative", - &GenesisState{ - Params: Params{}, - BaseFee: sdk.OneInt().Neg(), BlockGas: 0, }, false, diff --git a/x/feemarket/types/keys.go b/x/feemarket/types/keys.go index bfa6a9cfc1..26c122033b 100644 --- a/x/feemarket/types/keys.go +++ b/x/feemarket/types/keys.go @@ -12,14 +12,12 @@ const ( RouterKey = ModuleName ) -// prefix bytes for the EVM persistent store +// prefix bytes for the feemarket persistent store const ( prefixBlockGasUsed = iota + 1 - prefixBaseFee ) // KVStore key prefixes var ( KeyPrefixBlockGasUsed = []byte{prefixBlockGasUsed} - KeyPrefixBaseFee = []byte{prefixBaseFee} ) diff --git a/x/feemarket/types/params.go b/x/feemarket/types/params.go index b93bdcb534..732ba4378f 100644 --- a/x/feemarket/types/params.go +++ b/x/feemarket/types/params.go @@ -3,6 +3,7 @@ package types import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/params" ) @@ -14,7 +15,7 @@ var ( ParamStoreKeyNoBaseFee = []byte("NoBaseFee") ParamStoreKeyBaseFeeChangeDenominator = []byte("BaseFeeChangeDenominator") ParamStoreKeyElasticityMultiplier = []byte("ElasticityMultiplier") - ParamStoreKeyInitialBaseFee = []byte("InitialBaseFee") + ParamStoreKeyBaseFee = []byte("BaseFee") ParamStoreKeyEnableHeight = []byte("EnableHeight") ) @@ -24,12 +25,12 @@ func ParamKeyTable() paramtypes.KeyTable { } // NewParams creates a new Params instance -func NewParams(noBaseFee bool, baseFeeChangeDenom, elasticityMultiplier uint32, initialBaseFee, enableHeight int64) Params { +func NewParams(noBaseFee bool, baseFeeChangeDenom, elasticityMultiplier uint32, baseFee uint64, enableHeight int64) Params { return Params{ NoBaseFee: noBaseFee, BaseFeeChangeDenominator: baseFeeChangeDenom, ElasticityMultiplier: elasticityMultiplier, - InitialBaseFee: initialBaseFee, + BaseFee: sdk.NewIntFromUint64(baseFee), EnableHeight: enableHeight, } } @@ -40,7 +41,7 @@ func DefaultParams() Params { NoBaseFee: false, BaseFeeChangeDenominator: params.BaseFeeChangeDenominator, ElasticityMultiplier: params.ElasticityMultiplier, - InitialBaseFee: params.InitialBaseFee, + BaseFee: sdk.NewIntFromUint64(params.InitialBaseFee), EnableHeight: 0, } } @@ -51,7 +52,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(ParamStoreKeyNoBaseFee, &p.NoBaseFee, validateBool), paramtypes.NewParamSetPair(ParamStoreKeyBaseFeeChangeDenominator, &p.BaseFeeChangeDenominator, validateBaseFeeChangeDenominator), paramtypes.NewParamSetPair(ParamStoreKeyElasticityMultiplier, &p.ElasticityMultiplier, validateElasticityMultiplier), - paramtypes.NewParamSetPair(ParamStoreKeyInitialBaseFee, &p.InitialBaseFee, validateInitialBaseFee), + paramtypes.NewParamSetPair(ParamStoreKeyBaseFee, &p.BaseFee, validateBaseFee), paramtypes.NewParamSetPair(ParamStoreKeyEnableHeight, &p.EnableHeight, validateEnableHeight), } } @@ -62,8 +63,8 @@ func (p Params) Validate() error { return fmt.Errorf("base fee change denominator cannot be 0") } - if p.InitialBaseFee < 0 { - return fmt.Errorf("initial base fee cannot be negative: %d", p.InitialBaseFee) + if p.BaseFee.IsNegative() { + return fmt.Errorf("initial base fee cannot be negative: %s", p.BaseFee) } if p.EnableHeight < 0 { @@ -106,14 +107,14 @@ func validateElasticityMultiplier(i interface{}) error { return nil } -func validateInitialBaseFee(i interface{}) error { - value, ok := i.(int64) +func validateBaseFee(i interface{}) error { + value, ok := i.(sdk.Int) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - if value < 0 { - return fmt.Errorf("initial base fee cannot be negative: %d", value) + if value.IsNegative() { + return fmt.Errorf("base fee cannot be negative") } return nil diff --git a/x/feemarket/types/params_test.go b/x/feemarket/types/params_test.go index 86d7d427c9..64d6e97e8f 100644 --- a/x/feemarket/types/params_test.go +++ b/x/feemarket/types/params_test.go @@ -1,6 +1,7 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" "testing" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -41,16 +42,6 @@ func (suite *ParamsTestSuite) TestParamsValidate() { NewParams(true, 0, 3, 2000000000, int64(544435345345435345)), true, }, - { - "initial base fee cannot is negative", - NewParams(true, 7, 3, -2000000000, int64(544435345345435345)), - true, - }, - { - "initial base fee cannot is negative", - NewParams(true, 7, 3, 2000000000, int64(-544435345345435345)), - true, - }, } for _, tc := range testCases { @@ -72,9 +63,10 @@ func (suite *ParamsTestSuite) TestParamsValidatePriv() { suite.Require().NoError(validateBaseFeeChangeDenominator(uint32(7))) suite.Require().Error(validateElasticityMultiplier("")) suite.Require().NoError(validateElasticityMultiplier(uint32(2))) - suite.Require().Error(validateInitialBaseFee("")) - suite.Require().Error(validateInitialBaseFee(int64(-2000000000))) - suite.Require().NoError(validateInitialBaseFee(int64(2000000000))) + suite.Require().Error(validateBaseFee("")) + suite.Require().Error(validateBaseFee(int64(2000000000))) + suite.Require().Error(validateBaseFee(sdk.NewInt(-2000000000))) + suite.Require().NoError(validateBaseFee(sdk.NewInt(2000000000))) suite.Require().Error(validateEnableHeight("")) suite.Require().Error(validateEnableHeight(int64(-544435345345435345))) suite.Require().NoError(validateEnableHeight(int64(544435345345435345)))