Merge pull request #1116 from cosmos/cwgoes/slashing-staking-separation
Swap x/slashing to sdk.ValidatorSet
This commit is contained in:
commit
af1ab47b20
|
@ -21,7 +21,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
||||||
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
|
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
|
||||||
|
|
||||||
// Validator must exist
|
// Validator must exist
|
||||||
validator := k.stakeKeeper.Validator(ctx, msg.ValidatorAddr)
|
validator := k.validatorSet.Validator(ctx, msg.ValidatorAddr)
|
||||||
if validator == nil {
|
if validator == nil {
|
||||||
return ErrNoValidatorForAddress(k.codespace).Result()
|
return ErrNoValidatorForAddress(k.codespace).Result()
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
|
||||||
k.setValidatorSigningInfo(ctx, addr, info)
|
k.setValidatorSigningInfo(ctx, addr, info)
|
||||||
|
|
||||||
// Unrevoke the validator
|
// Unrevoke the validator
|
||||||
k.stakeKeeper.Unrevoke(ctx, validator.GetPubKey())
|
k.validatorSet.Unrevoke(ctx, validator.GetPubKey())
|
||||||
|
|
||||||
tags := sdk.NewTags("action", []byte("unrevoke"), "validator", msg.ValidatorAddr.Bytes())
|
tags := sdk.NewTags("action", []byte("unrevoke"), "validator", msg.ValidatorAddr.Bytes())
|
||||||
|
|
||||||
|
|
|
@ -5,27 +5,26 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/wire"
|
"github.com/cosmos/cosmos-sdk/wire"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Keeper of the slashing store
|
// Keeper of the slashing store
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
cdc *wire.Codec
|
cdc *wire.Codec
|
||||||
stakeKeeper stake.Keeper
|
validatorSet sdk.ValidatorSet
|
||||||
|
|
||||||
// codespace
|
// codespace
|
||||||
codespace sdk.CodespaceType
|
codespace sdk.CodespaceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper creates a slashing keeper
|
// NewKeeper creates a slashing keeper
|
||||||
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, sk stake.Keeper, codespace sdk.CodespaceType) Keeper {
|
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, codespace sdk.CodespaceType) Keeper {
|
||||||
keeper := Keeper{
|
keeper := Keeper{
|
||||||
storeKey: key,
|
storeKey: key,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
stakeKeeper: sk,
|
validatorSet: vs,
|
||||||
codespace: codespace,
|
codespace: codespace,
|
||||||
}
|
}
|
||||||
return keeper
|
return keeper
|
||||||
}
|
}
|
||||||
|
@ -43,7 +42,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, height int64, timestamp int64,
|
||||||
|
|
||||||
// Double sign confirmed
|
// Double sign confirmed
|
||||||
logger.Info(fmt.Sprintf("Confirmed double sign from %s at height %d, age of %d less than max age of %d", pubkey.Address(), height, age, MaxEvidenceAge))
|
logger.Info(fmt.Sprintf("Confirmed double sign from %s at height %d, age of %d less than max age of %d", pubkey.Address(), height, age, MaxEvidenceAge))
|
||||||
k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDoubleSign)
|
k.validatorSet.Slash(ctx, pubkey, height, SlashFractionDoubleSign)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle a validator signature, must be called once per validator per block
|
// handle a validator signature, must be called once per validator per block
|
||||||
|
@ -81,8 +80,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey,
|
||||||
if height > minHeight && signInfo.SignedBlocksCounter < MinSignedPerWindow {
|
if height > minHeight && signInfo.SignedBlocksCounter < MinSignedPerWindow {
|
||||||
// Downtime confirmed, slash, revoke, and jail the validator
|
// Downtime confirmed, slash, revoke, and jail the validator
|
||||||
logger.Info(fmt.Sprintf("Validator %s past min height of %d and below signed blocks threshold of %d", pubkey.Address(), minHeight, MinSignedPerWindow))
|
logger.Info(fmt.Sprintf("Validator %s past min height of %d and below signed blocks threshold of %d", pubkey.Address(), minHeight, MinSignedPerWindow))
|
||||||
k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDowntime)
|
k.validatorSet.Slash(ctx, pubkey, height, SlashFractionDowntime)
|
||||||
k.stakeKeeper.Revoke(ctx, pubkey)
|
k.validatorSet.Revoke(ctx, pubkey)
|
||||||
signInfo.JailedUntil = ctx.BlockHeader().Time + DowntimeUnbondDuration
|
signInfo.JailedUntil = ctx.BlockHeader().Time + DowntimeUnbondDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over all the validators which *should* have signed this block
|
// Iterate over all the validators which *should* have signed this block
|
||||||
sk.stakeKeeper.IterateValidatorsBonded(ctx, func(_ int64, validator sdk.Validator) (stop bool) {
|
sk.validatorSet.IterateValidatorsBonded(ctx, func(_ int64, validator sdk.Validator) (stop bool) {
|
||||||
pubkey := validator.GetPubKey()
|
pubkey := validator.GetPubKey()
|
||||||
present := true
|
present := true
|
||||||
if _, ok := absent[pubkey]; ok {
|
if _, ok := absent[pubkey]; ok {
|
||||||
|
|
Loading…
Reference in New Issue