From 7ae5d2c06d4f6ad2a0239c8efc83d4372f080c9f Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 25 Apr 2023 10:55:08 +0200 Subject: [PATCH] refactor(baseapp): set vote info to latest votes (#15930) --- CHANGELOG.md | 7 ++++--- baseapp/abci.go | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a06407172ba..1bd5a7efe6807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/feegrant) [#14294](https://github.com/cosmos/cosmos-sdk/pull/14294) Moved the logic of rejecting duplicate grant from `msg_server` to `keeper` method. * (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) `MsgUndelegateResponse` now includes undelegated amount. `x/staking` module's `keeper.Undelegate` now returns 3 values (completionTime,undelegateAmount,error) instead of 2. * (x/staking) (#15731) (https://github.com/cosmos/cosmos-sdk/pull/15731) Introducing a new index to retrieve the delegations by validator efficiently. +* (baseapp) [#15930](https://github.com/cosmos/cosmos-sdk/pull/15930) change vote info provided by prepare and process proposal to the one in the block ### API Breaking Changes @@ -173,9 +174,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/slashing) [#15875](https://github.com/cosmos/cosmos-sdk/pull/15875) `x/slashing.NewAppModule` now requires an `InterfaceRegistry` parameter. * (client) [#15822](https://github.com/cosmos/cosmos-sdk/pull/15822) The return type of the interface method `TxConfig.SignModeHandler` has been changed to `x/tx/signing.HandlerMap`. * (x/auth) [#15822](https://github.com/cosmos/cosmos-sdk/pull/15822) The type of struct field `ante.HandlerOptions.SignModeHandler` has been changed to `x/tx/signing.HandlerMap`. - * The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`. - * The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments. - * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. + * The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`. + * The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments. + * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. ### Client Breaking Changes diff --git a/baseapp/abci.go b/baseapp/abci.go index db82d3f97ddf2..6151e1508557d 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -284,7 +284,7 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. } app.prepareProposalState.ctx = app.getContextForProposal(app.prepareProposalState.ctx, req.Height). - WithVoteInfos(app.voteInfos). + WithVoteInfos(toVoteInfo(req.LocalLastCommit.Votes)). // this is a set of votes that are not finalized yet, wait for commit WithBlockHeight(req.Height). WithBlockTime(req.Time). WithProposer(req.ProposerAddress) @@ -341,7 +341,7 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. app.setState(runTxProcessProposal, emptyHeader) app.processProposalState.ctx = app.getContextForProposal(app.processProposalState.ctx, req.Height). - WithVoteInfos(app.voteInfos). + WithVoteInfos(req.ProposedLastCommit.Votes). // this is a set of votes that are not finalized yet, wait for commit WithBlockHeight(req.Height). WithBlockTime(req.Time). WithHeaderHash(req.Hash). @@ -1036,3 +1036,19 @@ func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Con return ctx } + +// toVoteInfo converts the new ExtendedVoteInfo to VoteInfo. +func toVoteInfo(votes []abci.ExtendedVoteInfo) []abci.VoteInfo { + legacyVotes := make([]abci.VoteInfo, len(votes)) + for i, vote := range votes { + legacyVotes[i] = abci.VoteInfo{ + Validator: abci.Validator{ + Address: vote.Validator.Address, + Power: vote.Validator.Power, + }, + SignedLastBlock: vote.SignedLastBlock, + } + } + + return legacyVotes +}