From 366d8f932356f63e72888764c8fcd33d9889b4eb Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 25 May 2018 00:12:40 +0200 Subject: [PATCH] Slash() and ForceUnbond() are functions of ValidatorSet, not Validator --- types/stake.go | 15 +++++++-------- x/slashing/keeper.go | 14 +++----------- x/stake/keeper.go | 8 ++++++++ x/stake/validator.go | 6 ------ 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/types/stake.go b/types/stake.go index 6e3d02c3d..fed241d01 100644 --- a/types/stake.go +++ b/types/stake.go @@ -17,14 +17,11 @@ const ( // validator for a delegated proof of stake system type Validator interface { - GetStatus() BondStatus // status of the validator - GetOwner() Address // owner address to receive/return validators coins - GetPubKey() crypto.PubKey // validation pubkey - GetPower() Rat // validation power - GetBondHeight() int64 // height in which the validator became active - Slash(Context, int64, Rat) // slash the validator and delegators of the validator - // for an offense at a specified height by a specified fraction - ForceUnbond(Context, int64) // force unbond the validator, including a duration which must pass before they can rebond + GetStatus() BondStatus // status of the validator + GetOwner() Address // owner address to receive/return validators coins + GetPubKey() crypto.PubKey // validation pubkey + GetPower() Rat // validation power + GetBondHeight() int64 // height in which the validator became active } // validator which fulfills abci validator interface for use in Tendermint @@ -48,6 +45,8 @@ type ValidatorSet interface { Validator(Context, Address) Validator // get a particular validator by owner address ValidatorByPubKey(Context, crypto.PubKey) Validator // get a particular validator by public key TotalPower(Context) Rat // total power of the validator set + Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction + ForceUnbond(Context, crypto.PubKey, int64) // force unbond the validator, including a duration which must pass before they can rebond } //_______________________________________________________________________________ diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 686f84b65..17cf349ad 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -71,11 +71,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, height int64, timestamp int64, return } logger.Info(fmt.Sprintf("Confirmed double sign from %v at height %d, age of %d less than max age of %d", pubkey.Address(), height, age, MaxEvidenceAge)) - validator := k.stakeKeeper.ValidatorByPubKey(ctx, pubkey) - if validator == nil { - panic(fmt.Errorf("Attempted to slash nonexistent validator with address %s", pubkey.Address())) - } - validator.Slash(ctx, height, SlashFractionDoubleSign) + k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDoubleSign) logger.Info(fmt.Sprintf("Slashed validator %s by fraction %v for double-sign at height %d", pubkey.Address(), SlashFractionDoubleSign, height)) } @@ -101,12 +97,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey, } minHeight := signInfo.StartHeight + SignedBlocksWindow if height > minHeight && signInfo.SignedBlocksCounter < MinSignedPerWindow { - validator := k.stakeKeeper.ValidatorByPubKey(ctx, pubkey) - if validator == nil { - panic(fmt.Errorf("Attempted to slash nonexistent validator with address %s", pubkey.Address())) - } - validator.Slash(ctx, height, SlashFractionDowntime) - validator.ForceUnbond(ctx, DowntimeUnbondDuration) + k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDowntime) + k.stakeKeeper.ForceUnbond(ctx, pubkey, DowntimeUnbondDuration) logger.Info(fmt.Sprintf("Slashed validator %s by fraction %v and unbonded for downtime at height %d, cannot rebond for %ds", address, SlashFractionDowntime, height, DowntimeUnbondDuration)) } diff --git a/x/stake/keeper.go b/x/stake/keeper.go index 83c5b0a0e..46790e849 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -776,3 +776,11 @@ func (k Keeper) IterateDelegators(ctx sdk.Context, delAddr sdk.Address, fn func( } iterator.Close() } + +// slash a validator +func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fraction sdk.Rat) { +} + +// force unbond a validator +func (k Keeper) ForceUnbond(ctx sdk.Context, pubkey crypto.PubKey, jailDuration int64) { +} diff --git a/x/stake/validator.go b/x/stake/validator.go index 7848724fd..88f061f31 100644 --- a/x/stake/validator.go +++ b/x/stake/validator.go @@ -236,9 +236,3 @@ func (v Validator) GetOwner() sdk.Address { return v.Owner } func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey } func (v Validator) GetPower() sdk.Rat { return v.PoolShares.Bonded() } func (v Validator) GetBondHeight() int64 { return v.BondHeight } -func (v Validator) Slash(ctx sdk.Context, height int64, fraction sdk.Rat) { - panic("not implemented") -} -func (v Validator) ForceUnbond(ctx sdk.Context, jailDuration int64) { - panic("not implemented") -}