From 7c0f9ea94fd635fb12533d653b7d0d807efd0fff Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 26 Dec 2024 13:39:11 +0100 Subject: [PATCH] add the merging of appmodule and basic --- docs/build/building-apps/upgrades/0.52.md | 84 +++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/docs/build/building-apps/upgrades/0.52.md b/docs/build/building-apps/upgrades/0.52.md index 7fd1069fec98..e50be6bd8294 100644 --- a/docs/build/building-apps/upgrades/0.52.md +++ b/docs/build/building-apps/upgrades/0.52.md @@ -22,7 +22,7 @@ Note: **v0.52** relies on [Comet v1](https://github.com/cometbft/cometbft/releas 2. [gRPC-Web](#grpc-web) 4. [Enable (or Skip) gRPC-Web Support](#enable-or-skip-grpc-web-support) 5. [Remove `GasConsumptionDecorator` and `IncreaseSequenceDecorator`](#remove-gasconsumptiondecorator-and-increasesequencedecorator) - 6. [Enable or Skip Unordered Transactions](#enable-or-skip-unordered-transactions) + 6. [Unordered Transactions](#unordered-transactions) 7. [Handle Sign Mode Textual](#handle-sign-mode-textual) 8. [Update Depinject `app_config.go` / `app.yml` if Applicable](#update-depinject-app_configgo--appyml-if-applicable) 9. [Protobuf Changes](#protobuf-changes) @@ -405,7 +405,83 @@ mintKeeper.SetMintFn(keeper.DefaultMintFn( `x/validate` is a module for antehandlers. If you are using runtime/depinject or v2 this module is required. Skip this step or define your own custom ante/post handlers, see `x/validate` documentation for more details. -### Preparing the Upgrade Handler (On-Chain) +### Remove AppmoduleBasic + +In 0.52, there is a single entry point for a module. The `appmodule` is the single entry point. In order to make the necessary changes the appmodulebasic struct in the module.go should be merged with appmodule. + +```diff +// AppModuleBasic defines the basic application module used by the bank module. +- type AppModuleBasic struct { +- cdc codec.Codec +- ac address.Codec +- } + +// AppModule implements an application module for the bank module. +type AppModule struct { +- AppModuleBasic ++ cdc codec.Codec + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + + // legacySubspace is used solely for migration of x/params managed parameters + legacySubspace exported.Subspace +} + +// Name returns the bank module's name. +- func (AppModuleBasic) Name() string { return types.ModuleName } ++ func (AppModule) Name() string { return types.ModuleName } + +// RegisterLegacyAminoCodec registers the bank module's types on the LegacyAmino codec. +- func (AppModuleBasic) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) { ++ func (AppModule) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) { + types.RegisterLegacyAminoCodec(cdc) +} + +// DefaultGenesis returns default genesis state as raw bytes for the bank +// module. +- func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { ++ func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the bank module. +- func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { ++ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { + var data types.GenesisState +- if err := cdc.UnmarshalJSON(bz, &data); err != nil { ++ if err := am.cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return data.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module. +- func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { ++ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root tx command for the bank module. +- func (ab AppModuleBasic) GetTxCmd() *cobra.Command { ++ func (ab AppModule) GetTxCmd() *cobra.Command { + return cli.NewTxCmd(ab.ac) +} + +// RegisterInterfaces registers interfaces and implementations of the bank module. +- func (AppModuleBasic) RegisterInterfaces(registry.InterfaceRegistrar) { ++ func (AppModule) RegisterInterfaces(registry.InterfaceRegistrar) { + types.RegisterInterfaces(registry) + + // Register legacy interfaces for migration scripts. + v1bank.RegisterInterfaces(registry) +} +``` + +## Preparing the Upgrade Handler (On-Chain) If your chain uses x/upgrade to do in-place upgrades: 1. Create a new upgrade name (e.g. v0.52). @@ -431,7 +507,7 @@ If your chain uses x/upgrade to do in-place upgrades: If your chain is small or you do not rely on x/upgrade, you can do a chain halt and manual restart with the new binary after updating your genesis (if needed). -### Testing & Verifying the Upgrade +## Testing & Verifying the Upgrade 1. Local test @@ -448,7 +524,7 @@ If your chain is small or you do not rely on x/upgrade, you can do a chain halt * Run a short-lived testnet with the new binary, replicate production environment if possible. -### Conclusion +## Conclusion Upgrading from Cosmos SDK v0.50 to v0.52 involves a number of structural and conceptual changes. The major points are: • Removing x/params for new parameter management,