feat(core): add migrations registering (#19370)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
parent
ac48269f98
commit
e15a0de251
@ -74,10 +74,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
* (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
|
||||
|
||||
### Deprecated
|
||||
|
||||
* (simapp) [#19146](https://github.com/cosmos/cosmos-sdk/pull/19146) Replace `--v` CLI option with `--validator-count`/`-n`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (baseapp) [#19338](https://github.com/cosmos/cosmos-sdk/pull/19338) Set HeaderInfo in context when calling `setState`.
|
||||
@ -144,6 +140,11 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
|
||||
* (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.HasServicecs` instead from Core API.
|
||||
|
||||
## [v0.50.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.3) - 2023-01-15
|
||||
|
||||
### Features
|
||||
|
||||
96
UPGRADING.md
96
UPGRADING.md
@ -5,7 +5,45 @@ Note, always read the **SimApp** section for more information on application wir
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Unordered Transactions
|
||||
### SimApp
|
||||
|
||||
In this section we describe the changes made in Cosmos SDK' SimApp.
|
||||
**These changes are directly applicable to your application wiring.**
|
||||
|
||||
#### 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.
|
||||
|
||||
#### Client (`root.go`)
|
||||
|
||||
The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.).
|
||||
This is part of the work of abstracting the SDK from the global bech32 config.
|
||||
|
||||
This means the address codecs must be provided in the `client.Context` in the application client (usually `root.go`).
|
||||
|
||||
```diff
|
||||
clientCtx = clientCtx.
|
||||
+ WithAddressCodec(addressCodec).
|
||||
+ WithValidatorAddressCodec(validatorAddressCodec).
|
||||
+ WithConsensusAddressCodec(consensusAddressCodec)
|
||||
```
|
||||
|
||||
**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.
|
||||
|
||||
### Core
|
||||
|
||||
`appmodule.Environment` interface was introduced to fetch different services from the application. This can be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. It needs to be passed into a module at instantiation.
|
||||
|
||||
Circuit Breaker is used as an example.
|
||||
|
||||
```go
|
||||
app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey]), nil), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())
|
||||
```
|
||||
|
||||
#### 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
|
||||
@ -80,57 +118,19 @@ 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.
|
||||
|
||||
### Params
|
||||
|
||||
* Params migrations were removed. It is required to migrate to 0.50 prior to upgrading to v0.51.
|
||||
|
||||
### SimApp
|
||||
|
||||
In this section we describe the changes made in Cosmos SDK' SimApp.
|
||||
**These changes are directly applicable to your application wiring.**
|
||||
|
||||
#### 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.
|
||||
|
||||
#### Client (`root.go`)
|
||||
|
||||
The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.).
|
||||
This is part of the work of abstracting the SDK from the global bech32 config.
|
||||
|
||||
This means the address codecs must be provided in the `client.Context` in the application client (usually `root.go`).
|
||||
|
||||
```diff
|
||||
clientCtx = clientCtx.
|
||||
+ WithAddressCodec(addressCodec).
|
||||
+ WithValidatorAddressCodec(validatorAddressCodec).
|
||||
+ WithConsensusAddressCodec(consensusAddressCodec)
|
||||
```
|
||||
|
||||
**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.
|
||||
|
||||
#### Dependency Injection
|
||||
|
||||
<!-- explain app_config.go changes -->
|
||||
|
||||
### Core
|
||||
|
||||
`appmodule.Environment` interface was introduced to fetch different services from the application. This can be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. It needs to be passed into a module at instantiation.
|
||||
|
||||
Circuit Breaker is used as an example.
|
||||
|
||||
```go
|
||||
app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey]), nil), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())
|
||||
```
|
||||
|
||||
### Modules
|
||||
|
||||
#### `**all**`
|
||||
|
||||
##### Dependency Injection
|
||||
##### Params
|
||||
|
||||
Old 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.
|
||||
|
||||
##### Core API
|
||||
|
||||
Core API has been introduces for modules in 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.
|
||||
|
||||
##### 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.
|
||||
|
||||
@ -41,8 +41,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service.
|
||||
* [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit.
|
||||
* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services
|
||||
* [#19370](https://github.com/cosmos/cosmos-sdk/pull/19370) Add `appmodule.Migrations` interface to handle migrations
|
||||
|
||||
### API Breaking
|
||||
### API Breaking Changes
|
||||
|
||||
* [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` to `x/tx`.
|
||||
* [#18861](httpes://github.com/cosmos/cosmos-sdk/pull/18861) Moved `coin.ParseCoin` to `client/v2/internal`.
|
||||
|
||||
16
core/appmodule/migrations.go
Normal file
16
core/appmodule/migrations.go
Normal file
@ -0,0 +1,16 @@
|
||||
package appmodule
|
||||
|
||||
import "context"
|
||||
|
||||
type MigrationRegistrar interface {
|
||||
// Register registers an in-place store migration for a module. The
|
||||
// handler is a migration script to perform in-place migrations from version
|
||||
// `fromVersion` to version `fromVersion+1`.
|
||||
//
|
||||
// EACH TIME a module's ConsensusVersion increments, a new migration MUST
|
||||
// be registered using this function. If a migration handler is missing for
|
||||
// a particular function, the upgrade logic (see RunMigrations function)
|
||||
// will panic. If the ConsensusVersion bump does not introduce any store
|
||||
// changes, then a no-op function must be registered here.
|
||||
Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error
|
||||
}
|
||||
@ -39,17 +39,12 @@ type HasServices interface {
|
||||
RegisterServices(grpc.ServiceRegistrar) error
|
||||
}
|
||||
|
||||
// HasPrepareCheckState is an extension interface that contains information about the AppModule
|
||||
// and PrepareCheckState.
|
||||
type HasPrepareCheckState interface {
|
||||
// HasMigrations is the extension interface that modules should implement to register migrations.
|
||||
type HasMigrations interface {
|
||||
AppModule
|
||||
PrepareCheckState(context.Context) error
|
||||
}
|
||||
|
||||
// HasPrecommit is an extension interface that contains information about the AppModule and Precommit.
|
||||
type HasPrecommit interface {
|
||||
AppModule
|
||||
Precommit(context.Context) error
|
||||
// RegisterMigrations registers the module's migrations with the app's migrator.
|
||||
RegisterMigrations(MigrationRegistrar) error
|
||||
}
|
||||
|
||||
// ResponsePreBlock represents the response from the PreBlock method.
|
||||
@ -100,3 +95,18 @@ type HasMsgHandler interface {
|
||||
// RegisterMsgHandlers is implemented by the module that will register msg handlers.
|
||||
RegisterMsgHandlers(router MsgHandlerRouter)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------- //
|
||||
|
||||
// HasPrepareCheckState is an extension interface that contains information about the AppModule
|
||||
// and PrepareCheckState.
|
||||
type HasPrepareCheckState interface {
|
||||
AppModule
|
||||
PrepareCheckState(context.Context) error
|
||||
}
|
||||
|
||||
// HasPrecommit is an extension interface that contains information about the AppModule and Precommit.
|
||||
type HasPrecommit interface {
|
||||
AppModule
|
||||
Precommit(context.Context) error
|
||||
}
|
||||
|
||||
2
docs/build/building-modules/13-upgrade.md
vendored
2
docs/build/building-modules/13-upgrade.md
vendored
@ -49,6 +49,8 @@ Since these migrations are functions that need access to a Keeper's store, use a
|
||||
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/keeper/migrations.go
|
||||
```
|
||||
|
||||
<!-- TODO v0.51: explain the new way with core -->
|
||||
|
||||
## Writing Migration Scripts
|
||||
|
||||
To define the functionality that takes place during an upgrade, write a migration script and place the functions in a `migrations/` directory. For example, to write migration scripts for the bank module, place the functions in `x/bank/migrations/`. Use the recommended naming convention for these functions. For example, `v2bank` is the script that migrates the package `x/bank/migrations/v2`:
|
||||
|
||||
@ -113,6 +113,8 @@ func (a *autocliConfigurator) RegisterMigration(string, uint64, module.Migration
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *autocliConfigurator) Register(string, uint64, func(context.Context) error) error { return nil }
|
||||
|
||||
func (a *autocliConfigurator) RegisterService(sd *grpc.ServiceDesc, ss interface{}) {
|
||||
if a.registryCache == nil {
|
||||
a.registryCache, a.err = proto.MergedRegistry()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/gogoproto/grpc"
|
||||
@ -20,6 +21,8 @@ import (
|
||||
// their services in the RegisterServices method. It is designed to eventually
|
||||
// support module object capabilities isolation as described in
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/7093
|
||||
// Deprecated: The Configurator is deprecated.
|
||||
// Preferably use core services for registering msg/query server and migrations.
|
||||
type Configurator interface {
|
||||
grpc.Server
|
||||
|
||||
@ -45,6 +48,10 @@ type Configurator interface {
|
||||
// will panic. If the ConsensusVersion bump does not introduce any store
|
||||
// changes, then a no-op function must be registered here.
|
||||
RegisterMigration(moduleName string, fromVersion uint64, handler MigrationHandler) error
|
||||
|
||||
// Register registers an in-place store migration for a module.
|
||||
// It permits to register modules migrations that have migrated to serverv2 but still be compatible with baseapp.
|
||||
Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error
|
||||
}
|
||||
|
||||
type configurator struct {
|
||||
@ -119,6 +126,14 @@ func (c *configurator) RegisterMigration(moduleName string, fromVersion uint64,
|
||||
return nil
|
||||
}
|
||||
|
||||
// Register implements the Configurator.Register method
|
||||
// It allows to register modules migrations that have migrated to server/v2 but still be compatible with baseapp.
|
||||
func (c *configurator) Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error {
|
||||
return c.RegisterMigration(moduleName, fromVersion, func(sdkCtx sdk.Context) error {
|
||||
return handler(sdkCtx)
|
||||
})
|
||||
}
|
||||
|
||||
// runModuleMigrations runs all in-place store migrations for one given module from a
|
||||
// version to another version.
|
||||
func (c *configurator) runModuleMigrations(ctx sdk.Context, moduleName string, fromVersion, toVersion uint64) error {
|
||||
|
||||
@ -200,6 +200,13 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if module, ok := c.module.(appmodule.HasMigrations); ok {
|
||||
err := module.RegisterMigrations(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {}
|
||||
|
||||
@ -467,6 +467,13 @@ func (m *Manager) RegisterServices(cfg Configurator) error {
|
||||
}
|
||||
}
|
||||
|
||||
if module, ok := module.(appmodule.HasMigrations); ok {
|
||||
err := module.RegisterMigrations(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Error() != nil {
|
||||
return cfg.Error()
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"github.com/cosmos/gogoproto/grpc"
|
||||
"context"
|
||||
|
||||
v5 "cosmossdk.io/x/auth/migrations/v5"
|
||||
"cosmossdk.io/x/auth/types"
|
||||
@ -11,23 +11,22 @@ import (
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
type Migrator struct {
|
||||
keeper AccountKeeper
|
||||
queryServer grpc.Server
|
||||
keeper AccountKeeper
|
||||
}
|
||||
|
||||
// NewMigrator returns a new Migrator.
|
||||
func NewMigrator(keeper AccountKeeper, queryServer grpc.Server) Migrator {
|
||||
return Migrator{keeper: keeper, queryServer: queryServer}
|
||||
func NewMigrator(keeper AccountKeeper) Migrator {
|
||||
return Migrator{keeper: keeper}
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate2to3 migrates from consensus version 2 to version 3. Specifically, for each account
|
||||
// we index the account's ID to their address.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -35,14 +34,14 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
// version 4. Specifically, it takes the parameters that are currently stored
|
||||
// and managed by the x/params modules and stores them directly into the x/auth
|
||||
// module state.
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate4To5 migrates the x/auth module state from the consensus version 4 to 5.
|
||||
// It migrates the GlobalAccountNumber from being a protobuf defined value to a
|
||||
// big-endian encoded uint64, it also migrates it to use a more canonical prefix.
|
||||
func (m Migrator) Migrate4To5(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate4To5(ctx context.Context) error {
|
||||
return v5.Migrate(ctx, m.keeper.storeService, m.keeper.AccountNumber)
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ func (m Migrator) Migrate4To5(ctx sdk.Context) error {
|
||||
// set the account without map to accAddr to accNumber.
|
||||
//
|
||||
// NOTE: This is used for testing purposes only.
|
||||
func (m Migrator) V45SetAccount(ctx sdk.Context, acc sdk.AccountI) error {
|
||||
func (m Migrator) V45SetAccount(ctx context.Context, acc sdk.AccountI) error {
|
||||
addr := acc.GetAddress()
|
||||
store := m.keeper.storeService.OpenKVStore(ctx)
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
@ -30,9 +31,10 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the auth module.
|
||||
@ -98,27 +100,31 @@ func NewAppModule(cdc codec.Codec, accountKeeper keeper.AccountKeeper, randGenAc
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterServices registers a GRPC query service to respond to the
|
||||
// module-specific GRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.accountKeeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.accountKeeper))
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.accountKeeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQueryServer(am.accountKeeper))
|
||||
|
||||
m := keeper.NewMigrator(am.accountKeeper, cfg.QueryServer())
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.accountKeeper)
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 2 to 3: %w", types.ModuleName, err)
|
||||
}
|
||||
if err := mr.Register(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 3 to 4: %w", types.ModuleName, err)
|
||||
}
|
||||
if err := mr.Register(types.ModuleName, 4, m.Migrate4To5); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 4 to 5: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4To5); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 4 to 5", types.ModuleName))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the auth module. It returns
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
v2 "cosmossdk.io/x/authz/migrations/v2"
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v2 "cosmossdk.io/x/authz/migrations/v2"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -17,6 +17,6 @@ func NewMigrator(keeper Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/errors"
|
||||
@ -26,10 +27,11 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the authz module.
|
||||
@ -42,16 +44,21 @@ func (AppModuleBasic) Name() string {
|
||||
return authz.ModuleName
|
||||
}
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the
|
||||
// module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
authz.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
authz.RegisterMsgServer(cfg.MsgServer(), am.keeper)
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
authz.RegisterQueryServer(registrar, am.keeper)
|
||||
authz.RegisterMsgServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
err := cfg.RegisterMigration(authz.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", authz.ModuleName, err))
|
||||
if err := mr.Register(authz.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", authz.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec registers the authz module's types for the given codec.
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
import "context"
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
type Migrator struct {
|
||||
@ -15,16 +13,16 @@ func NewMigrator(keeper BaseKeeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate2to3 migrates x/bank storage from version 2 to 3.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate3to4 migrates x/bank storage from version 3 to 4.
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/bank/client/cli"
|
||||
@ -31,10 +32,11 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the bank module.
|
||||
@ -95,23 +97,29 @@ type AppModule struct {
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper.(keeper.BaseKeeper))
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/bank from version 1 to 2: %v", err))
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/bank from version 1 to 2: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/bank from version 2 to 3: %v", err))
|
||||
if err := mr.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/bank from version 2 to 3: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/bank from version 3 to 4: %v", err))
|
||||
if err := mr.Register(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/bank from version 3 to 4: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/circuit/keeper"
|
||||
@ -25,9 +26,9 @@ const ConsensusVersion = 1
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the circuit module.
|
||||
@ -81,9 +82,11 @@ type AppModule struct {
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper))
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQueryServer(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
import "context"
|
||||
|
||||
// Migrator is a struct for handling in-place state migrations.
|
||||
type Migrator struct {
|
||||
@ -20,6 +18,6 @@ func NewMigrator(k *Keeper) Migrator {
|
||||
// version 2. Specifically, it takes the parameters that are currently stored
|
||||
// and managed by the x/params modules and stores them directly into the x/crisis
|
||||
// module state.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
|
||||
@ -26,10 +27,11 @@ const ConsensusVersion = 2
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// Module init related flags
|
||||
@ -109,13 +111,20 @@ func AddModuleInitFlags(startCmd *cobra.Command) {
|
||||
}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the crisis module. It returns
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v4 "cosmossdk.io/x/distribution/migrations/v4"
|
||||
"cosmossdk.io/x/distribution/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -18,7 +18,7 @@ func NewMigrator(keeper Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -26,13 +26,13 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
// version 2 to version 3. Specifically, it takes the parameters that are currently stored
|
||||
// and managed by the x/params module and stores them directly into the x/distribution
|
||||
// module state.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate3to4 migrates the x/distribution module state to use collections
|
||||
// Additionally it migrates distribution fee pool to use protocol pool module account
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
if err := v4.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
return m.migrateFunds(ctx)
|
||||
}
|
||||
|
||||
func (m Migrator) migrateFunds(ctx sdk.Context) error {
|
||||
func (m Migrator) migrateFunds(ctx context.Context) error {
|
||||
macc := m.keeper.GetDistributionAccount(ctx)
|
||||
poolMacc := m.keeper.authKeeper.GetModuleAccount(ctx, types.ProtocolPoolModuleName)
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ var (
|
||||
NewProposerKey = collections.NewPrefix(1)
|
||||
)
|
||||
|
||||
func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, cdc codec.BinaryCodec) error {
|
||||
func MigrateStore(ctx context.Context, storeService store.KVStoreService, cdc codec.BinaryCodec) error {
|
||||
store := storeService.OpenKVStore(ctx)
|
||||
bz, err := store.Get(OldProposerKey)
|
||||
if err != nil {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package v4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/x/distribution/types"
|
||||
@ -9,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// MigrateFunds migrates the distribution module funds to pool module
|
||||
func MigrateFunds(ctx sdk.Context, bankKeeper types.BankKeeper, feePool types.FeePool, macc, poolMacc sdk.ModuleAccountI) (types.FeePool, error) {
|
||||
func MigrateFunds(ctx context.Context, bankKeeper types.BankKeeper, feePool types.FeePool, macc, poolMacc sdk.ModuleAccountI) (types.FeePool, error) {
|
||||
poolBal, remainder := feePool.CommunityPool.TruncateDecimal()
|
||||
|
||||
distrbalances := bankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/distribution/client/cli"
|
||||
@ -29,11 +30,12 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the distribution module.
|
||||
@ -119,22 +121,28 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 2 to 3: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 3 to 4: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the distribution module. It returns
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
v2 "cosmossdk.io/x/feegrant/migrations/v2"
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v2 "cosmossdk.io/x/feegrant/migrations/v2"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -17,6 +17,6 @@ func NewMigrator(keeper Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/errors"
|
||||
@ -23,11 +24,12 @@ import (
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -44,16 +46,22 @@ func (ab AppModuleBasic) Name() string {
|
||||
return feegrant.ModuleName
|
||||
}
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the
|
||||
// module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
feegrant.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
feegrant.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
feegrant.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
feegrant.RegisterQueryServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
err := cfg.RegisterMigration(feegrant.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/feegrant from version 1 to 2: %v", err))
|
||||
|
||||
if err := mr.Register(feegrant.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/feegrant from version 1 to 2: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec registers the feegrant module's types for the given codec.
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v5 "cosmossdk.io/x/gov/migrations/v5"
|
||||
v6 "cosmossdk.io/x/gov/migrations/v6"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -20,26 +20,26 @@ func NewMigrator(keeper *Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate2to3 migrates from version 2 to 3.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate3to4 migrates from version 3 to 4.
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate4to5 migrates from version 4 to 5.
|
||||
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate4to5(ctx context.Context) error {
|
||||
return v5.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc, m.keeper.Constitution)
|
||||
}
|
||||
|
||||
// Migrate4to5 migrates from version 5 to 6.
|
||||
func (m Migrator) Migrate5to6(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate5to6(ctx context.Context) error {
|
||||
return v6.MigrateStore(ctx, m.keeper.Params, m.keeper.Proposals)
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package v5
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
corestoretypes "cosmossdk.io/core/store"
|
||||
govv1 "cosmossdk.io/x/gov/types/v1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -21,7 +22,7 @@ var (
|
||||
//
|
||||
// Addition of the new proposal expedited parameters that are set to 0 by default.
|
||||
// Set of default chain constitution.
|
||||
func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec, constitutionCollection collections.Item[string]) error {
|
||||
func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec, constitutionCollection collections.Item[string]) error {
|
||||
store := storeService.OpenKVStore(ctx)
|
||||
paramsBz, err := store.Get(ParamsKey)
|
||||
if err != nil {
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
package v6
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
v1 "cosmossdk.io/x/gov/types/v1"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// MigrateStore performs in-place store migrations from v5 (v0.50) to v6 (v0.51). The
|
||||
@ -14,7 +13,7 @@ import (
|
||||
//
|
||||
// Addition of new field in params to store types of proposals that can be submitted.
|
||||
// Addition of gov params for optimistic proposals.
|
||||
func MigrateStore(ctx sdk.Context, paramsCollection collections.Item[v1.Params], proposalCollection collections.Map[uint64, v1.Proposal]) error {
|
||||
func MigrateStore(ctx context.Context, paramsCollection collections.Item[v1.Params], proposalCollection collections.Map[uint64, v1.Proposal]) error {
|
||||
// Migrate proposals
|
||||
err := proposalCollection.Walk(ctx, nil, func(key uint64, proposal v1.Proposal) (bool, error) {
|
||||
if proposal.Expedited {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
@ -32,11 +33,12 @@ var (
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the gov module.
|
||||
@ -144,35 +146,40 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
msgServer := keeper.NewMsgServerImpl(am.keeper)
|
||||
v1beta1.RegisterMsgServer(cfg.MsgServer(), keeper.NewLegacyMsgServerImpl(am.accountKeeper.GetModuleAddress(govtypes.ModuleName).String(), msgServer))
|
||||
v1.RegisterMsgServer(cfg.MsgServer(), msgServer)
|
||||
v1beta1.RegisterMsgServer(registrar, keeper.NewLegacyMsgServerImpl(am.accountKeeper.GetModuleAddress(govtypes.ModuleName).String(), msgServer))
|
||||
v1.RegisterMsgServer(registrar, msgServer)
|
||||
|
||||
legacyQueryServer := keeper.NewLegacyQueryServer(am.keeper)
|
||||
v1beta1.RegisterQueryServer(cfg.QueryServer(), legacyQueryServer)
|
||||
v1.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper))
|
||||
v1beta1.RegisterQueryServer(registrar, keeper.NewLegacyQueryServer(am.keeper))
|
||||
v1.RegisterQueryServer(registrar, keeper.NewQueryServer(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
if err := cfg.RegisterMigration(govtypes.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 1 to 2: %v", err))
|
||||
if err := mr.Register(govtypes.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/gov from version 1 to 2: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(govtypes.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 2 to 3: %v", err))
|
||||
if err := mr.Register(govtypes.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/gov from version 2 to 3: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(govtypes.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 3 to 4: %v", err))
|
||||
if err := mr.Register(govtypes.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/gov from version 3 to 4: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(govtypes.ModuleName, 4, m.Migrate4to5); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 4 to 5: %v", err))
|
||||
if err := mr.Register(govtypes.ModuleName, 4, m.Migrate4to5); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/gov from version 4 to 5: %w", err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(govtypes.ModuleName, 5, m.Migrate5to6); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/gov from version 5 to 6: %v", err))
|
||||
if err := mr.Register(govtypes.ModuleName, 5, m.Migrate5to6); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/gov from version 5 to 6: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the gov module. It returns
|
||||
|
||||
@ -145,10 +145,6 @@ func (am AppModule) EndBlock(ctx context.Context) error {
|
||||
return EndBlocker(c, am.keeper)
|
||||
}
|
||||
|
||||
// ____________________________________________________________________________
|
||||
|
||||
// AppModuleSimulation functions
|
||||
|
||||
// GenerateGenesisState creates a randomized GenState of the group module.
|
||||
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
||||
simulation.RandomizedGenState(simState)
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
import "context"
|
||||
|
||||
// Migrator is a struct for handling in-place state migrations.
|
||||
type Migrator struct {
|
||||
@ -20,6 +18,6 @@ func NewMigrator(k Keeper) Migrator {
|
||||
// version 2. Specifically, it takes the parameters that are currently stored
|
||||
// and managed by the x/params modules and stores them directly into the x/mint
|
||||
// module state.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/mint/keeper"
|
||||
@ -26,10 +27,11 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the mint module.
|
||||
@ -110,17 +112,23 @@ func NewAppModule(
|
||||
// IsAppModule implements the appmodule.AppModule interface.
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the
|
||||
// module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQueryServerImpl(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterMigrations registers module migrations.
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the mint module. It returns
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/params/keeper"
|
||||
@ -19,9 +20,9 @@ import (
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
)
|
||||
|
||||
// ConsensusVersion defines the current x/params module consensus version.
|
||||
@ -72,10 +73,11 @@ func (am AppModule) IsAppModule() {}
|
||||
// GenerateGenesisState performs a no-op.
|
||||
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {}
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the
|
||||
// module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
proposal.RegisterQueryServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterStoreDecoder doesn't register any type.
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/protocolpool/keeper"
|
||||
@ -21,11 +22,13 @@ import (
|
||||
const ConsensusVersion = 1
|
||||
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the pool module.
|
||||
@ -76,15 +79,15 @@ type AppModule struct {
|
||||
bankKeeper types.BankKeeper
|
||||
}
|
||||
|
||||
var _ appmodule.AppModule = AppModule{}
|
||||
|
||||
// IsAppModule implements the appmodule.AppModule interface.
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v4 "cosmossdk.io/x/slashing/migrations/v4"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -18,7 +19,7 @@ func NewMigrator(keeper Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -26,14 +27,14 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
// version 2 to version 3. Specifically, it takes the parameters that are currently stored
|
||||
// and managed by the x/params modules and stores them directly into the x/slashing
|
||||
// module state.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate3to4 migrates the x/slashing module state from the consensus
|
||||
// version 3 to version 4. Specifically, it migrates the validator missed block
|
||||
// bitmap.
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
|
||||
params, err := m.keeper.Params.Get(ctx)
|
||||
if err != nil {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package v4
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/bits-and-blooms/bitset"
|
||||
gogotypes "github.com/cosmos/gogoproto/types"
|
||||
|
||||
@ -15,7 +17,7 @@ import (
|
||||
// Migrate migrates state to consensus version 4. Specifically, the migration
|
||||
// deletes all existing validator bitmap entries and replaces them with a real
|
||||
// "chunked" bitmap.
|
||||
func Migrate(ctx sdk.Context, cdc codec.BinaryCodec, store storetypes.KVStore, params types.Params) error {
|
||||
func Migrate(ctx context.Context, cdc codec.BinaryCodec, store storetypes.KVStore, params types.Params) error {
|
||||
// Get all the missed blocks for each validator, based on the existing signing
|
||||
// info.
|
||||
var missedBlocks []types.ValidatorMissedBlocks
|
||||
@ -57,7 +59,7 @@ func Migrate(ctx sdk.Context, cdc codec.BinaryCodec, store storetypes.KVStore, p
|
||||
}
|
||||
|
||||
func iterateValidatorSigningInfos(
|
||||
ctx sdk.Context,
|
||||
ctx context.Context,
|
||||
cdc codec.BinaryCodec,
|
||||
store storetypes.KVStore,
|
||||
cb func(address sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool),
|
||||
@ -77,7 +79,7 @@ func iterateValidatorSigningInfos(
|
||||
}
|
||||
|
||||
func iterateValidatorMissedBlockBitArray(
|
||||
ctx sdk.Context,
|
||||
ctx context.Context,
|
||||
cdc codec.BinaryCodec,
|
||||
store storetypes.KVStore,
|
||||
addr sdk.ConsAddress,
|
||||
@ -99,7 +101,7 @@ func iterateValidatorMissedBlockBitArray(
|
||||
}
|
||||
|
||||
func GetValidatorMissedBlocks(
|
||||
ctx sdk.Context,
|
||||
ctx context.Context,
|
||||
cdc codec.BinaryCodec,
|
||||
store storetypes.KVStore,
|
||||
addr sdk.ConsAddress,
|
||||
@ -114,7 +116,7 @@ func GetValidatorMissedBlocks(
|
||||
return missedBlocks
|
||||
}
|
||||
|
||||
func deleteValidatorMissedBlockBitArray(ctx sdk.Context, store storetypes.KVStore, addr sdk.ConsAddress) {
|
||||
func deleteValidatorMissedBlockBitArray(ctx context.Context, store storetypes.KVStore, addr sdk.ConsAddress) {
|
||||
iter := storetypes.KVStorePrefixIterator(store, validatorMissedBlockBitArrayPrefixKey(addr))
|
||||
defer iter.Close()
|
||||
|
||||
@ -123,7 +125,7 @@ func deleteValidatorMissedBlockBitArray(ctx sdk.Context, store storetypes.KVStor
|
||||
}
|
||||
}
|
||||
|
||||
func setMissedBlockBitmapValue(ctx sdk.Context, store storetypes.KVStore, addr sdk.ConsAddress, index int64, missed bool) error {
|
||||
func setMissedBlockBitmapValue(ctx context.Context, store storetypes.KVStore, addr sdk.ConsAddress, index int64, missed bool) error {
|
||||
// get the chunk or "word" in the logical bitmap
|
||||
chunkIndex := index / MissedBlockBitmapChunkSize
|
||||
key := ValidatorMissedBlockBitmapKey(addr, chunkIndex)
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/slashing/keeper"
|
||||
@ -26,10 +27,11 @@ var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the slashing module.
|
||||
@ -109,21 +111,29 @@ func NewAppModule(
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mh appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
|
||||
if err := mh.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
if err := mh.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 2 to 3: %w", types.ModuleName, err)
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
|
||||
|
||||
if err := mh.Register(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 3 to 4: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the slashing module. It returns
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v5 "cosmossdk.io/x/staking/migrations/v5"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Migrator is a struct for handling in-place store migrations.
|
||||
@ -20,22 +21,22 @@ func NewMigrator(keeper *Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate2to3 migrates x/staking state from consensus version 2 to 3.
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate3to4 migrates x/staking state from consensus version 3 to 4.
|
||||
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Migrate4to5 migrates x/staking state from consensus version 4 to 5.
|
||||
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate4to5(ctx context.Context) error {
|
||||
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
|
||||
return v5.MigrateStore(ctx, store, m.keeper.cdc)
|
||||
return v5.MigrateStore(ctx, store, m.keeper.cdc, m.keeper.Logger(ctx))
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/staking"
|
||||
@ -28,6 +29,7 @@ func TestHistoricalKeysMigration(t *testing.T) {
|
||||
tKey := storetypes.NewTransientStoreKey("transient_test")
|
||||
ctx := testutil.DefaultContext(storeKey, tKey)
|
||||
store := ctx.KVStore(storeKey)
|
||||
logger := log.NewTestLogger(t)
|
||||
|
||||
type testCase struct {
|
||||
oldKey, newKey []byte
|
||||
@ -63,7 +65,7 @@ func TestHistoricalKeysMigration(t *testing.T) {
|
||||
}
|
||||
|
||||
// migrate store to new key format
|
||||
require.NoErrorf(t, v5.MigrateStore(ctx, store, cdc), "v5.MigrateStore failed, seed: %d", seed)
|
||||
require.NoErrorf(t, v5.MigrateStore(ctx, store, cdc, logger), "v5.MigrateStore failed, seed: %d", seed)
|
||||
|
||||
// check results
|
||||
for _, tc := range testCases {
|
||||
@ -83,6 +85,7 @@ func TestDelegationsByValidatorMigrations(t *testing.T) {
|
||||
tKey := storetypes.NewTransientStoreKey("transient_test")
|
||||
ctx := testutil.DefaultContext(storeKey, tKey)
|
||||
store := ctx.KVStore(storeKey)
|
||||
logger := log.NewTestLogger(t)
|
||||
|
||||
accAddrs := sims.CreateIncrementalAccounts(11)
|
||||
valAddrs := sims.ConvertAddrsToValAddrs(accAddrs[0:1])
|
||||
@ -98,7 +101,7 @@ func TestDelegationsByValidatorMigrations(t *testing.T) {
|
||||
dels := getValDelegations(ctx, cdc, storeKey, valAddrs[0])
|
||||
assert.Len(t, dels, 0)
|
||||
|
||||
err := v5.MigrateStore(ctx, store, cdc)
|
||||
err := v5.MigrateStore(ctx, store, cdc, logger)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// after migration the state of delegations by val index should not be empty
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package v5
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@ -12,7 +13,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func migrateDelegationsByValidatorIndex(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
||||
func migrateDelegationsByValidatorIndex(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
||||
iterator := storetypes.KVStorePrefixIterator(store, DelegationKey)
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
@ -29,11 +30,11 @@ func migrateDelegationsByValidatorIndex(ctx sdk.Context, store storetypes.KVStor
|
||||
}
|
||||
|
||||
// MigrateStore performs in-place store migrations from v4 to v5.
|
||||
func MigrateStore(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
||||
func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec, logger log.Logger) error {
|
||||
if err := migrateDelegationsByValidatorIndex(ctx, store, cdc); err != nil {
|
||||
return err
|
||||
}
|
||||
return migrateHistoricalInfoKeys(store, ctx.Logger())
|
||||
return migrateHistoricalInfoKeys(store, logger)
|
||||
}
|
||||
|
||||
// migrateHistoricalInfoKeys migrate HistoricalInfo keys to binary format
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/depinject"
|
||||
@ -29,7 +30,6 @@ const (
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
_ module.HasABCIGenesis = AppModule{}
|
||||
_ module.HasABCIEndBlock = AppModule{}
|
||||
@ -37,6 +37,8 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic defines the basic application module used by the staking module.
|
||||
@ -120,24 +122,29 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
querier := keeper.Querier{Keeper: am.keeper}
|
||||
types.RegisterQueryServer(cfg.QueryServer(), querier)
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err)
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err)
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err)
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 4 to 5: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 4, m.Migrate4to5); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 4 to 5: %v", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the staking module.
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
@ -9,7 +10,6 @@ import (
|
||||
"cosmossdk.io/x/upgrade/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -28,11 +28,11 @@ func NewMigrator(keeper *Keeper) Migrator {
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate1to2(ctx context.Context) error {
|
||||
return migrateDoneUpgradeKeys(ctx, m.keeper.storeService)
|
||||
}
|
||||
|
||||
func migrateDoneUpgradeKeys(ctx sdk.Context, storeService storetypes.KVStoreService) error {
|
||||
func migrateDoneUpgradeKeys(ctx context.Context, storeService storetypes.KVStoreService) error {
|
||||
store := storeService.OpenKVStore(ctx)
|
||||
oldDoneStore := prefix.NewStore(runtime.KVStoreAdapter(store), []byte{types.DoneByte})
|
||||
oldDoneStoreIter := oldDoneStore.Iterator(nil, nil)
|
||||
@ -57,11 +57,11 @@ func migrateDoneUpgradeKeys(ctx sdk.Context, storeService storetypes.KVStoreServ
|
||||
// Migrate2to3 migrates from version 2 to 3.
|
||||
// It takes the legacy protocol version and if it exists, uses it to set
|
||||
// the app version (of the baseapp)
|
||||
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
|
||||
func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
return migrateAppVersion(ctx, m.keeper)
|
||||
}
|
||||
|
||||
func migrateAppVersion(ctx sdk.Context, keeper *Keeper) error {
|
||||
func migrateAppVersion(ctx context.Context, keeper *Keeper) error {
|
||||
if keeper.versionModifier == nil {
|
||||
return fmt.Errorf("version modifier is not set")
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
@ -30,10 +31,11 @@ const ConsensusVersion uint64 = 3
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasPreBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
// AppModuleBasic implements the sdk.AppModuleBasic interface
|
||||
@ -84,19 +86,24 @@ func NewAppModule(keeper *keeper.Keeper, ac address.Codec) AppModule {
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(registrar, am.keeper)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
m := keeper.NewMigrator(am.keeper)
|
||||
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err)
|
||||
}
|
||||
err = cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
|
||||
if err := mr.Register(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 2 to 3: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGenesis is ignored, no sense in serializing future upgrades
|
||||
|
||||
Loading…
Reference in New Issue
Block a user