From 084fbc7d8254bc70cc369480a1dc1dc801612c53 Mon Sep 17 00:00:00 2001 From: David Tumcharoen Date: Tue, 12 Mar 2024 16:28:20 +0700 Subject: [PATCH 1/3] fix(x/gov): grpc query tally for failed proposal (#19725) (cherry picked from commit d961aef76b637053b228dd4f0a41fb2279aa31e9) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 13 ++++++ x/gov/keeper/grpc_query.go | 2 +- x/gov/keeper/grpc_query_test.go | 75 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7e96487b31..6dd4845a48cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,9 +50,22 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +<<<<<<< HEAD * (types) [#19709](https://github.com/cosmos/cosmos-sdk/pull/19709) Fix skip staking genesis export when using `CoreAppModuleAdaptor` / `CoreAppModuleBasicAdaptor` for it. * (x/auth) [#19549](https://github.com/cosmos/cosmos-sdk/pull/19549) Accept custom get signers when injecting `x/auth/tx`. * (x/staking) Fix a possible bypass of delegator slashing: [GHSA-86h5-xcpx-cfqc](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-86h5-xcpx-cfqc) +======= +* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query. +* (baseapp) [#18727](https://github.com/cosmos/cosmos-sdk/pull/18727) Ensure that `BaseApp.Init` firstly returns any errors from a nil commit multistore instead of panicking on nil dereferencing and before sealing the app. +* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec. +* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found. +* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests. +* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server. +* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test. +* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test. +* (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT +* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object +>>>>>>> d961aef76 (fix(x/gov): grpc query tally for failed proposal (#19725)) ## [v0.50.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4) - 2024-02-19 diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index 77afbbffce12..b42a114cfb14 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -260,7 +260,7 @@ func (q queryServer) TallyResult(ctx context.Context, req *v1.QueryTallyResultRe case proposal.Status == v1.StatusDepositPeriod: tallyResult = v1.EmptyTallyResult() - case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected: + case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected || proposal.Status == v1.StatusFailed: tallyResult = *proposal.FinalTallyResult default: diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index c8509d743d9e..6be70fd9c511 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -1560,6 +1560,48 @@ func (suite *KeeperTestSuite) TestGRPCQueryTallyResult() { }, true, }, + { + "proposal status failed", + func() { + propTime := time.Now() + proposal := v1.Proposal{ + Id: 1, + Status: v1.StatusFailed, + FinalTallyResult: &v1.TallyResult{ + YesCount: "4", + AbstainCount: "1", + NoCount: "0", + NoWithVetoCount: "0", + OptionOneCount: "4", + OptionTwoCount: "1", + OptionThreeCount: "0", + OptionFourCount: "0", + SpamCount: "0", + }, + SubmitTime: &propTime, + VotingStartTime: &propTime, + VotingEndTime: &propTime, + Metadata: "proposal metadata", + } + err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal) + suite.Require().NoError(err) + + req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expTally = &v1.TallyResult{ + YesCount: "4", + AbstainCount: "1", + NoCount: "0", + NoWithVetoCount: "0", + OptionOneCount: "4", + OptionTwoCount: "1", + OptionThreeCount: "0", + OptionFourCount: "0", + SpamCount: "0", + } + }, + true, + }, } for _, testCase := range testCases { @@ -1696,6 +1738,39 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryTallyResult() { }, true, }, + { + "proposal status failed", + func() { + propTime := time.Now() + proposal := v1.Proposal{ + Id: 1, + Status: v1.StatusFailed, + FinalTallyResult: &v1.TallyResult{ + YesCount: "4", + AbstainCount: "1", + NoCount: "0", + NoWithVetoCount: "0", + SpamCount: "0", + }, + SubmitTime: &propTime, + VotingStartTime: &propTime, + VotingEndTime: &propTime, + Metadata: "proposal metadata", + } + err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal) + suite.Require().NoError(err) + + req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expTally = &v1beta1.TallyResult{ + Yes: math.NewInt(4), + Abstain: math.NewInt(1), + No: math.NewInt(0), + NoWithVeto: math.NewInt(0), + } + }, + true, + }, } for _, testCase := range testCases { From ef23ae11f4225e6bff382b04e0fb751a9341f1ce Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 12 Mar 2024 10:52:52 +0100 Subject: [PATCH 2/3] fix changelog --- CHANGELOG.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd4845a48cc..00f3548d90da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,22 +50,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -<<<<<<< HEAD +* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query. * (types) [#19709](https://github.com/cosmos/cosmos-sdk/pull/19709) Fix skip staking genesis export when using `CoreAppModuleAdaptor` / `CoreAppModuleBasicAdaptor` for it. * (x/auth) [#19549](https://github.com/cosmos/cosmos-sdk/pull/19549) Accept custom get signers when injecting `x/auth/tx`. * (x/staking) Fix a possible bypass of delegator slashing: [GHSA-86h5-xcpx-cfqc](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-86h5-xcpx-cfqc) -======= -* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query. -* (baseapp) [#18727](https://github.com/cosmos/cosmos-sdk/pull/18727) Ensure that `BaseApp.Init` firstly returns any errors from a nil commit multistore instead of panicking on nil dereferencing and before sealing the app. -* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec. -* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found. -* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests. -* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server. -* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test. -* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test. -* (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT -* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object ->>>>>>> d961aef76 (fix(x/gov): grpc query tally for failed proposal (#19725)) ## [v0.50.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4) - 2024-02-19 From 742a832d7f053695cf53f20986894f0d0ecd3675 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 12 Mar 2024 12:41:33 +0100 Subject: [PATCH 3/3] updates --- x/gov/keeper/grpc_query_test.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 6be70fd9c511..bba32ad3d43a 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -1568,15 +1568,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryTallyResult() { Id: 1, Status: v1.StatusFailed, FinalTallyResult: &v1.TallyResult{ - YesCount: "4", - AbstainCount: "1", - NoCount: "0", - NoWithVetoCount: "0", - OptionOneCount: "4", - OptionTwoCount: "1", - OptionThreeCount: "0", - OptionFourCount: "0", - SpamCount: "0", + YesCount: "4", + AbstainCount: "1", + NoCount: "0", + NoWithVetoCount: "0", }, SubmitTime: &propTime, VotingStartTime: &propTime, @@ -1589,15 +1584,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryTallyResult() { req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} expTally = &v1.TallyResult{ - YesCount: "4", - AbstainCount: "1", - NoCount: "0", - NoWithVetoCount: "0", - OptionOneCount: "4", - OptionTwoCount: "1", - OptionThreeCount: "0", - OptionFourCount: "0", - SpamCount: "0", + YesCount: "4", + AbstainCount: "1", + NoCount: "0", + NoWithVetoCount: "0", } }, true, @@ -1750,7 +1740,6 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryTallyResult() { AbstainCount: "1", NoCount: "0", NoWithVetoCount: "0", - SpamCount: "0", }, SubmitTime: &propTime, VotingStartTime: &propTime,