feemarket: update base fee in BeginBlock (#822)

* Update base fee in begin blocker

Closes: #820

* changelog

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
yihuang 2021-12-15 10:10:52 +08:00 committed by GitHub
parent 5d237a5ee4
commit 50e463725e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 9 deletions

View File

@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### State Machine Breaking ### State Machine Breaking
- (evm) [tharsis#840](https://github.com/tharsis/ethermint/pull/840) Store empty topics as empty array rather than nil. - (evm) [tharsis#840](https://github.com/tharsis/ethermint/pull/840) Store empty topics as empty array rather than nil.
- (feemarket) [tharsis#822](https://github.com/tharsis/ethermint/pull/822) Update EIP1559 base fee in `BeginBlock`.
### Improvements ### Improvements

View File

@ -439,6 +439,7 @@ func NewEthermintApp(
app.mm.SetOrderBeginBlockers( app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, upgradetypes.ModuleName,
capabilitytypes.ModuleName, capabilitytypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName, evmtypes.ModuleName,
minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,

View File

@ -955,7 +955,7 @@ func (e *EVMBackend) BaseFee(height int64) (*big.Int, error) {
return nil, err return nil, err
} }
baseFee := types.BaseFeeFromEvents(blockRes.EndBlockEvents) baseFee := types.BaseFeeFromEvents(blockRes.BeginBlockEvents)
if baseFee != nil { if baseFee != nil {
return baseFee, nil return baseFee, nil
} }

View File

@ -258,7 +258,7 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID {
continue continue
} }
baseFee := types.BaseFeeFromEvents(data.ResultEndBlock.Events) baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events)
header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee) header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee)
api.filtersMu.Lock() api.filtersMu.Lock()
@ -310,7 +310,7 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er
continue continue
} }
baseFee := types.BaseFeeFromEvents(data.ResultEndBlock.Events) baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events)
// TODO: fetch bloom from events // TODO: fetch bloom from events
header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee) header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee)

View File

@ -9,10 +9,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
// EndBlock also retrieves the bloom filter value from the transient store and commits it to the // BeginBlock updates base fee
// KVStore. The EVM end block logic doesn't update the validator set, thus it returns func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
// an empty slice.
func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) {
baseFee := k.CalculateBaseFee(ctx) baseFee := k.CalculateBaseFee(ctx)
// return immediately if base fee is nil // 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()), 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 { if ctx.BlockGasMeter() == nil {
k.Logger(ctx).Error("block gas meter is nil when setting block gas used") k.Logger(ctx).Error("block gas meter is nil when setting block gas used")
return return

View File

@ -10,7 +10,7 @@ import (
) )
// CalculateBaseFee calculates the base fee for the current block. This is only calculated once per // 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 // 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 // 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 { func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int {

View File

@ -135,7 +135,9 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
} }
// BeginBlock returns the begin block for the fee market module. // 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 // EndBlock returns the end blocker for the fee market module. It returns no validator
// updates. // updates.