Slash() and ForceUnbond() are functions of ValidatorSet, not Validator
This commit is contained in:
parent
66b4461543
commit
366d8f9323
|
@ -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
|
||||
}
|
||||
|
||||
//_______________________________________________________________________________
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue