Skip to content

Commit

Permalink
populate ctx.ConsensusParams for begin blockers
Browse files Browse the repository at this point in the history
Closes: #10724

changelog and unit test

revert change in getContextForTx
  • Loading branch information
yihuang committed Dec 13, 2021
1 parent 314e1d5 commit 7cc6894
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [\#9890] (https://github.com/cosmos/cosmos-sdk/pull/9890) Remove duplicate denom from denom metadata key.
* (x/upgrade) [\#10189](https://github.com/cosmos/cosmos-sdk/issues/10189) Removed potential sources of non-determinism in upgrades
* [\#10393](https://github.com/cosmos/cosmos-sdk/pull/10422) Add `MinCommissionRate` param to `x/staking` module.
* [#10725](https://github.com/cosmos/cosmos-sdk/pull/10725) populate `ctx.ConsensusParams` for begin/end blockers.

### Deprecated

Expand Down
3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
WithBlockGasMeter(gasMeter).
WithHeaderHash(req.Hash)

app.deliverState.ctx = app.deliverState.ctx.
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx))

// we also set block gas meter to checkState in case the application needs to
// verify gas consumption during (Re)CheckTx
if app.checkState != nil {
Expand Down
46 changes: 46 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baseapp_test

import (
"bytes"
"context"
"encoding/binary"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -239,6 +240,51 @@ func TestMountStores(t *testing.T) {
require.NotNil(t, store2)
}

type MockTxHandler struct {
T *testing.T
}

func (th MockTxHandler) CheckTx(goCtx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
require.NotNil(th.T, ctx.ConsensusParams())
return tx.Response{}, tx.ResponseCheckTx{}, nil
}

func (th MockTxHandler) DeliverTx(goCtx context.Context, req tx.Request) (tx.Response, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
require.NotNil(th.T, ctx.ConsensusParams())
return tx.Response{}, nil
}

func (th MockTxHandler) SimulateTx(goCtx context.Context, req tx.Request) (tx.Response, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
require.NotNil(th.T, ctx.ConsensusParams())
return tx.Response{}, nil
}

func TestConsensusParamsNotNil(t *testing.T) {
app := setupBaseApp(t, func(app *baseapp.BaseApp) {
app.SetBeginBlocker(func(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
require.NotNil(t, ctx.ConsensusParams())
return abci.ResponseBeginBlock{}
})
}, func(app *baseapp.BaseApp) {
app.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
require.NotNil(t, ctx.ConsensusParams())
return abci.ResponseEndBlock{}
})
}, func(app *baseapp.BaseApp) {
app.SetTxHandler(MockTxHandler{T: t})
})

header := tmproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.EndBlock(abci.RequestEndBlock{Height: header.Height})
app.CheckTx(abci.RequestCheckTx{})
app.DeliverTx(abci.RequestDeliverTx{})
app.Simulate([]byte{})
}

// Test that we can make commits and then reload old versions.
// Test that LoadLatestVersion actually does.
func TestLoadVersion(t *testing.T) {
Expand Down

0 comments on commit 7cc6894

Please sign in to comment.