Skip to content

Commit

Permalink
Rename revoke/unrevoke to jail/unjail
Browse files Browse the repository at this point in the history
Closes: #1305
  • Loading branch information
alessio committed Aug 22, 2018
1 parent 29634bf commit e5da7f4
Show file tree
Hide file tree
Showing 29 changed files with 132 additions and 132 deletions.
2 changes: 1 addition & 1 deletion cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.TestAndRunTx {
stakesim.SimulateMsgCompleteUnbonding(app.stakeKeeper),
stakesim.SimulateMsgBeginRedelegate(app.accountMapper, app.stakeKeeper),
stakesim.SimulateMsgCompleteRedelegate(app.stakeKeeper),
slashingsim.SimulateMsgUnrevoke(app.slashingKeeper),
slashingsim.SimulateMsgUnjail(app.slashingKeeper),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond("stake", cdc),
stakecmd.GetCmdRedelegate("stake", cdc),
slashingcmd.GetCmdUnrevoke(cdc),
slashingcmd.GetCmdUnjail(cdc),
)...)
rootCmd.AddCommand(
stakeCmd,
Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/cmd/basecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond("stake", cdc),
stakecmd.GetCmdRedelegate("stake", cdc),
slashingcmd.GetCmdUnrevoke(cdc),
slashingcmd.GetCmdUnjail(cdc),
)...)

// add proxy, version and key info
Expand Down
6 changes: 3 additions & 3 deletions examples/democoin/mock/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (v Validator) GetDelegatorShares() sdk.Dec {
}

// Implements sdk.Validator
func (v Validator) GetRevoked() bool {
func (v Validator) GetJailed() bool {
return false
}

Expand Down Expand Up @@ -127,11 +127,11 @@ func (vs *ValidatorSet) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int6
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Revoke(ctx sdk.Context, pubkey crypto.PubKey) {
func (vs *ValidatorSet) Jail(ctx sdk.Context, pubkey crypto.PubKey) {
panic("not implemented")
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Unrevoke(ctx sdk.Context, pubkey crypto.PubKey) {
func (vs *ValidatorSet) Unjail(ctx sdk.Context, pubkey crypto.PubKey) {
panic("not implemented")
}
6 changes: 3 additions & 3 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (b BondStatus) Equal(b2 BondStatus) bool {

// validator for a delegated proof of stake system
type Validator interface {
GetRevoked() bool // whether the validator is revoked
GetJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOperator() AccAddress // owner AccAddress to receive/return validators coins
Expand Down Expand Up @@ -73,8 +73,8 @@ type ValidatorSet interface {

// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(Context, crypto.PubKey, int64, int64, Dec)
Revoke(Context, crypto.PubKey) // revoke a validator
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
Jail(Context, crypto.PubKey) // jail a validator
Unjail(Context, crypto.PubKey) // unjail a validator
}

//_______________________________________________________________________________
Expand Down
4 changes: 2 additions & 2 deletions x/gov/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
require.False(t, tallyResults.Equals(EmptyTallyResult()))
}

func TestTallyRevokedValidator(t *testing.T) {
func TestTallyUnjailedValidator(t *testing.T) {
mapp, keeper, sk, addrs, _, _ := getMockApp(t, 10)
mapp.BeginBlock(abci.RequestBeginBlock{})
ctx := mapp.BaseApp.NewContext(false, abci.Header{})
Expand All @@ -368,7 +368,7 @@ func TestTallyRevokedValidator(t *testing.T) {

val2, found := sk.GetValidator(ctx, addrs[1])
require.True(t, found)
sk.Revoke(ctx, val2.PubKey)
sk.Unjail(ctx, val2.PubKey)

proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
proposalID := proposal.GetProposalID()
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func TestSlashingMsgs(t *testing.T) {
require.Equal(t, addr1, validator.Operator)
require.Equal(t, sdk.Bonded, validator.Status)
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
unrevokeMsg := MsgUnrevoke{ValidatorAddr: sdk.AccAddress(validator.PubKey.Address())}
unrevokeMsg := MsgUnjail{ValidatorAddr: sdk.AccAddress(validator.PubKey.Address())}

// no signing info yet
checkValidatorSigningInfo(t, mapp, keeper, sdk.ValAddress(addr1), false)

// unrevoke should fail with unknown validator
res := mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{unrevokeMsg}, []int64{0}, []int64{1}, false, priv1)
require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotRevoked), res.Code)
require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotJailed), res.Code)
}
10 changes: 5 additions & 5 deletions x/slashing/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/spf13/cobra"
)

// GetCmdUnrevoke implements the create unrevoke validator command.
func GetCmdUnrevoke(cdc *wire.Codec) *cobra.Command {
// GetCmdUnjail implements the create unjail validator command.
func GetCmdUnjail(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "unrevoke",
Use: "unjail",
Args: cobra.ExactArgs(0),
Short: "unrevoke validator previously revoked for downtime",
Short: "unjail validator previously jailed for downtime",
RunE: func(cmd *cobra.Command, args []string) error {
txCtx := authctx.NewTxContextFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
Expand All @@ -32,7 +32,7 @@ func GetCmdUnrevoke(cdc *wire.Codec) *cobra.Command {
return err
}

msg := slashing.NewMsgUnrevoke(validatorAddr)
msg := slashing.NewMsgUnjail(validatorAddr)

return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
},
Expand Down
14 changes: 7 additions & 7 deletions x/slashing/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (

func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc(
"/slashing/unrevoke",
unrevokeRequestHandlerFn(cdc, kb, cliCtx),
"/slashing/unjail",
unjailRequestHandlerFn(cdc, kb, cliCtx),
).Methods("POST")
}

// Unrevoke TX body
type UnrevokeBody struct {
// Unjail TX body
type UnjailBody struct {
LocalAccountName string `json:"name"`
Password string `json:"password"`
ChainID string `json:"chain_id"`
Expand All @@ -35,9 +35,9 @@ type UnrevokeBody struct {
ValidatorAddr string `json:"validator_addr"`
}

func unrevokeRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var m UnrevokeBody
var m UnjailBody
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -79,7 +79,7 @@ func unrevokeRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.C
Gas: m.Gas,
}

msg := slashing.NewMsgUnrevoke(validatorAddr)
msg := slashing.NewMsgUnjail(validatorAddr)

txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions x/slashing/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const (
// Default slashing codespace
DefaultCodespace sdk.CodespaceType = 10

CodeInvalidValidator CodeType = 101
CodeValidatorJailed CodeType = 102
CodeValidatorNotRevoked CodeType = 103
CodeInvalidValidator CodeType = 101
CodeValidatorJailed CodeType = 102
CodeValidatorNotJailed CodeType = 103
)

func ErrNoValidatorForAddress(codespace sdk.CodespaceType) sdk.Error {
Expand All @@ -24,8 +24,8 @@ func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidValidator, "validator does not exist for that address")
}
func ErrValidatorJailed(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeValidatorJailed, "validator jailed, cannot yet be unrevoked")
return sdk.NewError(codespace, CodeValidatorJailed, "validator jailed, cannot yet be unjailed")
}
func ErrValidatorNotRevoked(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeValidatorNotRevoked, "validator not revoked, cannot be unrevoked")
func ErrValidatorNotJailed(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeValidatorNotJailed, "validator not jailed, cannot be unjailed")
}
22 changes: 11 additions & 11 deletions x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ 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)
case MsgUnjail:
return handleMsgUnjail(ctx, msg, k)
default:
return sdk.ErrTxDecode("invalid message parse in staking module").Result()
}
}
}

// Validators must submit a transaction to unrevoke itself after
// having been revoked (and thus unbonded) for downtime
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
// Validators must submit a transaction to unjail itself after
// having been unjailed (and thus unbonded) for downtime
func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {

// Validator must exist
validator := k.validatorSet.Validator(ctx, msg.ValidatorAddr)
if validator == nil {
return ErrNoValidatorForAddress(k.codespace).Result()
}

if !validator.GetRevoked() {
return ErrValidatorNotRevoked(k.codespace).Result()
if !validator.GetJailed() {
return ErrValidatorNotJailed(k.codespace).Result()
}

addr := sdk.ValAddress(validator.GetPubKey().Address())
Expand All @@ -38,17 +38,17 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
return ErrNoValidatorForAddress(k.codespace).Result()
}

// Cannot be unrevoked until out of jail
// Cannot be unjailed until out of jail
if ctx.BlockHeader().Time.Before(info.JailedUntil) {
return ErrValidatorJailed(k.codespace).Result()
}

// Update the starting height (so the validator can't be immediately revoked again)
// Update the starting height (so the validator can't be immediately unjailed again)
info.StartHeight = ctx.BlockHeight()
k.setValidatorSigningInfo(ctx, addr, info)

// Unrevoke the validator
k.validatorSet.Unrevoke(ctx, validator.GetPubKey())
// Unjail the validator
k.validatorSet.Unjail(ctx, validator.GetPubKey())

tags := sdk.NewTags("action", []byte("unrevoke"), "validator", []byte(msg.ValidatorAddr.String()))

Expand Down
8 changes: 4 additions & 4 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestCannotUnrevokeUnlessRevoked(t *testing.T) {
require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins.Sub(amt)}})
require.True(t, sdk.NewDecFromInt(amt).Equal(sk.Validator(ctx, addr).GetPower()))

// assert non-revoked validator can't be unrevoked
got = slh(ctx, NewMsgUnrevoke(addr))
require.False(t, got.IsOK(), "allowed unrevoke of non-revoked validator")
require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotRevoked), got.Code)
// assert non-jailed validator can't be unjailed
got = slh(ctx, NewMsgUnjail(addr))
require.False(t, got.IsOK(), "allowed unrevoke of non-jailed validator")
require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotJailed), got.Code)
}
14 changes: 7 additions & 7 deletions x/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
// Slash validator
k.validatorSet.Slash(ctx, pubkey, infractionHeight, power, k.SlashFractionDoubleSign(ctx))

// Revoke validator
k.validatorSet.Revoke(ctx, pubkey)
// Jail validator
k.validatorSet.Jail(ctx, pubkey)

// Jail validator
signInfo, found := k.getValidatorSigningInfo(ctx, address)
Expand Down Expand Up @@ -113,16 +113,16 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
minHeight := signInfo.StartHeight + k.SignedBlocksWindow(ctx)
if height > minHeight && signInfo.SignedBlocksCounter < k.MinSignedPerWindow(ctx) {
validator := k.validatorSet.ValidatorByPubKey(ctx, pubkey)
if validator != nil && !validator.GetRevoked() {
// Downtime confirmed, slash, revoke, and jail the validator
if validator != nil && !validator.GetJailed() {
// Downtime confirmed, slash, jail, 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, k.MinSignedPerWindow(ctx)))
k.validatorSet.Slash(ctx, pubkey, height, power, k.SlashFractionDowntime(ctx))
k.validatorSet.Revoke(ctx, pubkey)
k.validatorSet.Jail(ctx, pubkey)
signInfo.JailedUntil = ctx.BlockHeader().Time.Add(k.DowntimeUnbondDuration(ctx))
} else {
// Validator was (a) not found or (b) already revoked, don't slash
logger.Info(fmt.Sprintf("Validator %s would have been slashed for downtime, but was either not found in store or already revoked",
// Validator was (a) not found or (b) already jailed, don't slash
logger.Info(fmt.Sprintf("Validator %s would have been slashed for downtime, but was either not found in store or already jailed",
pubkey.Address()))
}
}
Expand Down
30 changes: 15 additions & 15 deletions x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestHandleDoubleSign(t *testing.T) {
// double sign less than max age
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt)

// should be revoked
require.True(t, sk.Validator(ctx, addr).GetRevoked())
// unrevoke to measure power
sk.Unrevoke(ctx, val)
// should be jailed
require.True(t, sk.Validator(ctx, addr).GetJailed())
// unjail to measure power
sk.Unjail(ctx, val)
// power should be reduced
require.Equal(t, sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20))), sk.Validator(ctx, addr).GetPower())
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(1, 0).Add(keeper.MaxEvidenceAge(ctx))})
Expand Down Expand Up @@ -112,17 +112,17 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, int64(0), info.StartHeight)
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx)-1, info.SignedBlocksCounter)

// validator should have been revoked
// validator should have been jailed
validator, _ = sk.GetValidatorByPubKey(ctx, val)
require.Equal(t, sdk.Unbonded, validator.GetStatus())

// unrevocation should fail prior to jail expiration
got = slh(ctx, NewMsgUnrevoke(addr))
// unjail should fail prior to jail expiration
got = slh(ctx, NewMsgUnjail(addr))
require.False(t, got.IsOK())

// unrevocation should succeed after jail expiration
// unjail should succeed after jail expiration
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(1, 0).Add(keeper.DowntimeUnbondDuration(ctx))})
got = slh(ctx, NewMsgUnrevoke(addr))
got = slh(ctx, NewMsgUnjail(addr))
require.True(t, got.IsOK())

// validator should be rebonded now
Expand All @@ -140,7 +140,7 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, height, info.StartHeight)
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx)-1, info.SignedBlocksCounter)

// validator should not be immediately revoked again
// validator should not be immediately jailed again
height++
ctx = ctx.WithBlockHeight(height)
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
Expand All @@ -154,7 +154,7 @@ func TestHandleAbsentValidator(t *testing.T) {
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
}

// validator should be revoked again after 500 unsigned blocks
// validator should be jailed again after 500 unsigned blocks
nextHeight = height + keeper.MinSignedPerWindow(ctx) + 1
for ; height <= nextHeight; height++ {
ctx = ctx.WithBlockHeight(height)
Expand All @@ -166,7 +166,7 @@ func TestHandleAbsentValidator(t *testing.T) {

// Test a new validator entering the validator set
// Ensure that SigningInfo.StartHeight is set correctly
// and that they are not immediately revoked
// and that they are not immediately jailed
func TestHandleNewValidator(t *testing.T) {
// initial setup
ctx, ck, sk, _, keeper := createTestInput(t)
Expand Down Expand Up @@ -194,14 +194,14 @@ func TestHandleNewValidator(t *testing.T) {
require.Equal(t, int64(1), info.SignedBlocksCounter)
require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)

// validator should be bonded still, should not have been revoked or slashed
// validator should be bonded still, should not have been jailed or slashed
validator, _ := sk.GetValidatorByPubKey(ctx, val)
require.Equal(t, sdk.Bonded, validator.GetStatus())
pool := sk.GetPool(ctx)
require.Equal(t, int64(100), pool.BondedTokens.RoundInt64())
}

// Test a revoked validator being "down" twice
// Test a jailed validator being "down" twice
// Ensure that they're only slashed once
func TestHandleAlreadyRevoked(t *testing.T) {

Expand All @@ -228,7 +228,7 @@ func TestHandleAlreadyRevoked(t *testing.T) {
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
}

// validator should have been revoked and slashed
// validator should have been jailed and slashed
validator, _ := sk.GetValidatorByPubKey(ctx, val)
require.Equal(t, sdk.Unbonded, validator.GetStatus())

Expand Down
Loading

0 comments on commit e5da7f4

Please sign in to comment.