diff --git a/CHANGELOG.md b/CHANGELOG.md index 28720c3441ed..2160073cfb55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (bank) [#237](https://github.com/crypto-org-chain/cosmos-sdk/pull/237) Support virtual accounts in sending coins. * [#243](https://github.com/crypto-org-chain/cosmos-sdk/pull/243) Support `RunAtomic` API in `Context` to use new CoW branched cache store. * [#248](https://github.com/crypto-org-chain/cosmos-sdk/pull/248) Init btree store lazily to save allocations when no content insert into it. +* [#252](https://github.com/crypto-org-chain/cosmos-sdk/pull/252) Add `BlockGasWanted` to `Context` to support feemarket module. ## [Unreleased-Upstream] diff --git a/baseapp/abci.go b/baseapp/abci.go index ff391460f536..25efa3b224f6 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -796,13 +796,21 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request app.finalizeBlockState.ms = app.finalizeBlockState.ms.SetTracingContext(nil).(storetypes.CacheMultiStore) } - var blockGasUsed uint64 + var ( + blockGasUsed uint64 + blockGasWanted uint64 + ) for _, res := range txResults { blockGasUsed += uint64(res.GasUsed) + blockGasWanted += uint64(res.GasWanted) } - sdkCtx := app.finalizeBlockState.Context().WithBlockGasUsed(blockGasUsed) + app.finalizeBlockState.SetContext( + app.finalizeBlockState.Context(). + WithBlockGasUsed(blockGasUsed). + WithBlockGasWanted(blockGasWanted), + ) - endBlock, err := app.endBlock(sdkCtx) + endBlock, err := app.endBlock(ctx) if err != nil { return nil, err } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index aee79df5f658..99bbdcd1d2c7 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -807,7 +807,7 @@ func (app *BaseApp) deliverTxWithMultiStore(tx []byte, txIndex int, txMultiStore // endBlock is an application-defined function that is called after transactions // have been processed in FinalizeBlock. -func (app *BaseApp) endBlock(ctx context.Context) (sdk.EndBlock, error) { +func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) { var endblock sdk.EndBlock if app.endBlocker != nil { diff --git a/types/context.go b/types/context.go index 27f9b588842d..50452e13b79e 100644 --- a/types/context.go +++ b/types/context.go @@ -74,6 +74,8 @@ type Context struct { txCount int // sum the gas used by all the transactions in the current block, only accessible by end blocker blockGasUsed uint64 + // sum the gas wanted by all the transactions in the current block, only accessible by end blocker + blockGasWanted uint64 } // Proposed rename, not done to avoid API breakage @@ -105,6 +107,7 @@ func (c Context) TxIndex() int { return c.txInd func (c Context) MsgIndex() int { return c.msgIndex } func (c Context) TxCount() int { return c.txCount } func (c Context) BlockGasUsed() uint64 { return c.blockGasUsed } +func (c Context) BlockGasWanted() uint64 { return c.blockGasWanted } // clone the header before returning func (c Context) BlockHeader() cmtproto.Header { @@ -346,6 +349,11 @@ func (c Context) WithBlockGasUsed(gasUsed uint64) Context { return c } +func (c Context) WithBlockGasWanted(gasWanted uint64) Context { + c.blockGasWanted = gasWanted + return c +} + // TODO: remove??? func (c Context) IsZero() bool { return c.ms == nil