Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Staking misc rename #3314

Merged
merged 7 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ BREAKING CHANGES
* [gaia-lite] [\#2182] Renamed and merged all redelegations endpoints into `/staking/redelegations`
* [\#3176](https://github.com/cosmos/cosmos-sdk/issues/3176) `tx/sign` endpoint now expects `BaseReq` fields as nested object.
* [\#2222] all endpoints renamed from `/stake` -> `/staking`
* [\#3289] misc renames:
* `Validator.UnbondingMinTime` -> `Validator.UnbondingCompletionTime`
* `Delegation` -> `Value` in `MsgCreateValidator` and `MsgDelegate`
* `MsgBeginUnbonding` -> `MsgUndelegate`

* Gaia CLI (`gaiacli`)
* [\#810](https://github.com/cosmos/cosmos-sdk/issues/810) Don't fallback to any default values for chain ID.
Expand All @@ -31,6 +35,10 @@ BREAKING CHANGES
* [\#2222] [x/staking] `/stake` -> `/staking` module rename
* \#3292 [x/distribution] Enable or disable withdraw addresses with a parameter in the param store
* [staking] \#1402 Redelegation and unbonding-delegation structs changed to include multiple an array of entries
* [staking] \#3289 misc renames:
* `Validator.UnbondingMinTime` -> `Validator.UnbondingCompletionTime`
* `Delegation` -> `Value` in `MsgCreateValidator` and `MsgDelegate`
* `MsgBeginUnbonding` -> `MsgUndelegate`
* [\#3315] Increase decimal precision to 18

* Tendermint
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 @@ -442,7 +442,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, operAddrs[0], bondedValidator.OperatorAddr)

// testing unbonding
resultTx = doBeginUnbonding(t, port, name1, pw, addr, operAddrs[0], 30, fees)
resultTx = doUndelegate(t, port, name1, pw, addr, operAddrs[0], 30, fees)
tests.WaitForHeight(resultTx.Height+1, port)

require.Equal(t, uint32(0), resultTx.CheckTx.Code)
Expand Down
6 changes: 3 additions & 3 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,15 @@ type msgDelegationsInput struct {
}

// POST /staking/delegators/{delegatorAddr}/delegations Submit delegation
func doBeginUnbonding(t *testing.T, port, name, password string,
func doUndelegate(t *testing.T, port, name, password string,
delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) {

acc := getAccount(t, port, delAddr)
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, false, false)
msg := msgBeginUnbondingInput{
msg := msgUndelegateInput{
BaseReq: baseReq,
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
Expand All @@ -790,7 +790,7 @@ func doBeginUnbonding(t *testing.T, port, name, password string,
return result
}

type msgBeginUnbondingInput struct {
type msgUndelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
"account(s) %v not in genesis.json: %+v", strings.Join(accsNotInGenesis, " "), addrMap)
}

if delAcc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) {
if delAcc.Coins.AmountOf(msg.Value.Denom).LT(msg.Value.Amount) {
return appGenTxs, persistentPeers, fmt.Errorf(
"insufficient fund for delegation %v: %v < %v",
delAcc.Address, delAcc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount,
delAcc.Address, delAcc.Coins.AmountOf(msg.Value.Denom), msg.Value.Amount,
)
}

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 @@ -235,7 +235,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
{100, stakingsim.SimulateMsgCreateValidator(app.accountKeeper, app.stakingKeeper)},
{5, stakingsim.SimulateMsgEditValidator(app.stakingKeeper)},
{100, stakingsim.SimulateMsgDelegate(app.accountKeeper, app.stakingKeeper)},
{100, stakingsim.SimulateMsgBeginUnbonding(app.accountKeeper, app.stakingKeeper)},
{100, stakingsim.SimulateMsgUndelegate(app.accountKeeper, app.stakingKeeper)},
{100, stakingsim.SimulateMsgBeginRedelegate(app.accountKeeper, app.stakingKeeper)},
{100, slashingsim.SimulateMsgUnjail(app.slashingKeeper)},
}
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/distribution/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Create or modify delegation distribution

- triggered-by: `staking.TxDelegate`, `staking.TxBeginRedelegate`, `staking.TxBeginUnbonding`
- triggered-by: `staking.MsgDelegate`, `staking.MsgBeginRedelegate`, `staking.MsgUndelegate`

The pool of a new delegator bond will be 0 for the height at which the bond was
added, or the withdrawal has taken place. This is achieved by setting
`DelegationDistInfo.WithdrawalHeight` to the height of the triggering transaction.

## Commission rate change

- triggered-by: `staking.TxEditValidator`
- triggered-by: `staking.MsgEditValidator`

If a validator changes its commission rate, all commission on fees must be
simultaneously withdrawn using the transaction `TxWithdrawValidator`.
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/staking/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The staking module emits the following events/tags:

* [0] Time is formatted in the RFC3339 standard

### MsgBeginUnbonding
### MsgUndelegate

| Key | Value |
|------------------|---------------------------|
Expand Down
1 change: 1 addition & 0 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func TestJailedValidatorDelegations(t *testing.T) {
unbondShares := sdk.NewDec(10)

// unbond validator total self-delegations (which should jail the validator)
msgBeginUnbonding := staking.NewMsgBeginUnbonding(sdk.AccAddress(valAddr), valAddr, unbondShares)
got = staking.NewHandler(stakingKeeper)(ctx, msgBeginUnbonding)
msgUndelegate := staking.NewMsgUndelegate(sdk.AccAddress(valAddr), valAddr, unbondShares)
got = staking.NewHandler(stakingKeeper)(ctx, msgUndelegate)
require.True(t, got.IsOK(), "expected begin unbonding validator msg to be ok, got: %v", got)

err := stakingKeeper.CompleteUnbonding(ctx, sdk.AccAddress(valAddr), valAddr)
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestHandleDoubleSign(t *testing.T) {

// Should be able to unbond now
del, _ := sk.GetDelegation(ctx, sdk.AccAddress(operatorAddr), operatorAddr)
msgUnbond := staking.NewMsgBeginUnbonding(sdk.AccAddress(operatorAddr), operatorAddr, del.GetShares())
msgUnbond := staking.NewMsgUndelegate(sdk.AccAddress(operatorAddr), operatorAddr, del.GetShares())
res = staking.NewHandler(sk)(ctx, msgUnbond)
require.True(t, res.IsOK())
}
Expand Down
19 changes: 6 additions & 13 deletions x/slashing/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,13 @@ func testAddr(addr string) sdk.AccAddress {

func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator {
commission := staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
return staking.MsgCreateValidator{
Description: staking.Description{},
Commission: commission,
DelegatorAddr: sdk.AccAddress(address),
ValidatorAddr: address,
PubKey: pubKey,
Delegation: sdk.NewCoin(stakingTypes.DefaultBondDenom, amt),
}
return staking.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(stakingTypes.DefaultBondDenom, amt),
staking.Description{}, commission,
)
}

func newTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmount sdk.Int) staking.MsgDelegate {
return staking.MsgDelegate{
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
Delegation: sdk.NewCoin(stakingTypes.DefaultBondDenom, delAmount),
}
amount := sdk.NewCoin(staking.DefaultBondDenom, delAmount)
return staking.NewMsgDelegate(delAddr, valAddr, amount)
}
2 changes: 1 addition & 1 deletion x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestStakingMsgs(t *testing.T) {
checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), true, sdk.NewDec(10))

// begin unbonding
beginUnbondingMsg := NewMsgBeginUnbonding(addr2, sdk.ValAddress(addr1), sdk.NewDec(10))
beginUnbondingMsg := NewMsgUndelegate(addr2, sdk.ValAddress(addr1), sdk.NewDec(10))
mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{beginUnbondingMsg}, []uint64{0}, []uint64{2}, true, true, priv2)

// delegation should exist anymore
Expand Down
2 changes: 1 addition & 1 deletion x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
return err
}

msg := staking.NewMsgBeginUnbonding(delAddr, valAddr, sharesAmount)
msg := staking.NewMsgUndelegate(delAddr, valAddr, sharesAmount)

if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(os.Stdout, txBldr, cliCtx, []sdk.Msg{msg}, false)
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han
case isBondTx:
actions = append(actions, staking.MsgDelegate{}.Type())
case isUnbondTx:
actions = append(actions, staking.MsgBeginUnbonding{}.Type())
actions = append(actions, staking.MsgUndelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteUnbonding))
case isRedTx:
actions = append(actions, staking.MsgBeginRedelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteRedelegation))
case noQuery:
actions = append(actions, staking.MsgDelegate{}.Type())
actions = append(actions, staking.MsgBeginUnbonding{}.Type())
actions = append(actions, staking.MsgUndelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteUnbonding))
actions = append(actions, staking.MsgBeginRedelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteRedelegation))
Expand Down
6 changes: 3 additions & 3 deletions x/staking/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type (
SharesAmount sdk.Dec `json:"shares"`
}

msgBeginUnbondingInput struct {
msgUndelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
Expand Down Expand Up @@ -129,7 +129,7 @@ func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx contex

func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req msgBeginUnbondingInput
var req msgUndelegateInput

err := utils.ReadRESTReq(w, r, cdc, &req)
if err != nil {
Expand All @@ -153,7 +153,7 @@ func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx
return
}

msg := staking.NewMsgBeginUnbonding(req.DelegatorAddr, req.ValidatorAddr, req.SharesAmount)
msg := staking.NewMsgUndelegate(req.DelegatorAddr, req.ValidatorAddr, req.SharesAmount)
err = msg.ValidateBasic()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down
16 changes: 8 additions & 8 deletions x/staking/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
return handleMsgDelegate(ctx, msg, k)
case types.MsgBeginRedelegate:
return handleMsgBeginRedelegate(ctx, msg, k)
case types.MsgBeginUnbonding:
return handleMsgBeginUnbonding(ctx, msg, k)
case types.MsgUndelegate:
return handleMsgUndelegate(ctx, msg, k)
default:
return sdk.ErrTxDecode("invalid message parse in staking module").Result()
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
return ErrValidatorPubKeyExists(k.Codespace()).Result()
}

if msg.Delegation.Denom != k.GetParams(ctx).BondDenom {
if msg.Value.Denom != k.GetParams(ctx).BondDenom {
return ErrBadDenom(k.Codespace()).Result()
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k

// move coins from the msg.Address account to a (self-delegation) delegator account
// the validator account and global shares are updated within here
_, err = k.Delegate(ctx, msg.DelegatorAddr, msg.Delegation, validator, true)
_, err = k.Delegate(ctx, msg.DelegatorAddr, msg.Value, validator, true)
if err != nil {
return err.Result()
}
Expand Down Expand Up @@ -193,15 +193,15 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
return ErrNoValidatorFound(k.Codespace()).Result()
}

if msg.Delegation.Denom != k.GetParams(ctx).BondDenom {
if msg.Value.Denom != k.GetParams(ctx).BondDenom {
return ErrBadDenom(k.Codespace()).Result()
}

if validator.Jailed && !bytes.Equal(validator.OperatorAddr, msg.DelegatorAddr) {
return ErrValidatorJailed(k.Codespace()).Result()
}

_, err := k.Delegate(ctx, msg.DelegatorAddr, msg.Delegation, validator, true)
_, err := k.Delegate(ctx, msg.DelegatorAddr, msg.Value, validator, true)
if err != nil {
return err.Result()
}
Expand All @@ -216,8 +216,8 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
}
}

func handleMsgBeginUnbonding(ctx sdk.Context, msg types.MsgBeginUnbonding, k keeper.Keeper) sdk.Result {
completionTime, err := k.BeginUnbonding(ctx, msg.DelegatorAddr, msg.ValidatorAddr, msg.SharesAmount)
func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keeper) sdk.Result {
completionTime, err := k.Undelegate(ctx, msg.DelegatorAddr, msg.ValidatorAddr, msg.SharesAmount)
if err != nil {
return err.Result()
}
Expand Down
Loading