Skip to content

Commit e451fd3

Browse files
SpicyLemonmergify[bot]czarcas7icyihuangdependabot[bot]
authored
Merge pull request #605 from provenance-io/prov/dwedul/v50-bring-in-v0.50.5
* fix: in-place-testnet edgecases (backport cosmos#19516) (cosmos#19526) Co-authored-by: Adam Tucker <adam@osmosis.team> * fix(simapp): typo in GetStoreKeys (cosmos#19544) * build(deps): Bump cosmossdk.io/math from 1.2.0 to 1.3.0 (cosmos#19562) * fix(depinject): Authtx was not accepting custom signers (backport cosmos#19549) (cosmos#19551) Co-authored-by: Devon Bear <itsdevbear@berachain.com> Co-authored-by: Qt <golang.chen@gmail.com> Co-authored-by: Julien Robert <julien@rbrt.fr> * build(deps): Bump github.com/cosmos/cosmos-db from 1.0.0 to 1.0.2 (cosmos#19566) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr> * Merge pull request from GHSA-86h5-xcpx-cfqc * fix slashing hole with test * release notes + changelog * word * date * updates --------- Co-authored-by: Julien Robert <julien@rbrt.fr> * ci: run test pipeline on merge v0.50 branch (cosmos#19582) * fix(staking): fix impossible conditions (cosmos#19621) * docs: add section on creating a testnets from mainnet exports (backport cosmos#19475) (cosmos#19648) Co-authored-by: Marko <marbar3778@yahoo.com> * build(deps): Bump cosmossdk.io/x/tx from 0.13.0 to 0.13.1 (cosmos#19665) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * feat(client/v2): marshal enum as string (cosmos#19653) * refactor(x/auth): allow empty public keys for GetSignBytesAdapter (backport cosmos#19651) (cosmos#19675) Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: Julien Robert <julien@rbrt.fr> * fix(types): check for HasABCIGenesis in CoreAppModuleBasicAdaptor (cosmos#19709) * build(deps): Bump deps (backport cosmos#19655) (cosmos#19711) Co-authored-by: Julien Robert <julien@rbrt.fr> * Merge pull request from GHSA-95rx-m9m5-m94v * validate ExtendedCommit against LastCommit test cases * account for core.comet types * logging * linting * cherry-pick staking fix * nits * linting fix * run tests --------- Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com> * feat(baseapp): add option to disable block gas meter (cosmos#19626) * feat(x/distribution): add rewards-by-validator autocli config (backport cosmos#19707) (cosmos#19714) Co-authored-by: Julien Robert <julien@rbrt.fr> * fix(x/gov): grpc query tally for failed proposal (backport cosmos#19725) (cosmos#19727) Co-authored-by: David Tumcharoen <david@alleslabs.com> Co-authored-by: Julien Robert <julien@rbrt.fr> * chore: prepare v0.50.5 (cosmos#19715) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Devon Bear <itsdevbear@berachain.com> Co-authored-by: Qt <golang.chen@gmail.com> Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: khanh <50263489+catShaark@users.noreply.github.com> Co-authored-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com> Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com> Co-authored-by: David Tumcharoen <david@alleslabs.com>
2 parents 28a10ac + 597f1e7 commit e451fd3

67 files changed

Lines changed: 2075 additions & 1005 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr_labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
pull-requests: write # for actions/labeler to add labels to PRs
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/labeler@main
15+
- uses: actions/labeler@v4 # v5 is broken, ref https://github.com/actions/labeler/issues/712. Do not bump.
1616
with:
1717
configuration-path: .github/pr_labeler.yml
1818
repo-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
merge_group:
55
push:
66
branches:
7-
- main
7+
- release/v0.50.x
88

99
permissions:
1010
contents: read

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
# Changelog
3838

39-
## [Unreleased]
39+
## [Unreleased Provenance]
4040

4141
### Features
4242

@@ -61,7 +61,28 @@ Ref: https://keepachangelog.com/en/1.0.0/
6161

6262
---
6363

64-
## [v0.50.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4) - 2023-02-19
64+
## [Unreleased]
65+
66+
## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-03-12
67+
68+
### Features
69+
70+
* (baseapp) [#19626](https://github.com/cosmos/cosmos-sdk/pull/19626) Add `DisableBlockGasMeter` option to `BaseApp`, which removes the block gas meter during transaction execution.
71+
72+
### Improvements
73+
74+
* (x/distribution) [#19707](https://github.com/cosmos/cosmos-sdk/pull/19707) Add autocli config for `DelegationTotalRewards` for CLI consistency with `q rewards` commands in previous versions.
75+
* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`.
76+
77+
### Bug Fixes
78+
79+
* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query.
80+
* (types) [#19709](https://github.com/cosmos/cosmos-sdk/pull/19709) Fix skip staking genesis export when using `CoreAppModuleAdaptor` / `CoreAppModuleBasicAdaptor` for it.
81+
* (x/auth) [#19549](https://github.com/cosmos/cosmos-sdk/pull/19549) Accept custom get signers when injecting `x/auth/tx`.
82+
* (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)
83+
* (baseapp) Fix a bug in `baseapp.ValidateVoteExtensions` helper ([GHSA-95rx-m9m5-m94v](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-95rx-m9m5-m94v)). The helper has been fixed and for avoiding API breaking changes `currentHeight` and `chainID` arguments are ignored. Those arguments are removed from the helper in v0.51+.
84+
85+
## [v0.50.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4) - 2024-02-19
6586

6687
### Features
6788

@@ -81,7 +102,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
81102
* (baseapp) [#19177](https://github.com/cosmos/cosmos-sdk/pull/19177) Fix baseapp `DefaultProposalHandler` same-sender non-sequential sequence.
82103
* (crypto) [#19371](https://github.com/cosmos/cosmos-sdk/pull/19371) Avoid CLI redundant log in stdout, log to stderr instead.
83104

84-
## [v0.50.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.3) - 2023-01-15
105+
## [v0.50.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.3) - 2024-01-15
85106

86107
### Features
87108

RELEASE_NOTES.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# Cosmos SDK v0.50.4 Release Notes
1+
# Cosmos SDK v0.50.5 Release Notes
22

33
💬 [**Release Discussion**](https://github.com/orgs/cosmos/discussions/58)
44

55
## 🚀 Highlights
66

7-
Some months ago Cosmos SDK Eden was released. Missed the announcement? Read it [here](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.1).
8-
For this month patch release of the v0.50.x line, a few features and improvements were added to the SDK.
7+
This is time for another patch release of Cosmos SDK Eden.
8+
This release includes a few notable fixes:
99

10-
Notably, we added and fixed the following:
11-
12-
* Adds in-place testnet CLI command for creating testnets from local state (kudos to @czarcas7ic)
13-
* Multiple fixes in baseapp, with fixes in `DefaultProposalHandler` and vote extensions
14-
* Add a missed check in `x/auth/vesting`: [GHSA-4j93-fm92-rp4m](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-4j93-fm92-rp4m)
10+
* Fix a bypass delegator slashing: [GHSA-86h5-xcpx-cfqc](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-86h5-xcpx-cfqc)
11+
* Fix an issue in `baseapp.ValidateVoteExtensions` helper: [GHSA-95rx-m9m5-m94v](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-95rx-m9m5-m94v)
12+
* Allow to provide custom signers for `x/auth/tx` using depinject
1513

1614
We recommended to upgrade to this patch release as soon as possible.
17-
When upgrading from <= v0.50.3, please ensure that 2/3 of the validator power upgrade to v0.50.4.
15+
When upgrading from <= v0.50.4, please ensure that 2/3 of the validator power upgrade to v0.50.5.
1816

1917
## 📝 Changelog
2018

21-
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.50.4/CHANGELOG.md) for an exhaustive list of changes, or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/release/v0.50.3...v0.50.4) from the last release.
19+
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.50.5/CHANGELOG.md) for an exhaustive list of changes, or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/release/v0.50.4...v0.50.5) from the last release.
2220

2321
Refer to the [upgrading guide](https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/UPGRADING.md) when migrating from `v0.47.x` to `v0.50.1`.
24-
Note, that the next SDK release, v0.51.0, will not include `x/params` migration, when migrating from < v0.47, v0.50.x **or** v0.47.x, is a mandatory migration.
22+
Note, that the next SDK release, v0.51, will not include `x/params` migration, when migrating from < v0.47, v0.50.x **or** v0.47.x, is a mandatory migration.

api/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ require (
77
github.com/cosmos/gogoproto v1.4.11
88
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
99
google.golang.org/grpc v1.57.0
10-
google.golang.org/protobuf v1.32.0
10+
google.golang.org/protobuf v1.33.0
1111
)
1212

1313
require (
14-
github.com/golang/protobuf v1.5.3 // indirect
14+
github.com/golang/protobuf v1.5.4 // indirect
1515
github.com/google/go-cmp v0.6.0 // indirect
1616
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
1717
golang.org/x/net v0.14.0 // indirect

api/go.sum

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.4 h1:aEL7tU/rLOmxZQ9z4i7mzxcLbSCY48Od
22
github.com/cosmos/cosmos-proto v1.0.0-beta.4/go.mod h1:oeB+FyVzG3XrQJbJng0EnV8Vljfk9XvTIpGILNU/9Co=
33
github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g=
44
github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y=
5-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
6-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
7-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
8-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5+
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
6+
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
97
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
108
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
119
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA=
@@ -16,7 +14,6 @@ golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
1614
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1715
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
1816
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
19-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2017
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g=
2118
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8=
2219
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:z3vDksarJxsAKM5dmEGv0GHwE2hKJ096wZra71Vs4sw=
@@ -25,7 +22,5 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 h1:
2522
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
2623
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
2724
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
28-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
29-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
30-
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
31-
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
25+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
26+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=

baseapp/abci_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,10 @@ func TestABCI_PrepareProposal_VoteExtensions(t *testing.T) {
17901790
// set up baseapp
17911791
prepareOpt := func(bapp *baseapp.BaseApp) {
17921792
bapp.SetPrepareProposal(func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
1793-
err := baseapp.ValidateVoteExtensions(ctx, valStore, req.Height, bapp.ChainID(), req.LocalLastCommit)
1793+
ctx = ctx.WithBlockHeight(req.Height).WithChainID(bapp.ChainID())
1794+
_, info := extendedCommitToLastCommit(req.LocalLastCommit)
1795+
ctx = ctx.WithCometInfo(info)
1796+
err := baseapp.ValidateVoteExtensions(ctx, valStore, 0, "", req.LocalLastCommit)
17941797
if err != nil {
17951798
return nil, err
17961799
}
@@ -2097,7 +2100,10 @@ func TestBaseApp_VoteExtensions(t *testing.T) {
20972100

20982101
app.SetPrepareProposal(func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
20992102
txs := [][]byte{}
2100-
if err := baseapp.ValidateVoteExtensions(ctx, valStore, req.Height, app.ChainID(), req.LocalLastCommit); err != nil {
2103+
ctx = ctx.WithBlockHeight(req.Height).WithChainID(app.ChainID())
2104+
_, info := extendedCommitToLastCommit(req.LocalLastCommit)
2105+
ctx = ctx.WithCometInfo(info)
2106+
if err := baseapp.ValidateVoteExtensions(ctx, valStore, 0, "", req.LocalLastCommit); err != nil {
21012107
return nil, err
21022108
}
21032109
// add all VE as txs (in a real scenario we would need to check signatures too)

baseapp/abci_utils.go

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"slices"
78

89
"github.com/cockroachdb/errors"
910
abci "github.com/cometbft/cometbft/abci/types"
@@ -13,6 +14,8 @@ import (
1314
protoio "github.com/cosmos/gogoproto/io"
1415
"github.com/cosmos/gogoproto/proto"
1516

17+
"cosmossdk.io/core/comet"
18+
1619
sdk "github.com/cosmos/cosmos-sdk/types"
1720
"github.com/cosmos/cosmos-sdk/types/mempool"
1821
)
@@ -36,14 +39,26 @@ type (
3639
// a proposer in PrepareProposal. It returns an error if any signature is invalid
3740
// or if unexpected vote extensions and/or signatures are found or less than 2/3
3841
// power is received.
42+
// NOTE: From v0.50.5 `currentHeight` and `chainID` arguments are ignored for fixing an issue.
43+
// They will be removed from the function in v0.51+.
3944
func ValidateVoteExtensions(
4045
ctx sdk.Context,
4146
valStore ValidatorStore,
42-
currentHeight int64,
43-
chainID string,
47+
_ int64,
48+
_ string,
4449
extCommit abci.ExtendedCommitInfo,
4550
) error {
51+
// Get values from context
4652
cp := ctx.ConsensusParams()
53+
currentHeight := ctx.HeaderInfo().Height
54+
chainID := ctx.HeaderInfo().ChainID
55+
commitInfo := ctx.CometInfo().GetLastCommit()
56+
57+
// Check that both extCommit + commit are ordered in accordance with vp/address.
58+
if err := validateExtendedCommitAgainstLastCommit(extCommit, commitInfo); err != nil {
59+
return err
60+
}
61+
4762
// Start checking vote extensions only **after** the vote extensions enable
4863
// height, because when `currentHeight == VoteExtensionsEnableHeight`
4964
// PrepareProposal doesn't get any vote extensions in its request.
@@ -64,7 +79,6 @@ func ValidateVoteExtensions(
6479
sumVP int64
6580
)
6681

67-
cache := make(map[string]struct{})
6882
for _, vote := range extCommit.Votes {
6983
totalVP += vote.Validator.Power
7084

@@ -89,12 +103,7 @@ func ValidateVoteExtensions(
89103
return fmt.Errorf("vote extensions enabled; received empty vote extension signature at height %d", currentHeight)
90104
}
91105

92-
// Ensure that the validator has not already submitted a vote extension.
93106
valConsAddr := sdk.ConsAddress(vote.Validator.Address)
94-
if _, ok := cache[valConsAddr.String()]; ok {
95-
return fmt.Errorf("duplicate validator; validator %s has already submitted a vote extension", valConsAddr.String())
96-
}
97-
cache[valConsAddr.String()] = struct{}{}
98107

99108
pubKeyProto, err := valStore.GetPubKeyByConsAddr(ctx, valConsAddr)
100109
if err != nil {
@@ -140,6 +149,51 @@ func ValidateVoteExtensions(
140149
return nil
141150
}
142151

152+
// validateExtendedCommitAgainstLastCommit validates an ExtendedCommitInfo against a LastCommit. Specifically,
153+
// it checks that the ExtendedCommit + LastCommit (for the same height), are consistent with each other + that
154+
// they are ordered correctly (by voting power) in accordance with
155+
// [comet](https://github.com/cometbft/cometbft/blob/4ce0277b35f31985bbf2c25d3806a184a4510010/types/validator_set.go#L784).
156+
func validateExtendedCommitAgainstLastCommit(ec abci.ExtendedCommitInfo, lc comet.CommitInfo) error {
157+
// check that the rounds are the same
158+
if ec.Round != lc.Round() {
159+
return fmt.Errorf("extended commit round %d does not match last commit round %d", ec.Round, lc.Round())
160+
}
161+
162+
// check that the # of votes are the same
163+
if len(ec.Votes) != lc.Votes().Len() {
164+
return fmt.Errorf("extended commit votes length %d does not match last commit votes length %d", len(ec.Votes), lc.Votes().Len())
165+
}
166+
167+
// check sort order of extended commit votes
168+
if !slices.IsSortedFunc(ec.Votes, func(vote1, vote2 abci.ExtendedVoteInfo) int {
169+
if vote1.Validator.Power == vote2.Validator.Power {
170+
return bytes.Compare(vote1.Validator.Address, vote2.Validator.Address) // addresses sorted in ascending order (used to break vp conflicts)
171+
}
172+
return -int(vote1.Validator.Power - vote2.Validator.Power) // vp sorted in descending order
173+
}) {
174+
return fmt.Errorf("extended commit votes are not sorted by voting power")
175+
}
176+
177+
addressCache := make(map[string]struct{}, len(ec.Votes))
178+
// check that consistency between LastCommit and ExtendedCommit
179+
for i, vote := range ec.Votes {
180+
// cache addresses to check for duplicates
181+
if _, ok := addressCache[string(vote.Validator.Address)]; ok {
182+
return fmt.Errorf("extended commit vote address %X is duplicated", vote.Validator.Address)
183+
}
184+
addressCache[string(vote.Validator.Address)] = struct{}{}
185+
186+
if !bytes.Equal(vote.Validator.Address, lc.Votes().Get(i).Validator().Address()) {
187+
return fmt.Errorf("extended commit vote address %X does not match last commit vote address %X", vote.Validator.Address, lc.Votes().Get(i).Validator().Address())
188+
}
189+
if vote.Validator.Power != lc.Votes().Get(i).Validator().Power() {
190+
return fmt.Errorf("extended commit vote power %d does not match last commit vote power %d", vote.Validator.Power, lc.Votes().Get(i).Validator().Power())
191+
}
192+
}
193+
194+
return nil
195+
}
196+
143197
type (
144198
// ProposalTxVerifier defines the interface that is implemented by BaseApp,
145199
// that any custom ABCI PrepareProposal and ProcessProposal handler can use

0 commit comments

Comments
 (0)