Swap x/slashing to sdk.ValidatorSet

This commit is contained in:
Christopher Goes 2018-06-02 00:27:37 +02:00
parent 8240e9bc00
commit 024eaf6ac0
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
3 changed files with 14 additions and 15 deletions

View File

@ -21,7 +21,7 @@ func NewHandler(k Keeper) sdk.Handler {
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
// Validator must exist
validator := k.stakeKeeper.Validator(ctx, msg.ValidatorAddr)
validator := k.validatorSet.Validator(ctx, msg.ValidatorAddr)
if validator == nil {
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)
// 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())

View File

@ -5,27 +5,26 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/stake"
crypto "github.com/tendermint/go-crypto"
)
// Keeper of the slashing store
type Keeper struct {
storeKey sdk.StoreKey
cdc *wire.Codec
stakeKeeper stake.Keeper
storeKey sdk.StoreKey
cdc *wire.Codec
validatorSet sdk.ValidatorSet
// codespace
codespace sdk.CodespaceType
}
// 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{
storeKey: key,
cdc: cdc,
stakeKeeper: sk,
codespace: codespace,
storeKey: key,
cdc: cdc,
validatorSet: vs,
codespace: codespace,
}
return keeper
}
@ -43,7 +42,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, height int64, timestamp int64,
// 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))
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
@ -81,8 +80,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey,
if height > minHeight && signInfo.SignedBlocksCounter < MinSignedPerWindow {
// 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))
k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDowntime)
k.stakeKeeper.Revoke(ctx, pubkey)
k.validatorSet.Slash(ctx, pubkey, height, SlashFractionDowntime)
k.validatorSet.Revoke(ctx, pubkey)
signInfo.JailedUntil = ctx.BlockHeader().Time + DowntimeUnbondDuration
}

View File

@ -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
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()
present := true
if _, ok := absent[pubkey]; ok {