Skip to content

Commit

Permalink
add slashing ConsensusVersion&Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sin3A committed Aug 14, 2024
1 parent 39af267 commit e1cc878
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/slashing/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ func ProvideModule(in SlashingInputs) SlashingOutputs {
cosmosSlashingKeeper,
in.NodeKeeper,
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.StakingKeeper)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace)
return SlashingOutputs{SlashingKeeper: keeper, Module: m}
}
17 changes: 15 additions & 2 deletions modules/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing/types"

"github.com/cosmos/cosmos-sdk/x/slashing/exported"
cosmosslashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
"iritamod.bianjie.ai/modules/slashing/client/cli"
"iritamod.bianjie.ai/modules/slashing/keeper"
slashingtypes "iritamod.bianjie.ai/modules/slashing/types"
Expand Down Expand Up @@ -96,25 +98,36 @@ type AppModule struct {
accountKeeper AccountKeeper
bankKeeper BankKeeper
stakingKeeper StakingKeeper
// legacySubspace is used solely for migration of x/slashing managed parameters
legacySubspace exported.Subspace
}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
slashingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := cosmosslashingkeeper.NewMigrator(am.keeper.Keeper, am.legacySubspace)
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 := 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))
}
}

// NewAppModule creates a new AppModule object
func NewAppModule(
cdc codec.Codec, keeper Keeper, ak AccountKeeper,
bk BankKeeper, sk StakingKeeper,
bk BankKeeper, sk StakingKeeper, legacySubspace exported.Subspace,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
stakingKeeper: sk,
legacySubspace: legacySubspace,
}
}

Expand Down Expand Up @@ -162,7 +175,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 3 }

// BeginBlock returns the begin blocker for the slashing module.
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
Expand Down

0 comments on commit e1cc878

Please sign in to comment.