From b384313dad8bc4ca599c3c53d93552e29efd2d93 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 27 Mar 2024 08:12:49 +0100 Subject: [PATCH 1/5] feat(server): add custom start handler (#19854) (cherry picked from commit def211d8681856b4532e7f77a7653d5bb5945e00) # Conflicts: # CHANGELOG.md # UPGRADING.md # docs/docs/build/building-apps/05-app-testnet.md # server/start.go # server/util.go # simapp/simd/cmd/commands.go # simapp/simd/cmd/root.go # simapp/simd/cmd/root_v2.go --- CHANGELOG.md | 119 +++++++ UPGRADING.md | 298 ++++++++++++++++++ .../build/building-apps/05-app-testnet.md | 5 + server/start.go | 36 ++- server/types/app.go | 4 - server/util.go | 20 +- simapp/simd/cmd/commands.go | 10 +- simapp/simd/cmd/root.go | 12 + simapp/simd/cmd/root_v2.go | 4 + 9 files changed, 488 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 703883327cf5..07d13f160097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,12 +44,131 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +<<<<<<< HEAD * (x/gov) [#19853](https://github.com/cosmos/cosmos-sdk/pull/19853) Emit `depositor` in `EventTypeProposalDeposit`. * (x/gov) [#19844](https://github.com/cosmos/cosmos-sdk/pull/19844) Emit the proposer of governance proposals. +======= +* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Add customizability to start command. + * Add `StartCmdOptions` in `server.AddCommands` instead of `servertypes.ModuleInitFlags`. To set custom flags set them in the `StartCmdOptions` struct on the `AddFlags` field. + * Add `StartCommandHandler` to `StartCmdOptions` to allow custom start command handlers. Users now have total control over how the app starts. +* (types) [#19672](https://github.com/cosmos/cosmos-sdk/pull/19672) `PreBlock` now returns only an error for consistency with server/v2. The SDK has upgraded x/upgrade accordingly. `ResponsePreBlock` hence has been removed. +* (server) [#19455](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. +* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore (and all related helpers). + * The module manager now can do everything that the basic manager was doing. + * `AppModuleBasic` has been deprecated for extension interfaces. + * Modules can now implement `appmodule.HasRegisterInterfaces`, `modue.HasGRPCGateway` and `module.HasAminoCodec` when relevant. + * SDK modules now directly implement those extension interfaces on `AppModule` instead of `AppModuleBasic`. +* (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. +* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. +* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. +* (client/keys) [#18703](https://github.com/cosmos/cosmos-sdk/pull/18703) Improve ` keys add` and ` keys show` by checking whether there are duplicate keys in the multisig case. + * Usage of `Must...` kind of functions are avoided in keeper methods. +* (client/keys) [#18687](https://github.com/cosmos/cosmos-sdk/pull/18687) Improve ` keys mnemonic` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (client/keys) [#18684](https://github.com/cosmos/cosmos-sdk/pull/18684) Improve ` keys export` by displaying unarmored hex private key discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (client/keys) [#18663](https://github.com/cosmos/cosmos-sdk/pull/18663) Improve ` keys add` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (types) [#18440](https://github.com/cosmos/cosmos-sdk/pull/18440) Add `AmountOfNoValidation` to `sdk.DecCoins`. +* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details. +* (crypto/keyring) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Simplify keyring interfaces to use `[]byte` instead of `sdk.Address` for addresses. +* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated `fmt.Errorf` errors and using `errors.New` where appropriate. +* (rpc) [#17470](https://github.com/cosmos/cosmos-sdk/pull/17470) Avoid open 0.0.0.0 to public by default and add `listen-ip-address` argument for `testnet init-files` cmd. +* (types) [#17670](https://github.com/cosmos/cosmos-sdk/pull/17670) Use `ctx.CometInfo` in place of `ctx.VoteInfos` +* [#17733](https://github.com/cosmos/cosmos-sdk/pull/17733) Ensure `buf export` exports all proto dependencies +* (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1` +* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle. +* (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding +* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. +* (x/genutil) [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ## Bug Fixes +<<<<<<< HEAD * (crypto) [#19691](https://github.com/cosmos/cosmos-sdk/pull/19745) Fix tx sign doesn't throw an error when incorrect Ledger is used. +======= +* (baseapp) [#18727](https://github.com/cosmos/cosmos-sdk/pull/18727) Ensure that `BaseApp.Init` firstly returns any errors from a nil commit multistore instead of panicking on nil dereferencing and before sealing the app. +* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec. +* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found. +* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests. +* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server. +* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test. +* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test. +* (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT +* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object +* (crypto) [#19691](https://github.com/cosmos/cosmos-sdk/pull/19691) Fix tx sign doesn't throw an error when incorrect Ledger is used. +* [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk. +* [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov). + +### API Breaking Changes + +* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Remove `servertypes.ModuleInitFlags` types and from `server.AddCommands` as `StartCmdOptions` already achieves the same goal. +* (types) [#19792](https://github.com/cosmos/cosmos-sdk/pull/19792) In `MsgSimulatorFn` `sdk.Context` argument is replaced for an `address.Codec`. It also returns an error. +* (types) [#19742](https://github.com/cosmos/cosmos-sdk/pull/19742) Removes the use of `Accounts.String` + * `SimulationState` now has address and validator codecs as fields. +* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument. +* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`). + * The module manager now can do everything that the basic manager was doing. + * When using runtime, just inject the module manager when needed using your app config. + * All `AppModuleBasic` structs have been removed. +* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services. +* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does. +* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration. +* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration. +* (x/bank/testutil) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) `MsgSendExec` has been removed because of AutoCLI migration. +* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo. + * The Cosmos SDK has migrated away from using params, if your app still uses it, then you can leave it plugged into your app +* (types/simulation) [#17737](https://github.com/cosmos/cosmos-sdk/pull/17737) Remove unused parameter from `RandomFees` +* (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. +* (types) `module.BeginBlockAppModule` has been replaced by Core API `appmodule.HasBeginBlocker`. +* (types) `module.EndBlockAppModule` has been replaced by Core API `appmodule.HasEndBlocker` or `module.HasABCIEndBlock` when needing validator updates. +* (client) [#17259](https://github.com/cosmos/cosmos-sdk/pull/17259) Remove deprecated `clientCtx.PrintObjectLegacy`. Use `clientCtx.PrintProto` or `clientCtx.PrintRaw` instead. +* (types) [#16918](https://github.com/cosmos/cosmos-sdk/pull/16918) Remove `IntProto` and `DecProto`. Instead, `math.Int` and `math.LegacyDec` should be used respectively. Both types support `Marshal` and `Unmarshal` which should be used for binary marshaling. +* (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. +* (baseapp) [#16244](https://github.com/cosmos/cosmos-sdk/pull/16244) `SetProtocolVersion` has been renamed to `SetAppVersion`. It now updates the consensus params in baseapp's `ParamStore`. +* (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. +* (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 +* (types) [#17738](https://github.com/cosmos/cosmos-sdk/pull/17738) `WithBlockTime()` was removed & `BlockTime()` were deprecated in favor of `WithHeaderInfo()` & `HeaderInfo()`. `BlockTime` now gets data from `HeaderInfo()` instead of `BlockHeader()`. +* (client) [#17746](https://github.com/cosmos/cosmos-sdk/pull/17746) `txEncodeAmino` & `txDecodeAmino` txs via grpc and rest were removed + * `RegisterLegacyAmino` was removed from `AppModuleBasic` +* (types) [#17885](https://github.com/cosmos/cosmos-sdk/pull/17885) `InitGenesis` & `ExportGenesis` now take `context.Context` instead of `sdk.Context` +* (x/group) [#17937](https://github.com/cosmos/cosmos-sdk/pull/17937) Groups module was moved to its own go.mod `cosmossdk.io/x/group` +* (x/gov) [#18197](https://github.com/cosmos/cosmos-sdk/pull/18197) Gov module was moved to its own go.mod `cosmossdk.io/x/gov` +* (x/distribution) [#18199](https://github.com/cosmos/cosmos-sdk/pull/18199) Distribution module was moved to its own go.mod `cosmossdk.io/x/distribution` +* (x/slashing) [#18201](https://github.com/cosmos/cosmos-sdk/pull/18201) Slashing module was moved to its own go.mod `cosmossdk.io/x/slashing` +* (x/staking) [#18257](https://github.com/cosmos/cosmos-sdk/pull/18257) Staking module was moved to its own go.mod `cosmossdk.io/x/staking` +* (x/authz) [#18265](https://github.com/cosmos/cosmos-sdk/pull/18265) Authz module was moved to its own go.mod `cosmossdk.io/x/authz` +* (x/mint) [#18283](https://github.com/cosmos/cosmos-sdk/pull/18283) Mint module was moved to its own go.mod `cosmossdk.io/x/mint` +* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error +* (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress` +* (types) [#18268](https://github.com/cosmos/cosmos-sdk/pull/18268) Remove global setting of basedenom. Use the staking module parameter instead +* (x/auth) [#18351](https://github.com/cosmos/cosmos-sdk/pull/18351) Auth module was moved to its own go.mod `cosmossdk.io/x/auth` +* (types) [#18372](https://github.com/cosmos/cosmos-sdk/pull/18372) Removed global configuration for coin type and purpose. Setters and getters should be removed and access directly to defined types. +* (types) [#18695](https://github.com/cosmos/cosmos-sdk/pull/18695) Removed global configuration for txEncoder. +* (types) [#18607](https://github.com/cosmos/cosmos-sdk/pull/18607) Removed address verifier from global config, moved verifier function to bech32 codec. +* (server) [#18909](https://github.com/cosmos/cosmos-sdk/pull/18909) Remove configuration endpoint on grpc reflection endpoint in favour of auth module bech32prefix endpoint already exposed. +* (crypto) [#19541](https://github.com/cosmos/cosmos-sdk/pull/19541) The deprecated `FromTmProtoPublicKey`, `ToTmProtoPublicKey`, `FromTmPubKeyInterface` and `ToTmPubKeyInterface` functions have been removed. Use their replacements (`Cmt` instead of `Tm`) instead. +* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758) + * Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`. + * Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface. +* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) and [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) All genesis interfaces now don't take `codec.JsonCodec`. + * Every module has the codec already, passing it created an unneeded dependency. + * Additionally, to reflect this change, the module manager does not take a codec either. +* (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`. + +### Client Breaking Changes + +* (runtime) [#19040](https://github.com/cosmos/cosmos-sdk/pull/19040) Simplify app config implementation and deprecate `/cosmos/app/v1alpha1/config` query. + +### CLI Breaking Changes + +* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `appd export` has moved with other genesis commands, use `appd genesis export` instead. + +### Deprecated + +* (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. +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-03-12 diff --git a/UPGRADING.md b/UPGRADING.md index 354844624ae6..b1b7691c297b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -3,7 +3,305 @@ This guide provides instructions for upgrading to specific versions of Cosmos SDK. Note, always read the **SimApp** section for more information on application wiring updates. +<<<<<<< HEAD ## [v0.50.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0) +======= +## [Unreleased] + +### SimApp + +In this section we describe the changes made in Cosmos SDK' SimApp. +**These changes are directly applicable to your application wiring.** + +#### Client (`root.go`) + +The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.) +and address bech32 prefixes (address and validator address). +This is part of the work of abstracting the SDK from the global bech32 config. + +This means the address codecs and prefixes must be provided in the `client.Context` in the application client (usually `root.go`). + +```diff +clientCtx = clientCtx. ++ WithAddressCodec(addressCodec). ++ WithValidatorAddressCodec(validatorAddressCodec). ++ WithConsensusAddressCodec(consensusAddressCodec). ++ WithAddressPrefix("cosmos"). ++ WithValidatorPrefix("cosmosvaloper") +``` + +**When using `depinject` / `app v2`, the client codecs can be provided directly from application config.** + +Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a legacy app. + +Additionally, a simplification of the start command leads to the following change: + +```diff +- server.AddCommands(rootCmd, newApp, func(startCmd *cobra.Command) {}) ++ server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) +``` + +#### Server (`app.go`) + +##### Module Manager + +The basic module manager has been deleted. It was not necessary anymore and was simplified to use the `module.Manager` directly. +It can be removed from your `app.go`. + +For depinject users, it isn't necessary anymore to supply a `map[string]module.AppModuleBasic` for customizing the app module basic instantiation. +The custom parameters (such as genutil message validator or gov proposal handler, or evidence handler) can directly be supplied. +When requiring a module manager in `root.go`, inject `*module.Manager` using `depinject.Inject`. + +For non depinject users, simply call `RegisterLegacyAminoCodec` and `RegisterInterfaces` on the module manager: + +```diff +-app.BasicModuleManager = module.NewBasicManagerFromManager(...) +-app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) +-app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) ++app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino) ++app.ModuleManager.RegisterInterfaces(interfaceRegistry) +``` + +Additionally, thanks to the genesis simplification, as explained in [the genesis interface update](#genesis-interface), the module manager `InitGenesis` and `ExportGenesis` methods do not require the codec anymore. + +##### AnteHandlers + +The `GasConsumptionDecorator` and `IncreaseSequenceDecorator` have been merged with the SigVerificationDecorator, so you'll +need to remove them both from your app.go code, they will yield to unresolvable symbols when compiling. + +#### Unordered Transactions + +The Cosmos SDK now supports unordered transactions. This means that transactions +can be executed in any order and doesn't require the client to deal with or manage +nonces. This also means the order of execution is not guaranteed. To enable unordered +transactions in your application: + +* Update the `App` constructor to create, load, and save the unordered transaction + manager. + + ```go + func NewApp(...) *App { + // ... + + // create, start, and load the unordered tx manager + utxDataDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data") + app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir) + app.UnorderedTxManager.Start() + + if err := app.UnorderedTxManager.OnInit(); err != nil { + panic(fmt.Errorf("failed to initialize unordered tx manager: %w", err)) + } + } + ``` + +* Add the decorator to the existing AnteHandler chain, which should be as early + as possible. + + ```go + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), + // ... + ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, app.UnorderedTxManager), + // ... + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil + ``` + +* If the App has a SnapshotManager defined, you must also register the extension + for the TxManager. + + ```go + if manager := app.SnapshotManager(); manager != nil { + err := manager.RegisterExtensions(unorderedtx.NewSnapshotter(app.UnorderedTxManager)) + if err != nil { + panic(fmt.Errorf("failed to register snapshot extension: %s", err)) + } + } + ``` + +* Create or update the App's `Close()` method to close the unordered tx manager. + Note, this is critical as it ensures the manager's state is written to file + such that when the node restarts, it can recover the state to provide replay + protection. + + ```go + func (app *App) Close() error { + // ... + + // close the unordered tx manager + if e := app.UnorderedTxManager.Close(); e != nil { + err = errors.Join(err, e) + } + + return err + } + ``` + +To submit an unordered transaction, the client must set the `unordered` flag to +`true` and ensure a reasonable `timeout_height` is set. The `timeout_height` is +used as a TTL for the transaction and is used to provide replay protection. See +[ADR-070](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-070-unordered-transactions.md) +for more details. + +### Protobuf + +The `cosmossdk.io/api/tendermint` package has been removed as CometBFT now publishes its protos to `buf.build/tendermint` and `buf.build/cometbft`. +There is no longer a need for the Cosmos SDK to host these protos for itself and its dependencies. +That package containing proto v2 generated code, but the SDK now uses [buf generated go SDK instead](https://buf.build/docs/bsr/generated-sdks/go). +If you were depending on `cosmossdk.io/api/tendermint`, please use the buf generated go SDK instead, or ask CometBFT host the generated proto v2 code. + +### Modules + +#### `**all**` + +##### Simulation + +`MsgSimulatorFn` has been updated to return an error. Its context argument has been removed, and an address.Codec has +been added to avoid the use of the Accounts.String() method. + +```diff +-type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg ++type MsgSimulatorFn func(r *rand.Rand, accs []Account, cdc address.Codec) (sdk.Msg, error) +``` + +##### Core API + +Core API has been introduced for modules since v0.47. With the deprecation of `sdk.Context`, we strongly recommend to use the `cosmossdk.io/core/appmodule` interfaces for the modules. This will allow the modules to work out of the box with server/v2 and baseapp, as well as limit their dependencies on the SDK. + +Additionally, the `appmodule.Environment` interface is introduced to fetch different services from the application. +This should be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. +It needs to be passed into a module at instantiation. + +`x/circuit` is used as an example: + +```go +app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) +``` + +If your module requires a message server or query server, it should be passed in the environment as well. + +```diff +-govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AuthKeeper, app.BankKeeper,app.StakingKeeper, app.PoolKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) ++govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) +``` + +The signature of the extension interface `HasRegisterInterfaces` has been changed to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` instead of a `codec.InterfaceRegistry`. `HasRegisterInterfaces` is now a part of `cosmossdk.io/core/appmodule`. Modules should update their `HasRegisterInterfaces` implementation to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` interface. + +```diff +-func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { ++func (AppModule) RegisterInterfaces(registry registry.InterfaceRegistrar) { +``` + +##### Dependency Injection + +Previously `cosmossdk.io/core` held functions `Invoke`, `Provide` and `Register` were moved to `cosmossdk.io/depinject/appconfig`. +All modules using dependency injection must update their imports. + +##### Params + +Previous module migrations have been removed. It is required to migrate to v0.50 prior to upgrading to v0.51 for not missing any module migrations. + +##### Genesis Interface + +All genesis interfaces have been migrated to take `context.Context` instead of `sdk.Context`. +Secondly, the codec is no longer passed in by the framework. The codec is now passed in by the module. +Lastly, all InitGenesis and ExportGenesis functions now return an error. + +```go +// InitGenesis performs genesis initialization for the module. +func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { +} + +// ExportGenesis returns the exported genesis state as raw bytes for the module. +func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { +} +``` + +##### Migration to Collections + +Most of Cosmos SDK modules have migrated to [collections](https://docs.cosmos.network/main/build/packages/collections). +Many functions have been removed due to this changes as the API can be smaller thanks to collections. +For modules that have migrated, verify you are checking against `collections.ErrNotFound` when applicable. + +#### `x/auth` + +Auth was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/auth` + +#### `x/authz` + +Authz was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/authz` + +#### `x/bank` + +Bank was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/bank` + +#### `x/distribution` + +Distribution was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/distribution` + +The existing chains using x/distribution module needs to add the new x/protocolpool module. + +#### `x/group` + +Group was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/group` + +#### `x/gov` + +Gov was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/gov` + +Gov v1beta1 proposal handler has been changed to take in a `context.Context` instead of `sdk.Context`. +This change was made to allow legacy proposals to be compatible with server/v2. +If you wish to migrate to server/v2, you should update your proposal handler to take in a `context.Context` and use services. +On the other hand, if you wish to keep using baseapp, simply unwrap the sdk context in your proposal handler. + +#### `x/mint` + +Mint was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/mint` + +#### `x/slashing` + +Slashing was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/slashing` + +#### `x/staking` + +Staking was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/staking` + +#### `x/params` + +A standalone Go module was created and it is accessible at "cosmossdk.io/x/params". + +#### `x/protocolpool` + +Introducing a new `x/protocolpool` module to handle community pool funds. Its store must be added while upgrading to v0.51.x. + +Example: + +```go +func (app SimApp) RegisterUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler( + UpgradeName, + func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) + }, + ) + + // ... +} +``` + +Add `x/protocolpool` store while upgrading to v0.51.x: + +```go +storetypes.StoreUpgrades{ + Added: []string{ + protocolpooltypes.ModuleName, + }, +} +``` + +## [v0.50.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.0) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ### Migration to CometBFT (Part 2) diff --git a/docs/docs/build/building-apps/05-app-testnet.md b/docs/docs/build/building-apps/05-app-testnet.md index 607599cc1952..f06d805e17eb 100644 --- a/docs/docs/build/building-apps/05-app-testnet.md +++ b/docs/docs/build/building-apps/05-app-testnet.md @@ -195,8 +195,13 @@ Before we can run the testnet we must plug everything together. in `root.go`, in the `initRootCmd` function we add: ```diff +<<<<<<< HEAD:docs/docs/build/building-apps/05-app-testnet.md server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createsimAppAndExport, addModuleInitFlags) ++ server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp, addModuleInitFlags) +======= +server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createMerlinAppAndExport) ++server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)):docs/build/building-apps/05-app-testnet.md ``` Next we will add a newTestnetApp helper function: diff --git a/server/start.go b/server/start.go index 71874cd4269f..b68bb9168804 100644 --- a/server/start.go +++ b/server/start.go @@ -117,6 +117,8 @@ type StartCmdOptions struct { PostSetup func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) + // StartCommandHanlder can be used to customize the start command handler + StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error } // StartCmd runs the service passed in, either stand-alone or in-process with @@ -132,6 +134,10 @@ func StartCmdWithOptions(appCreator types.AppCreator, defaultNodeHome string, op opts.DBOpener = openDB } + if opts.StartCommandHandler == nil { + opts.StartCommandHandler = start + } + cmd := &cobra.Command{ Use: "start", Short: "Run the full node", @@ -187,7 +193,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. } err = wrapCPUProfile(serverCtx, func() error { - return start(serverCtx, clientCtx, appCreator, withCMT, opts) + return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts) }) serverCtx.Logger.Debug("received quit signal") @@ -271,10 +277,7 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie return err } - cmtCfg := svrCtx.Config - home := cmtCfg.RootDir - - err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, svrCtx.Config.RootDir, grpcSrv, metrics) if err != nil { return err } @@ -299,8 +302,6 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien metrics *telemetry.Metrics, opts StartCmdOptions, ) error { cmtCfg := svrCtx.Config - home := cmtCfg.RootDir - gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) g, ctx := getCtx(svrCtx, true) @@ -336,7 +337,7 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien return err } - err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, cmtCfg.RootDir, grpcSrv, metrics) if err != nil { return err } @@ -499,7 +500,6 @@ func startGrpcServer( func startAPIServer( ctx context.Context, g *errgroup.Group, - cmtCfg *cmtcfg.Config, svrCfg serverconfig.Config, clientCtx client.Context, svrCtx *Context, @@ -606,7 +606,12 @@ func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions } if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { +<<<<<<< HEAD app, err = testnetify(svrCtx, home, appCreator, db, traceWriter) +======= + var appPtr *T + appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) if err != nil { return app, traceCleanupFn, err } @@ -632,6 +637,10 @@ func InPlaceTestnetCreator(testnetAppCreator types.AppCreator) *cobra.Command { opts.DBOpener = openDB } + if opts.StartCommandHandler == nil { + opts.StartCommandHandler = start + } + cmd := &cobra.Command{ Use: "in-place-testnet [newChainID] [newOperatorAddress]", Short: "Create and start a testnet from current local state", @@ -696,7 +705,7 @@ you want to test the upgrade handler itself. serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) err = wrapCPUProfile(serverCtx, func() error { - return start(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) + return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) }) serverCtx.Logger.Debug("received quit signal") @@ -719,7 +728,11 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. +<<<<<<< HEAD func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) { +======= +func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) config := ctx.Config newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) @@ -765,9 +778,6 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d return nil, err } validatorAddress := userPubKey.Address() - if err != nil { - return nil, err - } stateStore := sm.NewStore(stateDB, sm.StoreOptions{ DiscardABCIResponses: config.Storage.DiscardABCIResponses, diff --git a/server/types/app.go b/server/types/app.go index 3b5feab3c0ca..bf2e728305ca 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -8,7 +8,6 @@ import ( cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/grpc" - "github.com/spf13/cobra" "cosmossdk.io/log" "cosmossdk.io/store/snapshots" @@ -68,9 +67,6 @@ type ( // application using various configurations. AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application - // ModuleInitFlags takes a start command and adds modules specific init flags. - ModuleInitFlags func(startCmd *cobra.Command) - // ExportedApp represents an exported app state, along with // validators, consensus params and latest app height. ExportedApp struct { diff --git a/server/util.go b/server/util.go index b1cbec13f751..072f63744674 100644 --- a/server/util.go +++ b/server/util.go @@ -311,8 +311,13 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo return conf, nil } +<<<<<<< HEAD // add server commands func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) { +======= +// AddCommands add server commands +func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) cometCmd := &cobra.Command{ Use: "comet", Aliases: []string{"cometbft", "tendermint"}, @@ -329,9 +334,13 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type BootstrapStateCmd(appCreator), ) +<<<<<<< HEAD startCmd := StartCmd(appCreator, defaultNodeHome) addStartFlags(startCmd) +======= + startCmd := StartCmdWithOptions(appCreator, opts) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) rootCmd.AddCommand( startCmd, cometCmd, @@ -341,10 +350,19 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type ) } +// AddCommandsWithStartCmdOptions adds server commands with the provided StartCmdOptions. +// Deprecated: Use AddCommands directly instead. +func AddCommandsWithStartCmdOptions[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { + AddCommands(rootCmd, appCreator, opts) +} + // AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory. +<<<<<<< HEAD func AddTestnetCreatorCommand(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) { +======= +func AddTestnetCreatorCommand[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T]) { +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) testnetCreateCmd := InPlaceTestnetCreator(appCreator) - addStartFlags(testnetCreateCmd) rootCmd.AddCommand(testnetCreateCmd) } diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index e8f59e5bc123..b3c5799e9e8c 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -21,8 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/snapshot" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -106,9 +104,13 @@ custom-field = "{{ .Custom.CustomField }}"` func initRootCmd( rootCmd *cobra.Command, txConfig client.TxConfig, +<<<<<<< HEAD interfaceRegistry codectypes.InterfaceRegistry, appCodec codec.Codec, basicManager module.BasicManager, +======= + moduleManager *module.Manager, +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ) { cfg := sdk.GetConfig() cfg.Seal() @@ -122,7 +124,11 @@ func initRootCmd( snapshot.Cmd(newApp), ) +<<<<<<< HEAD server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, appExport, addModuleInitFlags) +======= + server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index ee8d7e089892..e41d15419cf7 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -96,7 +96,19 @@ func NewRootCmd() *cobra.Command { }, } +<<<<<<< HEAD initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.BasicModuleManager) +======= + initRootCmd(rootCmd, encodingConfig.TxConfig, tempApp.ModuleManager) + + // autocli opts + customClientTemplate, customClientConfig := initClientConfig() + var err error + initClientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx, customClientTemplate, customClientConfig) + if err != nil { + panic(err) + } +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)) // add keyring to autocli opts autoCliOpts := tempApp.AutoCliOpts() diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 934ee3584925..492b7659a84c 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -84,7 +84,11 @@ func NewRootCmd() *cobra.Command { }, } +<<<<<<< HEAD:simapp/simd/cmd/root_v2.go initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager) +======= + initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager) +>>>>>>> def211d86 (feat(server): add custom start handler (#19854)):simapp/simd/cmd/root_di.go if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { panic(err) From 9ade16d98dc29e491db693bba199d6d0520f55e2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Mar 2024 12:37:44 +0100 Subject: [PATCH 2/5] fix conflicts --- CHANGELOG.md | 120 +------ UPGRADING.md | 298 ------------------ .../build/building-apps/05-app-testnet.md | 5 - server/start.go | 26 +- server/types/app.go | 4 + server/util.go | 42 ++- simapp/simd/cmd/commands.go | 20 +- simapp/simd/cmd/root_v2.go | 6 +- 8 files changed, 49 insertions(+), 472 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d13f160097..02a4c381ab8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,131 +44,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -<<<<<<< HEAD +* (server) [#19884](https://github.com/cosmos/cosmos-sdk/pull/19884) Add start customizability to start command options. * (x/gov) [#19853](https://github.com/cosmos/cosmos-sdk/pull/19853) Emit `depositor` in `EventTypeProposalDeposit`. * (x/gov) [#19844](https://github.com/cosmos/cosmos-sdk/pull/19844) Emit the proposer of governance proposals. -======= -* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Add customizability to start command. - * Add `StartCmdOptions` in `server.AddCommands` instead of `servertypes.ModuleInitFlags`. To set custom flags set them in the `StartCmdOptions` struct on the `AddFlags` field. - * Add `StartCommandHandler` to `StartCmdOptions` to allow custom start command handlers. Users now have total control over how the app starts. -* (types) [#19672](https://github.com/cosmos/cosmos-sdk/pull/19672) `PreBlock` now returns only an error for consistency with server/v2. The SDK has upgraded x/upgrade accordingly. `ResponsePreBlock` hence has been removed. -* (server) [#19455](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. -* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore (and all related helpers). - * The module manager now can do everything that the basic manager was doing. - * `AppModuleBasic` has been deprecated for extension interfaces. - * Modules can now implement `appmodule.HasRegisterInterfaces`, `modue.HasGRPCGateway` and `module.HasAminoCodec` when relevant. - * SDK modules now directly implement those extension interfaces on `AppModule` instead of `AppModuleBasic`. -* (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. -* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. -* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. -* (client/keys) [#18703](https://github.com/cosmos/cosmos-sdk/pull/18703) Improve ` keys add` and ` keys show` by checking whether there are duplicate keys in the multisig case. - * Usage of `Must...` kind of functions are avoided in keeper methods. -* (client/keys) [#18687](https://github.com/cosmos/cosmos-sdk/pull/18687) Improve ` keys mnemonic` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. -* (client/keys) [#18684](https://github.com/cosmos/cosmos-sdk/pull/18684) Improve ` keys export` by displaying unarmored hex private key discreetly on an alternate screen and adding `--indiscreet` option to disable it. -* (client/keys) [#18663](https://github.com/cosmos/cosmos-sdk/pull/18663) Improve ` keys add` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. -* (types) [#18440](https://github.com/cosmos/cosmos-sdk/pull/18440) Add `AmountOfNoValidation` to `sdk.DecCoins`. -* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details. -* (crypto/keyring) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Simplify keyring interfaces to use `[]byte` instead of `sdk.Address` for addresses. -* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated `fmt.Errorf` errors and using `errors.New` where appropriate. -* (rpc) [#17470](https://github.com/cosmos/cosmos-sdk/pull/17470) Avoid open 0.0.0.0 to public by default and add `listen-ip-address` argument for `testnet init-files` cmd. -* (types) [#17670](https://github.com/cosmos/cosmos-sdk/pull/17670) Use `ctx.CometInfo` in place of `ctx.VoteInfos` -* [#17733](https://github.com/cosmos/cosmos-sdk/pull/17733) Ensure `buf export` exports all proto dependencies -* (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1` -* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle. -* (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding -* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. -* (x/genutil) [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ## Bug Fixes -<<<<<<< HEAD * (crypto) [#19691](https://github.com/cosmos/cosmos-sdk/pull/19745) Fix tx sign doesn't throw an error when incorrect Ledger is used. -======= -* (baseapp) [#18727](https://github.com/cosmos/cosmos-sdk/pull/18727) Ensure that `BaseApp.Init` firstly returns any errors from a nil commit multistore instead of panicking on nil dereferencing and before sealing the app. -* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec. -* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found. -* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests. -* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server. -* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test. -* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test. -* (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT -* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object -* (crypto) [#19691](https://github.com/cosmos/cosmos-sdk/pull/19691) Fix tx sign doesn't throw an error when incorrect Ledger is used. -* [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk. -* [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov). - -### API Breaking Changes - -* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Remove `servertypes.ModuleInitFlags` types and from `server.AddCommands` as `StartCmdOptions` already achieves the same goal. -* (types) [#19792](https://github.com/cosmos/cosmos-sdk/pull/19792) In `MsgSimulatorFn` `sdk.Context` argument is replaced for an `address.Codec`. It also returns an error. -* (types) [#19742](https://github.com/cosmos/cosmos-sdk/pull/19742) Removes the use of `Accounts.String` - * `SimulationState` now has address and validator codecs as fields. -* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument. -* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`). - * The module manager now can do everything that the basic manager was doing. - * When using runtime, just inject the module manager when needed using your app config. - * All `AppModuleBasic` structs have been removed. -* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services. -* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does. -* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration. -* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration. -* (x/bank/testutil) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) `MsgSendExec` has been removed because of AutoCLI migration. -* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo. - * The Cosmos SDK has migrated away from using params, if your app still uses it, then you can leave it plugged into your app -* (types/simulation) [#17737](https://github.com/cosmos/cosmos-sdk/pull/17737) Remove unused parameter from `RandomFees` -* (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. -* (types) `module.BeginBlockAppModule` has been replaced by Core API `appmodule.HasBeginBlocker`. -* (types) `module.EndBlockAppModule` has been replaced by Core API `appmodule.HasEndBlocker` or `module.HasABCIEndBlock` when needing validator updates. -* (client) [#17259](https://github.com/cosmos/cosmos-sdk/pull/17259) Remove deprecated `clientCtx.PrintObjectLegacy`. Use `clientCtx.PrintProto` or `clientCtx.PrintRaw` instead. -* (types) [#16918](https://github.com/cosmos/cosmos-sdk/pull/16918) Remove `IntProto` and `DecProto`. Instead, `math.Int` and `math.LegacyDec` should be used respectively. Both types support `Marshal` and `Unmarshal` which should be used for binary marshaling. -* (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. -* (baseapp) [#16244](https://github.com/cosmos/cosmos-sdk/pull/16244) `SetProtocolVersion` has been renamed to `SetAppVersion`. It now updates the consensus params in baseapp's `ParamStore`. -* (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. -* (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 -* (types) [#17738](https://github.com/cosmos/cosmos-sdk/pull/17738) `WithBlockTime()` was removed & `BlockTime()` were deprecated in favor of `WithHeaderInfo()` & `HeaderInfo()`. `BlockTime` now gets data from `HeaderInfo()` instead of `BlockHeader()`. -* (client) [#17746](https://github.com/cosmos/cosmos-sdk/pull/17746) `txEncodeAmino` & `txDecodeAmino` txs via grpc and rest were removed - * `RegisterLegacyAmino` was removed from `AppModuleBasic` -* (types) [#17885](https://github.com/cosmos/cosmos-sdk/pull/17885) `InitGenesis` & `ExportGenesis` now take `context.Context` instead of `sdk.Context` -* (x/group) [#17937](https://github.com/cosmos/cosmos-sdk/pull/17937) Groups module was moved to its own go.mod `cosmossdk.io/x/group` -* (x/gov) [#18197](https://github.com/cosmos/cosmos-sdk/pull/18197) Gov module was moved to its own go.mod `cosmossdk.io/x/gov` -* (x/distribution) [#18199](https://github.com/cosmos/cosmos-sdk/pull/18199) Distribution module was moved to its own go.mod `cosmossdk.io/x/distribution` -* (x/slashing) [#18201](https://github.com/cosmos/cosmos-sdk/pull/18201) Slashing module was moved to its own go.mod `cosmossdk.io/x/slashing` -* (x/staking) [#18257](https://github.com/cosmos/cosmos-sdk/pull/18257) Staking module was moved to its own go.mod `cosmossdk.io/x/staking` -* (x/authz) [#18265](https://github.com/cosmos/cosmos-sdk/pull/18265) Authz module was moved to its own go.mod `cosmossdk.io/x/authz` -* (x/mint) [#18283](https://github.com/cosmos/cosmos-sdk/pull/18283) Mint module was moved to its own go.mod `cosmossdk.io/x/mint` -* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error -* (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress` -* (types) [#18268](https://github.com/cosmos/cosmos-sdk/pull/18268) Remove global setting of basedenom. Use the staking module parameter instead -* (x/auth) [#18351](https://github.com/cosmos/cosmos-sdk/pull/18351) Auth module was moved to its own go.mod `cosmossdk.io/x/auth` -* (types) [#18372](https://github.com/cosmos/cosmos-sdk/pull/18372) Removed global configuration for coin type and purpose. Setters and getters should be removed and access directly to defined types. -* (types) [#18695](https://github.com/cosmos/cosmos-sdk/pull/18695) Removed global configuration for txEncoder. -* (types) [#18607](https://github.com/cosmos/cosmos-sdk/pull/18607) Removed address verifier from global config, moved verifier function to bech32 codec. -* (server) [#18909](https://github.com/cosmos/cosmos-sdk/pull/18909) Remove configuration endpoint on grpc reflection endpoint in favour of auth module bech32prefix endpoint already exposed. -* (crypto) [#19541](https://github.com/cosmos/cosmos-sdk/pull/19541) The deprecated `FromTmProtoPublicKey`, `ToTmProtoPublicKey`, `FromTmPubKeyInterface` and `ToTmPubKeyInterface` functions have been removed. Use their replacements (`Cmt` instead of `Tm`) instead. -* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758) - * Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`. - * Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface. -* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) and [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) All genesis interfaces now don't take `codec.JsonCodec`. - * Every module has the codec already, passing it created an unneeded dependency. - * Additionally, to reflect this change, the module manager does not take a codec either. -* (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`. - -### Client Breaking Changes - -* (runtime) [#19040](https://github.com/cosmos/cosmos-sdk/pull/19040) Simplify app config implementation and deprecate `/cosmos/app/v1alpha1/config` query. - -### CLI Breaking Changes - -* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `appd export` has moved with other genesis commands, use `appd genesis export` instead. - -### Deprecated - -* (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. ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-03-12 diff --git a/UPGRADING.md b/UPGRADING.md index b1b7691c297b..354844624ae6 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -3,305 +3,7 @@ This guide provides instructions for upgrading to specific versions of Cosmos SDK. Note, always read the **SimApp** section for more information on application wiring updates. -<<<<<<< HEAD ## [v0.50.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0) -======= -## [Unreleased] - -### SimApp - -In this section we describe the changes made in Cosmos SDK' SimApp. -**These changes are directly applicable to your application wiring.** - -#### Client (`root.go`) - -The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.) -and address bech32 prefixes (address and validator address). -This is part of the work of abstracting the SDK from the global bech32 config. - -This means the address codecs and prefixes must be provided in the `client.Context` in the application client (usually `root.go`). - -```diff -clientCtx = clientCtx. -+ WithAddressCodec(addressCodec). -+ WithValidatorAddressCodec(validatorAddressCodec). -+ WithConsensusAddressCodec(consensusAddressCodec). -+ WithAddressPrefix("cosmos"). -+ WithValidatorPrefix("cosmosvaloper") -``` - -**When using `depinject` / `app v2`, the client codecs can be provided directly from application config.** - -Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a legacy app. - -Additionally, a simplification of the start command leads to the following change: - -```diff -- server.AddCommands(rootCmd, newApp, func(startCmd *cobra.Command) {}) -+ server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) -``` - -#### Server (`app.go`) - -##### Module Manager - -The basic module manager has been deleted. It was not necessary anymore and was simplified to use the `module.Manager` directly. -It can be removed from your `app.go`. - -For depinject users, it isn't necessary anymore to supply a `map[string]module.AppModuleBasic` for customizing the app module basic instantiation. -The custom parameters (such as genutil message validator or gov proposal handler, or evidence handler) can directly be supplied. -When requiring a module manager in `root.go`, inject `*module.Manager` using `depinject.Inject`. - -For non depinject users, simply call `RegisterLegacyAminoCodec` and `RegisterInterfaces` on the module manager: - -```diff --app.BasicModuleManager = module.NewBasicManagerFromManager(...) --app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) --app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) -+app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino) -+app.ModuleManager.RegisterInterfaces(interfaceRegistry) -``` - -Additionally, thanks to the genesis simplification, as explained in [the genesis interface update](#genesis-interface), the module manager `InitGenesis` and `ExportGenesis` methods do not require the codec anymore. - -##### AnteHandlers - -The `GasConsumptionDecorator` and `IncreaseSequenceDecorator` have been merged with the SigVerificationDecorator, so you'll -need to remove them both from your app.go code, they will yield to unresolvable symbols when compiling. - -#### Unordered Transactions - -The Cosmos SDK now supports unordered transactions. This means that transactions -can be executed in any order and doesn't require the client to deal with or manage -nonces. This also means the order of execution is not guaranteed. To enable unordered -transactions in your application: - -* Update the `App` constructor to create, load, and save the unordered transaction - manager. - - ```go - func NewApp(...) *App { - // ... - - // create, start, and load the unordered tx manager - utxDataDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data") - app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir) - app.UnorderedTxManager.Start() - - if err := app.UnorderedTxManager.OnInit(); err != nil { - panic(fmt.Errorf("failed to initialize unordered tx manager: %w", err)) - } - } - ``` - -* Add the decorator to the existing AnteHandler chain, which should be as early - as possible. - - ```go - anteDecorators := []sdk.AnteDecorator{ - ante.NewSetUpContextDecorator(), - // ... - ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, app.UnorderedTxManager), - // ... - } - - return sdk.ChainAnteDecorators(anteDecorators...), nil - ``` - -* If the App has a SnapshotManager defined, you must also register the extension - for the TxManager. - - ```go - if manager := app.SnapshotManager(); manager != nil { - err := manager.RegisterExtensions(unorderedtx.NewSnapshotter(app.UnorderedTxManager)) - if err != nil { - panic(fmt.Errorf("failed to register snapshot extension: %s", err)) - } - } - ``` - -* Create or update the App's `Close()` method to close the unordered tx manager. - Note, this is critical as it ensures the manager's state is written to file - such that when the node restarts, it can recover the state to provide replay - protection. - - ```go - func (app *App) Close() error { - // ... - - // close the unordered tx manager - if e := app.UnorderedTxManager.Close(); e != nil { - err = errors.Join(err, e) - } - - return err - } - ``` - -To submit an unordered transaction, the client must set the `unordered` flag to -`true` and ensure a reasonable `timeout_height` is set. The `timeout_height` is -used as a TTL for the transaction and is used to provide replay protection. See -[ADR-070](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-070-unordered-transactions.md) -for more details. - -### Protobuf - -The `cosmossdk.io/api/tendermint` package has been removed as CometBFT now publishes its protos to `buf.build/tendermint` and `buf.build/cometbft`. -There is no longer a need for the Cosmos SDK to host these protos for itself and its dependencies. -That package containing proto v2 generated code, but the SDK now uses [buf generated go SDK instead](https://buf.build/docs/bsr/generated-sdks/go). -If you were depending on `cosmossdk.io/api/tendermint`, please use the buf generated go SDK instead, or ask CometBFT host the generated proto v2 code. - -### Modules - -#### `**all**` - -##### Simulation - -`MsgSimulatorFn` has been updated to return an error. Its context argument has been removed, and an address.Codec has -been added to avoid the use of the Accounts.String() method. - -```diff --type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg -+type MsgSimulatorFn func(r *rand.Rand, accs []Account, cdc address.Codec) (sdk.Msg, error) -``` - -##### Core API - -Core API has been introduced for modules since v0.47. With the deprecation of `sdk.Context`, we strongly recommend to use the `cosmossdk.io/core/appmodule` interfaces for the modules. This will allow the modules to work out of the box with server/v2 and baseapp, as well as limit their dependencies on the SDK. - -Additionally, the `appmodule.Environment` interface is introduced to fetch different services from the application. -This should be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. -It needs to be passed into a module at instantiation. - -`x/circuit` is used as an example: - -```go -app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) -``` - -If your module requires a message server or query server, it should be passed in the environment as well. - -```diff --govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AuthKeeper, app.BankKeeper,app.StakingKeeper, app.PoolKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) -+govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) -``` - -The signature of the extension interface `HasRegisterInterfaces` has been changed to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` instead of a `codec.InterfaceRegistry`. `HasRegisterInterfaces` is now a part of `cosmossdk.io/core/appmodule`. Modules should update their `HasRegisterInterfaces` implementation to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` interface. - -```diff --func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { -+func (AppModule) RegisterInterfaces(registry registry.InterfaceRegistrar) { -``` - -##### Dependency Injection - -Previously `cosmossdk.io/core` held functions `Invoke`, `Provide` and `Register` were moved to `cosmossdk.io/depinject/appconfig`. -All modules using dependency injection must update their imports. - -##### Params - -Previous module migrations have been removed. It is required to migrate to v0.50 prior to upgrading to v0.51 for not missing any module migrations. - -##### Genesis Interface - -All genesis interfaces have been migrated to take `context.Context` instead of `sdk.Context`. -Secondly, the codec is no longer passed in by the framework. The codec is now passed in by the module. -Lastly, all InitGenesis and ExportGenesis functions now return an error. - -```go -// InitGenesis performs genesis initialization for the module. -func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { -} - -// ExportGenesis returns the exported genesis state as raw bytes for the module. -func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { -} -``` - -##### Migration to Collections - -Most of Cosmos SDK modules have migrated to [collections](https://docs.cosmos.network/main/build/packages/collections). -Many functions have been removed due to this changes as the API can be smaller thanks to collections. -For modules that have migrated, verify you are checking against `collections.ErrNotFound` when applicable. - -#### `x/auth` - -Auth was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/auth` - -#### `x/authz` - -Authz was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/authz` - -#### `x/bank` - -Bank was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/bank` - -#### `x/distribution` - -Distribution was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/distribution` - -The existing chains using x/distribution module needs to add the new x/protocolpool module. - -#### `x/group` - -Group was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/group` - -#### `x/gov` - -Gov was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/gov` - -Gov v1beta1 proposal handler has been changed to take in a `context.Context` instead of `sdk.Context`. -This change was made to allow legacy proposals to be compatible with server/v2. -If you wish to migrate to server/v2, you should update your proposal handler to take in a `context.Context` and use services. -On the other hand, if you wish to keep using baseapp, simply unwrap the sdk context in your proposal handler. - -#### `x/mint` - -Mint was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/mint` - -#### `x/slashing` - -Slashing was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/slashing` - -#### `x/staking` - -Staking was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/staking` - -#### `x/params` - -A standalone Go module was created and it is accessible at "cosmossdk.io/x/params". - -#### `x/protocolpool` - -Introducing a new `x/protocolpool` module to handle community pool funds. Its store must be added while upgrading to v0.51.x. - -Example: - -```go -func (app SimApp) RegisterUpgradeHandlers() { - app.UpgradeKeeper.SetUpgradeHandler( - UpgradeName, - func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) - }, - ) - - // ... -} -``` - -Add `x/protocolpool` store while upgrading to v0.51.x: - -```go -storetypes.StoreUpgrades{ - Added: []string{ - protocolpooltypes.ModuleName, - }, -} -``` - -## [v0.50.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.0) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ### Migration to CometBFT (Part 2) diff --git a/docs/docs/build/building-apps/05-app-testnet.md b/docs/docs/build/building-apps/05-app-testnet.md index f06d805e17eb..607599cc1952 100644 --- a/docs/docs/build/building-apps/05-app-testnet.md +++ b/docs/docs/build/building-apps/05-app-testnet.md @@ -195,13 +195,8 @@ Before we can run the testnet we must plug everything together. in `root.go`, in the `initRootCmd` function we add: ```diff -<<<<<<< HEAD:docs/docs/build/building-apps/05-app-testnet.md server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createsimAppAndExport, addModuleInitFlags) ++ server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp, addModuleInitFlags) -======= -server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, createMerlinAppAndExport) -+server.AddTestnetCreatorCommand(rootCmd, simapp.DefaultNodeHome, newTestnetApp) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)):docs/build/building-apps/05-app-testnet.md ``` Next we will add a newTestnetApp helper function: diff --git a/server/start.go b/server/start.go index b68bb9168804..e0bb1b621dd5 100644 --- a/server/start.go +++ b/server/start.go @@ -115,10 +115,12 @@ type StartCmdOptions struct { // PostSetup can be used to setup extra services under the same cancellable context, // it's not called in stand-alone mode, only for in-process mode. PostSetup func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + // PostSetupStandalone can be used to setup extra services under the same cancellable context, + PostSetupStandalone func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) // StartCommandHanlder can be used to customize the start command handler - StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error + StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator, inProcessConsensus bool, opts StartCmdOptions) error } // StartCmd runs the service passed in, either stand-alone or in-process with @@ -282,6 +284,12 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie return err } + if opts.PostSetupStandalone != nil { + if err := opts.PostSetupStandalone(svrCtx, clientCtx, ctx, g); err != nil { + return err + } + } + g.Go(func() error { if err := svr.Start(); err != nil { svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) @@ -299,8 +307,7 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie } func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, - metrics *telemetry.Metrics, opts StartCmdOptions, -) error { + metrics *telemetry.Metrics, opts StartCmdOptions) error { cmtCfg := svrCtx.Config gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) @@ -606,12 +613,7 @@ func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions } if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { -<<<<<<< HEAD - app, err = testnetify(svrCtx, home, appCreator, db, traceWriter) -======= - var appPtr *T - appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) + app, err = testnetify(svrCtx, appCreator, db, traceWriter) if err != nil { return app, traceCleanupFn, err } @@ -728,11 +730,7 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. -<<<<<<< HEAD -func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) { -======= -func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) +func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) { config := ctx.Config newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) diff --git a/server/types/app.go b/server/types/app.go index bf2e728305ca..3b5feab3c0ca 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -8,6 +8,7 @@ import ( cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/grpc" + "github.com/spf13/cobra" "cosmossdk.io/log" "cosmossdk.io/store/snapshots" @@ -67,6 +68,9 @@ type ( // application using various configurations. AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application + // ModuleInitFlags takes a start command and adds modules specific init flags. + ModuleInitFlags func(startCmd *cobra.Command) + // ExportedApp represents an exported app state, along with // validators, consensus params and latest app height. ExportedApp struct { diff --git a/server/util.go b/server/util.go index 072f63744674..7b29ab7ea88e 100644 --- a/server/util.go +++ b/server/util.go @@ -311,13 +311,8 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo return conf, nil } -<<<<<<< HEAD // add server commands func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) { -======= -// AddCommands add server commands -func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) cometCmd := &cobra.Command{ Use: "comet", Aliases: []string{"cometbft", "tendermint"}, @@ -334,13 +329,9 @@ func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.A BootstrapStateCmd(appCreator), ) -<<<<<<< HEAD startCmd := StartCmd(appCreator, defaultNodeHome) addStartFlags(startCmd) -======= - startCmd := StartCmdWithOptions(appCreator, opts) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) rootCmd.AddCommand( startCmd, cometCmd, @@ -351,17 +342,36 @@ func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.A } // AddCommandsWithStartCmdOptions adds server commands with the provided StartCmdOptions. -// Deprecated: Use AddCommands directly instead. -func AddCommandsWithStartCmdOptions[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], opts StartCmdOptions[T]) { - AddCommands(rootCmd, appCreator, opts) +func AddCommandsWithStartCmdOptions(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, opts StartCmdOptions) { + cometCmd := &cobra.Command{ + Use: "comet", + Aliases: []string{"cometbft", "tendermint"}, + Short: "CometBFT subcommands", + } + + cometCmd.AddCommand( + ShowNodeIDCmd(), + ShowValidatorCmd(), + ShowAddressCmd(), + VersionCmd(), + cmtcmd.ResetAllCmd, + cmtcmd.ResetStateCmd, + BootstrapStateCmd(appCreator), + ) + + startCmd := StartCmdWithOptions(appCreator, defaultNodeHome, opts) + + rootCmd.AddCommand( + startCmd, + cometCmd, + ExportCmd(appExport, defaultNodeHome), + version.NewVersionCommand(), + NewRollbackCmd(appCreator, defaultNodeHome), + ) } // AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory. -<<<<<<< HEAD func AddTestnetCreatorCommand(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) { -======= -func AddTestnetCreatorCommand[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T]) { ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) testnetCreateCmd := InPlaceTestnetCreator(appCreator) rootCmd.AddCommand(testnetCreateCmd) } diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index b3c5799e9e8c..7540dd7009a3 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -104,13 +104,7 @@ custom-field = "{{ .Custom.CustomField }}"` func initRootCmd( rootCmd *cobra.Command, txConfig client.TxConfig, -<<<<<<< HEAD - interfaceRegistry codectypes.InterfaceRegistry, - appCodec codec.Codec, basicManager module.BasicManager, -======= - moduleManager *module.Manager, ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) ) { cfg := sdk.GetConfig() cfg.Seal() @@ -124,11 +118,11 @@ func initRootCmd( snapshot.Cmd(newApp), ) -<<<<<<< HEAD - server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, appExport, addModuleInitFlags) -======= - server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) + server.AddCommandsWithStartCmdOptions(rootCmd, simapp.DefaultNodeHome, newApp, appExport, server.StartCmdOptions{ + AddFlags: func(startCmd *cobra.Command) { + crisis.AddModuleInitFlags(startCmd) + }, + }) // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( @@ -140,10 +134,6 @@ func initRootCmd( ) } -func addModuleInitFlags(startCmd *cobra.Command) { - crisis.AddModuleInitFlags(startCmd) -} - // genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command { cmd := genutilcli.Commands(txConfig, basicManager, simapp.DefaultNodeHome) diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 492b7659a84c..94ef4cd9d17b 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -84,11 +84,7 @@ func NewRootCmd() *cobra.Command { }, } -<<<<<<< HEAD:simapp/simd/cmd/root_v2.go - initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager) -======= - initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager) ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)):simapp/simd/cmd/root_di.go + initRootCmd(rootCmd, clientCtx.TxConfig, moduleBasicManager) if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { panic(err) From 830d1c08d55ccd5f3eff79c00b7972da989f7d84 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Mar 2024 12:41:00 +0100 Subject: [PATCH 3/5] nit --- server/util.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/util.go b/server/util.go index 7b29ab7ea88e..de656d949001 100644 --- a/server/util.go +++ b/server/util.go @@ -373,6 +373,7 @@ func AddCommandsWithStartCmdOptions(rootCmd *cobra.Command, defaultNodeHome stri // AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory. func AddTestnetCreatorCommand(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) { testnetCreateCmd := InPlaceTestnetCreator(appCreator) + addStartFlags(testnetCreateCmd) rootCmd.AddCommand(testnetCreateCmd) } From 914769d4460a05aa9268763fc1c4a53934d3c64a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Mar 2024 12:43:13 +0100 Subject: [PATCH 4/5] fix build --- simapp/simd/cmd/root.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index e41d15419cf7..f56b849a9c56 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -96,19 +96,7 @@ func NewRootCmd() *cobra.Command { }, } -<<<<<<< HEAD - initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, encodingConfig.Codec, tempApp.BasicModuleManager) -======= - initRootCmd(rootCmd, encodingConfig.TxConfig, tempApp.ModuleManager) - - // autocli opts - customClientTemplate, customClientConfig := initClientConfig() - var err error - initClientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx, customClientTemplate, customClientConfig) - if err != nil { - panic(err) - } ->>>>>>> def211d86 (feat(server): add custom start handler (#19854)) + initRootCmd(rootCmd, encodingConfig.TxConfig, tempApp.BasicModuleManager) // add keyring to autocli opts autoCliOpts := tempApp.AutoCliOpts() From 03d08e3d7aec7ca055ad748c50f53de151867b33 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Mar 2024 12:48:27 +0100 Subject: [PATCH 5/5] `make lint-fix` --- server/start.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index e0bb1b621dd5..c86c1cfc2dc6 100644 --- a/server/start.go +++ b/server/start.go @@ -307,7 +307,8 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie } func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, - metrics *telemetry.Metrics, opts StartCmdOptions) error { + metrics *telemetry.Metrics, opts StartCmdOptions, +) error { cmtCfg := svrCtx.Config gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly)