2018-05-28 12:38:02 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewHandler(k Keeper) sdk.Handler {
|
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
|
|
|
// NOTE msg already has validate basic run
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case MsgUnrevoke:
|
|
|
|
return handleMsgUnrevoke(ctx, msg, k)
|
|
|
|
default:
|
|
|
|
return sdk.ErrTxDecode("invalid message parse in staking module").Result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 15:25:18 -07:00
|
|
|
// Validators must submit a transaction to unrevoke itself after
|
2018-05-28 15:10:52 -07:00
|
|
|
// having been revoked (and thus unbonded) for downtime
|
2018-05-28 12:38:02 -07:00
|
|
|
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
|
2018-05-28 15:10:52 -07:00
|
|
|
|
|
|
|
// Validator must exist
|
2018-06-01 15:27:37 -07:00
|
|
|
validator := k.validatorSet.Validator(ctx, msg.ValidatorAddr)
|
2018-05-28 12:38:02 -07:00
|
|
|
if validator == nil {
|
|
|
|
return ErrNoValidatorForAddress(k.codespace).Result()
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:55:39 -07:00
|
|
|
addr := validator.GetPubKey().Address()
|
|
|
|
|
2018-05-28 15:10:52 -07:00
|
|
|
// Signing info must exist
|
2018-05-28 14:55:39 -07:00
|
|
|
info, found := k.getValidatorSigningInfo(ctx, addr)
|
2018-05-28 13:08:13 -07:00
|
|
|
if !found {
|
|
|
|
return ErrNoValidatorForAddress(k.codespace).Result()
|
|
|
|
}
|
|
|
|
|
2018-05-28 15:10:52 -07:00
|
|
|
// Cannot be unrevoked until out of jail
|
2018-05-28 13:08:13 -07:00
|
|
|
if ctx.BlockHeader().Time < info.JailedUntil {
|
|
|
|
return ErrValidatorJailed(k.codespace).Result()
|
|
|
|
}
|
2018-05-28 12:38:02 -07:00
|
|
|
|
|
|
|
if ctx.IsCheckTx() {
|
|
|
|
return sdk.Result{}
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:55:39 -07:00
|
|
|
// Update the starting height (so the validator can't be immediately revoked again)
|
|
|
|
info.StartHeight = ctx.BlockHeight()
|
|
|
|
k.setValidatorSigningInfo(ctx, addr, info)
|
|
|
|
|
|
|
|
// Unrevoke the validator
|
2018-06-01 15:27:37 -07:00
|
|
|
k.validatorSet.Unrevoke(ctx, validator.GetPubKey())
|
2018-05-28 12:38:02 -07:00
|
|
|
|
2018-06-29 20:34:55 -07:00
|
|
|
tags := sdk.NewTags("action", []byte("unrevoke"), "validator", []byte(msg.ValidatorAddr.String()))
|
2018-05-28 14:55:39 -07:00
|
|
|
|
2018-05-28 12:38:02 -07:00
|
|
|
return sdk.Result{
|
|
|
|
Tags: tags,
|
|
|
|
}
|
|
|
|
}
|