Skip to content

Commit

Permalink
Rename revoke(d) to jail(ed)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Aug 22, 2018
1 parent 6b1792b commit 879f78c
Show file tree
Hide file tree
Showing 41 changed files with 170 additions and 170 deletions.
2 changes: 1 addition & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ BREAKING CHANGES
* [cli] \#2061 changed proposalID in governance REST endpoints to proposal-id
* [cli] \#2014 `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively


* Gaia
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
* [x/stake] \#1901 Validator type's Owner field renamed to Operator; Validator's GetOwner() renamed accordingly to comply with the SDK's Validator interface.
* [x/stake, x/slashing] [#1305](https://github.com/cosmos/cosmos-sdk/issues/1305) - Rename "revoked" to "jailed"

* SDK
* [core] \#1807 Switch from use of rational to decimal
Expand Down
2 changes: 1 addition & 1 deletion client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/gorilla/mux"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/pkg/errors"
"github.com/tendermint/tmlibs/cli"
)

Expand Down
2 changes: 1 addition & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func TestVote(t *testing.T) {
require.Equal(t, gov.OptionYes, vote.Option)
}

func TestUnrevoke(t *testing.T) {
func TestUnjail(t *testing.T) {
_, password := "test", "1234567890"
addr, _ := CreateAddr(t, "test", password, GetKeyBase(t))
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
Expand Down
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 docs/light/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te

## ICS23 - SlashingAPI

The SlashingAPI exposes all functionalities needed to slash (*i.e* penalize) validators and delegators in Proof-of-Stake. The penalization is a fine of the staking coin and jail time, defined by governance parameters. During the jail period, the penalized validator is `Revoked`.
The SlashingAPI exposes all functionalities needed to slash (*i.e* penalize) validators and delegators in Proof-of-Stake. The penalization is a fine of the staking coin and jail time, defined by governance parameters. During the jail period, the penalized validator is "jailed".

### GET /slashing/validator/{validatorAddr}/signing-info

Expand Down
2 changes: 1 addition & 1 deletion docs/spec/slashing/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ type ValidatorSigningInfo struct {
Where:
* `StartHeight` is set to the height that the candidate became an active validator (with non-zero voting power).
* `IndexOffset` is incremented each time the candidate was a bonded validator in a block (and may have signed a precommit or not).
* `JailedUntil` is set whenever the candidate is revoked due to downtime
* `JailedUntil` is set whenever the candidate is jailed due to downtime
* `SignedBlocksCounter` is a counter kept to avoid unnecessary array reads. `SignedBlocksBitArray.Sum() == SignedBlocksCounter` always.
2 changes: 1 addition & 1 deletion docs/spec/staking/end_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The Tendermint validator set may be updated by state transitions that run at
the end of every block. The Tendermint validator set may be changed by
validators either being revoked due to inactivity/unexpected behaviour (covered
validators either being jailed due to inactivity/unexpected behaviour (covered
in slashing) or changed in validator power. Determining which validator set
changes must be made occurs during staking transactions (and slashing
transactions) - during end-block the already accounted changes are applied and
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/staking/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ validator.
```golang
type Validator struct {
ConsensusPubKey crypto.PubKey // Tendermint consensus pubkey of validator
Revoked bool // has the validator been revoked?
Jailed bool // has the validator been jailed?

Status sdk.BondStatus // validator status (bonded/unbonding/unbonded)
Tokens sdk.Dec // delegated tokens (incl. self-delegation)
Expand Down
10 changes: 5 additions & 5 deletions docs/validators/validator-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ gaiacli stake signing-information <validator-pubkey>\
--chain-id=<chain_id>
```

### Unrevoke Validator
### Unjail Validator

When a validator is `Revoked` for downtime, you must submit an `Unrevoke` transaction in order to be able to get block proposer rewards again (depends on the zone fee distribution).
When a validator is "jailed" for downtime, you must submit an `Unjail` transaction in order to be able to get block proposer rewards again (depends on the zone fee distribution).

```bash
gaiacli stake unrevoke \
gaiacli stake unjail \
--from=<key_name> \
--chain-id=<chain_id>
--validator=<account_cosmosaccaddr> \
Expand Down Expand Up @@ -113,11 +113,11 @@ gaiad start
Wait for your full node to catch up to the latest block. Next, run the following command. Note that `<cosmosaccaddr>` is the address of your validator account, and `<name>` is the name of the validator account. You can find this info by running `gaiacli keys list`.

```bash
gaiacli stake unrevoke <cosmosaccaddr> --chain-id=<chain_id> --name=<name>
gaiacli stake unjail <cosmosaccaddr> --chain-id=<chain_id> --name=<name>
```

::: danger Warning
If you don't wait for `gaiad` to sync before running `unrevoke`, you will receive an error message telling you your validator is still jailed.
If you don't wait for `gaiad` to sync before running `unjail`, you will receive an error message telling you your validator is still jailed.
:::

Lastly, check your validator again to see if your voting power is back.
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
2 changes: 1 addition & 1 deletion x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
authctx "github.com/cosmos/cosmos-sdk/x/auth/client/context"
"github.com/cosmos/cosmos-sdk/x/gov"

"encoding/json"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"io/ioutil"
"encoding/json"
"strings"
)

Expand Down
4 changes: 2 additions & 2 deletions x/gov/client/cli/tx_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cli

import (
"testing"
"github.com/spf13/viper"
"io/ioutil"
"github.com/stretchr/testify/require"
"io/ioutil"
"testing"
)

func TestParseSubmitProposalFlags(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions x/gov/client/rest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ func parseInt64OrReturnBadRequest(s string, w http.ResponseWriter) (n int64, ok
var err error
n, err = strconv.ParseInt(s, 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
err := fmt.Errorf("'%s' is not a valid int64", s)
w.Write([]byte(err.Error()))
return 0, false
w.WriteHeader(http.StatusBadRequest)
err := fmt.Errorf("'%s' is not a valid int64", s)
w.Write([]byte(err.Error()))
return 0, false
}
return n, true
}
}
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 TestTallyJailedValidator(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.Jail(ctx, val2.PubKey)

proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
proposalID := proposal.GetProposalID()
Expand Down
8 changes: 4 additions & 4 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())}
unjailMsg := 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)
// unjail should fail with unknown validator
res := mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{unjailMsg}, []int64{0}, []int64{1}, false, priv1)
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 still 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")
}
24 changes: 12 additions & 12 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 jailed (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,19 +38,19 @@ 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 jailed 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()))
tags := sdk.NewTags("action", []byte("unjail"), "validator", []byte(msg.ValidatorAddr.String()))

return sdk.Result{
Tags: tags,
Expand Down
Loading

0 comments on commit 879f78c

Please sign in to comment.