fix: populate ctx.ConsensusParams for begin blockers (#10725)
Closes: #10724 ## Description --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
45cad1df0a
commit
675be9d6db
|
@ -189,6 +189,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/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
|
* (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.
|
* [\#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
|
### Deprecated
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
|
||||||
|
|
||||||
app.deliverState.ctx = app.deliverState.ctx.
|
app.deliverState.ctx = app.deliverState.ctx.
|
||||||
WithBlockGasMeter(gasMeter).
|
WithBlockGasMeter(gasMeter).
|
||||||
WithHeaderHash(req.Hash)
|
WithHeaderHash(req.Hash).
|
||||||
|
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx))
|
||||||
|
|
||||||
// we also set block gas meter to checkState in case the application needs to
|
// we also set block gas meter to checkState in case the application needs to
|
||||||
// verify gas consumption during (Re)CheckTx
|
// verify gas consumption during (Re)CheckTx
|
||||||
|
|
|
@ -2,6 +2,7 @@ package baseapp_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -239,6 +240,51 @@ func TestMountStores(t *testing.T) {
|
||||||
require.NotNil(t, store2)
|
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 we can make commits and then reload old versions.
|
||||||
// Test that LoadLatestVersion actually does.
|
// Test that LoadLatestVersion actually does.
|
||||||
func TestLoadVersion(t *testing.T) {
|
func TestLoadVersion(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue