From 99206edc50f350be6f6431eecb377ee9facf18f8 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 30 Aug 2023 10:36:57 +0200 Subject: [PATCH 01/10] keyring: new keyctl backend keyctl is a Linux kernel's interface to help protect cryptohtaphic data from a whole class of potential security vulnerabilities. The Keyctl backend leverages such Linux's kernel feature to store keys in memory securely. For more information, please see: https://docs.kernel.org/security/keys/core.html The keyctl backend is available on Linux platforms only. --- CHANGELOG.md | 1 + crypto/keyring/keyring.go | 2 +- crypto/keyring/keyring_linux.go | 42 +++++++++++++++++++++++++++++++++ crypto/keyring/keyring_other.go | 16 +++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 crypto/keyring/keyring_linux.go create mode 100644 crypto/keyring/keyring_other.go diff --git a/CHANGELOG.md b/CHANGELOG.md index cc5737069103..66761f7367ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages. * (cli) [#21372](https://github.com/cosmos/cosmos-sdk/pull/21372) Add a `bulk-add-genesis-account` genesis command to add many genesis accounts at once. +* (crypto/keyring) [#21653](https://github.com/cosmos/cosmos-sdk/pull/21653) New Linux-only backend that adds Linux kernel's `keyctl` support. ### Improvements diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index aee52a62563c..c1766b29b20c 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -180,7 +180,7 @@ func NewInMemoryWithKeyring(kr keyring.Keyring, cdc codec.Codec, opts ...Option) // New creates a new instance of a keyring. // Keyring options can be applied when generating the new instance. // Available backends are "os", "file", "kwallet", "memory", "pass", "test". -func New( +func newKeyringGeneric( appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, ) (Keyring, error) { var ( diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go new file mode 100644 index 000000000000..0b477dfec2b4 --- /dev/null +++ b/crypto/keyring/keyring_linux.go @@ -0,0 +1,42 @@ +//go:build linux +// +build linux + +package keyring + +import ( + "fmt" + "io" + + "github.com/99designs/keyring" + "github.com/cosmos/cosmos-sdk/codec" +) + +const BackendKeyctl = "keyctl" + +func newKeyctlBackendConfig(appName, _ string, _ io.Reader) keyring.Config { + return keyring.Config{ + AllowedBackends: []keyring.BackendType{keyring.KeyCtlBackend}, + ServiceName: appName, + KeyCtlScope: "user", + KeyCtlPerm: 0x3f3f0000, + } +} + +// New creates a new instance of a keyring. +// Keyring options can be applied when generating the new instance. +// Available backends are "os", "file", "kwallet", "memory", "pass", "test". +func New( + appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, +) (Keyring, error) { + + if backend != BackendKeyctl { + return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) + } + + db, err := keyring.Open(newKeyctlBackendConfig(appName, "", userInput)) + if err != nil { + return nil, fmt.Errorf("couldn't open keyring for %q: %w", appName, err) + } + + return newKeystore(db, cdc, backend, opts...), nil +} diff --git a/crypto/keyring/keyring_other.go b/crypto/keyring/keyring_other.go new file mode 100644 index 000000000000..48b90fe5dd1e --- /dev/null +++ b/crypto/keyring/keyring_other.go @@ -0,0 +1,16 @@ +//go:build !linux +// +build !linux + +package keyring + +import ( + "io" + + "github.com/cosmos/cosmos-sdk/codec" +) + +func New( + appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, +) (Keyring, error) { + return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) +} From f1d40b031e4d096f4a7fea15ba418fd52448234d Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 11 Sep 2024 20:44:59 +0800 Subject: [PATCH 02/10] update godoc --- crypto/keyring/doc.go | 2 ++ crypto/keyring/keyring_linux.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crypto/keyring/doc.go b/crypto/keyring/doc.go index a3bc8d8824ac..87a9e0908b36 100644 --- a/crypto/keyring/doc.go +++ b/crypto/keyring/doc.go @@ -33,6 +33,8 @@ // https://github.com/KDE/kwallet // pass This backend uses the pass command line utility to store and retrieve keys: // https://www.passwordstore.org/ +// keyctl This backend leverages the Linux's kernel security key management system +// to store cryptographic keys securely in memory. This is available on Linux only. // test This backend stores keys insecurely to disk. It does not prompt for a password to // be unlocked and it should be used only for testing purposes. // memory Same instance as returned by NewInMemory. This backend uses a transient storage. Keys diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go index 0b477dfec2b4..7abdb4748892 100644 --- a/crypto/keyring/keyring_linux.go +++ b/crypto/keyring/keyring_linux.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) +// Linux-only backend options. const BackendKeyctl = "keyctl" func newKeyctlBackendConfig(appName, _ string, _ io.Reader) keyring.Config { @@ -24,7 +25,7 @@ func newKeyctlBackendConfig(appName, _ string, _ io.Reader) keyring.Config { // New creates a new instance of a keyring. // Keyring options can be applied when generating the new instance. -// Available backends are "os", "file", "kwallet", "memory", "pass", "test". +// Available backends are "os", "file", "kwallet", "memory", "pass", "test", "keyctl". func New( appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, ) (Keyring, error) { From 590c8cbf79a08b9622bd52ff475d793aef4f535f Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 14:29:28 +0800 Subject: [PATCH 03/10] allow user to set scope --- crypto/keyring/keyring.go | 17 ------------ crypto/keyring/keyring_linux.go | 49 ++++++++++++++++++++++++++++++--- crypto/keyring/keyring_other.go | 19 +++++++++++++ 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index c1766b29b20c..ef3b0a16df08 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -147,23 +147,6 @@ type Exporter interface { // Option overrides keyring configuration options. type Option func(options *Options) -// Options define the options of the Keyring. -type Options struct { - // supported signing algorithms for keyring - SupportedAlgos SigningAlgoList - // supported signing algorithms for Ledger - SupportedAlgosLedger SigningAlgoList - // define Ledger Derivation function - LedgerDerivation func() (ledger.SECP256K1, error) - // define Ledger key generation function - LedgerCreateKey func([]byte) types.PubKey - // define Ledger app name - LedgerAppName string - // indicate whether Ledger should skip DER Conversion on signature, - // depending on which format (DER or BER) the Ledger app returns signatures - LedgerSigSkipDERConv bool -} - // NewInMemory creates a transient keyring useful for testing // purposes and on-the-fly key generation. // Keybase options can be applied when generating this new Keybase. diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go index 7abdb4748892..009aef525599 100644 --- a/crypto/keyring/keyring_linux.go +++ b/crypto/keyring/keyring_linux.go @@ -9,17 +9,51 @@ import ( "github.com/99designs/keyring" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/ledger" + "github.com/cosmos/cosmos-sdk/crypto/types" ) // Linux-only backend options. const BackendKeyctl = "keyctl" -func newKeyctlBackendConfig(appName, _ string, _ io.Reader) keyring.Config { +func KeyctlScopeUser(options *Options) { setKeyctlScope(options, "user") } +func KeyctlScopeUserSession(options *Options) { setKeyctlScope(options, "usersession") } +func KeyctlScopeSession(options *Options) { setKeyctlScope(options, "session") } +func KeyctlScopeProcess(options *Options) { setKeyctlScope(options, "process") } +func KeyctlScopeThread(options *Options) { setKeyctlScope(options, "thread") } + +// Options define the options of the Keyring. +type Options struct { + // supported signing algorithms for keyring + SupportedAlgos SigningAlgoList + // supported signing algorithms for Ledger + SupportedAlgosLedger SigningAlgoList + // define Ledger Derivation function + LedgerDerivation func() (ledger.SECP256K1, error) + // define Ledger key generation function + LedgerCreateKey func([]byte) types.PubKey + // define Ledger app name + LedgerAppName string + // indicate whether Ledger should skip DER Conversion on signature, + // depending on which format (DER or BER) the Ledger app returns signatures + LedgerSigSkipDERConv bool + // KeyctlScope defines the scope of the keyctl's keyring. + KeyctlScope string +} + +func newKeyctlBackendConfig(appName, _ string, _ io.Reader, opts ...Option) keyring.Config { + options := Options{ + KeyctlScope: keyctlDefaultScope, // currently "process" + } + + for _, optionFn := range opts { + optionFn(&options) + } + return keyring.Config{ AllowedBackends: []keyring.BackendType{keyring.KeyCtlBackend}, ServiceName: appName, - KeyCtlScope: "user", - KeyCtlPerm: 0x3f3f0000, + KeyCtlScope: options.KeyctlScope, } } @@ -34,10 +68,17 @@ func New( return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) } - db, err := keyring.Open(newKeyctlBackendConfig(appName, "", userInput)) + db, err := keyring.Open(newKeyctlBackendConfig(appName, "", userInput, opts...)) if err != nil { return nil, fmt.Errorf("couldn't open keyring for %q: %w", appName, err) } return newKeystore(db, cdc, backend, opts...), nil } + +func setKeyctlScope(options *Options, scope string) { options.KeyctlScope = scope } + +// this is private as it is meant to be here for SDK devs convenience +// as the user does not need to pick any default when he wants to +// initialize keyctl with the default scope. +const keyctlDefaultScope = "process" diff --git a/crypto/keyring/keyring_other.go b/crypto/keyring/keyring_other.go index 48b90fe5dd1e..9c25a1e954e2 100644 --- a/crypto/keyring/keyring_other.go +++ b/crypto/keyring/keyring_other.go @@ -7,8 +7,27 @@ import ( "io" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/ledger" + "github.com/cosmos/cosmos-sdk/crypto/types" ) +// Options define the options of the Keyring. +type Options struct { + // supported signing algorithms for keyring + SupportedAlgos SigningAlgoList + // supported signing algorithms for Ledger + SupportedAlgosLedger SigningAlgoList + // define Ledger Derivation function + LedgerDerivation func() (ledger.SECP256K1, error) + // define Ledger key generation function + LedgerCreateKey func([]byte) types.PubKey + // define Ledger app name + LedgerAppName string + // indicate whether Ledger should skip DER Conversion on signature, + // depending on which format (DER or BER) the Ledger app returns signatures + LedgerSigSkipDERConv bool +} + func New( appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, ) (Keyring, error) { From 88b166d46e30fec8afb72a468758244609f68a86 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 12 Sep 2024 01:00:42 -0500 Subject: [PATCH 04/10] refactor: remove viper as a direct dependency (#21635) --- core/server/config.go | 8 ++++ go.mod | 1 + go.sum | 2 - runtime/v2/builder.go | 47 ++++++++----------- runtime/v2/go.mod | 15 +----- runtime/v2/go.sum | 35 -------------- runtime/v2/module.go | 8 ++-- simapp/go.mod | 1 + simapp/go.sum | 2 - simapp/simd/cmd/testnet_test.go | 6 ++- simapp/v2/app_di.go | 16 +++++-- simapp/v2/go.mod | 1 + simapp/v2/go.sum | 2 - simapp/v2/simdv2/cmd/commands.go | 29 +++++++++--- simapp/v2/simdv2/cmd/root_di.go | 2 +- tests/e2e/genutil/export_test.go | 2 +- tests/go.mod | 3 +- tests/go.sum | 2 - .../integration/genutil}/export_test.go | 2 +- .../integration/genutil}/genaccount_test.go | 34 ++++++++++---- .../integration/genutil}/init_test.go | 20 ++++---- testutil/network/util.go | 8 +++- .../x/genutil/helper.go | 2 +- x/auth/tx/config/depinject.go | 8 ++-- x/genutil/v2/cli/commands.go | 7 ++- x/genutil/v2/cli/export.go | 10 ++-- x/genutil/v2/types.go | 8 +--- x/upgrade/depinject.go | 18 ++----- x/upgrade/go.mod | 3 +- x/upgrade/go.sum | 2 - 30 files changed, 148 insertions(+), 156 deletions(-) create mode 100644 core/server/config.go rename {x/genutil/client/cli => tests/integration/genutil}/export_test.go (99%) rename {x/genutil/client/cli => tests/integration/genutil}/genaccount_test.go (90%) rename {x/genutil/client/cli => tests/integration/genutil}/init_test.go (94%) rename x/genutil/client/testutil/helpers.go => testutil/x/genutil/helper.go (99%) diff --git a/core/server/config.go b/core/server/config.go new file mode 100644 index 000000000000..997633fe46b3 --- /dev/null +++ b/core/server/config.go @@ -0,0 +1,8 @@ +package server + +// DynamicConfig defines an interface for configuration that can be dynamically +// fetched at runtime by an arbitrary key. +type DynamicConfig interface { + Get(string) any + GetString(string) string +} diff --git a/go.mod b/go.mod index 888de0a6c75e..de2df0c42a7a 100644 --- a/go.mod +++ b/go.mod @@ -185,6 +185,7 @@ require ( replace ( cosmossdk.io/api => ./api cosmossdk.io/collections => ./collections + cosmossdk.io/core => ./core cosmossdk.io/core/testing => ./core/testing cosmossdk.io/store => ./store cosmossdk.io/x/bank => ./x/bank diff --git a/go.sum b/go.sum index f0812105d45b..6a656b750879 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/runtime/v2/builder.go b/runtime/v2/builder.go index 33e4f46bb77a..2dc6ca7227d2 100644 --- a/runtime/v2/builder.go +++ b/runtime/v2/builder.go @@ -7,10 +7,9 @@ import ( "io" "path/filepath" - "github.com/spf13/viper" - "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/appmanager" @@ -25,8 +24,8 @@ import ( // the existing app.go initialization conventions. type AppBuilder[T transaction.Tx] struct { app *App[T] - storeOptions *rootstore.FactoryOptions - viper *viper.Viper + config server.DynamicConfig + storeOptions rootstore.Options // the following fields are used to overwrite the default branch func(state store.ReaderMap) store.WriterMap @@ -73,9 +72,6 @@ func (a *AppBuilder[T]) RegisterModules(modules map[string]appmodulev2.AppModule // To be used in combination of RegisterModules. func (a *AppBuilder[T]) RegisterStores(keys ...string) { a.app.storeKeys = append(a.app.storeKeys, keys...) - if a.storeOptions != nil { - a.storeOptions.StoreKeys = append(a.storeOptions.StoreKeys, keys...) - } } // Build builds an *App instance. @@ -124,29 +120,26 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) { } a.app.stf = stf - storeOpts := rootstore.DefaultStoreOptions() - if s := a.viper.Sub("store.options"); s != nil { - if err := s.Unmarshal(&storeOpts); err != nil { - return nil, fmt.Errorf("failed to unmarshal store options: %w", err) - } - } - - home := a.viper.GetString(FlagHome) - scRawDb, err := db.NewDB(db.DBType(a.viper.GetString("store.app-db-backend")), "application", filepath.Join(home, "data"), nil) + home := a.config.GetString(FlagHome) + scRawDb, err := db.NewDB( + db.DBType(a.config.GetString("store.app-db-backend")), + "application", + filepath.Join(home, "data"), + nil, + ) if err != nil { panic(err) } - storeOptions := &rootstore.FactoryOptions{ + factoryOptions := &rootstore.FactoryOptions{ Logger: a.app.logger, RootDir: home, - Options: storeOpts, + Options: a.storeOptions, StoreKeys: append(a.app.storeKeys, "stf"), SCRawDB: scRawDb, } - a.storeOptions = storeOptions - rs, err := rootstore.CreateRootStore(a.storeOptions) + rs, err := rootstore.CreateRootStore(factoryOptions) if err != nil { return nil, fmt.Errorf("failed to create root store: %w", err) } @@ -217,14 +210,14 @@ func AppBuilderWithTxValidator[T transaction.Tx](txValidators func(ctx context.C // AppBuilderWithPostTxExec sets logic that will be executed after each transaction. // When not provided, a no-op function will be used. -func AppBuilderWithPostTxExec[T transaction.Tx]( - postTxExec func( - ctx context.Context, - tx T, - success bool, - ) error, -) AppBuilderOption[T] { +func AppBuilderWithPostTxExec[T transaction.Tx](postTxExec func(ctx context.Context, tx T, success bool) error) AppBuilderOption[T] { return func(a *AppBuilder[T]) { a.postTxExec = postTxExec } } + +func AppBuilderWithStoreOptions[T transaction.Tx](opts rootstore.Options) AppBuilderOption[T] { + return func(a *AppBuilder[T]) { + a.storeOptions = opts + } +} diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index e898e3c0035e..51ec7919d1c1 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -5,6 +5,7 @@ go 1.23 // server v2 integration replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/core/testing => ../../core/testing cosmossdk.io/server/v2/appmanager => ../../server/v2/appmanager cosmossdk.io/server/v2/stf => ../../server/v2/stf @@ -22,7 +23,6 @@ require ( cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000 cosmossdk.io/x/tx v0.13.3 github.com/cosmos/gogoproto v1.7.0 - github.com/spf13/viper v1.19.0 google.golang.org/grpc v1.66.1 google.golang.org/protobuf v1.34.2 ) @@ -45,7 +45,6 @@ require ( github.com/cosmos/ics23/go v0.11.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/dot v1.6.2 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/snappy v0.0.4 // indirect @@ -54,19 +53,15 @@ require ( github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-metrics v0.5.3 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect - github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.22 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/onsi/gomega v1.28.1 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.3 // indirect @@ -75,18 +70,11 @@ require ( github.com/prometheus/procfs v0.15.1 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/zerolog v1.33.0 // indirect - github.com/sagikazarmark/locafero v0.4.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/sourcegraph/conc v0.3.0 // indirect - github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.9.0 // indirect - github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect - go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.27.0 // indirect golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/net v0.29.0 // indirect @@ -95,7 +83,6 @@ require ( golang.org/x/text v0.18.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/runtime/v2/go.sum b/runtime/v2/go.sum index 17b285973436..7ef0e6524b68 100644 --- a/runtime/v2/go.sum +++ b/runtime/v2/go.sum @@ -2,8 +2,6 @@ buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fed buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2/go.mod h1:1+3gJj2NvZ1mTLAtHu+lMhOjGgQPiCKCeo+9MBww0Eo= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 h1:b7EEYTUHmWSBEyISHlHvXbJPqtKiHRuUignL1tsHnNQ= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA= @@ -123,8 +121,6 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -145,8 +141,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/linxGnu/grocksdb v1.8.14 h1:HTgyYalNwBSG/1qCQUIott44wU5b2Y9Kr3z7SK5OfGQ= github.com/linxGnu/grocksdb v1.8.14/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= @@ -156,8 +150,6 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= @@ -182,8 +174,6 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -219,39 +209,19 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99 github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= -github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= -github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= -github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs= github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= @@ -263,8 +233,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -363,8 +331,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -373,7 +339,6 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/runtime/v2/module.go b/runtime/v2/module.go index 1cda0a577fd4..3a9aafe3f06d 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -6,7 +6,6 @@ import ( "slices" "github.com/cosmos/gogoproto/proto" - "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoregistry" @@ -18,6 +17,7 @@ import ( appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" "cosmossdk.io/core/registry" + "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" @@ -145,7 +145,7 @@ type AppInputs struct { InterfaceRegistrar registry.InterfaceRegistrar LegacyAmino registry.AminoRegistrar Logger log.Logger - Viper *viper.Viper `optional:"true"` // can be nil in client wiring + DynamicConfig server.DynamicConfig `optional:"true"` // can be nil in client wiring } func SetupAppBuilder(inputs AppInputs) { @@ -156,8 +156,8 @@ func SetupAppBuilder(inputs AppInputs) { app.moduleManager.RegisterInterfaces(inputs.InterfaceRegistrar) app.moduleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino) - if inputs.Viper != nil { - inputs.AppBuilder.viper = inputs.Viper + if inputs.DynamicConfig != nil { + inputs.AppBuilder.config = inputs.DynamicConfig } } diff --git a/simapp/go.mod b/simapp/go.mod index 592237457cba..8ba341e967b6 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -241,6 +241,7 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections + cosmossdk.io/core => ../core cosmossdk.io/core/testing => ../core/testing cosmossdk.io/store => ../store cosmossdk.io/tools/confix => ../tools/confix diff --git a/simapp/go.sum b/simapp/go.sum index 4998b693ccd9..bdff4b296d92 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 2e2653c20e4b..f60a56596c27 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -18,10 +18,10 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/configurator" + genutiltest "github.com/cosmos/cosmos-sdk/testutil/x/genutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/auth" - genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -72,7 +72,9 @@ func Test_TestnetCmd(t *testing.T) { ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := testnetInitFilesCmd(moduleManager) - cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}) + cmd.SetArgs( + []string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}, + ) err = cmd.ExecuteContext(ctx) require.NoError(t, err) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 3d780f7cc601..1411b28823ba 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/runtime/v2" + "cosmossdk.io/store/v2/root" "cosmossdk.io/x/accounts" authzkeeper "cosmossdk.io/x/authz/keeper" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -96,8 +97,10 @@ func NewSimApp[T transaction.Tx]( viper *viper.Viper, ) *SimApp[T] { var ( - app = &SimApp[T]{} - appBuilder *runtime.AppBuilder[T] + app = &SimApp[T]{} + appBuilder *runtime.AppBuilder[T] + err error + storeOptions = root.DefaultStoreOptions() // merge the AppConfig and other configuration in one config appConfig = depinject.Configs( @@ -187,8 +190,13 @@ func NewSimApp[T transaction.Tx]( panic(err) } - var err error - app.App, err = appBuilder.Build() + if sub := viper.Sub("store.options"); sub != nil { + err = sub.Unmarshal(&storeOptions) + if err != nil { + panic(err) + } + } + app.App, err = appBuilder.Build(runtime.AppBuilderWithStoreOptions[T](storeOptions)) if err != nil { panic(err) } diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index ab2e5368aae6..bd4a502a9750 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -287,6 +287,7 @@ replace ( // server v2 integration replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/core/testing => ../../core/testing cosmossdk.io/runtime/v2 => ../../runtime/v2 cosmossdk.io/server/v2 => ../../server/v2 diff --git a/simapp/v2/go.sum b/simapp/v2/go.sum index 3c065e3b33b5..7e5bce683a3a 100644 --- a/simapp/v2/go.sum +++ b/simapp/v2/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index eaa3483d4ea1..2e315c64a186 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "errors" "fmt" @@ -8,6 +9,7 @@ import ( "github.com/spf13/viper" "cosmossdk.io/client/v2/offchain" + corectx "cosmossdk.io/core/context" "cosmossdk.io/core/transaction" "cosmossdk.io/log" runtimev2 "cosmossdk.io/runtime/v2" @@ -63,7 +65,7 @@ func initRootCmd[T transaction.Tx]( // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( - genesisCommand(moduleManager, appExport[T]), + genesisCommand(moduleManager), queryCommand(), txCommand(), keys.Commands(), @@ -84,13 +86,16 @@ func initRootCmd[T transaction.Tx]( } } -// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter +// genesisCommand builds genesis-related `simd genesis` command. func genesisCommand[T transaction.Tx]( moduleManager *runtimev2.MM[T], - appExport genutilv2.AppExporter, cmds ...*cobra.Command, ) *cobra.Command { - cmd := v2.Commands(moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule), moduleManager, appExport) + cmd := v2.Commands( + moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule), + moduleManager, + appExport[T], + ) for _, subCmd := range cmds { cmd.AddCommand(subCmd) @@ -143,11 +148,23 @@ func txCommand() *cobra.Command { // appExport creates a new simapp (optionally at a given height) and exports state. func appExport[T transaction.Tx]( - logger log.Logger, + ctx context.Context, height int64, jailAllowedAddrs []string, - viper *viper.Viper, ) (genutilv2.ExportedApp, error) { + value := ctx.Value(corectx.ViperContextKey) + viper, ok := value.(*viper.Viper) + if !ok { + return genutilv2.ExportedApp{}, + fmt.Errorf("incorrect viper type %T: expected *viper.Viper in context", value) + } + value = ctx.Value(corectx.LoggerContextKey) + logger, ok := value.(log.Logger) + if !ok { + return genutilv2.ExportedApp{}, + fmt.Errorf("incorrect logger type %T: expected log.Logger in context", value) + } + // overwrite the FlagInvCheckPeriod viper.Set(server.FlagInvCheckPeriod, 1) viper.Set(serverv2.FlagHome, simapp.DefaultNodeHome) diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 9653106d36c1..fd5b62b9384b 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -82,7 +82,7 @@ func NewRootCmd[T transaction.Tx]() *cobra.Command { }, } - initRootCmd[T](rootCmd, clientCtx.TxConfig, moduleManager) + initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager) nodeCmds := nodeservice.NewNodeCommands() autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions) diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index cb41aa53d2c5..a920a9e6f9e0 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -30,9 +30,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + gentestutil "github.com/cosmos/cosmos-sdk/testutil/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) diff --git a/tests/go.mod b/tests/go.mod index 8da1a0ffb34a..fec3b2d0ccaa 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -50,6 +50,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/gofuzz v1.2.0 github.com/jhump/protoreflect v1.17.0 + github.com/rs/zerolog v1.33.0 github.com/spf13/viper v1.19.0 ) @@ -180,7 +181,6 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.11.0 // indirect - github.com/rs/zerolog v1.33.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.5 // indirect @@ -237,6 +237,7 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections + cosmossdk.io/core => ../core cosmossdk.io/core/testing => ../core/testing cosmossdk.io/store => ../store cosmossdk.io/x/accounts => ../x/accounts diff --git a/tests/go.sum b/tests/go.sum index 5a4c6593f4e0..4f393d4f5567 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/x/genutil/client/cli/export_test.go b/tests/integration/genutil/export_test.go similarity index 99% rename from x/genutil/client/cli/export_test.go rename to tests/integration/genutil/export_test.go index 270fa98bfaed..e583aa59e970 100644 --- a/x/genutil/client/cli/export_test.go +++ b/tests/integration/genutil/export_test.go @@ -1,4 +1,4 @@ -package cli_test +package genutil import ( "context" diff --git a/x/genutil/client/cli/genaccount_test.go b/tests/integration/genutil/genaccount_test.go similarity index 90% rename from x/genutil/client/cli/genaccount_test.go rename to tests/integration/genutil/genaccount_test.go index c75894f3a2fc..739adda97d2b 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/tests/integration/genutil/genaccount_test.go @@ -1,4 +1,4 @@ -package cli_test +package genutil import ( "context" @@ -19,12 +19,12 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil/testdata" + genutilhelpers "github.com/cosmos/cosmos-sdk/testutil/x/genutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -78,10 +78,13 @@ func TestAddGenesisAccountCmd(t *testing.T) { logger := log.NewNopLogger() v := viper.New() - encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig( + codectestutil.CodecOptions{}, + auth.AppModule{}, + ) appCodec := encodingConfig.Codec txConfig := encodingConfig.TxConfig - err = genutiltest.ExecInitCmd(testMbm, home, appCodec) + err = genutilhelpers.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) err := writeAndTrackDefaultConfig(v, home) @@ -93,7 +96,13 @@ func TestAddGenesisAccountCmd(t *testing.T) { path := hd.CreateHDPath(118, 0, 0).String() kr, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, home, nil, appCodec) require.NoError(t, err) - _, _, err = kr.NewMnemonic(tc.addr, keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + _, _, err = kr.NewMnemonic( + tc.addr, + keyring.English, + path, + keyring.DefaultBIP39Passphrase, + hd.Secp256k1, + ) require.NoError(t, err) clientCtx = clientCtx.WithKeyring(kr) } @@ -214,10 +223,13 @@ func TestBulkAddGenesisAccountCmd(t *testing.T) { logger := log.NewNopLogger() v := viper.New() - encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig( + codectestutil.CodecOptions{}, + auth.AppModule{}, + ) appCodec := encodingConfig.Codec txConfig := encodingConfig.TxConfig - err = genutiltest.ExecInitCmd(testMbm, home, appCodec) + err = genutilhelpers.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) err = writeAndTrackDefaultConfig(v, home) @@ -269,7 +281,13 @@ func TestBulkAddGenesisAccountCmd(t *testing.T) { require.EqualValues(t, len(tc.expected), len(bankState.Balances)) for _, acc := range bankState.Balances { - require.True(t, tc.expected[acc.Address].Equal(acc.Coins), "expected: %v, got: %v", tc.expected[acc.Address], acc.Coins) + require.True( + t, + tc.expected[acc.Address].Equal(acc.Coins), + "expected: %v, got: %v", + tc.expected[acc.Address], + acc.Coins, + ) } expectedSupply := sdk.NewCoins() diff --git a/x/genutil/client/cli/init_test.go b/tests/integration/genutil/init_test.go similarity index 94% rename from x/genutil/client/cli/init_test.go rename to tests/integration/genutil/init_test.go index 7dfa70b688d0..9116db0ce8fe 100644 --- a/x/genutil/client/cli/init_test.go +++ b/tests/integration/genutil/init_test.go @@ -1,4 +1,4 @@ -package cli_test +package genutil import ( "bytes" @@ -28,11 +28,11 @@ import ( "github.com/cosmos/cosmos-sdk/server/mock" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/network" + genutilhelpers "github.com/cosmos/cosmos-sdk/testutil/x/genutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -125,7 +125,9 @@ func TestInitRecover(t *testing.T) { }) // use valid mnemonic and complete recovery key generation successfully - mockIn.Reset("decide praise business actor peasant farm drastic weather extend front hurt later song give verb rhythm worry fun pond reform school tumble august one\n") + mockIn.Reset( + "decide praise business actor peasant farm drastic weather extend front hurt later song give verb rhythm worry fun pond reform school tumble august one\n", + ) require.NoError(t, cmd.ExecuteContext(ctx)) } @@ -213,7 +215,7 @@ func TestStartStandAlone(t *testing.T) { logger := log.NewNopLogger() interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) - err := genutiltest.ExecInitCmd(testMbm, home, marshaler) + err := genutilhelpers.ExecInitCmd(testMbm, home, marshaler) require.NoError(t, err) app, err := mock.NewApp(home, logger) @@ -241,7 +243,7 @@ func TestStartStandAlone(t *testing.T) { func TestInitNodeValidatorFiles(t *testing.T) { home := t.TempDir() - cfg, err := genutiltest.CreateDefaultCometConfig(home) + cfg, err := genutilhelpers.CreateDefaultCometConfig(home) require.NoError(t, err) nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(cfg, ed25519.KeyType) @@ -303,7 +305,7 @@ func TestInitWithHeight(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() viper := viper.New() - cfg, err := genutiltest.CreateDefaultCometConfig(home) + cfg, err := genutilhelpers.CreateDefaultCometConfig(home) require.NoError(t, err) err = writeAndTrackDefaultConfig(viper, home) @@ -340,7 +342,7 @@ func TestInitWithNegativeHeight(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() viper := viper.New() - cfg, err := genutiltest.CreateDefaultCometConfig(home) + cfg, err := genutilhelpers.CreateDefaultCometConfig(home) require.NoError(t, err) err = writeAndTrackDefaultConfig(viper, home) @@ -385,9 +387,9 @@ func makeCodec() codec.Codec { } func writeAndTrackDefaultConfig(v *viper.Viper, home string) error { - cfg, err := genutiltest.CreateDefaultCometConfig(home) + cfg, err := genutilhelpers.CreateDefaultCometConfig(home) if err != nil { return err } - return genutiltest.WriteAndTrackCometConfig(v, home, cfg) + return genutilhelpers.WriteAndTrackCometConfig(v, home, cfg) } diff --git a/testutil/network/util.go b/testutil/network/util.go index cc2297f77fcd..08ee1b0c5d99 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -23,6 +23,7 @@ import ( banktypes "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" @@ -30,7 +31,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -180,7 +180,11 @@ func collectGenFiles(cfg Config, vals []*Validator, cmtConfigs []*cmtcfg.Config, } v := vals[i].GetViper() - err = genutiltest.TrackCometConfig(v, nodeDir) + v.Set(flags.FlagHome, nodeDir) + v.SetConfigType("toml") + v.SetConfigName("config") + v.AddConfigPath(filepath.Join(nodeDir, "config")) + err = v.ReadInConfig() if err != nil { return err } diff --git a/x/genutil/client/testutil/helpers.go b/testutil/x/genutil/helper.go similarity index 99% rename from x/genutil/client/testutil/helpers.go rename to testutil/x/genutil/helper.go index 459f325bc755..a6eae578d0f0 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/testutil/x/genutil/helper.go @@ -1,4 +1,4 @@ -package testutil +package genutil import ( "context" diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 5efed67e2c79..9c753fbd4729 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -6,7 +6,6 @@ import ( "fmt" gogoproto "github.com/cosmos/gogoproto/proto" - "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" @@ -16,6 +15,7 @@ import ( txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/address" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -66,7 +66,7 @@ type ModuleInputs struct { ExtraTxValidators []appmodulev2.TxValidator[transaction.Tx] `optional:"true"` UnorderedTxManager *unorderedtx.Manager `optional:"true"` TxFeeChecker ante.TxFeeChecker `optional:"true"` - Viper *viper.Viper `optional:"true"` // server v2 + DynamicConfig server.DynamicConfig `optional:"true"` } type ModuleOutputs struct { @@ -126,8 +126,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { feeTxValidator *ante.DeductFeeDecorator unorderedTxValidator *ante.UnorderedTxDecorator ) - if in.AccountKeeper != nil && in.BankKeeper != nil && in.Viper != nil { - minGasPricesStr := in.Viper.GetString(flagMinGasPricesV2) + if in.AccountKeeper != nil && in.BankKeeper != nil && in.DynamicConfig != nil { + minGasPricesStr := in.DynamicConfig.GetString(flagMinGasPricesV2) minGasPrices, err = sdk.ParseDecCoins(minGasPricesStr) if err != nil { panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) diff --git a/x/genutil/v2/cli/commands.go b/x/genutil/v2/cli/commands.go index 515bf329a52a..7b871ec074a4 100644 --- a/x/genutil/v2/cli/commands.go +++ b/x/genutil/v2/cli/commands.go @@ -26,7 +26,12 @@ func Commands(genutilModule genutil.AppModule, genMM genesisMM, appExport v2.App // CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map. // This custom migration map can be used by the application to add its own migration map. -func CommandsWithCustomMigrationMap(genutilModule genutil.AppModule, genMM genesisMM, appExport v2.AppExporter, migrationMap genutiltypes.MigrationMap) *cobra.Command { +func CommandsWithCustomMigrationMap( + genutilModule genutil.AppModule, + genMM genesisMM, + appExport v2.AppExporter, + migrationMap genutiltypes.MigrationMap, +) *cobra.Command { cmd := &cobra.Command{ Use: "genesis", Short: "Application's genesis-related subcommands", diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index c19a02f870e3..318ad58d8a47 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -29,8 +29,6 @@ func ExportCmd(appExporter v2.AppExporter) *cobra.Command { Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { config := client.GetConfigFromCmd(cmd) - viper := client.GetViperFromCmd(cmd) - logger := client.GetLoggerFromCmd(cmd) if _, err := os.Stat(config.GenesisFile()); os.IsNotExist(err) { return err @@ -62,7 +60,7 @@ func ExportCmd(appExporter v2.AppExporter) *cobra.Command { jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs) outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - exported, err := appExporter(logger, height, jailAllowedAddrs, viper) + exported, err := appExporter(cmd.Context(), height, jailAllowedAddrs) if err != nil { return fmt.Errorf("error exporting state: %w", err) } @@ -99,8 +97,10 @@ func ExportCmd(appExporter v2.AppExporter) *cobra.Command { } cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)") - cmd.Flags().StringSlice(flagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") - cmd.Flags().String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") + cmd.Flags(). + StringSlice(flagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") + cmd.Flags(). + String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") return cmd } diff --git a/x/genutil/v2/types.go b/x/genutil/v2/types.go index 1b94c8bbc9be..3199a5a5afb4 100644 --- a/x/genutil/v2/types.go +++ b/x/genutil/v2/types.go @@ -1,20 +1,16 @@ package v2 import ( + "context" "encoding/json" - - "github.com/spf13/viper" - - "cosmossdk.io/log" ) // AppExporter is a function that dumps all app state to // JSON-serializable structure and returns the current validator set. type AppExporter func( - logger log.Logger, + ctx context.Context, height int64, jailAllowedAddrs []string, - viper *viper.Viper, ) (ExportedApp, error) // ExportedApp represents an exported app state, along with diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index 1d9dcaa5089a..d0ad08a1c34e 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -2,7 +2,6 @@ package upgrade import ( "github.com/spf13/cast" - "github.com/spf13/viper" modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" "cosmossdk.io/core/address" @@ -16,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -43,8 +41,7 @@ type ModuleInputs struct { AppVersionModifier coreserver.VersionModifier ConsensusKeeper types.ConsensusKeeper - AppOpts servertypes.AppOptions `optional:"true"` // server v0 - Viper *viper.Viper `optional:"true"` // server v2 + DynamicConfig coreserver.DynamicConfig `optional:"true"` } type ModuleOutputs struct { @@ -60,18 +57,13 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { skipUpgradeHeights = make(map[int64]bool) ) - if in.Viper != nil { // viper takes precedence over app options - for _, h := range in.Viper.GetIntSlice(server.FlagUnsafeSkipUpgrades) { + if in.DynamicConfig != nil { + skipUpgrades := cast.ToIntSlice(in.DynamicConfig.Get(server.FlagUnsafeSkipUpgrades)) + for _, h := range skipUpgrades { skipUpgradeHeights[int64(h)] = true } - homePath = in.Viper.GetString(flags.FlagHome) - } else if in.AppOpts != nil { - for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true - } - - homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome)) + homePath = in.DynamicConfig.GetString(flags.FlagHome) } // default to governance authority if not provided diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index f88a4f041ddd..7811ae78ecac 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -26,7 +26,6 @@ require ( github.com/spf13/cast v1.7.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 google.golang.org/grpc v1.66.1 @@ -160,6 +159,7 @@ require ( github.com/sasha-s/go-deadlock v0.3.5 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect @@ -203,6 +203,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/core/testing => ../../core/testing cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index c613fe60dd7d..c3ed86c29f1d 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -194,8 +194,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.1 h1:iElkDJhxmy51aLMSLMZcfsqcv4QG4/1UHbHiW8Llw6k= -cosmossdk.io/core v1.0.0-alpha.1/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= From 846e9a8fbcf0ccc56cda4ada57ec4925661b5fcd Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 15:04:45 +0800 Subject: [PATCH 05/10] chore: sync changelog with latest releases (#21658) --- CHANGELOG.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66761f7367ea..a2ef81ebe7a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,23 +48,14 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Improvements -* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`. -* (internal) [#21412](https://github.com/cosmos/cosmos-sdk/pull/21412) Using unsafe.String and unsafe.SliceData. -* (x/genutil) [#21249](https://github.com/cosmos/cosmos-sdk/pull/21249) Incremental JSON parsing for AppGenesis where possible. - ### Bug Fixes * (baseapp) [#21256](https://github.com/cosmos/cosmos-sdk/pull/21256) Halt height will not commit the block indicated, meaning that if halt-height is set to 10, only blocks until 9 (included) will be committed. This is to go back to the original behavior before a change was introduced in v0.50.0. -* (baseapp) [#21413](https://github.com/cosmos/cosmos-sdk/pull/21413) Fix data race in sdk mempool. ### API Breaking Changes -* (baseapp) [#21413](https://github.com/cosmos/cosmos-sdk/pull/21413) Add `SelectBy` method to `Mempool` interface, which is thread-safe to use. - ### Deprecated -* (types) [#21435](https://github.com/cosmos/cosmos-sdk/pull/21435) The `String()` method on `AccAddress`, `ValAddress` and `ConsAddress` have been deprecated. This is done because those are still using the deprecated global `sdk.Config`. Use an `address.Codec` instead. - ## [v0.52.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.52.0) - 2024-XX-XX Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. @@ -135,6 +126,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (baseapp) [#20380](https://github.com/cosmos/cosmos-sdk/pull/20380) Enhanced OfferSnapshot documentation. * (client) [#20771](https://github.com/cosmos/cosmos-sdk/pull/20771) Remove `ReadDefaultValuesFromDefaultClientConfig` from `client` package. (It was introduced in `v0.50.6` as a quick fix). * (grpcserver) [#20945](https://github.com/cosmos/cosmos-sdk/pull/20945) Adds error handling for out-of-gas panics in grpc query handlers. +* (internal) [#21412](https://github.com/cosmos/cosmos-sdk/pull/21412) Using unsafe.String and unsafe.SliceData. +* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`. +* (x/genutil) [#21249](https://github.com/cosmos/cosmos-sdk/pull/21249) Incremental JSON parsing for AppGenesis where possible. ### Bug Fixes @@ -155,7 +149,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (client) [#17215](https://github.com/cosmos/cosmos-sdk/pull/17215) `server.StartCmd`,`server.ExportCmd`,`server.NewRollbackCmd`,`pruning.Cmd`,`genutilcli.InitCmd`,`genutilcli.GenTxCmd`,`genutilcli.CollectGenTxsCmd`,`genutilcli.AddGenesisAccountCmd`, do not take a home directory anymore. It is inferred from the root command. * (client) [#17259](https://github.com/cosmos/cosmos-sdk/pull/17259) Remove deprecated `clientCtx.PrintObjectLegacy`. Use `clientCtx.PrintProto` or `clientCtx.PrintRaw` instead. * (types) [#17348](https://github.com/cosmos/cosmos-sdk/pull/17348) Remove the `WrapServiceResult` function. - * The `*sdk.Result` returned by the msg server router will not contain the `.Data` field. + * The `*sdk.Result` returned by the msg server router will not contain the `.Data` field. * (types) [#17426](https://github.com/cosmos/cosmos-sdk/pull/17426) `NewContext` does not take a `cmtproto.Header{}` any longer. * `WithChainID` / `WithBlockHeight` / `WithBlockHeader` must be used to set values on the context * (client/keys) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) `clientkeys.NewKeyOutput`, `MkConsKeyOutput`, `MkValKeyOutput`, `MkAccKeyOutput`, `MkAccKeysOutput` now take their corresponding address codec instead of using the global SDK config. @@ -209,7 +203,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`. * (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument. * (server) [#20140](https://github.com/cosmos/cosmos-sdk/pull/20140) Remove embedded grpc-web proxy in favor of standalone grpc-web proxy. [Envoy Proxy](https://www.envoyproxy.io/docs/envoy/latest/start/start) -* (client) [#20255](https://github.com/cosmos/cosmos-sdk/pull/20255) Use comet proofOp proto type instead of sdk version to avoid needing to translate to later be proven in the merkle proof runtime. +* (client) [#20255](https://github.com/cosmos/cosmos-sdk/pull/20255) Use comet proofOp proto type instead of sdk version to avoid needing to translate to later be proven in the merkle proof runtime. * (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`. * (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Deprecated `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetCometConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config` * (x/genutil) [#20740](https://github.com/cosmos/cosmos-sdk/pull/20740) Update `genutilcli.Commands` and `genutilcli.CommandsWithCustomMigrationMap` to take the genesis module and abstract the module manager. @@ -218,10 +212,12 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * Remove parameter `txConfig` from `genutilcli.Commands`,`genutilcli.CommandsWithCustomMigrationMap`,`genutilcli.GenTxCmd`. * Remove parameter `addressCodec` from `genutilcli.GenTxCmd`,`genutilcli.AddGenesisAccountCmd`,`stakingcli.BuildCreateValidatorMsg`. * (sims) [#21039](https://github.com/cosmos/cosmos-sdk/pull/21039): Remove Baseapp from sims by a new interface `simtypes.AppEntrypoint`. +* (x/genutil) [#21372](https://github.com/cosmos/cosmos-sdk/pull/21372) Remove `AddGenesisAccount` for `AddGenesisAccounts`. +* (baseapp) [#21413](https://github.com/cosmos/cosmos-sdk/pull/21413) Add `SelectBy` method to `Mempool` interface, which is thread-safe to use. ### Client Breaking Changes -* (runtime) [#19040](https://github.com/cosmos/cosmos-sdk/pull/19040) Simplify app config implementation and deprecate `/cosmos/app/v1alpha1/config` query. +* (runtime) [#19040](https://github.com/cosmos/cosmos-sdk/pull/19040) Simplify app config implementation and deprecate `/cosmos/app/v1alpha1/config` query. ### CLI Breaking Changes @@ -233,6 +229,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (simapp) [#19146](https://github.com/cosmos/cosmos-sdk/pull/19146) Replace `--v` CLI option with `--validator-count`/`-n`. * (module) [#19370](https://github.com/cosmos/cosmos-sdk/pull/19370) Deprecate `module.Configurator`, use `appmodule.HasMigrations` and `appmodule.HasServices` instead from Core API. +* (types) [#21435](https://github.com/cosmos/cosmos-sdk/pull/21435) The `String()` method on `AccAddress`, `ValAddress` and `ConsAddress` have been deprecated. This is done because those are still using the deprecated global `sdk.Config`. Use an `address.Codec` instead. ## [v0.50.9](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.9) - 2024-08-07 From 98405b1227bfb992ca8228df19e9559c0f797e4d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 12 Sep 2024 08:24:28 +0200 Subject: [PATCH 06/10] refactor(server/v2): kill viper from server components (#21663) --- server/v2/api/grpc/server.go | 15 +++++++-------- server/v2/api/grpcgateway/server.go | 11 +++++------ server/v2/cometbft/config.go | 14 -------------- server/v2/cometbft/go.mod | 2 +- server/v2/cometbft/server.go | 21 ++++++++++++++------- server/v2/commands.go | 2 +- server/v2/config.go | 19 +++++++++++-------- server/v2/config_test.go | 5 +++-- server/v2/server.go | 15 +++++++-------- server/v2/server_mock_test.go | 4 +--- server/v2/server_test.go | 5 +++-- server/v2/store/server.go | 11 +++++------ 12 files changed, 58 insertions(+), 66 deletions(-) diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index b66be16da602..0003f2343222 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" - "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -47,10 +46,10 @@ func New[T transaction.Tx](cfgOptions ...CfgOption) *Server[T] { // Init returns a correctly configured and initialized gRPC server. // Note, the caller is responsible for starting the server. -func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { - cfg := s.Config().(*Config) - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, s.Name(), &cfg); err != nil { +func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { + serverCfg := s.Config().(*Config) + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } @@ -58,8 +57,8 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logge grpcSrv := grpc.NewServer( grpc.ForceServerCodec(newProtoCodec(appI.InterfaceRegistry()).GRPCCodec()), - grpc.MaxSendMsgSize(cfg.MaxSendMsgSize), - grpc.MaxRecvMsgSize(cfg.MaxRecvMsgSize), + grpc.MaxSendMsgSize(serverCfg.MaxSendMsgSize), + grpc.MaxRecvMsgSize(serverCfg.MaxRecvMsgSize), grpc.UnknownServiceHandler( makeUnknownServiceHandler(methodsMap, appI.GetAppManager()), ), @@ -69,7 +68,7 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logge gogoreflection.Register(grpcSrv, slices.Collect(maps.Keys(methodsMap)), logger.With("sub-module", "grpc-reflection")) s.grpcSrv = grpcSrv - s.config = cfg + s.config = serverCfg s.logger = logger.With(log.ModuleKey, s.Name()) return nil diff --git a/server/v2/api/grpcgateway/server.go b/server/v2/api/grpcgateway/server.go index 028027a83a07..05a6bf1aa829 100644 --- a/server/v2/api/grpcgateway/server.go +++ b/server/v2/api/grpcgateway/server.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/gogoproto/jsonpb" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/viper" "google.golang.org/grpc" "cosmossdk.io/core/transaction" @@ -83,10 +82,10 @@ func (s *GRPCGatewayServer[T]) Config() any { return s.config } -func (s *GRPCGatewayServer[T]) Init(appI serverv2.AppI[transaction.Tx], v *viper.Viper, logger log.Logger) error { - cfg := s.Config().(*Config) - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, s.Name(), &cfg); err != nil { +func (s *GRPCGatewayServer[T]) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error { + serverCfg := s.Config().(*Config) + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } @@ -95,7 +94,7 @@ func (s *GRPCGatewayServer[T]) Init(appI serverv2.AppI[transaction.Tx], v *viper // appI.RegisterGRPCGatewayRoutes(s.GRPCGatewayRouter, s.GRPCSrv) s.logger = logger - s.config = cfg + s.config = serverCfg return nil } diff --git a/server/v2/cometbft/config.go b/server/v2/cometbft/config.go index 56860a78ddaf..81f3aeb33354 100644 --- a/server/v2/cometbft/config.go +++ b/server/v2/cometbft/config.go @@ -2,9 +2,6 @@ package cometbft import ( cmtcfg "github.com/cometbft/cometbft/config" - "github.com/spf13/viper" - - serverv2 "cosmossdk.io/server/v2" ) // Config is the configuration for the CometBFT application @@ -53,14 +50,3 @@ func OverwriteDefaultAppTomlConfig(newCfg *AppTomlConfig) CfgOption { cfg.AppTomlConfig = newCfg } } - -func getConfigTomlFromViper(v *viper.Viper) *cmtcfg.Config { - rootDir := v.GetString(serverv2.FlagHome) - - conf := cmtcfg.DefaultConfig() - if err := v.Unmarshal(conf); err != nil { - return cmtcfg.DefaultConfig().SetRoot(rootDir) - } - - return conf.SetRoot(rootDir) -} diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 3709cd1f4561..57b947da1fe3 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -37,7 +37,6 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 google.golang.org/grpc v1.66.1 @@ -150,6 +149,7 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect + github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 14e7cdb7bcaa..26cd99ff97cd 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -19,7 +19,6 @@ import ( "github.com/cometbft/cometbft/proxy" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/spf13/viper" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -58,23 +57,31 @@ func New[T transaction.Tx](txCodec transaction.Codec[T], serverOptions ServerOpt } } -func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { +func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { + home, _ := cfg[serverv2.FlagHome].(string) + // get configs (app.toml + config.toml) from viper appTomlConfig := s.Config().(*AppTomlConfig) - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, s.Name(), &appTomlConfig); err != nil { + configTomlConfig := cmtcfg.DefaultConfig().SetRoot(home) + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &appTomlConfig); err != nil { + return fmt.Errorf("failed to unmarshal config: %w", err) + } + + if err := serverv2.UnmarshalSubConfig(cfg, "", &configTomlConfig); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } + s.config = Config{ - ConfigTomlConfig: getConfigTomlFromViper(v), + ConfigTomlConfig: configTomlConfig, AppTomlConfig: appTomlConfig, } - chainID := v.GetString(FlagChainID) + chainID, _ := cfg[FlagChainID].(string) if chainID == "" { // fallback to genesis chain-id - reader, err := os.Open(filepath.Join(v.GetString(serverv2.FlagHome), "config", "genesis.json")) + reader, err := os.Open(filepath.Join(home, "config", "genesis.json")) if err != nil { panic(err) } diff --git a/server/v2/commands.go b/server/v2/commands.go index 101a23d3983e..8651074f406f 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -112,7 +112,7 @@ func createStartCommand[T transaction.Tx]( return err } - if err := server.Init(newApp(l, v), v, l); err != nil { + if err := server.Init(newApp(l, v), v.AllSettings(), l); err != nil { return err } diff --git a/server/v2/config.go b/server/v2/config.go index b5c525fdf682..0670bc374a24 100644 --- a/server/v2/config.go +++ b/server/v2/config.go @@ -39,16 +39,19 @@ func ReadConfig(configPath string) (*viper.Viper, error) { return v, nil } -// UnmarshalSubConfig unmarshals the given subconfig from the viper instance. -// It unmarshals the config, env, flags into the target struct. -// Use this instead of viper.Sub because viper does not unmarshal flags. -func UnmarshalSubConfig(v *viper.Viper, subName string, target any) error { +// UnmarshalSubConfig unmarshals the given (sub) config from the main config (given as a map) into the target. +// If subName is empty, the main config is unmarshaled into the target. +func UnmarshalSubConfig(cfg map[string]any, subName string, target any) error { var sub any - for k, val := range v.AllSettings() { - if k == subName { - sub = val - break + if subName != "" { + for k, val := range cfg { + if k == subName { + sub = val + break + } } + } else { + sub = cfg } // Create a new decoder with custom decoding options diff --git a/server/v2/config_test.go b/server/v2/config_test.go index a24cd4cf3d2e..6577b81192fb 100644 --- a/server/v2/config_test.go +++ b/server/v2/config_test.go @@ -31,16 +31,17 @@ func TestUnmarshalSubConfig(t *testing.T) { v, err := serverv2.ReadConfig(configPath) require.NoError(t, err) + cfg := v.AllSettings() grpcConfig := grpc.DefaultConfig() - err = serverv2.UnmarshalSubConfig(v, "grpc", &grpcConfig) + err = serverv2.UnmarshalSubConfig(cfg, "grpc", &grpcConfig) require.NoError(t, err) require.True(t, grpc.DefaultConfig().Enable) require.False(t, grpcConfig.Enable) storeConfig := store.Config{} - err = serverv2.UnmarshalSubConfig(v, "store", &storeConfig) + err = serverv2.UnmarshalSubConfig(cfg, "store", &storeConfig) require.NoError(t, err) require.Equal(t, *store.DefaultConfig(), storeConfig) } diff --git a/server/v2/server.go b/server/v2/server.go index 08ae9a6a06fa..d1062618ab60 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -10,7 +10,6 @@ import ( "github.com/pelletier/go-toml/v2" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/spf13/viper" "golang.org/x/sync/errgroup" "cosmossdk.io/core/transaction" @@ -23,7 +22,7 @@ type ServerComponent[T transaction.Tx] interface { Start(context.Context) error Stop(context.Context) error - Init(AppI[T], *viper.Viper, log.Logger) error + Init(AppI[T], map[string]any, log.Logger) error } // HasStartFlags is a server module that has start flags. @@ -189,10 +188,10 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { // Init initializes all server components with the provided application, configuration, and logger. // It returns an error if any component fails to initialize. -func (s *Server[T]) Init(appI AppI[T], v *viper.Viper, logger log.Logger) error { - cfg := s.config - if v != nil { - if err := UnmarshalSubConfig(v, s.Name(), &cfg); err != nil { +func (s *Server[T]) Init(appI AppI[T], cfg map[string]any, logger log.Logger) error { + serverCfg := s.config + if len(cfg) > 0 { + if err := UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } @@ -200,14 +199,14 @@ func (s *Server[T]) Init(appI AppI[T], v *viper.Viper, logger log.Logger) error var components []ServerComponent[T] for _, mod := range s.components { mod := mod - if err := mod.Init(appI, v, logger); err != nil { + if err := mod.Init(appI, cfg, logger); err != nil { return err } components = append(components, mod) } - s.config = cfg + s.config = serverCfg s.components = components return nil } diff --git a/server/v2/server_mock_test.go b/server/v2/server_mock_test.go index ae238d66a57a..8b590ba2d32f 100644 --- a/server/v2/server_mock_test.go +++ b/server/v2/server_mock_test.go @@ -5,8 +5,6 @@ import ( "fmt" "math/rand" - "github.com/spf13/viper" - "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" @@ -33,7 +31,7 @@ func (s *mockServer) Name() string { return s.name } -func (s *mockServer) Init(appI serverv2.AppI[transaction.Tx], v *viper.Viper, logger log.Logger) error { +func (s *mockServer) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error { return nil } diff --git a/server/v2/server_test.go b/server/v2/server_test.go index 98b1def5ab9f..e84bcd598890 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -56,14 +56,15 @@ func TestServer(t *testing.T) { if err != nil { v = viper.New() } + cfg := v.AllSettings() logger := log.NewLogger(os.Stdout) grpcServer := grpc.New[transaction.Tx]() - err = grpcServer.Init(&mockApp[transaction.Tx]{}, v, logger) + err = grpcServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) require.NoError(t, err) storeServer := store.New[transaction.Tx](nil /* nil appCreator as not using CLI commands */) - err = storeServer.Init(&mockApp[transaction.Tx]{}, v, logger) + err = storeServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) require.NoError(t, err) mockServer := &mockServer{name: "mock-server-1", ch: make(chan string, 100)} diff --git a/server/v2/store/server.go b/server/v2/store/server.go index 1177c6a0c414..e16a09137a4b 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/spf13/viper" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -24,14 +23,14 @@ func New[T transaction.Tx](appCreator serverv2.AppCreator[T]) *StoreComponent[T] return &StoreComponent[T]{appCreator: appCreator} } -func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { - cfg := DefaultConfig() - if v != nil { - if err := serverv2.UnmarshalSubConfig(v, s.Name(), &cfg); err != nil { +func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { + serverCfg := DefaultConfig() + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } - s.config = cfg + s.config = serverCfg return nil } From 22a4a87444f243125a5f2d0f01e1a44537197413 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 14:47:07 +0800 Subject: [PATCH 07/10] build: don't reinstall golangci-lint if already installed (#21662) --- scripts/build/linting.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build/linting.mk b/scripts/build/linting.mk index 58d481a235fb..6e723c5f84f7 100644 --- a/scripts/build/linting.mk +++ b/scripts/build/linting.mk @@ -1,4 +1,5 @@ golangci_version=v1.60.1 +golangci_installed_version=$(shell golangci-lint version --format short 2>/dev/null) #? setup-pre-commit: Set pre-commit git hook setup-pre-commit: @@ -9,8 +10,10 @@ setup-pre-commit: #? lint-install: Install golangci-lint lint-install: +ifneq ($(golangci_installed_version),$(golangci_version)) @echo "--> Installing golangci-lint $(golangci_version)" @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) +endif #? lint: Run golangci-lint lint: From dbeb3f63305feadc430b8e2801348e2b03f09051 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 15:09:21 +0800 Subject: [PATCH 08/10] fix linter warning --- crypto/keyring/keyring_linux.go | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go index 009aef525599..9ca03073a5c2 100644 --- a/crypto/keyring/keyring_linux.go +++ b/crypto/keyring/keyring_linux.go @@ -8,6 +8,7 @@ import ( "io" "github.com/99designs/keyring" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/ledger" "github.com/cosmos/cosmos-sdk/crypto/types" From 434b5f237bdca0412f254cb3d5090df331a29691 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 15:28:46 +0800 Subject: [PATCH 09/10] add tests Signed-off-by: Alessio Treglia --- crypto/keyring/keyring_linux_test.go | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 crypto/keyring/keyring_linux_test.go diff --git a/crypto/keyring/keyring_linux_test.go b/crypto/keyring/keyring_linux_test.go new file mode 100644 index 000000000000..50d5db3e8c0d --- /dev/null +++ b/crypto/keyring/keyring_linux_test.go @@ -0,0 +1,50 @@ +//go:build linux +// +build linux + +package keyring + +import ( + "errors" + "io" + "strings" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" +) + +func TestNewKeyctlKeyring(t *testing.T) { + cdc := getCodec() + + tests := []struct { + name string + appName string + backend string + dir string + userInput io.Reader + cdc codec.Codec + expectedErr error + }{ + { + name: "keyctl backend", + appName: "cosmos", + backend: BackendKeyctl, + dir: t.TempDir(), + userInput: strings.NewReader(""), + cdc: cdc, + expectedErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + kr, err := New(tt.appName, tt.backend, tt.dir, tt.userInput, tt.cdc) + if tt.expectedErr == nil { + require.NoError(t, err) + } else { + require.Error(t, err) + require.Nil(t, kr) + require.True(t, errors.Is(err, tt.expectedErr)) + } + }) + } +} From fedc20ac371612c02c2ab100769f2a985b23b684 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Sep 2024 15:50:03 +0800 Subject: [PATCH 10/10] fix linter warnings Signed-off-by: Alessio Treglia --- crypto/keyring/keyring_linux.go | 1 - crypto/keyring/keyring_linux_test.go | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go index 9ca03073a5c2..7db47961bab1 100644 --- a/crypto/keyring/keyring_linux.go +++ b/crypto/keyring/keyring_linux.go @@ -64,7 +64,6 @@ func newKeyctlBackendConfig(appName, _ string, _ io.Reader, opts ...Option) keyr func New( appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, ) (Keyring, error) { - if backend != BackendKeyctl { return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) } diff --git a/crypto/keyring/keyring_linux_test.go b/crypto/keyring/keyring_linux_test.go index 50d5db3e8c0d..a6695b6b9471 100644 --- a/crypto/keyring/keyring_linux_test.go +++ b/crypto/keyring/keyring_linux_test.go @@ -9,8 +9,9 @@ import ( "strings" "testing" - "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec" ) func TestNewKeyctlKeyring(t *testing.T) {