diff --git a/x/staking/genesis.go b/x/staking/genesis.go index b97c3c829..50011cba1 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -139,7 +139,11 @@ func InitGenesis( } var update abci.ValidatorUpdate - if wormholeKeeper.IsGuardian(ctx, valAddr) { + isGuardian, err := wormholeKeeper.IsConsensusGuardian(ctx, valAddr) + if err != nil { + panic(err) + } + if isGuardian { update = validator.ABCIValidatorUpdate() } else { update = validator.ABCIValidatorUpdateZero() diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index f19bef09f..af038855a 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -58,8 +58,8 @@ func NewKeeper( } } -func (k Keeper) IsGuardian(ctx sdk.Context, addr sdk.ValAddress) bool { - return k.wormholeKeeper.IsGuardian(ctx, addr) +func (k Keeper) IsConsensusGuardian(ctx sdk.Context, addr sdk.ValAddress) (bool, error) { + return k.wormholeKeeper.IsConsensusGuardian(ctx, addr) } // Logger returns a module-specific logger. diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 43c927e60..c453b9ce1 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -114,6 +114,8 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt() // TODO(csongor): add new guardians that were not here before (from gov) + // TODO(csongor): total voting power should be size of the guardian set. + // I'll just rewrite this whole function // Retrieve the last validator set. // The persistent set is updated later in this function. @@ -139,7 +141,12 @@ 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 !k.IsGuardian(ctx, valAddr) { + isGuardian := false + isGuardian, err = k.IsConsensusGuardian(ctx, valAddr) + if err != nil { + return nil, err + } + if !isGuardian { continue } @@ -198,7 +205,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab return } amtFromBondedToNotBonded = amtFromBondedToNotBonded.Add(validator.GetTokens()) - k.DeleteLastValidatorPower(ctx, validator.GetOperator()) // remove from gov validators + k.DeleteLastValidatorPower(ctx, validator.GetOperator()) // remove from gov validators updates = append(updates, validator.ABCIValidatorUpdateZero()) // remove from tendermint validators } diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 620f9abb9..865d5685a 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -24,7 +24,7 @@ type AccountKeeper interface { } type WormholeKeeper interface { - IsGuardian(ctx sdk.Context, addr sdk.ValAddress) bool + IsConsensusGuardian(ctx sdk.Context, addr sdk.ValAddress) (bool, error) } // BankKeeper defines the expected interface needed to retrieve account balances.