From 024eaf6ac041c46a144b52756c58a54ab0b989cf Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Sat, 2 Jun 2018 00:27:37 +0200 Subject: [PATCH] Swap x/slashing to sdk.ValidatorSet --- x/slashing/handler.go | 4 ++-- x/slashing/keeper.go | 23 +++++++++++------------ x/slashing/tick.go | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index 98e9d30ad..5994bb8f1 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -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()) diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index a37c5a07b..d558cc04b 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -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 } diff --git a/x/slashing/tick.go b/x/slashing/tick.go index c77e96887..d7bb79e27 100644 --- a/x/slashing/tick.go +++ b/x/slashing/tick.go @@ -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 {