From 6dc53e06dcfc1e2c2153ded8c361cba93f084448 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 9 Jun 2022 17:05:27 -0400 Subject: [PATCH 1/8] Update tag.yml --- .github/workflows/tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 19d2d9f1f5ed..6bab6816911c 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -21,6 +21,6 @@ jobs: - name: Create release uses: goreleaser/goreleaser-action@v2.6.1 with: - args: release --rm-dist --release-notes ./RELEASE_CHANGELOG.md + args: release --rm-dist --release-notes ./RELEASE_NOTES.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 63d768c257865c95eeebe16c935c6a95bba954d5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 10 Jun 2022 10:28:25 +0200 Subject: [PATCH 2/8] fix: update index of crisis invariant check logs (backport #12208) (#12210) * fix: update index of crisis invariant check logs (#12208) ## Description the info log messages describing invariant checks use the index to state progress (eg. `asserting crisis invariants inv=0/15`). this simple change makes them 1-indexed (eg. `asserting crisis invariants inv=1/15`). example before: Screen Shot 2022-06-09 at 12 06 58 PM Closes: #XXXX --- ### 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... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - N/A - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - N/A - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - N/A - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - N/A - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - N/A - [x] updated the relevant documentation or specification - N/A - [x] reviewed "Files changed" and left comments if necessary - N/A - [x] 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 907df327edf731147a9cd74d4b3ac19bec212822) # Conflicts: # CHANGELOG.md * fix conflict Co-authored-by: Robert Pirtle Co-authored-by: Julien Robert --- CHANGELOG.md | 4 ++++ x/crisis/keeper/keeper.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82975b4fafe7..bb7d44dc9ac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. + ## [v0.45.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.5) - 2022-06-09 ### Improvements diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index b9c563d5293d..b52ad7352cd4 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -76,7 +76,7 @@ func (k Keeper) AssertInvariants(ctx sdk.Context) { invarRoutes := k.Routes() n := len(invarRoutes) for i, ir := range invarRoutes { - logger.Info("asserting crisis invariants", "inv", fmt.Sprint(i, "/", n), "name", ir.FullRoute()) + logger.Info("asserting crisis invariants", "inv", fmt.Sprint(i+1, "/", n), "name", ir.FullRoute()) if res, stop := ir.Invar(ctx); stop { // TODO: Include app name as part of context to allow for this to be // variable. From aeab66a32d22260c9bc53b9368c87a857aed42d7 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 15 Jun 2022 12:03:23 -0400 Subject: [PATCH 3/8] fix: Refactor GetLastCompletedUpgrade [v0.45.x] (#12264) --- CHANGELOG.md | 1 + x/upgrade/keeper/keeper.go | 24 ++++++++++++++++++++++-- x/upgrade/keeper/keeper_test.go | 12 ++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7d44dc9ac4..aafaa0c42680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (x/upgrade) [#12264](https://github.com/cosmos/cosmos-sdk/pull/12264) Fix `GetLastCompleteUpgrade` to properly return the latest upgrade. * (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. ## [v0.45.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.5) - 2022-06-09 diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 4d2c834991d7..c38c2efef670 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -26,6 +26,12 @@ import ( // UpgradeInfoFileName file to store upgrade information const UpgradeInfoFileName string = "upgrade-info.json" +// upgrade defines a comparable structure for sorting upgrades. +type upgrade struct { + Name string + BlockHeight int64 +} + type Keeper struct { homePath string // root directory of app config skipUpgradeHeights map[int64]bool // map of heights to skip for an upgrade @@ -236,8 +242,22 @@ func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([] func (k Keeper) GetLastCompletedUpgrade(ctx sdk.Context) (string, int64) { iter := sdk.KVStoreReversePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) defer iter.Close() - if iter.Valid() { - return parseDoneKey(iter.Key()), int64(binary.BigEndian.Uint64(iter.Value())) + + var upgrades []upgrade + for ; iter.Valid(); iter.Next() { + name := parseDoneKey(iter.Key()) + value := int64(sdk.BigEndianToUint64(iter.Value())) + + upgrades = append(upgrades, upgrade{Name: name, BlockHeight: value}) + } + + // sort upgrades in descending order by block height + sort.SliceStable(upgrades, func(i, j int) bool { + return upgrades[i].BlockHeight > upgrades[j].BlockHeight + }) + + if len(upgrades) > 0 { + return upgrades[0].Name, upgrades[0].BlockHeight } return "", 0 diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 1cb2f072abb8..a8ef854b0656 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -241,33 +241,33 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { require.Equal("", name) require.Equal(int64(0), height) - keeper.SetUpgradeHandler("test0", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.9", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) keeper.ApplyUpgrade(s.ctx, types.Plan{ - Name: "test0", + Name: "test-v0.9", Height: 10, }) s.T().Log("verify valid upgrade name and height") name, height = keeper.GetLastCompletedUpgrade(s.ctx) - require.Equal("test0", name) + require.Equal("test-v0.9", name) require.Equal(int64(10), height) - keeper.SetUpgradeHandler("test1", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.10", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) newCtx := s.ctx.WithBlockHeight(15) keeper.ApplyUpgrade(newCtx, types.Plan{ - Name: "test1", + Name: "test-v0.10", Height: 15, }) s.T().Log("verify valid upgrade name and height with multiple upgrades") name, height = keeper.GetLastCompletedUpgrade(newCtx) - require.Equal("test1", name) + require.Equal("test-v0.10", name) require.Equal(int64(15), height) } From bf7348e631066ca9b1e9732246253b8e7bc87224 Mon Sep 17 00:00:00 2001 From: HaeSung Date: Tue, 21 Jun 2022 22:48:54 +0900 Subject: [PATCH 4/8] fix: defaultGenTxGas to 10 times (#12314) --- simapp/helpers/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 9ccecbd976c4..1eb496e57a71 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -14,7 +14,7 @@ import ( // SimAppChainID hardcoded chainID for simulation const ( - DefaultGenTxGas = 1000000 + DefaultGenTxGas = 10000000 SimAppChainID = "simulation-app" ) From cece44df7b613e48587e9c77d897417668b91b25 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 21 Jun 2022 20:58:20 +0530 Subject: [PATCH 5/8] fix: edit validator bug from cli (#12317) --- CHANGELOG.md | 1 + x/staking/client/cli/flags.go | 3 +- x/staking/client/cli/tx.go | 2 +- x/staking/client/testutil/cli_test.go | 1 + x/staking/client/testutil/suite.go | 48 +++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafaa0c42680..ced29009f6e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* [\#12317](https://github.com/cosmos/cosmos-sdk/pull/12317) Rename `edit-validator` command's `--moniker` flag to `--new-moniker` * (x/upgrade) [#12264](https://github.com/cosmos/cosmos-sdk/pull/12264) Fix `GetLastCompleteUpgrade` to properly return the latest upgrade. * (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. diff --git a/x/staking/client/cli/flags.go b/x/staking/client/cli/flags.go index d6725e8c1da4..85879567a6af 100644 --- a/x/staking/client/cli/flags.go +++ b/x/staking/client/cli/flags.go @@ -16,6 +16,7 @@ const ( FlagSharesFraction = "shares-fraction" FlagMoniker = "moniker" + FlagEditMoniker = "new-moniker" FlagIdentity = "identity" FlagWebsite = "website" FlagSecurityContact = "security-contact" @@ -82,7 +83,7 @@ func FlagSetPublicKey() *flag.FlagSet { func flagSetDescriptionEdit() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.String(FlagMoniker, types.DoNotModifyDesc, "The validator's name") + fs.String(FlagEditMoniker, types.DoNotModifyDesc, "The validator's name") fs.String(FlagIdentity, types.DoNotModifyDesc, "The (optional) identity signature (ex. UPort or Keybase)") fs.String(FlagWebsite, types.DoNotModifyDesc, "The validator's (optional) website") fs.String(FlagSecurityContact, types.DoNotModifyDesc, "The validator's (optional) security contact email") diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index cafee004c1b4..138bfa24930d 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -98,7 +98,7 @@ func NewEditValidatorCmd() *cobra.Command { return err } valAddr := clientCtx.GetFromAddress() - moniker, _ := cmd.Flags().GetString(FlagMoniker) + moniker, _ := cmd.Flags().GetString(FlagEditMoniker) identity, _ := cmd.Flags().GetString(FlagIdentity) website, _ := cmd.Flags().GetString(FlagWebsite) security, _ := cmd.Flags().GetString(FlagSecurityContact) diff --git a/x/staking/client/testutil/cli_test.go b/x/staking/client/testutil/cli_test.go index 0a7a5cc25871..f23e88847c30 100644 --- a/x/staking/client/testutil/cli_test.go +++ b/x/staking/client/testutil/cli_test.go @@ -1,3 +1,4 @@ +//go:build norace // +build norace package testutil diff --git a/x/staking/client/testutil/suite.go b/x/staking/client/testutil/suite.go index 807e2b6e7667..a0ef083d47fd 100644 --- a/x/staking/client/testutil/suite.go +++ b/x/staking/client/testutil/suite.go @@ -1353,3 +1353,51 @@ func (s *IntegrationTestSuite) TestBlockResults() { s.network.WaitForNextBlock() } } + +// https://github.com/cosmos/cosmos-sdk/issues/10660 +func (s *IntegrationTestSuite) TestEditValidatorMoniker() { + val := s.network.Validators[0] + require := s.Require() + + txCmd := cli.NewEditValidatorCmd() + moniker := "testing" + _, err := clitestutil.ExecTestCLICmd(val.ClientCtx, txCmd, []string{ + val.ValAddress.String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", cli.FlagEditMoniker, moniker), + fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }) + require.NoError(err) + + queryCmd := cli.GetCmdQueryValidator() + res, err := clitestutil.ExecTestCLICmd( + val.ClientCtx, queryCmd, + []string{val.ValAddress.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, + ) + require.NoError(err) + var result types.Validator + require.NoError(val.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &result)) + require.Equal(result.GetMoniker(), moniker) + + _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, txCmd, []string{ + val.ValAddress.String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }) + require.NoError(err) + + res, err = clitestutil.ExecTestCLICmd( + val.ClientCtx, queryCmd, + []string{val.ValAddress.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, + ) + require.NoError(err) + + require.NoError(val.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &result)) + require.Equal(result.GetMoniker(), moniker) +} From dced7ec56a99cf9200dc1f5e84cf88aeaf374a20 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 28 Jun 2022 14:54:05 +0100 Subject: [PATCH 6/8] chore: update release notes (#12377) --- CHANGELOG.md | 6 ++++++ RELEASE_NOTES.md | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ced29009f6e3..b155be189a0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v0.45.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.6) - 2022-06-28 + +### Improvements + +* (simapp) [#12314](https://github.com/cosmos/cosmos-sdk/pull/12314) Increase `DefaultGenTxGas` from `1000000` to `10000000` + ### Bug Fixes * [\#12317](https://github.com/cosmos/cosmos-sdk/pull/12317) Rename `edit-validator` command's `--moniker` flag to `--new-moniker` diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f79faacb5529..a5b3da6eadaa 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,10 +1,9 @@ -# Cosmos SDK v0.45.5 Release Notes +# Cosmos SDK v0.45.6 Release Notes -This release introduces a few bug fixes and improvements. Notably, it removes -the redacted error message, fixes a few bugs in the `types` package, and -indexing of events for failed txs. +This release introduces a few bug fixes and improvements. +Notably, it fixes `GetLastCompleteUpgrade` in `x/upgrade` to properly return the latest upgrade. -See the [Cosmos SDK v0.45.5 Changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/CHANGELOG.md) +See the [Cosmos SDK v0.45.6 Changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.45.6/CHANGELOG.md) for the exhaustive list of all changes. -**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.45.4...v0.45.5 +**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.45.5...v0.45.6 From f2d94445c0f5f52cf5ed999b81048b575de94964 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 28 Jun 2022 12:42:01 -0400 Subject: [PATCH 7/8] feat: add query.GenericFilteredPaginated (backport #12253) (#12371) --- .github/workflows/lint.yml | 2 +- .github/workflows/release-sims.yml | 2 +- .github/workflows/sims.yml | 14 +-- .github/workflows/tag.yml | 2 +- .github/workflows/test.yml | 12 +- CHANGELOG.md | 5 + README.md | 2 +- contrib/images/simd-dlv/Dockerfile | 2 +- contrib/images/simd-env/Dockerfile | 2 +- contrib/rosetta/node/Dockerfile | 2 +- contrib/rosetta/rosetta-cli/Dockerfile | 2 +- go.mod | 2 +- types/query/filtered_pagination.go | 147 ++++++++++++++++++++++++- x/authz/keeper/grpc_query.go | 126 +++++++++------------ x/authz/keeper/grpc_query_test.go | 12 +- 15 files changed, 232 insertions(+), 102 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 97cd90d025c9..830eb1307759 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.4 with: - go-version: 1.17 + go-version: 1.18 - uses: technote-space/get-diff-action@v5 id: git_diff with: diff --git a/.github/workflows/release-sims.yml b/.github/workflows/release-sims.yml index 4635ccd3b1fa..19e42718d432 100644 --- a/.github/workflows/release-sims.yml +++ b/.github/workflows/release-sims.yml @@ -21,7 +21,7 @@ jobs: steps: - name: install runsim run: | - export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0 + export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - uses: actions/cache@v2.1.6 with: path: ~/go/bin diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 21b7df21a4d7..4d885b46896e 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - run: make build @@ -26,11 +26,11 @@ jobs: steps: - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - name: Install runsim - run: export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0 + run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - uses: actions/cache@v2.1.6 with: path: ~/go/bin @@ -43,7 +43,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - uses: technote-space/get-diff-action@v4 @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - uses: technote-space/get-diff-action@v4 @@ -97,7 +97,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - uses: technote-space/get-diff-action@v4 @@ -125,7 +125,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - uses: technote-space/get-diff-action@v4 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 6bab6816911c..4dc80047f552 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -15,7 +15,7 @@ jobs: - name: Install Go uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Unshallow run: git fetch --prune --unshallow - name: Create release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 92de857521ec..1d9ceb298871 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - name: install tparse @@ -32,7 +32,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - uses: technote-space/get-diff-action@v4 id: git_diff with: @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - name: Display go version run: go version - uses: technote-space/get-diff-action@v4 @@ -102,7 +102,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | @@ -180,7 +180,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | @@ -224,7 +224,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.17 + go-version: 1.18 - uses: technote-space/get-diff-action@v4 id: git_diff with: diff --git a/CHANGELOG.md b/CHANGELOG.md index b155be189a0d..c3b5f366dd52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (simapp) [#12314](https://github.com/cosmos/cosmos-sdk/pull/12314) Increase `DefaultGenTxGas` from `1000000` to `10000000` +* [#12371](https://github.com/cosmos/cosmos-sdk/pull/12371) Update min required Golang version to 1.18. ### Bug Fixes @@ -49,6 +50,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/upgrade) [#12264](https://github.com/cosmos/cosmos-sdk/pull/12264) Fix `GetLastCompleteUpgrade` to properly return the latest upgrade. * (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. +### Features + +* (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX. + ## [v0.45.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.5) - 2022-06-09 ### Improvements diff --git a/README.md b/README.md index 43ccc56cc255..b41c08b845c4 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The Cosmos SDK is a framework for building blockchain applications. [Tendermint **WARNING**: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes. -**Note**: Requires [Go 1.17+](https://golang.org/dl/) +**Note**: Requires [Go 1.18+](https://golang.org/dl/) ## Quick Start diff --git a/contrib/images/simd-dlv/Dockerfile b/contrib/images/simd-dlv/Dockerfile index 9d15d621d761..f55463b26e66 100644 --- a/contrib/images/simd-dlv/Dockerfile +++ b/contrib/images/simd-dlv/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17-alpine AS build +FROM golang:1.18-alpine AS build RUN apk add build-base git linux-headers libc-dev RUN go install github.com/go-delve/delve/cmd/dlv@latest WORKDIR /work diff --git a/contrib/images/simd-env/Dockerfile b/contrib/images/simd-env/Dockerfile index 7c5fcf7644b4..b83c3b831bac 100644 --- a/contrib/images/simd-env/Dockerfile +++ b/contrib/images/simd-env/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17-alpine AS build +FROM golang:1.18-alpine AS build RUN apk add build-base git linux-headers WORKDIR /work COPY go.mod go.sum /work/ diff --git a/contrib/rosetta/node/Dockerfile b/contrib/rosetta/node/Dockerfile index f3a9fb19d774..31458884ce01 100644 --- a/contrib/rosetta/node/Dockerfile +++ b/contrib/rosetta/node/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17-alpine as build +FROM golang:1.18-alpine as build RUN apk add --no-cache tar diff --git a/contrib/rosetta/rosetta-cli/Dockerfile b/contrib/rosetta/rosetta-cli/Dockerfile index 86ecfa7fa66f..e24efbdda72b 100644 --- a/contrib/rosetta/rosetta-cli/Dockerfile +++ b/contrib/rosetta/rosetta-cli/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17-alpine as build +FROM golang:1.18-alpine as build RUN apk add git gcc libc-dev --no-cache diff --git a/go.mod b/go.mod index d855f7eaf011..576950222bca 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -go 1.17 +go 1.18 module github.com/cosmos/cosmos-sdk diff --git a/types/query/filtered_pagination.go b/types/query/filtered_pagination.go index 2856d513f225..200d1493f4fe 100644 --- a/types/query/filtered_pagination.go +++ b/types/query/filtered_pagination.go @@ -3,6 +3,7 @@ package query import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/types" ) @@ -46,8 +47,10 @@ func FilteredPaginate( iterator := getIterator(prefixStore, key, reverse) defer iterator.Close() - var numHits uint64 - var nextKey []byte + var ( + numHits uint64 + nextKey []byte + ) for ; iterator.Valid(); iterator.Next() { if numHits == limit { @@ -79,8 +82,10 @@ func FilteredPaginate( end := offset + limit - var numHits uint64 - var nextKey []byte + var ( + numHits uint64 + nextKey []byte + ) for ; iterator.Valid(); iterator.Next() { if iterator.Error() != nil { @@ -113,3 +118,137 @@ func FilteredPaginate( return res, nil } + +// GenericFilteredPaginate does pagination of all the results in the PrefixStore based on the +// provided PageRequest. `onResult` should be used to filter or transform the results. +// `c` is a constructor function that needs to return a new instance of the type T (this is to +// workaround some generic pitfalls in which we can't instantiate a T struct inside the function). +// If key is provided, the pagination uses the optimized querying. +// If offset is used, the pagination uses lazy filtering i.e., searches through all the records. +// The resulting slice (of type F) can be of a different type than the one being iterated through +// (type T), so it's possible to do any necessary transformation inside the onResult function. +func GenericFilteredPaginate[T codec.ProtoMarshaler, F codec.ProtoMarshaler]( + cdc codec.BinaryCodec, + prefixStore types.KVStore, + pageRequest *PageRequest, + onResult func(key []byte, value T) (F, error), + constructor func() T, +) ([]F, *PageResponse, error) { + // if the PageRequest is nil, use default PageRequest + if pageRequest == nil { + pageRequest = &PageRequest{} + } + + offset := pageRequest.Offset + key := pageRequest.Key + limit := pageRequest.Limit + countTotal := pageRequest.CountTotal + reverse := pageRequest.Reverse + results := []F{} + + if offset > 0 && key != nil { + return results, nil, fmt.Errorf("invalid request, either offset or key is expected, got both") + } + + if limit == 0 { + limit = DefaultLimit + + // count total results when the limit is zero/not supplied + countTotal = true + } + + if len(key) != 0 { + iterator := getIterator(prefixStore, key, reverse) + defer iterator.Close() + + var ( + numHits uint64 + nextKey []byte + ) + + for ; iterator.Valid(); iterator.Next() { + if numHits == limit { + nextKey = iterator.Key() + break + } + + if iterator.Error() != nil { + return nil, nil, iterator.Error() + } + + protoMsg := constructor() + + err := cdc.Unmarshal(iterator.Value(), protoMsg) + if err != nil { + return nil, nil, err + } + + val, err := onResult(iterator.Key(), protoMsg) + if err != nil { + return nil, nil, err + } + + if val.Size() != 0 { + results = append(results, val) + numHits++ + } + } + + return results, &PageResponse{ + NextKey: nextKey, + }, nil + } + + iterator := getIterator(prefixStore, nil, reverse) + defer iterator.Close() + + end := offset + limit + + var ( + numHits uint64 + nextKey []byte + ) + + for ; iterator.Valid(); iterator.Next() { + if iterator.Error() != nil { + return nil, nil, iterator.Error() + } + + protoMsg := constructor() + + err := cdc.Unmarshal(iterator.Value(), protoMsg) + if err != nil { + return nil, nil, err + } + + val, err := onResult(iterator.Key(), protoMsg) + if err != nil { + return nil, nil, err + } + + if val.Size() != 0 { + // Previously this was the "accumulate" flag + if numHits >= offset && numHits < end { + results = append(results, val) + } + numHits++ + } + + if numHits == end+1 { + if nextKey == nil { + nextKey = iterator.Key() + } + + if !countTotal { + break + } + } + } + + res := &PageResponse{NextKey: nextKey} + if countTotal { + res.Total = numHits + } + + return results, res, nil +} diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index ac1b718ac4d5..1751cab97003 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -6,9 +6,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - proto "github.com/gogo/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,10 +32,6 @@ func (k Keeper) Grants(c context.Context, req *authz.QueryGrantsRequest) (*authz } ctx := sdk.UnwrapSDKContext(c) - store := ctx.KVStore(k.storeKey) - key := grantStoreKey(grantee, granter, "") - authStore := prefix.NewStore(store, key) - if req.MsgTypeUrl != "" { authorization, expiration := k.GetCleanAuthorization(ctx, grantee, granter, req.MsgTypeUrl) if authorization == nil { @@ -56,29 +49,26 @@ func (k Keeper) Grants(c context.Context, req *authz.QueryGrantsRequest) (*authz }, nil } - var authorizations []*authz.Grant - pageRes, err := query.FilteredPaginate(authStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { - auth, err := unmarshalAuthorization(k.cdc, value) + store := ctx.KVStore(k.storeKey) + key := grantStoreKey(grantee, granter, "") + grantsStore := prefix.NewStore(store, key) + + authorizations, pageRes, err := query.GenericFilteredPaginate(k.cdc, grantsStore, req.Pagination, func(key []byte, auth *authz.Grant) (*authz.Grant, error) { + auth1 := auth.GetAuthorization() if err != nil { - return false, err + return nil, err } - auth1 := auth.GetAuthorization() - if accumulate { - msg, ok := auth1.(proto.Message) - if !ok { - return false, status.Errorf(codes.Internal, "can't protomarshal %T", msg) - } - - authorizationAny, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return false, status.Errorf(codes.Internal, err.Error()) - } - authorizations = append(authorizations, &authz.Grant{ - Authorization: authorizationAny, - Expiration: auth.Expiration, - }) + + authorizationAny, err := codectypes.NewAnyWithValue(auth1) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) } - return true, nil + return &authz.Grant{ + Authorization: authorizationAny, + Expiration: auth.Expiration, + }, nil + }, func() *authz.Grant { + return &authz.Grant{} }) if err != nil { return nil, err @@ -105,32 +95,29 @@ func (k Keeper) GranterGrants(c context.Context, req *authz.QueryGranterGrantsRe store := ctx.KVStore(k.storeKey) authzStore := prefix.NewStore(store, grantStoreKey(nil, granter, "")) - var grants []*authz.GrantAuthorization - pageRes, err := query.FilteredPaginate(authzStore, req.Pagination, func(key []byte, value []byte, - accumulate bool, - ) (bool, error) { - auth, err := unmarshalAuthorization(k.cdc, value) + grants, pageRes, err := query.GenericFilteredPaginate(k.cdc, authzStore, req.Pagination, func(key []byte, auth *authz.Grant) (*authz.GrantAuthorization, error) { + auth1 := auth.GetAuthorization() if err != nil { - return false, err + return nil, err } - auth1 := auth.GetAuthorization() - if accumulate { - any, err := codectypes.NewAnyWithValue(auth1) - if err != nil { - return false, status.Errorf(codes.Internal, err.Error()) - } - - grantee := firstAddressFromGrantStoreKey(key) - grants = append(grants, &authz.GrantAuthorization{ - Granter: granter.String(), - Grantee: grantee.String(), - Authorization: any, - Expiration: auth.Expiration, - }) + any, err := codectypes.NewAnyWithValue(auth1) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) } - return true, nil + + grantee := firstAddressFromGrantStoreKey(key) + return &authz.GrantAuthorization{ + Granter: granter.String(), + Grantee: grantee.String(), + Authorization: any, + Expiration: auth.Expiration, + }, nil + + }, func() *authz.Grant { + return &authz.Grant{} }) + if err != nil { return nil, err } @@ -155,35 +142,30 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe ctx := sdk.UnwrapSDKContext(c) store := prefix.NewStore(ctx.KVStore(k.storeKey), GrantKey) - var authorizations []*authz.GrantAuthorization - pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte, - accumulate bool, - ) (bool, error) { - auth, err := unmarshalAuthorization(k.cdc, value) + authorizations, pageRes, err := query.GenericFilteredPaginate(k.cdc, store, req.Pagination, func(key []byte, auth *authz.Grant) (*authz.GrantAuthorization, error) { + auth1 := auth.GetAuthorization() if err != nil { - return false, err + return nil, err } granter, g := addressesFromGrantStoreKey(append(GrantKey, key...)) if !g.Equals(grantee) { - return false, nil + return nil, nil } - auth1 := auth.GetAuthorization() - if accumulate { - any, err := codectypes.NewAnyWithValue(auth1) - if err != nil { - return false, status.Errorf(codes.Internal, err.Error()) - } - - authorizations = append(authorizations, &authz.GrantAuthorization{ - Authorization: any, - Expiration: auth.Expiration, - Granter: granter.String(), - Grantee: grantee.String(), - }) + authorizationAny, err := codectypes.NewAnyWithValue(auth1) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) } - return true, nil + + return &authz.GrantAuthorization{ + Authorization: authorizationAny, + Expiration: auth.Expiration, + Granter: granter.String(), + Grantee: grantee.String(), + }, nil + }, func() *authz.Grant { + return &authz.Grant{} }) if err != nil { return nil, err @@ -194,9 +176,3 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe Pagination: pageRes, }, nil } - -// unmarshal an authorization from a store value -func unmarshalAuthorization(cdc codec.BinaryCodec, value []byte) (v authz.Grant, err error) { - err = cdc.Unmarshal(value, &v) - return v, err -} diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index f10163b27a24..92bc17be815d 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -214,7 +214,8 @@ func (suite *TestSuite) TestGRPCQueryGranterGrants() { }, { "valid case, pagination", - func() {}, + func() { + }, false, authz.QueryGranterGrantsRequest{ Granter: addrs[0].String(), @@ -273,6 +274,15 @@ func (suite *TestSuite) TestGRPCQueryGranteeGrants() { }, 1, }, + { + "valid case, no authorization found", + func() {}, + false, + authz.QueryGranteeGrantsRequest{ + Grantee: addrs[2].String(), + }, + 0, + }, { "valid case, multiple authorization", func() { From 1608eff15d83f2723940858b8c0867fda81196cb Mon Sep 17 00:00:00 2001 From: John Letey Date: Wed, 29 Jun 2022 13:40:18 +0200 Subject: [PATCH 8/8] chore: correctly install `tparse` in workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d9ceb298871..ac96013b1833 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: run: go version - name: install tparse run: | - export GO111MODULE="on" && go get github.com/mfridman/tparse@v0.8.3 + export GO111MODULE="on" && go install github.com/mfridman/tparse@v0.8.3 - uses: actions/cache@v2.1.6 with: path: ~/go/bin