Skip to content

Commit

Permalink
add the merging of appmodule and basic
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Dec 26, 2024
1 parent 61afdf3 commit 7c0f9ea
Showing 1 changed file with 80 additions and 4 deletions.
84 changes: 80 additions & 4 deletions docs/build/building-apps/upgrades/0.52.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Expand All @@ -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

Expand All @@ -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,
Expand Down

0 comments on commit 7c0f9ea

Please sign in to comment.