Skip to content

Commit

Permalink
Merge pull request cosmos#1116 from cosmos/cwgoes/slashing-staking-se…
Browse files Browse the repository at this point in the history
…paration

Swap x/slashing to sdk.ValidatorSet
rigelrozanski authored Jun 1, 2018
2 parents 8240e9b + 024eaf6 commit af1ab47
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions x/slashing/handler.go
Original file line number Diff line number Diff line change
@@ -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())

23 changes: 11 additions & 12 deletions x/slashing/keeper.go
Original file line number Diff line number Diff line change
@@ -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
}

2 changes: 1 addition & 1 deletion x/slashing/tick.go
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit af1ab47

Please sign in to comment.