Implement IsConsensusGuardian

This commit is contained in:
Csongor Kiss 2022-03-14 15:44:59 +00:00 committed by Conor Patrick
parent cb38675560
commit 63d6cfe5d8
4 changed files with 17 additions and 6 deletions

View File

@ -139,7 +139,11 @@ func InitGenesis(
} }
var update abci.ValidatorUpdate 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() update = validator.ABCIValidatorUpdate()
} else { } else {
update = validator.ABCIValidatorUpdateZero() update = validator.ABCIValidatorUpdateZero()

View File

@ -58,8 +58,8 @@ func NewKeeper(
} }
} }
func (k Keeper) IsGuardian(ctx sdk.Context, addr sdk.ValAddress) bool { func (k Keeper) IsConsensusGuardian(ctx sdk.Context, addr sdk.ValAddress) (bool, error) {
return k.wormholeKeeper.IsGuardian(ctx, addr) return k.wormholeKeeper.IsConsensusGuardian(ctx, addr)
} }
// Logger returns a module-specific logger. // Logger returns a module-specific logger.

View File

@ -114,6 +114,8 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt() amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt()
// TODO(csongor): add new guardians that were not here before (from gov) // 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. // Retrieve the last validator set.
// The persistent set is updated later in this function. // 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 // 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 !k.IsGuardian(ctx, valAddr) { isGuardian := false
isGuardian, err = k.IsConsensusGuardian(ctx, valAddr)
if err != nil {
return nil, err
}
if !isGuardian {
continue continue
} }
@ -198,7 +205,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
return return
} }
amtFromBondedToNotBonded = amtFromBondedToNotBonded.Add(validator.GetTokens()) 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 updates = append(updates, validator.ABCIValidatorUpdateZero()) // remove from tendermint validators
} }

View File

@ -24,7 +24,7 @@ type AccountKeeper interface {
} }
type WormholeKeeper 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. // BankKeeper defines the expected interface needed to retrieve account balances.