From 60122a2d76948616829c267a05822d3a8a8042dc Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 14 Jun 2023 23:20:54 +0200 Subject: [PATCH 01/17] build(deps): bump cometbft to v0.34.29 (#16553) --- CHANGELOG.md | 6 +++++- RELEASE_NOTES.md | 11 ++++------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 946863844363..5697dfed413b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,9 +37,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (deps) [#16553](https://github.com/cosmos/cosmos-sdk/pull/16553) Bump CometBFT to [v0.34.29](https://github.com/cometbft/cometbft/blob/v0.34.29/CHANGELOG.md#v03429). + ## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08 -## Features +### Features * (snapshots) [#16060](https://github.com/cosmos/cosmos-sdk/pull/16060) Support saving and restoring snapshot locally. * (baseapp) [#16290](https://github.com/cosmos/cosmos-sdk/pull/16290) Add circuit breaker setter in baseapp. diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 27610b6ec13a..681d9696f68b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,9 +1,6 @@ -# Cosmos SDK v0.46.13 Release Notes +# Cosmos SDK v0.46.14 Release Notes -This release includes few improvements and bug fixes. -Notably, the [barberry security fix](https://forum.cosmos.network/t/cosmos-sdk-security-advisory-barberry/10825). All chains using Cosmos SDK v0.46.0 and above must upgrade to `v0.46.13` **immediately**. A chain is safe as soon as **33%+1** of the voting power has upgraded. Coordinate with your validators to upgrade as soon as possible. - -Additionally, it includes new commands for snapshots management and bootstrapping from a local snapshot (add `snapshot.Cmd(appCreator)` to the chain root command for using it). + Did you know Cosmos SDK Twilight (a.k.a v0.47) has been released? Upgrade easily by reading the [upgrading guide](https://github.com/cosmos/cosmos-sdk/blob/release/v0.47.x/UPGRADING.md#v047x). @@ -11,11 +8,11 @@ Ensure you have the following replaces in the `go.mod` of your application: ```go // use cometbft -replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 +replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29 // replace broken goleveldb replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ``` Please see the [CHANGELOG](https://github.com/cosmos/cosmos-sdk/blob/release/v0.46.x/CHANGELOG.md) for an exhaustive list of changes. -**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.46.12...v0.46.13 +**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.46.13...v0.46.14 diff --git a/go.mod b/go.mod index 3aaf3c199e8a..c212610d9396 100644 --- a/go.mod +++ b/go.mod @@ -174,7 +174,7 @@ replace ( // replace broken goleveldb. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // use cometbft - github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 + github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29 ) retract ( diff --git a/go.sum b/go.sum index 1035a8293d2f..cd25d3acdee9 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,8 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= -github.com/cometbft/cometbft v0.34.28 h1:gwryf55P1SWMUP4nOXpRVI2D0yPoYEzN+IBqmRBOsDc= -github.com/cometbft/cometbft v0.34.28/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= +github.com/cometbft/cometbft v0.34.29 h1:Q4FqMevP9du2pOgryZJHpDV2eA6jg/kMYxBj9ZTY6VQ= +github.com/cometbft/cometbft v0.34.29/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= From f34e99d2f1d3b627e73e115efd9bd01099f1b40c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 11:06:02 +0000 Subject: [PATCH 02/17] fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.Validate (backport #16554) (#16570) Co-authored-by: Emmanuel T Odeke Co-authored-by: Julien Robert --- CHANGELOG.md | 4 ++++ x/auth/types/account.go | 4 ++++ x/auth/types/account_test.go | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5697dfed413b..122dd9a9fbe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (deps) [#16553](https://github.com/cosmos/cosmos-sdk/pull/16553) Bump CometBFT to [v0.34.29](https://github.com/cometbft/cometbft/blob/v0.34.29/CHANGELOG.md#v03429). +### Bug Fixes + +* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. + ## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08 ### Features diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 104fe0e4d333..36f043d80244 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -225,6 +225,10 @@ func (ma ModuleAccount) Validate() error { return errors.New("module account name cannot be blank") } + if ma.BaseAccount == nil { + return errors.New("uninitialized ModuleAccount: BaseAccount is nil") + } + if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() { return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index ad24595c3fcf..3cdeaae6fb8d 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -209,3 +209,8 @@ func TestGenesisAccountsContains(t *testing.T) { genAccounts = append(genAccounts, acc) require.True(t, genAccounts.Contains(acc.GetAddress())) } + +func TestModuleAccountValidateNilBaseAccount(t *testing.T) { + ma := &types.ModuleAccount{Name: "foo"} + _ = ma.Validate() +} From 56df2b2e33a120a248addbad3cd7fab6bddb5c7b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 09:45:11 +0200 Subject: [PATCH 03/17] fix: snapshotter's failure is not propogated (backport #16588) (#16604) Co-authored-by: yihuang --- CHANGELOG.md | 1 + snapshots/chunk.go | 8 +++++--- snapshots/helpers_test.go | 32 ++++++++++++++++++++++++++++++++ snapshots/manager_test.go | 12 ++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 122dd9a9fbe8..9a7388571089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. +* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before). ## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08 diff --git a/snapshots/chunk.go b/snapshots/chunk.go index 74503f058027..af05303b4536 100644 --- a/snapshots/chunk.go +++ b/snapshots/chunk.go @@ -58,11 +58,13 @@ func (w *ChunkWriter) Close() error { // CloseWithError closes the writer and sends an error to the reader. func (w *ChunkWriter) CloseWithError(err error) { if !w.closed { + if w.pipe == nil { + // create a dummy pipe just to propagate the error to the reader, it always returns nil + _ = w.chunk() + } w.closed = true close(w.ch) - if w.pipe != nil { - _ = w.pipe.CloseWithError(err) // CloseWithError always returns nil - } + _ = w.pipe.CloseWithError(err) // CloseWithError always returns nil } } diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 24051a17a927..04448bc0e02a 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -158,6 +158,38 @@ func (m *mockSnapshotter) SetSnapshotInterval(snapshotInterval uint64) { m.snapshotInterval = snapshotInterval } +type mockErrorSnapshotter struct{} + +var _ snapshottypes.Snapshotter = (*mockErrorSnapshotter)(nil) + +func (m *mockErrorSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) error { + return errors.New("mock snapshot error") +} + +func (m *mockErrorSnapshotter) Restore( + height uint64, format uint32, protoReader protoio.Reader, +) (snapshottypes.SnapshotItem, error) { + return snapshottypes.SnapshotItem{}, errors.New("mock restore error") +} + +func (m *mockErrorSnapshotter) SnapshotFormat() uint32 { + return snapshottypes.CurrentFormat +} + +func (m *mockErrorSnapshotter) SupportedFormats() []uint32 { + return []uint32{snapshottypes.CurrentFormat} +} + +func (m *mockErrorSnapshotter) PruneSnapshotHeight(height int64) { +} + +func (m *mockErrorSnapshotter) GetSnapshotInterval() uint64 { + return 0 +} + +func (m *mockErrorSnapshotter) SetSnapshotInterval(snapshotInterval uint64) { +} + // setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1. // The snapshot will complete when the returned closer is called. func setupBusyManager(t *testing.T) *snapshots.Manager { diff --git a/snapshots/manager_test.go b/snapshots/manager_test.go index d379f09cb9f1..d41819e3f136 100644 --- a/snapshots/manager_test.go +++ b/snapshots/manager_test.go @@ -7,9 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/snapshots/types" + "github.com/cosmos/cosmos-sdk/testutil" ) var opts = types.NewSnapshotOptions(1500, 2) @@ -235,3 +237,13 @@ func TestManager_Restore(t *testing.T) { }) require.NoError(t, err) } + +func TestManager_TakeError(t *testing.T) { + snapshotter := &mockErrorSnapshotter{} + store, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t)) + require.NoError(t, err) + manager := snapshots.NewManager(store, opts, snapshotter, nil, log.NewNopLogger()) + + _, err = manager.Create(1) + require.Error(t, err) +} From a7631357d81ad9844bc721aa713b9d855fbb56e5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 28 Jun 2023 19:30:09 +0000 Subject: [PATCH 04/17] feat: add custom max gas for block for sim config (backport #16656) (#16731) Co-authored-by: mmsqe Co-authored-by: marbar3778 --- CHANGELOG.md | 4 ++++ types/simulation/config.go | 3 ++- x/simulation/params.go | 4 ++-- x/simulation/simulate.go | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a7388571089..dde8d8e5a977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +* (sims) [#16656](https://github.com/cosmos/cosmos-sdk/pull/16656) Add custom max gas for block for sim config with unlimited as default. + ### Improvements * (deps) [#16553](https://github.com/cosmos/cosmos-sdk/pull/16553) Bump CometBFT to [v0.34.29](https://github.com/cometbft/cometbft/blob/v0.34.29/CHANGELOG.md#v03429). diff --git a/types/simulation/config.go b/types/simulation/config.go index 7f520004d478..4ed9530a92bc 100644 --- a/types/simulation/config.go +++ b/types/simulation/config.go @@ -22,5 +22,6 @@ type Config struct { OnOperation bool // run slow invariants every operation AllInvariants bool // print all failed invariants if a broken invariant is found - DBBackend string // custom db backend type + DBBackend string // custom db backend type + BlockMaxGas int64 // custom max gas for block } diff --git a/x/simulation/params.go b/x/simulation/params.go index 51dfb6439f10..f1346535eec3 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -151,7 +151,7 @@ func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulato // Param change proposals // randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state. -func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *abci.ConsensusParams { +func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec, maxGas int64) *abci.ConsensusParams { var genesisState map[string]json.RawMessage err := json.Unmarshal(appState, &genesisState) if err != nil { @@ -162,7 +162,7 @@ func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSO consensusParams := &abci.ConsensusParams{ Block: &abci.BlockParams{ MaxBytes: int64(simulation.RandIntBetween(r, 20000000, 30000000)), - MaxGas: -1, + MaxGas: maxGas, }, Validator: &tmproto.ValidatorParams{ PubKeyTypes: []string{types.ABCIPubKeyTypeEd25519}, diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index e1ee5ffced24..5fd3975815d8 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -31,8 +31,12 @@ func initChain( config simulation.Config, cdc codec.JSONCodec, ) (mockValidators, time.Time, []simulation.Account, string) { + blockMaxGas := int64(-1) + if config.BlockMaxGas > 0 { + blockMaxGas = config.BlockMaxGas + } appState, accounts, chainID, genesisTimestamp := appStateFn(r, accounts, config) - consensusParams := randomConsensusParams(r, appState, cdc) + consensusParams := randomConsensusParams(r, appState, cdc, blockMaxGas) req := abci.RequestInitChain{ AppStateBytes: appState, ChainId: chainID, From b39cdb2e74ad46e5e6ed31cea223cce0ed7601a6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:32:28 +0200 Subject: [PATCH 05/17] fix: accaddr cachefix (backport #15433) (#16823) Co-authored-by: KyleMoser Co-authored-by: HuangYi --- CHANGELOG.md | 1 + types/address.go | 61 +++++++++++++++++++++++++++---------- types/address_test.go | 71 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dde8d8e5a977..f9f2deaef376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. * [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before). +* (types) [#15433](https://github.com/cosmos/cosmos-sdk/pull/15433) Allow disabling of account address caches (for printing bech32 account addresses). ## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08 diff --git a/types/address.go b/types/address.go index 2212e1e23545..08af3ec4655b 100644 --- a/types/address.go +++ b/types/address.go @@ -8,6 +8,7 @@ import ( "fmt" "strings" "sync" + "sync/atomic" "github.com/hashicorp/golang-lru/simplelru" "sigs.k8s.io/yaml" @@ -83,6 +84,8 @@ var ( consAddrCache *simplelru.LRU valAddrMu sync.Mutex valAddrCache *simplelru.LRU + + isCachingEnabled atomic.Bool ) // sentinel errors @@ -92,6 +95,8 @@ var ( func init() { var err error + SetAddrCacheEnabled(true) + // in total the cache size is 61k entries. Key is 32 bytes and value is around 50-70 bytes. // That will make around 92 * 61k * 2 (LRU) bytes ~ 11 MB if accAddrCache, err = simplelru.NewLRU(60000, nil); err != nil { @@ -105,6 +110,16 @@ func init() { } } +// SetAddrCacheEnabled enables or disables accAddrCache, consAddrCache, and valAddrCache. By default, caches are enabled. +func SetAddrCacheEnabled(enabled bool) { + isCachingEnabled.Store(enabled) +} + +// IsAddrCacheEnabled returns if the address caches are enabled. +func IsAddrCacheEnabled() bool { + return isCachingEnabled.Load() +} + // Address is a common interface for different types of addresses used by the SDK type Address interface { Equals(Address) bool @@ -285,11 +300,15 @@ func (aa AccAddress) String() string { } key := conv.UnsafeBytesToStr(aa) - accAddrMu.Lock() - defer accAddrMu.Unlock() - addr, ok := accAddrCache.Get(key) - if ok { - return addr.(string) + + if IsAddrCacheEnabled() { + accAddrMu.Lock() + defer accAddrMu.Unlock() + + addr, ok := accAddrCache.Get(key) + if ok { + return addr.(string) + } } return cacheBech32Addr(GetConfig().GetBech32AccountAddrPrefix(), aa, accAddrCache, key) } @@ -435,11 +454,15 @@ func (va ValAddress) String() string { } key := conv.UnsafeBytesToStr(va) - valAddrMu.Lock() - defer valAddrMu.Unlock() - addr, ok := valAddrCache.Get(key) - if ok { - return addr.(string) + + if IsAddrCacheEnabled() { + valAddrMu.Lock() + defer valAddrMu.Unlock() + + addr, ok := valAddrCache.Get(key) + if ok { + return addr.(string) + } } return cacheBech32Addr(GetConfig().GetBech32ValidatorAddrPrefix(), va, valAddrCache, key) } @@ -590,11 +613,15 @@ func (ca ConsAddress) String() string { } key := conv.UnsafeBytesToStr(ca) - consAddrMu.Lock() - defer consAddrMu.Unlock() - addr, ok := consAddrCache.Get(key) - if ok { - return addr.(string) + + if IsAddrCacheEnabled() { + consAddrMu.Lock() + defer consAddrMu.Unlock() + + addr, ok := consAddrCache.Get(key) + if ok { + return addr.(string) + } } return cacheBech32Addr(GetConfig().GetBech32ConsensusAddrPrefix(), ca, consAddrCache, key) } @@ -674,6 +701,8 @@ func cacheBech32Addr(prefix string, addr []byte, cache *simplelru.LRU, cacheKey if err != nil { panic(err) } - cache.Add(cacheKey, bech32Addr) + if IsAddrCacheEnabled() { + cache.Add(cacheKey, bech32Addr) + } return bech32Addr } diff --git a/types/address_test.go b/types/address_test.go index 18bb929c61fa..06a23a14d21c 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -125,6 +125,77 @@ func (s *addressTestSuite) TestRandBech32AccAddrConsistency() { s.Require().Equal(types.ErrEmptyHexAddress, err) } +// Test that the account address cache ignores the bech32 prefix setting, retrieving bech32 addresses from the cache. +// This will cause the AccAddress.String() to print out unexpected prefixes if the config was changed between bech32 lookups. +// See https://github.com/cosmos/cosmos-sdk/issues/15317. +func (s *addressTestSuite) TestAddrCache() { + // Use a random key + pubBz := make([]byte, ed25519.PubKeySize) + pub := &ed25519.PubKey{Key: pubBz} + rand.Read(pub.Key) + + // Set SDK bech32 prefixes to 'osmo' + prefix := "osmo" + conf := types.GetConfig() + conf.SetBech32PrefixForAccount(prefix, prefix+"pub") + conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub") + conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub") + + acc := types.AccAddress(pub.Address()) + osmoAddrBech32 := acc.String() + + // Set SDK bech32 to 'cosmos' + prefix = "cosmos" + conf.SetBech32PrefixForAccount(prefix, prefix+"pub") + conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub") + conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub") + + // We name this 'addrCosmos' to prove a point, but the bech32 address will still begin with 'osmo' due to the cache behavior. + addrCosmos := types.AccAddress(pub.Address()) + cosmosAddrBech32 := addrCosmos.String() + + // The default behavior will retrieve the bech32 address from the cache, ignoring the bech32 prefix change. + s.Require().Equal(osmoAddrBech32, cosmosAddrBech32) + s.Require().True(strings.HasPrefix(osmoAddrBech32, "osmo")) + s.Require().True(strings.HasPrefix(cosmosAddrBech32, "osmo")) +} + +// Test that the bech32 prefix is respected when the address cache is disabled. +// This causes AccAddress.String() to print out the expected prefixes if the config is changed between bech32 lookups. +// See https://github.com/cosmos/cosmos-sdk/issues/15317. +func (s *addressTestSuite) TestAddrCacheDisabled() { + types.SetAddrCacheEnabled(false) + + // Use a random key + pubBz := make([]byte, ed25519.PubKeySize) + pub := &ed25519.PubKey{Key: pubBz} + rand.Read(pub.Key) + + // Set SDK bech32 prefixes to 'osmo' + prefix := "osmo" + conf := types.GetConfig() + conf.SetBech32PrefixForAccount(prefix, prefix+"pub") + conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub") + conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub") + + acc := types.AccAddress(pub.Address()) + osmoAddrBech32 := acc.String() + + // Set SDK bech32 to 'cosmos' + prefix = "cosmos" + conf.SetBech32PrefixForAccount(prefix, prefix+"pub") + conf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub") + conf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub") + + addrCosmos := types.AccAddress(pub.Address()) + cosmosAddrBech32 := addrCosmos.String() + + // retrieve the bech32 address from the cache, respecting the bech32 prefix change. + s.Require().NotEqual(osmoAddrBech32, cosmosAddrBech32) + s.Require().True(strings.HasPrefix(osmoAddrBech32, "osmo")) + s.Require().True(strings.HasPrefix(cosmosAddrBech32, "cosmos")) +} + func (s *addressTestSuite) TestValAddr() { pubBz := make([]byte, ed25519.PubKeySize) pub := &ed25519.PubKey{Key: pubBz} From 74580474728ccb6df93833c55433584d29def783 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 7 Jul 2023 14:24:50 +0200 Subject: [PATCH 06/17] fix(cli): improve `prune` command ux (backport #16856) (#16876) Co-authored-by: Julien Robert --- CHANGELOG.md | 1 + client/pruning/main.go | 72 ++++++++++++++++++++++++----------------- simapp/simd/cmd/root.go | 2 +- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f2deaef376..557ba5be9ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (cli) [#16856](https://github.com/cosmos/cosmos-sdk/pull/16856) Improve `simd prune` UX by using the app default home directory and set pruning method as first variable argument (defaults to default). `pruning.PruningCmd` rest unchanged for API compability, use `pruning.Cmd` instead. * (deps) [#16553](https://github.com/cosmos/cosmos-sdk/pull/16553) Bump CometBFT to [v0.34.29](https://github.com/cometbft/cometbft/blob/v0.34.29/CHANGELOG.md#v03429). ### Bug Fixes diff --git a/client/pruning/main.go b/client/pruning/main.go index fb62dd21a050..655279412539 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -21,41 +21,60 @@ const FlagAppDBBackend = "app-db-backend" // PruningCmd prunes the sdk root multi store history versions based on the pruning options // specified by command flags. +// Deprecated: Use Cmd instead. func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command { + cmd := Cmd(appCreator, "") + cmd.Flags().String(server.FlagPruning, pruningtypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") + + return cmd +} + +// Cmd prunes the sdk root multi store history versions based on the pruning options +// specified by command flags. +func Cmd(appCreator servertypes.AppCreator, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ - Use: "prune", + Use: "prune [pruning-method]", Short: "Prune app history states by keeping the recent heights and deleting old heights", Long: `Prune app history states by keeping the recent heights and deleting old heights. - The pruning option is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent' - - For '--pruning' the options are as follows: - - default: the last 362880 states are kept - nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) - everything: 2 latest states will be kept - custom: allow pruning options to be manually specified through 'pruning-keep-recent'. - besides pruning options, database home directory and database backend type should also be specified via flags - '--home' and '--app-db-backend'. - valid app-db-backend type includes 'goleveldb', 'cleveldb', 'rocksdb', 'boltdb', and 'badgerdb'. - `, - Example: "prune --home './' --app-db-backend 'goleveldb' --pruning 'custom' --pruning-keep-recent 100", - RunE: func(cmd *cobra.Command, _ []string) error { - vp := viper.New() +The pruning option is provided via the 'pruning' argument or alternatively with '--pruning-keep-recent' - // Bind flags to the Context's Viper so we can get pruning options. +- default: the last 362880 states are kept +- nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) +- everything: 2 latest states will be kept +- custom: allow pruning options to be manually specified through 'pruning-keep-recent' + +Note: When the --app-db-backend flag is not specified, the default backend type is 'goleveldb'. +Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, + Example: "prune custom --pruning-keep-recent 100 --app-db-backend 'goleveldb'", + Args: cobra.RangeArgs(0, 1), + RunE: func(cmd *cobra.Command, args []string) error { + // bind flags to the Context's Viper so we can get pruning options. + vp := viper.New() if err := vp.BindPFlags(cmd.Flags()); err != nil { return err } + + // use the first argument if present to set the pruning method + if len(args) > 0 { + vp.Set(server.FlagPruning, args[0]) + } else if vp.GetString(server.FlagPruning) == "" { // this differs from orignal https://github.com/cosmos/cosmos-sdk/pull/16856 for compatibility + vp.Set(server.FlagPruning, pruningtypes.PruningOptionDefault) + } pruningOptions, err := server.GetPruningOptionsFromFlags(vp) if err != nil { return err } - fmt.Printf("get pruning options from command flags, strategy: %v, keep-recent: %v\n", + + cmd.Printf("get pruning options from command flags, strategy: %v, keep-recent: %v\n", pruningOptions.Strategy, pruningOptions.KeepRecent, ) home := vp.GetString(flags.FlagHome) + if home == "" { + home = defaultNodeHome + } + db, err := openDB(home, server.GetAppDBBackend(vp)) if err != nil { return err @@ -82,27 +101,22 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command { } } if len(pruningHeights) == 0 { - fmt.Printf("no heights to prune\n") + cmd.Println("no heights to prune") return nil } - fmt.Printf( - "pruning heights start from %v, end at %v\n", - pruningHeights[0], - pruningHeights[len(pruningHeights)-1], - ) + cmd.Printf("pruning heights start from %v, end at %v\n", pruningHeights[0], pruningHeights[len(pruningHeights)-1]) - err = rootMultiStore.PruneStores(false, pruningHeights) - if err != nil { + if err = rootMultiStore.PruneStores(false, pruningHeights); err != nil { return err } - fmt.Printf("successfully pruned the application root multi stores\n") + + cmd.Println("successfully pruned the application root multi stores") return nil }, } - cmd.Flags().String(flags.FlagHome, "", "The database home directory") + cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases") - cmd.Flags().String(server.FlagPruning, pruningtypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") cmd.Flags().Uint64(server.FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')") cmd.Flags().Uint64(server.FlagPruningInterval, 10, `Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom'), diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 03261d516ca1..fe232d65768d 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -169,7 +169,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { NewTestnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}), debug.Cmd(), config.Cmd(), - pruning.PruningCmd(a.newApp), + pruning.Cmd(a.newApp, simapp.DefaultNodeHome), snapshot.Cmd(a.newApp), ) From 38ea2823ad233c862142f643b9a63c5ebd3c5051 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Fri, 14 Jul 2023 03:02:29 -0400 Subject: [PATCH 07/17] fix: query tx events with `>=` and `<=` operators (#16994) --- x/auth/tx/service.go | 3 ++- x/auth/tx/service_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 6bc4c95120c0..52c788fd6c75 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -45,7 +45,8 @@ var ( _ txtypes.ServiceServer = txServer{} // EventRegex checks that an event string is formatted with {alphabetic}.{alphabetic}={value} - EventRegex = regexp.MustCompile(`^[a-zA-Z_]+\.[a-zA-Z_]+=\S+$`) + // Note: in addition to equality, the `>=` and `<=` operators are also valid. + EventRegex = regexp.MustCompile(`^[a-zA-Z_]+\.[a-zA-Z_]+[<>]?=\S+$`) ) const ( diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index e61abadd7a48..e80a3891ba74 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -184,6 +184,16 @@ func TestEventRegex(t *testing.T) { event: "tx.signature='foobar/baz123=='", match: true, }, + { + name: "valid: with >= operator", + event: "tx.height>=10'", + match: true, + }, + { + name: "valid: with <= operator", + event: "tx.height<=10'", + match: true, + }, } for _, tc := range testCases { From ffe7a5ed983364a05f752bb7ddac713979e888a4 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 10:36:31 +0200 Subject: [PATCH 08/17] docs: change bank multi-send command description (backport #16950) (#17019) --- x/bank/client/cli/tx.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 5deb617b8952..142f6e47afe8 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -74,15 +75,16 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. // For a better UX this command is limited to send funds from one account to two or more accounts. func NewMultiSendTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "multi-send [from_key_or_address] [to_address_1, to_address_2, ...] [amount]", + Use: "multi-send [from_key_or_address] [to_address_1 to_address_2 ...] [amount]", Short: "Send funds from one account to two or more accounts.", Long: `Send funds from one account to two or more accounts. By default, sends the [amount] to each address of the list. Using the '--split' flag, the [amount] is split equally between the addresses. -Note, the '--from' flag is ignored as it is implied from [from_key_or_address]. -When using '--dry-run' a key name cannot be used, only a bech32 address. -`, - Args: cobra.MinimumNArgs(4), +Note, the '--from' flag is ignored as it is implied from [from_key_or_address] and +separate addresses with space. +When using '--dry-run' a key name cannot be used, only a bech32 address.`, + Example: fmt.Sprintf("%s tx bank multi-send cosmos1... cosmos1... cosmos1... cosmos1... 10stake", version.AppName), + Args: cobra.MinimumNArgs(4), RunE: func(cmd *cobra.Command, args []string) error { cmd.Flags().Set(flags.FlagFrom, args[0]) clientCtx, err := client.GetClientTxContext(cmd) From 2a48f6d7a24b728ac64eafe0929bb8893cc23ccf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 17 Jul 2023 16:05:43 +0200 Subject: [PATCH 09/17] chore: prepare v0.46.14 (#16879) --- CHANGELOG.md | 5 ++++- RELEASE_NOTES.md | 4 +--- go.mod | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557ba5be9ea8..0c09d1af0240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v0.46.14](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-07-17 + ### Features * (sims) [#16656](https://github.com/cosmos/cosmos-sdk/pull/16656) Add custom max gas for block for sim config with unlimited as default. @@ -48,8 +50,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (x/auth) [#16994](https://github.com/cosmos/cosmos-sdk/pull/16994) Fix regression where querying transactions events with `<=` or `>=` would not work. * (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. -* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before). +* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate snapshotter failures to the caller, (it would create an empty snapshot silently before). * (types) [#15433](https://github.com/cosmos/cosmos-sdk/pull/15433) Allow disabling of account address caches (for printing bech32 account addresses). ## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 681d9696f68b..4577d6ab670a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,8 +1,6 @@ # Cosmos SDK v0.46.14 Release Notes - - -Did you know Cosmos SDK Twilight (a.k.a v0.47) has been released? Upgrade easily by reading the [upgrading guide](https://github.com/cosmos/cosmos-sdk/blob/release/v0.47.x/UPGRADING.md#v047x). +This patch release introduces a few bug fixes and improvements to the v0.46.x line of the Cosmos SDK. Notably, an improvement to ` prune` UX and improving the error handling when there is a snapshot creation failure. Ensure you have the following replaces in the `go.mod` of your application: diff --git a/go.mod b/go.mod index c212610d9396..582d644db1d8 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/spf13/viper v1.13.0 github.com/stretchr/testify v1.8.2 github.com/tendermint/go-amino v0.16.0 - github.com/tendermint/tendermint v0.34.28 + github.com/tendermint/tendermint v0.34.29 github.com/tendermint/tm-db v0.6.7 github.com/tidwall/btree v1.5.0 golang.org/x/crypto v0.7.0 From 16d52690792e6e9446097ca5b48179a01a0c24e9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 09:03:09 +0000 Subject: [PATCH 10/17] refactor: add MigrateHandler to allow reuse migrate genesis related function (backport #17296) (#17301) Co-authored-by: mmsqe Co-authored-by: Julien Robert --- CHANGELOG.md | 5 ++ x/genutil/client/cli/migrate.go | 140 +++++++++++++++++--------------- 2 files changed, 78 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c09d1af0240..9bd17d1a2cf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. + * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. + ## [v0.46.14](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-07-17 ### Features diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index c16fcb843d06..ee7816e12085 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -62,73 +62,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 `, version.AppName), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - var err error - - target := args[0] - importGenesis := args[1] - - genDoc, err := validateGenDoc(importGenesis) - if err != nil { - return err - } - - // Since some default values are valid values, we just print to - // make sure the user didn't forget to update these values. - if genDoc.ConsensusParams.Evidence.MaxBytes == 0 { - fmt.Printf("Warning: consensus_params.evidence.max_bytes is set to 0. If this is"+ - " deliberate, feel free to ignore this warning. If not, please have a look at the chain"+ - " upgrade guide at %s.\n", chainUpgradeGuide) - } - - var initialState types.AppMap - if err := json.Unmarshal(genDoc.AppState, &initialState); err != nil { - return errors.Wrap(err, "failed to JSON unmarshal initial genesis state") - } - - migrationFunc := GetMigrationCallback(target) - if migrationFunc == nil { - return fmt.Errorf("unknown migration function for version: %s", target) - } - - // TODO: handler error from migrationFunc call - newGenState := migrationFunc(initialState, clientCtx) - - genDoc.AppState, err = json.Marshal(newGenState) - if err != nil { - return errors.Wrap(err, "failed to JSON marshal migrated genesis state") - } - - genesisTime, _ := cmd.Flags().GetString(flagGenesisTime) - if genesisTime != "" { - var t time.Time - - err := t.UnmarshalText([]byte(genesisTime)) - if err != nil { - return errors.Wrap(err, "failed to unmarshal genesis time") - } - - genDoc.GenesisTime = t - } - - chainID, _ := cmd.Flags().GetString(flags.FlagChainID) - if chainID != "" { - genDoc.ChainID = chainID - } - - bz, err := tmjson.Marshal(genDoc) - if err != nil { - return errors.Wrap(err, "failed to marshal genesis doc") - } - - sortedBz, err := sdk.SortJSON(bz) - if err != nil { - return errors.Wrap(err, "failed to sort JSON genesis doc") - } - - cmd.Println(string(sortedBz)) - return nil + return MigrateHandler(cmd, args, migrationMap) }, } @@ -137,3 +71,75 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 return cmd } + +// MigrateHandler handles the migration command with a migration map as input, +// returning an error upon failure. +func MigrateHandler(cmd *cobra.Command, args []string, migrations types.MigrationMap) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + var err error + + target := args[0] + importGenesis := args[1] + + genDoc, err := validateGenDoc(importGenesis) + if err != nil { + return err + } + + // Since some default values are valid values, we just print to + // make sure the user didn't forget to update these values. + if genDoc.ConsensusParams.Evidence.MaxBytes == 0 { + fmt.Printf("Warning: consensus_params.evidence.max_bytes is set to 0. If this is"+ + " deliberate, feel free to ignore this warning. If not, please have a look at the chain"+ + " upgrade guide at %s.\n", chainUpgradeGuide) + } + + var initialState types.AppMap + if err := json.Unmarshal(genDoc.AppState, &initialState); err != nil { + return errors.Wrap(err, "failed to JSON unmarshal initial genesis state") + } + + migrationFunc := GetMigrationCallback(target) + if migrationFunc == nil { + return fmt.Errorf("unknown migration function for version: %s", target) + } + + // TODO: handler error from migrationFunc call + newGenState := migrationFunc(initialState, clientCtx) + + genDoc.AppState, err = json.Marshal(newGenState) + if err != nil { + return errors.Wrap(err, "failed to JSON marshal migrated genesis state") + } + + genesisTime, _ := cmd.Flags().GetString(flagGenesisTime) + if genesisTime != "" { + var t time.Time + + err := t.UnmarshalText([]byte(genesisTime)) + if err != nil { + return errors.Wrap(err, "failed to unmarshal genesis time") + } + + genDoc.GenesisTime = t + } + + chainID, _ := cmd.Flags().GetString(flags.FlagChainID) + if chainID != "" { + genDoc.ChainID = chainID + } + + bz, err := tmjson.Marshal(genDoc) + if err != nil { + return errors.Wrap(err, "failed to marshal genesis doc") + } + + sortedBz, err := sdk.SortJSON(bz) + if err != nil { + return errors.Wrap(err, "failed to sort JSON genesis doc") + } + + cmd.Println(string(sortedBz)) + return nil +} From 537257060180220f8eafa318d28d67c5b0268620 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 7 Aug 2023 18:45:42 +0800 Subject: [PATCH 11/17] fix: resolve migration map in MigrateHandler (#17301) (#17302) --- x/genutil/client/cli/migrate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index ee7816e12085..33b2d0c760b2 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -100,7 +100,7 @@ func MigrateHandler(cmd *cobra.Command, args []string, migrations types.Migratio return errors.Wrap(err, "failed to JSON unmarshal initial genesis state") } - migrationFunc := GetMigrationCallback(target) + migrationFunc := migrations[target] if migrationFunc == nil { return fmt.Errorf("unknown migration function for version: %s", target) } From dd028ed35d7c86807f10ecb0f2699ceadde0dca8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 08:39:23 +0000 Subject: [PATCH 12/17] feat(x/gov): Emit VoterAddr (backport #17354) (#17357) Co-authored-by: Devon Bear Co-authored-by: Julien Robert --- CHANGELOG.md | 1 + x/gov/keeper/vote.go | 1 + x/gov/types/events.go | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd17d1a2cf4..9d0448dcdbac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (x/gov) [#17354](https://github.com/cosmos/cosmos-sdk/issues/17354) Emit `VoterAddr` in `proposal_vote` event. * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. diff --git a/x/gov/keeper/vote.go b/x/gov/keeper/vote.go index 4e2436ff84b5..8fa690eeca87 100644 --- a/x/gov/keeper/vote.go +++ b/x/gov/keeper/vote.go @@ -38,6 +38,7 @@ func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeProposalVote, + sdk.NewAttribute(types.AttributeKeyVoter, voterAddr.String()), sdk.NewAttribute(types.AttributeKeyOption, options.String()), sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)), ), diff --git a/x/gov/types/events.go b/x/gov/types/events.go index 7217e7e38793..9468c0fc9862 100644 --- a/x/gov/types/events.go +++ b/x/gov/types/events.go @@ -10,6 +10,7 @@ const ( EventTypeSignalProposal = "signal_proposal" AttributeKeyProposalResult = "proposal_result" + AttributeKeyVoter = "voter" AttributeKeyOption = "option" AttributeKeyProposalID = "proposal_id" AttributeKeyProposalMessages = "proposal_messages" // Msg type_urls in the proposal From 6f486fd40cf22c7f66c5b704860d03f8f5d3ca25 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:02:41 +0000 Subject: [PATCH 13/17] feat(x/gov): add MsgSubmitProposal SetMsgs method (backport #17387) (#17388) Co-authored-by: Julien Robert --- CHANGELOG.md | 1 + x/gov/types/v1/msgs.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0448dcdbac..6a3e86401617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method. * (x/gov) [#17354](https://github.com/cosmos/cosmos-sdk/issues/17354) Emit `VoterAddr` in `proposal_vote` event. * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index dd83bf5dfa47..e78121b0ab19 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -40,6 +40,18 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) { return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") } +// SetMsgs packs sdk.Msg's into m.Messages Any's +// NOTE: this will overwrite any existing messages +func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error { + anys, err := sdktx.SetMsgs(msgs) + if err != nil { + return err + } + + m.Messages = anys + return nil +} + // Route implements Msg func (m MsgSubmitProposal) Route() string { return types.RouterKey } From f83dca028c10eaad117a07793f6187d864e47ac5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 21:47:16 +0200 Subject: [PATCH 14/17] fix: use correct config key for db_backend (backport #17406) (#17412) Co-authored-by: Julien Robert --- CHANGELOG.md | 4 ++++ server/util.go | 2 +- server/util_test.go | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3e86401617..333d98858146 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. +## Bug Fixes + +* (server) [#17181](https://github.com/cosmos/cosmos-sdk/pull/17181) Fix `db_backend` lookup fallback from `config.toml`. + ## [v0.46.14](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-07-17 ### Features diff --git a/server/util.go b/server/util.go index b28e339bff5f..be3103a7a74a 100644 --- a/server/util.go +++ b/server/util.go @@ -371,7 +371,7 @@ func GetAppDBBackend(opts types.AppOptions) dbm.BackendType { rv = sdk.DBBackend } if len(rv) == 0 { - rv = cast.ToString(opts.Get("db-backend")) + rv = cast.ToString(opts.Get("db_backend")) } if len(rv) != 0 { return dbm.BackendType(rv) diff --git a/server/util_test.go b/server/util_test.go index 630a2795dc3f..4f89b73f9faa 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -470,10 +470,10 @@ func TestGetAppDBBackend(t *testing.T) { }, { - name: "only db-backend set", + name: "only db_backend set", dbBack: "", - opts: mapGetter{"db-backend": "db-backend value 1"}, - exp: dbm.BackendType("db-backend value 1"), + opts: mapGetter{"db_backend": "db_backend value 1"}, + exp: dbm.BackendType("db_backend value 1"), }, { name: "only DBBackend set", @@ -491,7 +491,7 @@ func TestGetAppDBBackend(t *testing.T) { { name: "app-db-backend and db-backend set", dbBack: "", - opts: mapGetter{"db-backend": "db-backend value 4", "app-db-backend": "app-db-backend value 5"}, + opts: mapGetter{"db_backend": "db_backend value 4", "app-db-backend": "app-db-backend value 5"}, exp: dbm.BackendType("app-db-backend value 5"), }, { @@ -501,16 +501,16 @@ func TestGetAppDBBackend(t *testing.T) { exp: dbm.BackendType("app-db-backend value 7"), }, { - name: "db-backend and DBBackend set", + name: "db_backend and DBBackend set", dbBack: "DBBackend value 8", - opts: mapGetter{"db-backend": "db-backend value 9"}, + opts: mapGetter{"db_backend": "db_backend value 9"}, exp: dbm.BackendType("DBBackend value 8"), }, { name: "all of app-db-backend db-backend DBBackend set", dbBack: "DBBackend value 10", - opts: mapGetter{"db-backend": "db-backend value 11", "app-db-backend": "app-db-backend value 12"}, + opts: mapGetter{"db_backend": "db_backend value 11", "app-db-backend": "app-db-backend value 12"}, exp: dbm.BackendType("app-db-backend value 12"), }, } From d6d929843bbd331b885467475bcb3050788e30ca Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 21 Aug 2023 10:08:16 +0200 Subject: [PATCH 15/17] chore: prepare v0.46.15 (#17408) --- CHANGELOG.md | 2 ++ RELEASE_NOTES.md | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 333d98858146..8f0d56d069bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v0.46.15](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-08-21 + ### Improvements * (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method. diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4577d6ab670a..40f7869d8a7c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,6 @@ -# Cosmos SDK v0.46.14 Release Notes +# Cosmos SDK v0.46.15 Release Notes -This patch release introduces a few bug fixes and improvements to the v0.46.x line of the Cosmos SDK. Notably, an improvement to ` prune` UX and improving the error handling when there is a snapshot creation failure. +This patch release introduces a few bug fixes and improvements to the v0.46.x line of the Cosmos SDK. Ensure you have the following replaces in the `go.mod` of your application: @@ -11,6 +11,11 @@ replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.2 replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ``` -Please see the [CHANGELOG](https://github.com/cosmos/cosmos-sdk/blob/release/v0.46.x/CHANGELOG.md) for an exhaustive list of changes. +Please see the [CHANGELOG](https://github.com/cosmos/cosmos-sdk/blob/v0.46.15/CHANGELOG.md) for an exhaustive list of changes. -**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.46.13...v0.46.14 +**Full Commit History**: https://github.com/cosmos/cosmos-sdk/compare/v0.46.14...v0.46.15 + +## Deprecation Notice + +Get ready for v0.50.0 and start integrating with the next [Cosmos SDK](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-rc.0) release. +Once the Eden release is out, as per our [maintenance policy](https://github.com/cosmos/cosmos-sdk/blob/main/RELEASE_PROCESS.md#major-release-maintenance) we will no longer support the v0.46.x line of the Cosmos SDK, apart from critical security fixes. From 22c28366466e64ebf0df1ce5bec8b1130523552c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 24 Aug 2023 19:53:38 +0000 Subject: [PATCH 16/17] fix(x/authz): GetAuthorizations (backport #17334) (#17527) Co-authored-by: devon <80245700+devon-chain@users.noreply.github.com> Co-authored-by: Julien Robert --- CHANGELOG.md | 6 +++++- x/authz/keeper/keeper.go | 2 +- x/authz/keeper/keeper_test.go | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f0d56d069bb..882d02bb8d7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* (x/authz) [#17524](https://github.com/cosmos/cosmos-sdk/pull/17524) Fix an issue where the `cachedValue` of an authorization would not be correcty populated when there are multiple authorizations returned in `GetAuthorizations`. + ## [v0.46.15](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-08-21 ### Improvements @@ -46,7 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. -## Bug Fixes +### Bug Fixes * (server) [#17181](https://github.com/cosmos/cosmos-sdk/pull/17181) Fix `db_backend` lookup fallback from `config.toml`. diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index c1291c95708f..0b0bf29ef8ee 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -233,9 +233,9 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant iter := sdk.KVStorePrefixIterator(store, key) defer iter.Close() - var authorization authz.Grant var authorizations []authz.Authorization for ; iter.Valid(); iter.Next() { + var authorization authz.Grant if err := k.cdc.Unmarshal(iter.Value(), &authorization); err != nil { return nil, err } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index fdf8d5d08135..f10119361afe 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -445,6 +445,27 @@ func (s *TestSuite) TestGetAuthorization() { } } +func (s *TestSuite) TestGetAuthorizations() { + require := s.Require() + addr1 := s.addrs[1] + addr2 := s.addrs[2] + + genAuthMulti := authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgMultiSend{})) + genAuthSend := authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgSend{})) + + start := s.ctx.BlockHeader().Time + expired := start.Add(time.Duration(1) * time.Second) + + s.Require().NoError(s.app.AuthzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, &expired), "creating multi send grant 1->2") + s.Require().NoError(s.app.AuthzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthSend, &expired), "creating send grant 1->2") + + authzs, err := s.app.AuthzKeeper.GetAuthorizations(s.ctx, addr1, addr2) + require.NoError(err) + require.Len(authzs, 2) + require.Equal(sdk.MsgTypeURL(&banktypes.MsgMultiSend{}), authzs[0].MsgTypeURL()) + require.Equal(sdk.MsgTypeURL(&banktypes.MsgSend{}), authzs[1].MsgTypeURL()) +} + func TestTestSuite(t *testing.T) { suite.Run(t, new(TestSuite)) } From 7aec30d3e9993ba09ce6b647f93b64c8500001b5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:26:00 +0000 Subject: [PATCH 17/17] docs: update x/group create-proposal to submit-proposal (backport #17544) (#17549) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: FĂ©lix C. Morency <1102868+fmorency@users.noreply.github.com> --- x/group/spec/05_client.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/group/spec/05_client.md b/x/group/spec/05_client.md index 4df6b42731a1..b4543cfc1a22 100644 --- a/x/group/spec/05_client.md +++ b/x/group/spec/05_client.md @@ -537,18 +537,18 @@ Example: simd tx group update-group-policy-decision-policy cosmos1.. cosmos1.. '{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"2", "windows": {"voting_period": "120h", "min_execution_period": "0s"}}' ``` -#### create-proposal +#### submit-proposal -The `create-proposal` command allows users to submit a new proposal. +The `submit-proposal` command allows users to submit a new proposal. ```bash -simd tx group create-proposal [group-policy-account] [proposer[,proposer]*] [msg_tx_json_file] [metadata] [flags] +simd tx group submit-proposal [group-policy-account] [proposer[,proposer]*] [msg_tx_json_file] [metadata] [flags] ``` Example: ```bash -simd tx group create-proposal cosmos1.. cosmos1.. msg_tx.json "AQ==" +simd tx group submit-proposal cosmos1.. cosmos1.. msg_tx.json "AQ==" ``` #### withdraw-proposal