From 868718e6ac82f24ed707e41c2be85eafc5db5b67 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 15 Dec 2021 19:10:05 +0800 Subject: [PATCH 1/3] 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) (cherry picked from commit 675be9d6dbef2d82dd1ca8ee790314b30b1bfe3a) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 22 ++++++++++++++++++++ baseapp/abci.go | 3 ++- baseapp/baseapp_test.go | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 425076ab31a2..a8d1b377e54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,28 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (bank) [\#10394](https://github.com/cosmos/cosmos-sdk/pull/10394) Fix: query account balance by ibc denom. * [\10608](https://github.com/cosmos/cosmos-sdk/pull/10608) Change the order of module migration by pushing x/auth to the end. Auth module depends on other modules and should be run last. We have updated the documentation to provide more details how to change module migration order. This is technically a breaking change, but only impacts updates between the upgrades with version change, hence migrating from the previous patch release doesn't cause new migration and doesn't break the state. * [\#10674](https://github.com/cosmos/cosmos-sdk/pull/10674) Fix issue with `Error.Wrap` and `Error.Wrapf` usage with `errors.Is`. +<<<<<<< HEAD +======= + +### State Machine Breaking + +* [\#10536](https://github.com/cosmos/cosmos-sdk/pull/10536]) Enable `SetSequence` for `ModuleAccount`. +* (store) [#10247](https://github.com/cosmos/cosmos-sdk/pull/10247) Charge gas for the key length in gas meter. +* (store) [#10218](https://github.com/cosmos/cosmos-sdk/pull/10218) Charge gas even when there are no entries while seeking. +* (x/auth)[\#9596](https://github.com/cosmos/cosmos-sdk/pull/9596) Enable creating periodic vesting accounts with a transactions instead of requiring them to be created in genesis. +* (x/bank) [\#9611](https://github.com/cosmos/cosmos-sdk/pull/9611) Introduce a new index to act as a reverse index between a denomination and address allowing to query for + token holders of a specific denomination. `DenomOwners` is updated to use the new reverse index. +* (x/bank) [\#9832] (https://github.com/cosmos/cosmos-sdk/pull/9832) Account balance is stored as `sdk.Int` rather than `sdk.Coin`. +* (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 + +* (x/upgrade) [\#9906](https://github.com/cosmos/cosmos-sdk/pull/9906) Deprecate `UpgradeConsensusState` gRPC query since this functionality is only used for IBC, which now has its own [IBC replacement](https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54) + +>>>>>>> 675be9d6d (fix: populate ctx.ConsensusParams for begin blockers (#10725)) ## [v0.44.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.3) - 2021-10-21 ### Improvements diff --git a/baseapp/abci.go b/baseapp/abci.go index b5a21f33058c..f674f88d1884 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -179,7 +179,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg app.deliverState.ctx = app.deliverState.ctx. 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 // verify gas consumption during (Re)CheckTx diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index df891e136936..534aef91d21c 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -2,6 +2,7 @@ package baseapp import ( "bytes" + "context" "encoding/binary" "encoding/json" "fmt" @@ -202,6 +203,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) { From 3173061ef9b0011abcc4a866d7207e4f04746c60 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 15 Dec 2021 12:17:33 +0100 Subject: [PATCH 2/3] fix cl --- CHANGELOG.md | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d1b377e54a..11b7fef6e7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* [#10725](https://github.com/cosmos/cosmos-sdk/pull/10725) populate `ctx.ConsensusParams` for begin/end blockers. + ## [v0.44.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.5) - 2021-12-02 ### Improvements @@ -62,28 +66,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (bank) [\#10394](https://github.com/cosmos/cosmos-sdk/pull/10394) Fix: query account balance by ibc denom. * [\10608](https://github.com/cosmos/cosmos-sdk/pull/10608) Change the order of module migration by pushing x/auth to the end. Auth module depends on other modules and should be run last. We have updated the documentation to provide more details how to change module migration order. This is technically a breaking change, but only impacts updates between the upgrades with version change, hence migrating from the previous patch release doesn't cause new migration and doesn't break the state. * [\#10674](https://github.com/cosmos/cosmos-sdk/pull/10674) Fix issue with `Error.Wrap` and `Error.Wrapf` usage with `errors.Is`. -<<<<<<< HEAD -======= - -### State Machine Breaking - -* [\#10536](https://github.com/cosmos/cosmos-sdk/pull/10536]) Enable `SetSequence` for `ModuleAccount`. -* (store) [#10247](https://github.com/cosmos/cosmos-sdk/pull/10247) Charge gas for the key length in gas meter. -* (store) [#10218](https://github.com/cosmos/cosmos-sdk/pull/10218) Charge gas even when there are no entries while seeking. -* (x/auth)[\#9596](https://github.com/cosmos/cosmos-sdk/pull/9596) Enable creating periodic vesting accounts with a transactions instead of requiring them to be created in genesis. -* (x/bank) [\#9611](https://github.com/cosmos/cosmos-sdk/pull/9611) Introduce a new index to act as a reverse index between a denomination and address allowing to query for - token holders of a specific denomination. `DenomOwners` is updated to use the new reverse index. -* (x/bank) [\#9832] (https://github.com/cosmos/cosmos-sdk/pull/9832) Account balance is stored as `sdk.Int` rather than `sdk.Coin`. -* (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 - -* (x/upgrade) [\#9906](https://github.com/cosmos/cosmos-sdk/pull/9906) Deprecate `UpgradeConsensusState` gRPC query since this functionality is only used for IBC, which now has its own [IBC replacement](https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54) ->>>>>>> 675be9d6d (fix: populate ctx.ConsensusParams for begin blockers (#10725)) ## [v0.44.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.3) - 2021-10-21 ### Improvements From 3cf2fb4c73b888d5c17a9399eec04586d6e39a52 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Wed, 15 Dec 2021 12:19:45 +0100 Subject: [PATCH 3/3] remove test --- baseapp/baseapp_test.go | 46 ----------------------------------------- 1 file changed, 46 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 534aef91d21c..df891e136936 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -2,7 +2,6 @@ package baseapp import ( "bytes" - "context" "encoding/binary" "encoding/json" "fmt" @@ -203,51 +202,6 @@ 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) {