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

Commit

Permalink
get consensus params from module
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Apr 16, 2024
1 parent f14c208 commit d8c69a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,15 @@ func NewEthermintApp(
feeMarketSs := app.GetSubspace(feemarkettypes.ModuleName)
app.FeeMarketKeeper = feemarketkeeper.NewKeeper(
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], feeMarketSs,
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], feeMarketSs, app.ConsensusParamsKeeper,
)

// Set authority to x/gov module account to only expect the module account to update params
evmSs := app.GetSubspace(evmtypes.ModuleName)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
nil, geth.NewEVM, tracer, evmSs,
nil, geth.NewEVM, tracer, evmSs, app.ConsensusParamsKeeper,
)

// Create IBC Keeper
Expand Down
5 changes: 4 additions & 1 deletion x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
hi = uint64(*args.Gas)
} else {
// Query block gas limit
params := ctx.ConsensusParams()
params, err := k.ck.Get(ctx)
if err != nil {
return nil, err
}
if params != nil && params.Block != nil && params.Block.MaxGas > 0 {
hi = uint64(params.Block.MaxGas)
} else {
Expand Down
4 changes: 4 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"

consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
Expand Down Expand Up @@ -78,6 +79,7 @@ type Keeper struct {
evmConstructor evm.Constructor
// Legacy subspace
ss paramstypes.Subspace
ck consensusparamkeeper.Keeper
}

// NewKeeper generates new evm module keeper
Expand All @@ -93,6 +95,7 @@ func NewKeeper(
evmConstructor evm.Constructor,
tracer string,
ss paramstypes.Subspace,
ck consensusparamkeeper.Keeper,
) *Keeper {
// ensure evm module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -118,6 +121,7 @@ func NewKeeper(
evmConstructor: evmConstructor,
tracer: tracer,
ss: ss,
ck: ck,
}
}

Expand Down
6 changes: 4 additions & 2 deletions x/feemarket/keeper/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int {
if !params.IsBaseFeeEnabled(ctx.BlockHeight()) {
return nil
}
consParams := ctx.ConsensusParams()

consParams, err := k.ck.Get(ctx)
if err != nil {
return nil
}
// If the current block is the first EIP-1559 block, return the base fee
// defined in the parameters (DefaultBaseFee if it hasn't been changed by
// governance).
Expand Down
2 changes: 1 addition & 1 deletion x/feemarket/keeper/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestCalculateBaseFee() {
MaxBytes: 10,
}
consParams := tmproto.ConsensusParams{Block: &blockParams}
suite.ctx = suite.ctx.WithConsensusParams(&consParams)
suite.app.ConsensusParamsKeeper.Set(suite.ctx, &consParams)

fee := suite.app.FeeMarketKeeper.CalculateBaseFee(suite.ctx)
if tc.NoBaseFee {
Expand Down
5 changes: 4 additions & 1 deletion x/feemarket/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/evmos/ethermint/x/feemarket/types"
Expand All @@ -41,11 +42,12 @@ type Keeper struct {
authority sdk.AccAddress
// Legacy subspace
ss paramstypes.Subspace
ck consensusparamkeeper.Keeper
}

// NewKeeper generates new fee market module keeper
func NewKeeper(
cdc codec.BinaryCodec, authority sdk.AccAddress, storeKey, transientKey storetypes.StoreKey, ss paramstypes.Subspace,
cdc codec.BinaryCodec, authority sdk.AccAddress, storeKey, transientKey storetypes.StoreKey, ss paramstypes.Subspace, ck consensusparamkeeper.Keeper,
) Keeper {
// ensure authority account is correctly formatted
if err := sdk.VerifyAddressFormat(authority); err != nil {
Expand All @@ -58,6 +60,7 @@ func NewKeeper(
authority: authority,
transientKey: transientKey,
ss: ss,
ck: ck,
}
}

Expand Down

0 comments on commit d8c69a4

Please sign in to comment.