diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d39bcd17b0..0592756764db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,9 +37,34 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### 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. + +## [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. + +### 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 + +* (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 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 -## 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..4577d6ab670a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,21 +1,16 @@ -# 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). +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: ```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/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/go.mod b/go.mod index 9ec9309533c4..f6abddddc2db 100644 --- a/go.mod +++ b/go.mod @@ -96,6 +96,8 @@ require ( github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/golang/glog v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -137,6 +139,9 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect + github.com/pyroscope-io/client v0.7.2 // indirect + github.com/pyroscope-io/godeltaprof v0.1.2 // indirect + github.com/pyroscope-io/otel-profiling-go v0.4.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/rs/cors v1.8.2 // indirect @@ -151,6 +156,10 @@ require ( github.com/zondax/ledger-go v0.14.1 // indirect go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/otel v1.15.1 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.15.1 // indirect + go.opentelemetry.io/otel/sdk v1.15.1 // indirect + go.opentelemetry.io/otel/trace v1.15.1 // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/oauth2 v0.6.0 // indirect golang.org/x/sys v0.7.0 // indirect @@ -179,7 +188,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/celestiaorg/celestia-core v1.24.0-tm-v0.34.28 + github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.26.2-tm-v0.34.28 ) retract ( diff --git a/go.sum b/go.sum index 971d64cb3a69..30abd16628c2 100644 --- a/go.sum +++ b/go.sum @@ -163,8 +163,8 @@ github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/celestiaorg/celestia-core v1.24.0-tm-v0.34.28 h1:eXS3v26nob8Xs2+flKHVxcTzhzQW44KgTcooR3OxnK4= -github.com/celestiaorg/celestia-core v1.24.0-tm-v0.34.28/go.mod h1:J/GsBjoTZaFz71VeyrLZbG8rV+Rzi6oFEUZUipQ97hQ= +github.com/celestiaorg/celestia-core v1.26.2-tm-v0.34.28 h1:2efXQaggLFknz0wQufr4nUEz5G7pSVHS1j7NuJDsvII= +github.com/celestiaorg/celestia-core v1.26.2-tm-v0.34.28/go.mod h1:++dNzzzjP9jYg+NopN9G8sg1HEZ58lv1TPtg71evZ0E= github.com/celestiaorg/nmt v0.18.1 h1:zU3apzW4y0fs0ilQA74XnEYW8FvRv0CUK2LXK66L3rA= github.com/celestiaorg/nmt v0.18.1/go.mod h1:0l8q6UYRju1xNrxtvV6NwPdW3lfsN6KuZ0htRnModdc= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= @@ -345,6 +345,11 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= @@ -436,6 +441,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= @@ -833,6 +839,12 @@ github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/pyroscope-io/client v0.7.2 h1:OX2qdUQsS8RSkn/3C8isD7f/P0YiZQlRbAlecAaj/R8= +github.com/pyroscope-io/client v0.7.2/go.mod h1:FEocnjn+Ngzxy6EtU9ZxXWRvQ0+pffkrBxHLnPpxwi8= +github.com/pyroscope-io/godeltaprof v0.1.2 h1:MdlEmYELd5w+lvIzmZvXGNMVzW2Qc9jDMuJaPOR75g4= +github.com/pyroscope-io/godeltaprof v0.1.2/go.mod h1:psMITXp90+8pFenXkKIpNhrfmI9saQnPbba27VIaiQE= +github.com/pyroscope-io/otel-profiling-go v0.4.0 h1:Hk/rbUqOWoByoWy1tt4r5BX5xoKAvs5drr0511Ki8ic= +github.com/pyroscope-io/otel-profiling-go v0.4.0/go.mod h1:MXaofiWU7PgLP7eISUZJYVO4Z8WYMqpkYgeP4XrPLyg= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -997,6 +1009,16 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/otel v1.4.1/go.mod h1:StM6F/0fSwpd8dKWDCdRr7uRvEPYdW0hBSlbdTiUde4= +go.opentelemetry.io/otel v1.15.1 h1:3Iwq3lfRByPaws0f6bU3naAqOR1n5IeDWd9390kWHa8= +go.opentelemetry.io/otel v1.15.1/go.mod h1:mHHGEHVDLal6YrKMmk9LqC4a3sF5g+fHfrttQIB1NTc= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.15.1 h1:2PunuO5SbkN5MhCbuHCd3tC6qrcaj+uDAkX/qBU5BAs= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.15.1/go.mod h1:q8+Tha+5LThjeSU8BW93uUC5w5/+DnYHMKBMpRCsui0= +go.opentelemetry.io/otel/sdk v1.15.1 h1:5FKR+skgpzvhPQHIEfcwMYjCBr14LWzs3uSqKiQzETI= +go.opentelemetry.io/otel/sdk v1.15.1/go.mod h1:8rVtxQfrbmbHKfqzpQkT5EzZMcbMBwTzNAggbEAM0KA= +go.opentelemetry.io/otel/trace v1.4.1/go.mod h1:iYEVbroFCNut9QkwEczV9vMRPHNKSSwYZjulEtsmhFc= +go.opentelemetry.io/otel/trace v1.15.1 h1:uXLo6iHJEzDfrNC0L0mNjItIp06SyaBQxu5t3xMlngY= +go.opentelemetry.io/otel/trace v1.15.1/go.mod h1:IWdQG/5N1x7f6YUlmdLeJvH9yxtuJAfc4VW5Agv9r/8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= 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), ) 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) +} 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} 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/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() +} 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) 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 } 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,