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
|
// 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()
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue