From 5009edb96a0be96c96baef5630bbc01740c1f283 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 10 Dec 2021 16:19:04 +0800 Subject: [PATCH 1/2] Update base fee in begin blocker Closes: #820 --- app/app.go | 1 + rpc/ethereum/backend/backend.go | 2 +- rpc/ethereum/namespaces/eth/filters/api.go | 4 ++-- x/feemarket/keeper/abci.go | 11 +++++++---- x/feemarket/keeper/eip1559.go | 2 +- x/feemarket/module.go | 4 +++- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index a998acaaff..5d00dc7877 100644 --- a/app/app.go +++ b/app/app.go @@ -439,6 +439,7 @@ func NewEthermintApp( app.mm.SetOrderBeginBlockers( upgradetypes.ModuleName, capabilitytypes.ModuleName, + feemarkettypes.ModuleName, evmtypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index 1e18ff3542..bf81790a71 100644 --- a/rpc/ethereum/backend/backend.go +++ b/rpc/ethereum/backend/backend.go @@ -955,7 +955,7 @@ func (e *EVMBackend) BaseFee(height int64) (*big.Int, error) { return nil, err } - baseFee := types.BaseFeeFromEvents(blockRes.EndBlockEvents) + baseFee := types.BaseFeeFromEvents(blockRes.BeginBlockEvents) if baseFee != nil { return baseFee, nil } diff --git a/rpc/ethereum/namespaces/eth/filters/api.go b/rpc/ethereum/namespaces/eth/filters/api.go index 4da5a286c9..2fb3a73d02 100644 --- a/rpc/ethereum/namespaces/eth/filters/api.go +++ b/rpc/ethereum/namespaces/eth/filters/api.go @@ -258,7 +258,7 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID { continue } - baseFee := types.BaseFeeFromEvents(data.ResultEndBlock.Events) + baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events) header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee) api.filtersMu.Lock() @@ -310,7 +310,7 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er continue } - baseFee := types.BaseFeeFromEvents(data.ResultEndBlock.Events) + baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events) // TODO: fetch bloom from events header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee) diff --git a/x/feemarket/keeper/abci.go b/x/feemarket/keeper/abci.go index 8c99b6f2c5..4ad50e8f59 100644 --- a/x/feemarket/keeper/abci.go +++ b/x/feemarket/keeper/abci.go @@ -9,10 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// EndBlock also retrieves the bloom filter value from the transient store and commits it to the -// KVStore. The EVM end block logic doesn't update the validator set, thus it returns -// an empty slice. -func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) { +// BeginBlock updates base fee +func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { baseFee := k.CalculateBaseFee(ctx) // return immediately if base fee is nil @@ -29,7 +27,12 @@ func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) { sdk.NewAttribute(types.AttributeKeyBaseFee, baseFee.String()), ), }) +} +// EndBlock update block gas used. +// The EVM end block logic doesn't update the validator set, thus it returns +// an empty slice. +func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) { if ctx.BlockGasMeter() == nil { k.Logger(ctx).Error("block gas meter is nil when setting block gas used") return diff --git a/x/feemarket/keeper/eip1559.go b/x/feemarket/keeper/eip1559.go index 68261c9b78..93fd055aa8 100644 --- a/x/feemarket/keeper/eip1559.go +++ b/x/feemarket/keeper/eip1559.go @@ -10,7 +10,7 @@ import ( ) // CalculateBaseFee calculates the base fee for the current block. This is only calculated once per -// block during EndBlock. If the NoBaseFee parameter is enabled or below activation height, this function returns nil. +// block during BeginBlock. If the NoBaseFee parameter is enabled or below activation height, this function returns nil. // NOTE: This code is inspired from the go-ethereum EIP1559 implementation and adapted to Cosmos SDK-based // chains. For the canonical code refer to: https://github.com/ethereum/go-ethereum/blob/master/consensus/misc/eip1559.go func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { diff --git a/x/feemarket/module.go b/x/feemarket/module.go index 88939671be..3abf7c769b 100644 --- a/x/feemarket/module.go +++ b/x/feemarket/module.go @@ -135,7 +135,9 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd } // BeginBlock returns the begin block for the fee market module. -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + am.keeper.BeginBlock(ctx, req) +} // EndBlock returns the end blocker for the fee market module. It returns no validator // updates. From a7b0781039708f03399e1aff395d3c5bebdd029c Mon Sep 17 00:00:00 2001 From: HuangYi Date: Sun, 12 Dec 2021 13:57:46 +0800 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b39a9c52e3..483fece421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### State Machine Breaking + +- (feemarket) [tharsis#822](https://github.com/tharsis/ethermint/pull/822) Update base fee in begin blocker + ## [v0.9.0] - 2021-12-01 ### State Machine Breaking