github.com/cosmos/cosmos-sdk@v0.50.10/UPGRADING.md (about) 1 # Upgrading Cosmos SDK 2 3 This guide provides instructions for upgrading to specific versions of Cosmos SDK. 4 Note, always read the **SimApp** section for more information on application wiring updates. 5 6 ## [v0.50.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0) 7 8 ### Migration to CometBFT (Part 2) 9 10 The Cosmos SDK has migrated in its previous versions, to CometBFT. 11 Some functions have been renamed to reflect the naming change. 12 13 Following an exhaustive list: 14 15 * `client.TendermintRPC` -> `client.CometRPC` 16 * `clitestutil.MockTendermintRPC` -> `clitestutil.MockCometRPC` 17 * `clitestutilgenutil.CreateDefaultTendermintConfig` -> `clitestutilgenutil.CreateDefaultCometConfig` 18 * Package `client/grpc/tmservice` -> `client/grpc/cmtservice` 19 20 Additionally, the commands and flags mentioning `tendermint` have been renamed to `comet`. 21 These commands and flags are still supported for backward compatibility. 22 23 For backward compatibility, the `**/tendermint/**` gRPC services are still supported. 24 25 Additionally, the SDK is starting its abstraction from CometBFT Go types through the codebase: 26 27 * The usage of the CometBFT logger has been replaced by the Cosmos SDK logger interface (`cosmossdk.io/log.Logger`). 28 * The usage of `github.com/cometbft/cometbft/libs/bytes.HexByte` has been replaced by `[]byte`. 29 * Usage of an application genesis (see [genutil](#xgenutil)). 30 31 #### Enable Vote Extensions 32 33 :::tip 34 This is an optional feature that is disabled by default. 35 ::: 36 37 Once all the code changes required to implement Vote Extensions are in place, 38 they can be enabled by setting the consensus param `Abci.VoteExtensionsEnableHeight` 39 to a value greater than zero. 40 41 In a new chain, this can be done in the `genesis.json` file. 42 43 For existing chains this can be done in two ways: 44 45 * During an upgrade the value is set in an upgrade handler. 46 * A governance proposal that changes the consensus param **after a coordinated upgrade has taken place**. 47 48 ### BaseApp 49 50 All ABCI methods now accept a pointer to the request and response types defined 51 by CometBFT. In addition, they also return errors. An ABCI method should only 52 return errors in cases where a catastrophic failure has occurred and the application 53 should halt. However, this is abstracted away from the application developer. Any 54 handler that an application can define or set that returns an error, will gracefully 55 by handled by `BaseApp` on behalf of the application. 56 57 BaseApp calls of `BeginBlock` & `Endblock` are now private but are still exposed 58 to the application to define via the `Manager` type. `FinalizeBlock` is public 59 and should be used in order to test and run operations. This means that although 60 `BeginBlock` & `Endblock` no longer exist in the ABCI interface, they are automatically 61 called by `BaseApp` during `FinalizeBlock`. Specifically, the order of operations 62 is `BeginBlock` -> `DeliverTx` (for all txs) -> `EndBlock`. 63 64 ABCI++ 2.0 also brings `ExtendVote` and `VerifyVoteExtension` ABCI methods. These 65 methods allow applications to extend and verify pre-commit votes. The Cosmos SDK 66 allows an application to define handlers for these methods via `ExtendVoteHandler` 67 and `VerifyVoteExtensionHandler` respectively. Please see [here](https://docs.cosmos.network/v0.50/build/building-apps/vote-extensions) 68 for more info. 69 70 #### Set PreBlocker 71 72 A `SetPreBlocker` method has been added to BaseApp. This is essential for BaseApp to run `PreBlock` which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics. 73 Read more about other use cases [here](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-068-preblock.md). 74 75 `depinject` / app di users need to add `x/upgrade` in their `app_config.go` / `app.yml`: 76 77 ```diff 78 + PreBlockers: []string{ 79 + upgradetypes.ModuleName, 80 + }, 81 BeginBlockers: []string{ 82 - upgradetypes.ModuleName, 83 minttypes.ModuleName, 84 } 85 ``` 86 87 When using (legacy) application wiring, the following must be added to `app.go`: 88 89 ```diff 90 +app.ModuleManager.SetOrderPreBlockers( 91 + upgradetypes.ModuleName, 92 +) 93 94 app.ModuleManager.SetOrderBeginBlockers( 95 - upgradetypes.ModuleName, 96 ) 97 98 + app.SetPreBlocker(app.PreBlocker) 99 100 // ... // 101 102 +func (app *SimApp) PreBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { 103 + return app.ModuleManager.PreBlock(ctx, req) 104 +} 105 ``` 106 107 #### Events 108 109 The log section of `abci.TxResult` is not populated in the case of successful 110 msg(s) execution. Instead a new attribute is added to all messages indicating 111 the `msg_index` which identifies which events and attributes relate the same 112 transaction. 113 114 `BeginBlock` & `EndBlock` Events are now emitted through `FinalizeBlock` but have 115 an added attribute, `mode=BeginBlock|EndBlock`, to identify if the event belongs 116 to `BeginBlock` or `EndBlock`. 117 118 ### Config files 119 120 Confix is a new SDK tool for modifying and migrating configuration of the SDK. 121 It is the replacement of the `config.Cmd` command from the `client/config` package. 122 123 Use the following command to migrate your configuration: 124 125 ```bash 126 simd config migrate v0.50 127 ``` 128 129 If you were using `<appd> config [key]` or `<appd> config [key] [value]` to set and get values from the `client.toml`, replace it with `<appd> config get client [key]` and `<appd> config set client [key] [value]`. The extra verbosity is due to the extra functionalities added in config. 130 131 More information about [confix](https://docs.cosmos.network/main/tooling/confix) and how to add it in your application binary in the [documentation](https://docs.cosmos.network/main/tooling/confix). 132 133 #### gRPC-Web 134 135 gRPC-Web is now listening to the same address and port as the gRPC Gateway API server (default: `localhost:1317`). 136 The possibility to listen to a different address has been removed, as well as its settings. 137 Use `confix` to clean-up your `app.toml`. A nginx (or alike) reverse-proxy can be set to keep the previous behavior. 138 139 #### Database Support 140 141 ClevelDB, BoltDB and BadgerDB are not supported anymore. To migrate from a unsupported database to a supported database please use a database migration tool. 142 143 ### Protobuf 144 145 With the deprecation of the Amino JSON codec defined in [cosmos/gogoproto](https://github.com/cosmos/gogoproto) in favor of the protoreflect powered x/tx/aminojson codec, module developers are encouraged verify that their messages have the correct protobuf annotations to deterministically produce identical output from both codecs. 146 147 For core SDK types equivalence is asserted by generative testing of [SignableTypes](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/tests/integration/rapidgen/rapidgen.go#L102) in [TestAminoJSON_Equivalence](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/tests/integration/tx/aminojson/aminojson_test.go#L94). 148 149 **TODO: summarize proto annotation requirements.** 150 151 #### Stringer 152 153 The `gogoproto.goproto_stringer = false` annotation has been removed from most proto files. This means that the `String()` method is being generated for types that previously had this annotation. The generated `String()` method uses `proto.CompactTextString` for _stringifying_ structs. 154 [Verify](https://github.com/cosmos/cosmos-sdk/pull/13850#issuecomment-1328889651) the usage of the modified `String()` methods and double-check that they are not used in state-machine code. 155 156 ### SimApp 157 158 In this section we describe the changes made in Cosmos SDK' SimApp. 159 **These changes are directly applicable to your application wiring.** 160 161 #### Module Assertions 162 163 Previously, all modules were required to be set in `OrderBeginBlockers`, `OrderEndBlockers` and `OrderInitGenesis / OrderExportGenesis` in `app.go` / `app_config.go`. This is no longer the case, the assertion has been loosened to only require modules implementing, respectively, the `appmodule.HasBeginBlocker`, `appmodule.HasEndBlocker` and `appmodule.HasGenesis` / `module.HasGenesis` interfaces. 164 165 #### Module wiring 166 167 The following modules `NewKeeper` function now take a `KVStoreService` instead of a `StoreKey`: 168 169 * `x/auth` 170 * `x/authz` 171 * `x/bank` 172 * `x/consensus` 173 * `x/crisis` 174 * `x/distribution` 175 * `x/evidence` 176 * `x/feegrant` 177 * `x/gov` 178 * `x/mint` 179 * `x/nft` 180 * `x/slashing` 181 * `x/upgrade` 182 183 **Users using `depinject` / app di do not need any changes, this is abstracted for them.** 184 185 Users manually wiring their chain need to use the `runtime.NewKVStoreService` method to create a `KVStoreService` from a `StoreKey`: 186 187 ```diff 188 app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper( 189 appCodec, 190 - keys[consensusparamtypes.StoreKey] 191 + runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), 192 authtypes.NewModuleAddress(govtypes.ModuleName).String(), 193 ) 194 ``` 195 196 #### Logger 197 198 Replace all your CometBFT logger imports by `cosmossdk.io/log`. 199 200 Additionally, `depinject` / app di users must now supply a logger through the main `depinject.Supply` function instead of passing it to `appBuilder.Build`. 201 202 ```diff 203 appConfig = depinject.Configs( 204 AppConfig, 205 depinject.Supply( 206 // supply the application options 207 appOpts, 208 + logger, 209 ... 210 ``` 211 212 ```diff 213 - app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) 214 + app.App = appBuilder.Build(db, traceStore, baseAppOptions...) 215 ``` 216 217 User manually wiring their chain need to add the logger argument when creating the `x/bank` keeper. 218 219 #### Module Basics 220 221 Previously, the `ModuleBasics` was a global variable that was used to register all modules' `AppModuleBasic` implementation. 222 The global variable has been removed and the basic module manager can be now created from the module manager. 223 224 This is automatically done for `depinject` / app di users, however for supplying different app module implementation, pass them via `depinject.Supply` in the main `AppConfig` (`app_config.go`): 225 226 ```go 227 depinject.Supply( 228 // supply custom module basics 229 map[string]module.AppModuleBasic{ 230 genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), 231 govtypes.ModuleName: gov.NewAppModuleBasic( 232 []govclient.ProposalHandler{ 233 paramsclient.ProposalHandler, 234 }, 235 ), 236 }, 237 ) 238 ``` 239 240 Users manually wiring their chain need to use the new `module.NewBasicManagerFromManager` function, after the module manager creation, and pass a `map[string]module.AppModuleBasic` as argument for optionally overriding some module's `AppModuleBasic`. 241 242 #### AutoCLI 243 244 [`AutoCLI`](https://docs.cosmos.network/main/core/autocli) has been implemented by the SDK for all its module CLI queries. This means chains must add the following in their `root.go` to enable `AutoCLI` in their application: 245 246 ```go 247 if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { 248 panic(err) 249 } 250 ``` 251 252 Where `autoCliOpts` is the autocli options of the app, containing all modules and codecs. 253 That value can injected by depinject ([see root_v2.go](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/simapp/simd/cmd/root_v2.go#L49-L67)) or manually provided by the app ([see legacy app.go](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/simapp/app.go#L636-L655)). 254 255 :::warning 256 Not doing this will result in all core SDK modules queries not to be included in the binary. 257 ::: 258 259 Additionally `AutoCLI` automatically adds the custom modules commands to the root command for all modules implementing the [`appmodule.AppModule`](https://pkg.go.dev/cosmossdk.io/core/appmodule#AppModule) interface. 260 This means, after ensuring all the used modules implement this interface, the following can be removed from your `root.go`: 261 262 ```diff 263 func txCommand() *cobra.Command { 264 .... 265 - appd.ModuleBasics.AddTxCommands(cmd) 266 } 267 ``` 268 269 ```diff 270 func queryCommand() *cobra.Command { 271 .... 272 - appd.ModuleBasics.AddQueryCommands(cmd) 273 } 274 ``` 275 276 ### Packages 277 278 #### Math 279 280 References to `types/math.go` which contained aliases for math types aliasing the `cosmossdk.io/math` package have been removed. 281 Import directly the `cosmossdk.io/math` package instead. 282 283 #### Store 284 285 References to `types/store.go` which contained aliases for store types have been remapped to point to appropriate `store/types`, hence the `types/store.go` file is no longer needed and has been removed. 286 287 ##### Extract Store to a standalone module 288 289 The `store` module is extracted to have a separate go.mod file which allows it be a standalone module. 290 All the store imports are now renamed to use `cosmossdk.io/store` instead of `github.com/cosmos/cosmos-sdk/store` across the SDK. 291 292 ##### Streaming 293 294 [ADR-38](https://docs.cosmos.network/main/architecture/adr-038-state-listening) has been implemented in the SDK. 295 296 To continue using state streaming, replace `streaming.LoadStreamingServices` by the following in your `app.go`: 297 298 ```go 299 if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil { 300 panic(err) 301 } 302 ``` 303 304 #### Client 305 306 The return type of the interface method `TxConfig.SignModeHandler()` has been changed from `x/auth/signing.SignModeHandler` to `x/tx/signing.HandlerMap`. This change is transparent to most users as the `TxConfig` interface is typically implemented by private `x/auth/tx.config` struct (as returned by `auth.NewTxConfig`) which has been updated to return the new type. If users have implemented their own `TxConfig` interface, they will need to update their implementation to return the new type. 307 308 ##### Textual sign mode 309 310 A new sign mode is available in the SDK that produces more human readable output, currently only available on Ledger 311 devices but soon to be implemented in other UIs. 312 313 :::tip 314 This sign mode does not allow offline signing 315 ::: 316 317 When using (legacy) application wiring, the following must be added to `app.go` after setting the app's bank keeper: 318 319 ```go 320 enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) 321 txConfigOpts := tx.ConfigOptions{ 322 EnabledSignModes: enabledSignModes, 323 TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), 324 } 325 txConfig, err := tx.NewTxConfigWithOptions( 326 appCodec, 327 txConfigOpts, 328 ) 329 if err != nil { 330 log.Fatalf("Failed to create new TxConfig with options: %v", err) 331 } 332 app.txConfig = txConfig 333 ``` 334 335 When using `depinject` / `app di`, **it's enabled by default** if there's a bank keeper present. 336 337 And in the application client (usually `root.go`): 338 339 ```go 340 if !clientCtx.Offline { 341 txConfigOpts.EnabledSignModes = append(txConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) 342 txConfigOpts.TextualCoinMetadataQueryFn = txmodule.NewGRPCCoinMetadataQueryFn(clientCtx) 343 txConfigWithTextual, err := tx.NewTxConfigWithOptions( 344 codec.NewProtoCodec(clientCtx.InterfaceRegistry), 345 txConfigOpts, 346 ) 347 if err != nil { 348 return err 349 } 350 clientCtx = clientCtx.WithTxConfig(txConfigWithTextual) 351 } 352 ``` 353 354 When using `depinject` / `app di`, the a tx config should be recreated from the `txConfigOpts` to use `NewGRPCCoinMetadataQueryFn` instead of depending on the bank keeper (that is used in the server). 355 356 To learn more see the [docs](https://docs.cosmos.network/main/learn/advanced/transactions#sign_mode_textual) and the [ADR-050](https://docs.cosmos.network/main/build/architecture/adr-050-sign-mode-textual). 357 358 ### Modules 359 360 #### `**all**` 361 362 * [RFC 001](https://docs.cosmos.network/main/rfc/rfc-001-tx-validation) has defined a simplification of the message validation process for modules. 363 The `sdk.Msg` interface has been updated to not require the implementation of the `ValidateBasic` method. 364 It is now recommended to validate message directly in the message server. When the validation is performed in the message server, the `ValidateBasic` method on a message is no longer required and can be removed. 365 366 * Messages no longer need to implement the `LegacyMsg` interface and implementations of `GetSignBytes` can be deleted. Because of this change, global legacy Amino codec definitions and their registration in `init()` can safely be removed as well. 367 368 * The `AppModuleBasic` interface has been simplified. Defining `GetTxCmd() *cobra.Command` and `GetQueryCmd() *cobra.Command` is no longer required. The module manager detects when module commands are defined. If AutoCLI is enabled, `EnhanceRootCommand()` will add the auto-generated commands to the root command, unless a custom module command is defined and register that one instead. 369 370 * The following modules' `Keeper` methods now take in a `context.Context` instead of `sdk.Context`. Any module that has an interfaces for them (like "expected keepers") will need to update and re-generate mocks if needed: 371 372 * `x/authz` 373 * `x/bank` 374 * `x/mint` 375 * `x/crisis` 376 * `x/distribution` 377 * `x/evidence` 378 * `x/gov` 379 * `x/slashing` 380 * `x/upgrade` 381 382 * `BeginBlock` and `EndBlock` have changed their signature, so it is important that any module implementing them are updated accordingly. 383 384 ```diff 385 - BeginBlock(sdk.Context, abci.RequestBeginBlock) 386 + BeginBlock(context.Context) error 387 ``` 388 389 ```diff 390 - EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate 391 + EndBlock(context.Context) error 392 ``` 393 394 In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it can use the `HasABCIEndBlock` interface instead. 395 396 ```diff 397 - EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate 398 + EndBlock(context.Context) ([]abci.ValidatorUpdate, error) 399 ``` 400 401 :::tip 402 It is possible to ensure that a module implements the correct interfaces by using compiler assertions in your `x/{moduleName}/module.go`: 403 404 ```go 405 var ( 406 _ module.AppModuleBasic = (*AppModule)(nil) 407 _ module.AppModuleSimulation = (*AppModule)(nil) 408 _ module.HasGenesis = (*AppModule)(nil) 409 410 _ appmodule.AppModule = (*AppModule)(nil) 411 _ appmodule.HasBeginBlocker = (*AppModule)(nil) 412 _ appmodule.HasEndBlocker = (*AppModule)(nil) 413 ... 414 ) 415 ``` 416 417 Read more on those interfaces [here](https://docs.cosmos.network/v0.50/building-modules/module-manager#application-module-interfaces). 418 419 ::: 420 421 * `GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. 422 423 To find out more please read the [signer field](../../build/building-modules/05-protobuf-annotations.md#signer) & [here](https://github.com/cosmos/cosmos-sdk/blob/7352d0bce8e72121e824297df453eb1059c28da8/docs/docs/build/building-modules/02-messages-and-queries.md#L40) documentation. 424 <!-- Link to docs once redeployed --> 425 426 #### `x/auth` 427 428 For ante handler construction via `ante.NewAnteHandler`, the field `ante.HandlerOptions.SignModeHandler` has been updated to `x/tx/signing/HandlerMap` from `x/auth/signing/SignModeHandler`. Callers typically fetch this value from `client.TxConfig.SignModeHandler()` (which is also changed) so this change should be transparent to most users. 429 430 #### `x/capability` 431 432 Capability has been moved to [IBC Go](https://github.com/cosmos/ibc-go). IBC v8 will contain the necessary changes to incorporate the new module location. 433 434 #### `x/genutil` 435 436 The Cosmos SDK has migrated from a CometBFT genesis to a application managed genesis file. 437 The genesis is now fully handled by `x/genutil`. This has no consequences for running chains: 438 439 * Importing a CometBFT genesis is still supported. 440 * Exporting a genesis now exports the genesis as an application genesis. 441 442 When needing to read an application genesis, use the following helpers from the `x/genutil/types` package: 443 444 ```go 445 // AppGenesisFromReader reads the AppGenesis from the reader. 446 func AppGenesisFromReader(reader io.Reader) (*AppGenesis, error) 447 448 // AppGenesisFromFile reads the AppGenesis from the provided file. 449 func AppGenesisFromFile(genFile string) (*AppGenesis, error) 450 ``` 451 452 #### `x/gov` 453 454 ##### Expedited Proposals 455 456 The `gov` v1 module now supports expedited governance proposals. When a proposal is expedited, the voting period will be shortened to `ExpeditedVotingPeriod` parameter. An expedited proposal must have an higher voting threshold than a classic proposal, that threshold is defined with the `ExpeditedThreshold` parameter. 457 458 ##### Cancelling Proposals 459 460 The `gov` module now supports cancelling governance proposals. When a proposal is canceled, all the deposits of the proposal are either burnt or sent to `ProposalCancelDest` address. The deposits burn rate will be determined by a new parameter called `ProposalCancelRatio` parameter. 461 462 ```text 463 1. deposits * proposal_cancel_ratio will be burned or sent to `ProposalCancelDest` address , if `ProposalCancelDest` is empty then deposits will be burned. 464 2. deposits * (1 - proposal_cancel_ratio) will be sent to depositors. 465 ``` 466 467 By default, the new `ProposalCancelRatio` parameter is set to `0.5` during migration and `ProposalCancelDest` is set to empty string (i.e. burnt). 468 469 #### `x/evidence` 470 471 ##### Extract evidence to a standalone module 472 473 The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module. 474 All the evidence imports are now renamed to use `cosmossdk.io/x/evidence` instead of `github.com/cosmos/cosmos-sdk/x/evidence` across the SDK. 475 476 #### `x/nft` 477 478 ##### Extract nft to a standalone module 479 480 The `x/nft` module is extracted to have a separate go.mod file which allows it to be a standalone module. 481 All the evidence imports are now renamed to use `cosmossdk.io/x/nft` instead of `github.com/cosmos/cosmos-sdk/x/nft` across the SDK. 482 483 #### x/feegrant 484 485 ##### Extract feegrant to a standalone module 486 487 The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module. 488 All the feegrant imports are now renamed to use `cosmossdk.io/x/feegrant` instead of `github.com/cosmos/cosmos-sdk/x/feegrant` across the SDK. 489 490 #### `x/upgrade` 491 492 ##### Extract upgrade to a standalone module 493 494 The `x/upgrade` module is extracted to have a separate go.mod file which allows it to be a standalone module. 495 All the upgrade imports are now renamed to use `cosmossdk.io/x/upgrade` instead of `github.com/cosmos/cosmos-sdk/x/upgrade` across the SDK. 496 497 ### Tooling 498 499 #### Rosetta 500 501 Rosetta has moved to it's own [repo](https://github.com/cosmos/rosetta) and not imported by the Cosmos SDK SimApp by default. 502 Any user who is interested on using the tool can connect it standalone to any node without the need to add it as part of the node binary. 503 504 The rosetta tool also allows multi chain connections.