diff --git a/x/staking/genesis.go b/x/staking/genesis.go index e298bec7a..b97c3c829 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -20,7 +20,7 @@ import ( // Returns final validator set after applying all declaration and delegations func InitGenesis( 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) { bondedTokens := sdk.ZeroInt() notBondedTokens := sdk.ZeroInt() @@ -139,7 +139,7 @@ func InitGenesis( } var update abci.ValidatorUpdate - if validator.IsGuardian() { + if wormholeKeeper.IsGuardian(ctx, valAddr) { update = validator.ABCIValidatorUpdate() } else { update = validator.ABCIValidatorUpdateZero() diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 6211dcf6a..f19bef09f 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -19,17 +19,18 @@ var _ types.DelegationSet = Keeper{} // keeper of the staking store type Keeper struct { - storeKey sdk.StoreKey - cdc codec.BinaryCodec - authKeeper types.AccountKeeper - bankKeeper types.BankKeeper - hooks types.StakingHooks - paramstore paramtypes.Subspace + storeKey sdk.StoreKey + cdc codec.BinaryCodec + authKeeper types.AccountKeeper + bankKeeper types.BankKeeper + wormholeKeeper types.WormholeKeeper + hooks types.StakingHooks + paramstore paramtypes.Subspace } // NewKeeper creates a new staking Keeper instance 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, ) Keeper { // set KeyTable if it has not already been set @@ -47,15 +48,20 @@ func NewKeeper( } return Keeper{ - storeKey: key, - cdc: cdc, - authKeeper: ak, - bankKeeper: bk, - paramstore: ps, - hooks: nil, + storeKey: key, + cdc: cdc, + authKeeper: ak, + bankKeeper: bk, + wormholeKeeper: wk, + 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. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+types.ModuleName) diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 9144f3d68..43c927e60 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -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 // update), we kick it out - if !validator.IsGuardian() { + if !k.IsGuardian(ctx, valAddr) { continue } diff --git a/x/staking/module.go b/x/staking/module.go index 3892a8aa9..93aba5c5f 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -93,18 +93,20 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + wormholeKeeper types.WormholeKeeper } // 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{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, accountKeeper: ak, bankKeeper: bk, + wormholeKeeper: wk, } } @@ -150,7 +152,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. 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 diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 313db78e7..620f9abb9 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -23,6 +23,10 @@ type AccountKeeper interface { 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. type BankKeeper interface { GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index 7734c307d..e4dd25dc6 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -167,12 +167,6 @@ func (v Validator) IsBonded() bool { 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 func (v Validator) IsUnbonded() bool { return v.GetStatus() == Unbonded