Make staking keeper know about wormhole keeper
This commit is contained in:
parent
e980b6880c
commit
cb38675560
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue