forked from cerc-io/laconicd-deprecated
rpc, feemarket: store base fee in event (#673)
* store base fee in event * update changelog
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tharsis/ethermint/x/feemarket/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@@ -13,13 +14,22 @@ import (
|
||||
// an empty slice.
|
||||
func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) {
|
||||
baseFee := k.CalculateBaseFee(ctx)
|
||||
|
||||
// return immediately if base fee is nil
|
||||
if baseFee == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// only set base fee if the NoBaseFee param is false
|
||||
k.SetBaseFee(ctx, baseFee)
|
||||
|
||||
// Store current base fee in event
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
types.EventTypeFeeMarket,
|
||||
sdk.NewAttribute(types.AttributeKeyBaseFee, baseFee.String()),
|
||||
),
|
||||
})
|
||||
|
||||
if ctx.BlockGasMeter() == nil {
|
||||
k.Logger(ctx).Error("block gas meter is nil when setting block gas used")
|
||||
return
|
||||
|
||||
@@ -10,20 +10,21 @@ 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, this function returns nil.
|
||||
// block during EndBlock. 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 {
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
if params.NoBaseFee {
|
||||
// Ignore the calculation if not enable
|
||||
if !params.IsBaseFeeEnabled(ctx.BlockHeight()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
consParams := ctx.ConsensusParams()
|
||||
|
||||
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
|
||||
if ctx.BlockHeight() <= params.EnableHeight {
|
||||
if ctx.BlockHeight() == params.EnableHeight {
|
||||
return new(big.Int).SetInt64(params.InitialBaseFee)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func (k Keeper) SetBlockGasUsed(ctx sdk.Context, gas uint64) {
|
||||
// Required by EIP1559 base fee calculation.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// GetBlockGasUsed returns the last block gas used value from the store.
|
||||
// GetLastBaseFee returns the last base fee value from the store.
|
||||
func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.KeyPrefixBaseFee)
|
||||
@@ -82,7 +82,7 @@ func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
|
||||
return new(big.Int).SetBytes(bz)
|
||||
}
|
||||
|
||||
// SetBlockGasUsed gets the current block gas consumed to the store.
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user