Make staking keeper know about wormhole keeper

This commit is contained in:
Csongor Kiss 2022-03-05 20:02:40 +00:00 committed by Conor Patrick
parent e980b6880c
commit cb38675560
6 changed files with 33 additions and 27 deletions

View File

@ -20,7 +20,7 @@ import (
// Returns final validator set after applying all declaration and delegations // Returns final validator set after applying all declaration and delegations
func InitGenesis( func InitGenesis(
ctx sdk.Context, keeper keeper.Keeper, accountKeeper types.AccountKeeper, ctx sdk.Context, keeper keeper.Keeper, accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper, data *types.GenesisState, bankKeeper types.BankKeeper, wormholeKeeper types.WormholeKeeper, data *types.GenesisState,
) (res []abci.ValidatorUpdate) { ) (res []abci.ValidatorUpdate) {
bondedTokens := sdk.ZeroInt() bondedTokens := sdk.ZeroInt()
notBondedTokens := sdk.ZeroInt() notBondedTokens := sdk.ZeroInt()
@ -139,7 +139,7 @@ func InitGenesis(
} }
var update abci.ValidatorUpdate var update abci.ValidatorUpdate
if validator.IsGuardian() { if wormholeKeeper.IsGuardian(ctx, valAddr) {
update = validator.ABCIValidatorUpdate() update = validator.ABCIValidatorUpdate()
} else { } else {
update = validator.ABCIValidatorUpdateZero() update = validator.ABCIValidatorUpdateZero()

View File

@ -19,17 +19,18 @@ var _ types.DelegationSet = Keeper{}
// keeper of the staking store // keeper of the staking store
type Keeper struct { type Keeper struct {
storeKey sdk.StoreKey storeKey sdk.StoreKey
cdc codec.BinaryCodec cdc codec.BinaryCodec
authKeeper types.AccountKeeper authKeeper types.AccountKeeper
bankKeeper types.BankKeeper bankKeeper types.BankKeeper
hooks types.StakingHooks wormholeKeeper types.WormholeKeeper
paramstore paramtypes.Subspace hooks types.StakingHooks
paramstore paramtypes.Subspace
} }
// NewKeeper creates a new staking Keeper instance // NewKeeper creates a new staking Keeper instance
func NewKeeper( func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, cdc codec.BinaryCodec, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, wk types.WormholeKeeper,
ps paramtypes.Subspace, ps paramtypes.Subspace,
) Keeper { ) Keeper {
// set KeyTable if it has not already been set // set KeyTable if it has not already been set
@ -47,15 +48,20 @@ func NewKeeper(
} }
return Keeper{ return Keeper{
storeKey: key, storeKey: key,
cdc: cdc, cdc: cdc,
authKeeper: ak, authKeeper: ak,
bankKeeper: bk, bankKeeper: bk,
paramstore: ps, wormholeKeeper: wk,
hooks: nil, paramstore: ps,
hooks: nil,
} }
} }
func (k Keeper) IsGuardian(ctx sdk.Context, addr sdk.ValAddress) bool {
return k.wormholeKeeper.IsGuardian(ctx, addr)
}
// Logger returns a module-specific logger. // Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger { func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName) return ctx.Logger().With("module", "x/"+types.ModuleName)

View File

@ -139,7 +139,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
// if we get to a validator that's not a guardian (after a guardian set // if we get to a validator that's not a guardian (after a guardian set
// update), we kick it out // update), we kick it out
if !validator.IsGuardian() { if !k.IsGuardian(ctx, valAddr) {
continue continue
} }

View File

@ -93,18 +93,20 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct { type AppModule struct {
AppModuleBasic AppModuleBasic
keeper keeper.Keeper keeper keeper.Keeper
accountKeeper types.AccountKeeper accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper bankKeeper types.BankKeeper
wormholeKeeper types.WormholeKeeper
} }
// NewAppModule creates a new AppModule object // NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, wk types.WormholeKeeper) AppModule {
return AppModule{ return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc}, AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper, keeper: keeper,
accountKeeper: ak, accountKeeper: ak,
bankKeeper: bk, bankKeeper: bk,
wormholeKeeper: wk,
} }
} }
@ -150,7 +152,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
cdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, &genesisState) return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, am.wormholeKeeper, &genesisState)
} }
// ExportGenesis returns the exported genesis state as raw bytes for the staking // ExportGenesis returns the exported genesis state as raw bytes for the staking

View File

@ -23,6 +23,10 @@ type AccountKeeper interface {
SetModuleAccount(sdk.Context, authtypes.ModuleAccountI) SetModuleAccount(sdk.Context, authtypes.ModuleAccountI)
} }
type WormholeKeeper interface {
IsGuardian(ctx sdk.Context, addr sdk.ValAddress) bool
}
// BankKeeper defines the expected interface needed to retrieve account balances. // BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface { type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

View File

@ -167,12 +167,6 @@ func (v Validator) IsBonded() bool {
return v.GetStatus() == Bonded return v.GetStatus() == Bonded
} }
func (*Validator) IsGuardian() bool {
// TODO(csongor): write logic to work out if this is a guardian
// This will require the staking module to use the wormhole module's state keeper
return true
}
// IsUnbonded checks if the validator status equals Unbonded // IsUnbonded checks if the validator status equals Unbonded
func (v Validator) IsUnbonded() bool { func (v Validator) IsUnbonded() bool {
return v.GetStatus() == Unbonded return v.GetStatus() == Unbonded