From 8f7a222308d9cf4d069d331978d1d2040a65ab14 Mon Sep 17 00:00:00 2001 From: frog power 4000 Date: Thu, 17 Jan 2019 12:53:22 -0500 Subject: [PATCH] Merge PR #3314: Staking misc rename --- PENDING.md | 8 +++ client/lcd/lcd_test.go | 2 +- client/lcd/test_helpers.go | 6 +- cmd/gaia/app/genesis.go | 4 +- cmd/gaia/app/sim_test.go | 2 +- docs/spec/distribution/hooks.md | 4 +- docs/spec/staking/tags.md | 2 +- x/gov/client/utils/query.go | 1 + x/slashing/handler_test.go | 4 +- x/slashing/keeper_test.go | 2 +- x/slashing/test_common.go | 19 ++---- x/staking/app_test.go | 2 +- x/staking/client/cli/tx.go | 2 +- x/staking/client/rest/query.go | 4 +- x/staking/client/rest/tx.go | 6 +- x/staking/handler.go | 16 ++--- x/staking/handler_test.go | 88 ++++++++++++++-------------- x/staking/keeper/delegation.go | 4 +- x/staking/keeper/delegation_test.go | 32 +++++----- x/staking/keeper/test_common.go | 2 +- x/staking/keeper/val_state_change.go | 2 +- x/staking/keeper/validator.go | 10 ++-- x/staking/querier/querier_test.go | 2 +- x/staking/simulation/msgs.go | 30 ++++------ x/staking/staking.go | 4 +- x/staking/test_common.go | 17 ++---- x/staking/types/codec.go | 2 +- x/staking/types/msg.go | 38 ++++++------ x/staking/types/msg_test.go | 4 +- x/staking/types/validator.go | 76 ++++++++++++------------ 30 files changed, 191 insertions(+), 204 deletions(-) diff --git a/PENDING.md b/PENDING.md index de7cce4f5c7a..1fdbd0ec9b9d 100644 --- a/PENDING.md +++ b/PENDING.md @@ -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. @@ -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 diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index e7761df2533d..ba85b95e3b15 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -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) diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 799e9e9693ee..0e6a0cbc5116 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -763,7 +763,7 @@ 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) @@ -771,7 +771,7 @@ func doBeginUnbonding(t *testing.T, port, name, password string, 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, @@ -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 diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 129786f3b472..fe39bb598a45 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -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, ) } diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index db9402377762..fdacc04c504b 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -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)}, } diff --git a/docs/spec/distribution/hooks.md b/docs/spec/distribution/hooks.md index ca18dad080db..fac39fb89db9 100644 --- a/docs/spec/distribution/hooks.md +++ b/docs/spec/distribution/hooks.md @@ -2,7 +2,7 @@ ## 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 @@ -10,7 +10,7 @@ added, or the withdrawal has taken place. This is achieved by setting ## 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`. diff --git a/docs/spec/staking/tags.md b/docs/spec/staking/tags.md index 05c98a9caf10..c2efd3b37747 100644 --- a/docs/spec/staking/tags.md +++ b/docs/spec/staking/tags.md @@ -47,7 +47,7 @@ The staking module emits the following events/tags: * [0] Time is formatted in the RFC3339 standard -### MsgBeginUnbonding +### MsgUndelegate | Key | Value | |------------------|---------------------------| diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index d269924ff11b..fe890c3c0456 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -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" diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index 516d1b2b99ae..a363a497be35 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -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) diff --git a/x/slashing/keeper_test.go b/x/slashing/keeper_test.go index 9c9e7a28e967..9c4ead9d4727 100644 --- a/x/slashing/keeper_test.go +++ b/x/slashing/keeper_test.go @@ -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()) } diff --git a/x/slashing/test_common.go b/x/slashing/test_common.go index 803ce2124107..97bd477e9bad 100644 --- a/x/slashing/test_common.go +++ b/x/slashing/test_common.go @@ -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) } diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 80f416d716f3..f4c35d2450a0 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -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 diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 6788a2db65a0..4a2ed6eb4def 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -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) diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index aa9f52b52bed..c51f9e7ad0ac 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -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)) diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 26e7c9ea210c..73d86ce423fa 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -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 @@ -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 { @@ -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()) diff --git a/x/staking/handler.go b/x/staking/handler.go index 40e8ea839521..bfb50898f0c5 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -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() } @@ -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() } @@ -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() } @@ -193,7 +193,7 @@ 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() } @@ -201,7 +201,7 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper) 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() } @@ -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() } diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 16a763be75b5..3caecca44078 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -92,8 +92,8 @@ func TestValidatorByPowerIndex(t *testing.T) { require.Equal(t, power2, power3) // unbond self-delegation - msgBeginUnbonding := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(1000000)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(1000000)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected msg to be ok, got %v", got) var finishTime time.Time types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) @@ -247,9 +247,9 @@ func TestLegacyValidatorDelegations(t *testing.T) { // unbond validator total self-delegations (which should jail the validator) unbondShares := sdk.NewDec(10) - msgBeginUnbonding := NewMsgBeginUnbonding(sdk.AccAddress(valAddr), valAddr, unbondShares) + msgUndelegate := NewMsgUndelegate(sdk.AccAddress(valAddr), valAddr, unbondShares) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected begin unbonding validator msg to be ok, got %v", got) var finishTime time.Time @@ -413,11 +413,11 @@ func TestIncrementsMsgUnbond(t *testing.T) { // just send the same msgUnbond multiple times // TODO use decimals here unbondShares := sdk.NewDec(10) - msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) + msgUndelegate := NewMsgUndelegate(delegatorAddr, validatorAddr, unbondShares) numUnbonds := 5 for i := 0; i < numUnbonds; i++ { - got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + got := handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got) var finishTime time.Time types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) @@ -459,8 +459,8 @@ func TestIncrementsMsgUnbond(t *testing.T) { } for _, c := range errorCases { unbondShares := sdk.NewDec(c) - msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(delegatorAddr, validatorAddr, unbondShares) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.False(t, got.IsOK(), "expected unbond msg to fail") } @@ -468,17 +468,17 @@ func TestIncrementsMsgUnbond(t *testing.T) { // should be unable to unbond one more than we have unbondShares = sdk.NewDec(leftBonded + 1) - msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate = NewMsgUndelegate(delegatorAddr, validatorAddr, unbondShares) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.False(t, got.IsOK(), - "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares.String(), leftBonded) + "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgUndelegate, unbondShares.String(), leftBonded) // should be able to unbond just what we have unbondShares = sdk.NewDec(leftBonded) - msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate = NewMsgUndelegate(delegatorAddr, validatorAddr, unbondShares) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), - "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares, leftBonded) + "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgUndelegate, unbondShares, leftBonded) } func TestMultipleMsgCreateValidator(t *testing.T) { @@ -510,8 +510,8 @@ func TestMultipleMsgCreateValidator(t *testing.T) { for i, validatorAddr := range validatorAddrs { _, found := keeper.GetValidator(ctx, validatorAddr) require.True(t, found) - msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddrs[i], validatorAddr, sdk.NewDec(10)) // remove delegation - got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(delegatorAddrs[i], validatorAddr, sdk.NewDec(10)) // remove delegation + got := handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got) var finishTime time.Time // Jump to finishTime for unbonding period and remove from unbonding queue @@ -557,8 +557,8 @@ func TestMultipleMsgDelegate(t *testing.T) { // unbond them all for i, delegatorAddr := range delegatorAddrs { - msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewDec(10)) - got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(delegatorAddr, validatorAddr, sdk.NewDec(10)) + got := handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got) var finishTime time.Time types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) @@ -587,8 +587,8 @@ func TestJailValidator(t *testing.T) { require.True(t, got.IsOK(), "expected ok, got %v", got) // unbond the validators bond portion - msgBeginUnbondingValidator := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingValidator, keeper) + msgUndelegateValidator := NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegateValidator, keeper) require.True(t, got.IsOK(), "expected no error: %v", got) var finishTime time.Time types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) @@ -604,8 +604,8 @@ func TestJailValidator(t *testing.T) { require.False(t, got.IsOK(), "expected error, got %v", got) // test that the delegator can still withdraw their bonds - msgBeginUnbondingDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingDelegator, keeper) + msgUndelegateDelegator := NewMsgUndelegate(delegatorAddr, validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegateDelegator, keeper) require.True(t, got.IsOK(), "expected no error") types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) ctx = ctx.WithBlockTime(finishTime) @@ -638,8 +638,8 @@ func TestValidatorQueue(t *testing.T) { EndBlocker(ctx, keeper) // unbond the all self-delegation to put validator in unbonding state - msgBeginUnbondingValidator := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingValidator, keeper) + msgUndelegateValidator := NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegateValidator, keeper) require.True(t, got.IsOK(), "expected no error: %v", got) var finishTime time.Time types.MsgCdc.MustUnmarshalBinaryLengthPrefixed(got.Data, &finishTime) @@ -683,8 +683,8 @@ func TestUnbondingPeriod(t *testing.T) { EndBlocker(ctx, keeper) // begin unbonding - msgBeginUnbonding := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected no error") origHeader := ctx.BlockHeader() @@ -724,8 +724,8 @@ func TestUnbondingFromUnbondingValidator(t *testing.T) { require.True(t, got.IsOK(), "expected ok, got %v", got) // unbond the validators bond portion - msgBeginUnbondingValidator := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingValidator, keeper) + msgUndelegateValidator := NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegateValidator, keeper) require.True(t, got.IsOK(), "expected no error") // change the ctx to Block Time one second before the validator would have unbonded @@ -734,8 +734,8 @@ func TestUnbondingFromUnbondingValidator(t *testing.T) { ctx = ctx.WithBlockTime(finishTime.Add(time.Second * -1)) // unbond the delegator from the validator - msgBeginUnbondingDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewDec(10)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingDelegator, keeper) + msgUndelegateDelegator := NewMsgUndelegate(delegatorAddr, validatorAddr, sdk.NewDec(10)) + got = handleMsgUndelegate(ctx, msgUndelegateDelegator, keeper) require.True(t, got.IsOK(), "expected no error") // move the Block time forward by one second @@ -973,8 +973,8 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) { // begin an unbonding delegation selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) - msgBeginUnbonding := NewMsgBeginUnbonding(selfDelAddr, valAddr, sdk.NewDec(5)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, sdk.NewDec(5)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) // there should only be one entry in the ubd object @@ -983,8 +983,8 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) { require.Len(t, ubd.Entries, 1) // start a second ubd at this same time as the first - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - require.True(t, got.IsOK(), "expected no error, msg: %v", msgBeginUnbonding) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) + require.True(t, got.IsOK(), "expected no error, msg: %v", msgUndelegate) // now there should be two entries ubd, found = keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) @@ -1018,8 +1018,8 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { // begin an unbonding delegation selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) - msgBeginUnbonding := NewMsgBeginUnbonding(selfDelAddr, valAddr, sdk.NewDec(5)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) + msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, sdk.NewDec(5)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) // there should only be one entry in the ubd object @@ -1029,8 +1029,8 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { // move forwaubd in time and start a second redelegation ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - require.True(t, got.IsOK(), "expected no error, msg: %v", msgBeginUnbonding) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) + require.True(t, got.IsOK(), "expected no error, msg: %v", msgUndelegate) // now there should be two entries ubd, found = keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) @@ -1086,9 +1086,9 @@ func TestUnbondingWhenExcessValidators(t *testing.T) { require.Equal(t, 2, len(keeper.GetLastValidators(ctx))) // unbond the valdator-2 - msgBeginUnbonding := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr2), validatorAddr2, sdk.NewDec(30)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding") + msgUndelegate := NewMsgUndelegate(sdk.AccAddress(validatorAddr2), validatorAddr2, sdk.NewDec(30)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) + require.True(t, got.IsOK(), "expected no error on runMsgUndelegate") // apply TM updates keeper.ApplyAndReturnValidatorSetUpdates(ctx) @@ -1129,9 +1129,9 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { ctx = ctx.WithBlockHeight(1) // begin unbonding 4 stake - msgBeginUnbonding := NewMsgBeginUnbonding(del, valA, sdk.NewDec(4)) - got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding") + msgUndelegate := NewMsgUndelegate(del, valA, sdk.NewDec(4)) + got = handleMsgUndelegate(ctx, msgUndelegate, keeper) + require.True(t, got.IsOK(), "expected no error on runMsgUndelegate") // begin redelegate 6 stake msgBeginRedelegate := NewMsgBeginRedelegate(del, valA, valB, sdk.NewDec(6)) diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index d4f35431d7cf..619a05e6941b 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -546,7 +546,7 @@ func (k Keeper) getBeginInfo(ctx sdk.Context, valSrcAddr sdk.ValAddress) ( return completionTime, height, true case validator.Status == sdk.Unbonding: - completionTime = validator.UnbondingMinTime + completionTime = validator.UnbondingCompletionTime height = validator.UnbondingHeight return completionTime, height, false @@ -556,7 +556,7 @@ func (k Keeper) getBeginInfo(ctx sdk.Context, valSrcAddr sdk.ValAddress) ( } // begin unbonding an unbonding record -func (k Keeper) BeginUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, +func (k Keeper) Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (completionTime time.Time, sdkErr sdk.Error) { // create the unbonding delegation diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index 5c11a91adabf..84b4581e0e06 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -249,7 +249,7 @@ func TestUndelegateSelfDelegation(t *testing.T) { keeper.SetDelegation(ctx, delegation) val0AccAddr := sdk.AccAddress(addrVals[0].Bytes()) - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -305,7 +305,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { // unbond the all self-delegation to put validator in unbonding state val0AccAddr := sdk.AccAddress(addrVals[0].Bytes()) - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -316,7 +316,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { require.True(t, found) require.Equal(t, blockHeight, validator.UnbondingHeight) params := keeper.GetParams(ctx) - require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingMinTime)) + require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime)) //change the context header = ctx.BlockHeader() @@ -327,7 +327,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { ctx = ctx.WithBlockHeader(header) // unbond some of the other delegation's shares - _, err = keeper.BeginUnbonding(ctx, addrDels[0], addrVals[0], sdk.NewDec(6)) + _, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(6)) require.NoError(t, err) // retrieve the unbonding delegation @@ -378,7 +378,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { ctx = ctx.WithBlockTime(time.Unix(333, 0)) // unbond the all self-delegation to put validator in unbonding state - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -389,10 +389,10 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { require.True(t, found) require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight) params := keeper.GetParams(ctx) - require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingMinTime)) + require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime)) // unbond the validator - ctx = ctx.WithBlockTime(validator.UnbondingMinTime) + ctx = ctx.WithBlockTime(validator.UnbondingCompletionTime) keeper.UnbondAllMatureValidatorQueue(ctx) // Make sure validator is still in state because there is still an outstanding delegation @@ -401,7 +401,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { require.Equal(t, validator.Status, sdk.Unbonded) // unbond some of the other delegation's shares - _, err = keeper.BeginUnbonding(ctx, addrDels[0], addrVals[0], sdk.NewDec(6)) + _, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(6)) require.NoError(t, err) // no ubd should have been found, coins should have been returned direcly to account @@ -409,7 +409,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { require.False(t, found, "%v", ubd) // unbond rest of the other delegation's shares - _, err = keeper.BeginUnbonding(ctx, addrDels[0], addrVals[0], sdk.NewDec(4)) + _, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(4)) require.NoError(t, err) // now validator should now be deleted from state @@ -457,7 +457,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { ctx = ctx.WithBlockTime(time.Unix(333, 0)) // unbond the all self-delegation to put validator in unbonding state - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -465,7 +465,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { require.Equal(t, 1, len(updates)) // unbond all the remaining delegation - _, err = keeper.BeginUnbonding(ctx, addrDels[0], addrVals[0], sdk.NewDec(10)) + _, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // validator should still be in state and still be in unbonding state @@ -474,7 +474,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { require.Equal(t, validator.Status, sdk.Unbonding) // unbond the validator - ctx = ctx.WithBlockTime(validator.UnbondingMinTime) + ctx = ctx.WithBlockTime(validator.UnbondingCompletionTime) keeper.UnbondAllMatureValidatorQueue(ctx) // validator should now be deleted from state @@ -698,7 +698,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) { ctx = ctx.WithBlockHeader(header) // unbond the all self-delegation to put validator in unbonding state - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -709,7 +709,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) { require.True(t, found) require.Equal(t, blockHeight, validator.UnbondingHeight) params := keeper.GetParams(ctx) - require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingMinTime)) + require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime)) //change the context header = ctx.BlockHeader() @@ -779,7 +779,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) { ctx = ctx.WithBlockTime(time.Unix(333, 0)) // unbond the all self-delegation to put validator in unbonding state - _, err := keeper.BeginUnbonding(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) + _, err := keeper.Undelegate(ctx, val0AccAddr, addrVals[0], sdk.NewDec(10)) require.NoError(t, err) // end block @@ -790,7 +790,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) { require.True(t, found) require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight) params := keeper.GetParams(ctx) - require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingMinTime)) + require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime)) // unbond the validator keeper.unbondingToUnbonded(ctx, validator) diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index 7555b65db84d..9e583790f205 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -63,7 +63,7 @@ func MakeTestCodec() *codec.Codec { cdc.RegisterConcrete(bank.MsgSend{}, "test/staking/Send", nil) cdc.RegisterConcrete(types.MsgCreateValidator{}, "test/staking/CreateValidator", nil) cdc.RegisterConcrete(types.MsgEditValidator{}, "test/staking/EditValidator", nil) - cdc.RegisterConcrete(types.MsgBeginUnbonding{}, "test/staking/BeginUnbonding", nil) + cdc.RegisterConcrete(types.MsgUndelegate{}, "test/staking/Undelegate", nil) cdc.RegisterConcrete(types.MsgBeginRedelegate{}, "test/staking/BeginRedelegate", nil) // Register AppAccount diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 84d13d655cbd..1900c589c387 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -219,7 +219,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat validator, pool = validator.UpdateStatus(pool, sdk.Unbonding) k.SetPool(ctx, pool) - validator.UnbondingMinTime = ctx.BlockHeader().Time.Add(params.UnbondingTime) + validator.UnbondingCompletionTime = ctx.BlockHeader().Time.Add(params.UnbondingTime) validator.UnbondingHeight = ctx.BlockHeader().Height // save the now unbonded validator record and power index diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index 56467d531691..159330cd912f 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -330,19 +330,19 @@ func (k Keeper) DeleteValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Ti // Insert an validator address to the appropriate timeslice in the validator queue func (k Keeper) InsertValidatorQueue(ctx sdk.Context, val types.Validator) { - timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingMinTime) + timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime) var keys []sdk.ValAddress if len(timeSlice) == 0 { keys = []sdk.ValAddress{val.OperatorAddr} } else { keys = append(timeSlice, val.OperatorAddr) } - k.SetValidatorQueueTimeSlice(ctx, val.UnbondingMinTime, keys) + k.SetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime, keys) } // Delete a validator address from the validator queue func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) { - timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingMinTime) + timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime) newTimeSlice := []sdk.ValAddress{} for _, addr := range timeSlice { if !bytes.Equal(addr, val.OperatorAddr) { @@ -350,9 +350,9 @@ func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) { } } if len(newTimeSlice) == 0 { - k.DeleteValidatorQueueTimeSlice(ctx, val.UnbondingMinTime) + k.DeleteValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime) } else { - k.SetValidatorQueueTimeSlice(ctx, val.UnbondingMinTime, newTimeSlice) + k.SetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime, newTimeSlice) } } diff --git a/x/staking/querier/querier_test.go b/x/staking/querier/querier_test.go index c20fc3ce52b1..3793e119a429 100644 --- a/x/staking/querier/querier_test.go +++ b/x/staking/querier/querier_test.go @@ -296,7 +296,7 @@ func TestQueryDelegation(t *testing.T) { require.Equal(t, delegationsRes[0], delegation) // Query unbonging delegation - _, err = keeper.BeginUnbonding(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10)) + _, err = keeper.Undelegate(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10)) require.Nil(t, err) queryBondParams = NewQueryBondsParams(addrAcc2, addrVal1) diff --git a/x/staking/simulation/msgs.go b/x/staking/simulation/msgs.go index 473681cc0707..7487671eed2f 100644 --- a/x/staking/simulation/msgs.go +++ b/x/staking/simulation/msgs.go @@ -42,14 +42,9 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k staking.Keeper) simulati return "no-operation", nil, nil } - msg := staking.MsgCreateValidator{ - Description: description, - Commission: commission, - ValidatorAddr: address, - DelegatorAddr: acc.Address, - PubKey: acc.PubKey, - Delegation: sdk.NewCoin(denom, amount), - } + selfDelegation := sdk.NewCoin(denom, amount) + msg := staking.NewMsgCreateValidator(address, acc.PubKey, + selfDelegation, description, commission) if msg.ValidateBasic() != nil { return "", nil, fmt.Errorf("expected msg to pass ValidateBasic: %s", msg.GetSignBytes()) @@ -127,11 +122,10 @@ func SimulateMsgDelegate(m auth.AccountKeeper, k staking.Keeper) simulation.Oper if amount.Equal(sdk.ZeroInt()) { return "no-operation", nil, nil } - msg := staking.MsgDelegate{ - DelegatorAddr: delegatorAddress, - ValidatorAddr: validatorAddress, - Delegation: sdk.NewCoin(denom, amount), - } + + msg := staking.NewMsgDelegate( + delegatorAddress, validatorAddress, sdk.NewCoin(denom, amount)) + if msg.ValidateBasic() != nil { return "", nil, fmt.Errorf("expected msg to pass ValidateBasic: %s", msg.GetSignBytes()) } @@ -146,8 +140,8 @@ func SimulateMsgDelegate(m auth.AccountKeeper, k staking.Keeper) simulation.Oper } } -// SimulateMsgBeginUnbonding -func SimulateMsgBeginUnbonding(m auth.AccountKeeper, k staking.Keeper) simulation.Operation { +// SimulateMsgUndelegate +func SimulateMsgUndelegate(m auth.AccountKeeper, k staking.Keeper) simulation.Operation { handler := staking.NewHandler(k) return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, event func(string)) ( @@ -165,7 +159,7 @@ func SimulateMsgBeginUnbonding(m auth.AccountKeeper, k staking.Keeper) simulatio if numShares.Equal(sdk.ZeroDec()) { return "no-operation", nil, nil } - msg := staking.MsgBeginUnbonding{ + msg := staking.MsgUndelegate{ DelegatorAddr: delegatorAddress, ValidatorAddr: delegation.ValidatorAddr, SharesAmount: numShares, @@ -179,8 +173,8 @@ func SimulateMsgBeginUnbonding(m auth.AccountKeeper, k staking.Keeper) simulatio if result.IsOK() { write() } - event(fmt.Sprintf("staking/MsgBeginUnbonding/%v", result.IsOK())) - action = fmt.Sprintf("TestMsgBeginUnbonding: ok %v, msg %s", result.IsOK(), msg.GetSignBytes()) + event(fmt.Sprintf("staking/MsgUndelegate/%v", result.IsOK())) + action = fmt.Sprintf("TestMsgUndelegate: ok %v, msg %s", result.IsOK(), msg.GetSignBytes()) return action, nil, nil } } diff --git a/x/staking/staking.go b/x/staking/staking.go index 096c3d24ec06..81b78107d1cc 100644 --- a/x/staking/staking.go +++ b/x/staking/staking.go @@ -21,7 +21,7 @@ type ( MsgCreateValidator = types.MsgCreateValidator MsgEditValidator = types.MsgEditValidator MsgDelegate = types.MsgDelegate - MsgBeginUnbonding = types.MsgBeginUnbonding + MsgUndelegate = types.MsgUndelegate MsgBeginRedelegate = types.MsgBeginRedelegate GenesisState = types.GenesisState QueryDelegatorParams = querier.QueryDelegatorParams @@ -82,7 +82,7 @@ var ( NewMsgCreateValidatorOnBehalfOf = types.NewMsgCreateValidatorOnBehalfOf NewMsgEditValidator = types.NewMsgEditValidator NewMsgDelegate = types.NewMsgDelegate - NewMsgBeginUnbonding = types.NewMsgBeginUnbonding + NewMsgUndelegate = types.NewMsgUndelegate NewMsgBeginRedelegate = types.NewMsgBeginRedelegate NewQuerier = querier.NewQuerier diff --git a/x/staking/test_common.go b/x/staking/test_common.go index e4bc3a22e329..d13aab892561 100644 --- a/x/staking/test_common.go +++ b/x/staking/test_common.go @@ -43,20 +43,11 @@ func NewTestMsgCreateValidatorWithCommission(address sdk.ValAddress, pubKey cryp } func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt int64) MsgDelegate { - return MsgDelegate{ - DelegatorAddr: delAddr, - ValidatorAddr: valAddr, - Delegation: sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)), - } + amount := sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)) + return NewMsgDelegate(delAddr, valAddr, amount) } func NewTestMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.ValAddress, valPubKey crypto.PubKey, amt int64) MsgCreateValidator { - return MsgCreateValidator{ - Description: Description{}, - Commission: commissionMsg, - DelegatorAddr: delAddr, - ValidatorAddr: valAddr, - PubKey: valPubKey, - Delegation: sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)), - } + amount := sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)) + return NewMsgCreateValidatorOnBehalfOf(delAddr, valAddr, valPubKey, amount, Description{}, commissionMsg) } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index bc3764ffe901..c290e0d14c8d 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -9,7 +9,7 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) - cdc.RegisterConcrete(MsgBeginUnbonding{}, "cosmos-sdk/BeginUnbonding", nil) + cdc.RegisterConcrete(MsgUndelegate{}, "cosmos-sdk/Undelegate", nil) cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/BeginRedelegate", nil) } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index f6e14269437b..f2f7176fff5a 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -20,7 +20,7 @@ type MsgCreateValidator struct { DelegatorAddr sdk.AccAddress `json:"delegator_address"` ValidatorAddr sdk.ValAddress `json:"validator_address"` PubKey crypto.PubKey `json:"pubkey"` - Delegation sdk.Coin `json:"delegation"` + Value sdk.Coin `json:"value"` } // Default way to create validator. Delegator address and validator address are the same @@ -34,13 +34,13 @@ func NewMsgCreateValidator(valAddr sdk.ValAddress, pubkey crypto.PubKey, // Creates validator msg by delegator address on behalf of validator address func NewMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.ValAddress, - pubkey crypto.PubKey, delegation sdk.Coin, description Description, commission CommissionMsg) MsgCreateValidator { + pubkey crypto.PubKey, value sdk.Coin, description Description, commission CommissionMsg) MsgCreateValidator { return MsgCreateValidator{ Description: description, DelegatorAddr: delAddr, ValidatorAddr: valAddr, PubKey: pubkey, - Delegation: delegation, + Value: value, Commission: commission, } } @@ -70,12 +70,12 @@ func (msg MsgCreateValidator) GetSignBytes() []byte { DelegatorAddr sdk.AccAddress `json:"delegator_address"` ValidatorAddr sdk.ValAddress `json:"validator_address"` PubKey string `json:"pubkey"` - Delegation sdk.Coin `json:"delegation"` + Value sdk.Coin `json:"value"` }{ Description: msg.Description, ValidatorAddr: msg.ValidatorAddr, PubKey: sdk.MustBech32ifyConsPub(msg.PubKey), - Delegation: msg.Delegation, + Value: msg.Value, }) if err != nil { panic(err) @@ -91,7 +91,7 @@ func (msg MsgCreateValidator) ValidateBasic() sdk.Error { if msg.ValidatorAddr == nil { return ErrNilValidatorAddr(DefaultCodespace) } - if !(msg.Delegation.Amount.GT(sdk.ZeroInt())) { + if !(msg.Value.Amount.GT(sdk.ZeroInt())) { return ErrBadDelegationAmount(DefaultCodespace) } if msg.Description == (Description{}) { @@ -168,14 +168,14 @@ func (msg MsgEditValidator) ValidateBasic() sdk.Error { type MsgDelegate struct { DelegatorAddr sdk.AccAddress `json:"delegator_addr"` ValidatorAddr sdk.ValAddress `json:"validator_addr"` - Delegation sdk.Coin `json:"delegation"` + Value sdk.Coin `json:"value"` } -func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delegation sdk.Coin) MsgDelegate { +func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, value sdk.Coin) MsgDelegate { return MsgDelegate{ DelegatorAddr: delAddr, ValidatorAddr: valAddr, - Delegation: delegation, + Value: value, } } @@ -203,7 +203,7 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error { if msg.ValidatorAddr == nil { return ErrNilValidatorAddr(DefaultCodespace) } - if !(msg.Delegation.Amount.GT(sdk.ZeroInt())) { + if !(msg.Value.Amount.GT(sdk.ZeroInt())) { return ErrBadDelegationAmount(DefaultCodespace) } return nil @@ -275,15 +275,15 @@ func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error { //______________________________________________________________________ -// MsgBeginUnbonding - struct for unbonding transactions -type MsgBeginUnbonding struct { +// MsgUndelegate - struct for unbonding transactions +type MsgUndelegate struct { DelegatorAddr sdk.AccAddress `json:"delegator_addr"` ValidatorAddr sdk.ValAddress `json:"validator_addr"` SharesAmount sdk.Dec `json:"shares_amount"` } -func NewMsgBeginUnbonding(delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) MsgBeginUnbonding { - return MsgBeginUnbonding{ +func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) MsgUndelegate { + return MsgUndelegate{ DelegatorAddr: delAddr, ValidatorAddr: valAddr, SharesAmount: sharesAmount, @@ -291,12 +291,12 @@ func NewMsgBeginUnbonding(delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares } //nolint -func (msg MsgBeginUnbonding) Route() string { return RouterKey } -func (msg MsgBeginUnbonding) Type() string { return "begin_unbonding" } -func (msg MsgBeginUnbonding) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} } +func (msg MsgUndelegate) Route() string { return RouterKey } +func (msg MsgUndelegate) Type() string { return "begin_unbonding" } +func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} } // get the bytes for the message signer to sign on -func (msg MsgBeginUnbonding) GetSignBytes() []byte { +func (msg MsgUndelegate) GetSignBytes() []byte { b, err := MsgCdc.MarshalJSON(struct { DelegatorAddr sdk.AccAddress `json:"delegator_addr"` ValidatorAddr sdk.ValAddress `json:"validator_addr"` @@ -313,7 +313,7 @@ func (msg MsgBeginUnbonding) GetSignBytes() []byte { } // quick validity check -func (msg MsgBeginUnbonding) ValidateBasic() sdk.Error { +func (msg MsgUndelegate) ValidateBasic() sdk.Error { if msg.DelegatorAddr == nil { return ErrNilDelegatorAddr(DefaultCodespace) } diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index e5cb8a9f09c5..6eba60437783 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -173,7 +173,7 @@ func TestMsgBeginRedelegate(t *testing.T) { } // test ValidateBasic for MsgUnbond -func TestMsgBeginUnbonding(t *testing.T) { +func TestMsgUndelegate(t *testing.T) { tests := []struct { name string delegatorAddr sdk.AccAddress @@ -189,7 +189,7 @@ func TestMsgBeginUnbonding(t *testing.T) { } for _, tc := range tests { - msg := NewMsgBeginUnbonding(tc.delegatorAddr, tc.validatorAddr, tc.sharesAmount) + msg := NewMsgUndelegate(tc.delegatorAddr, tc.validatorAddr, tc.sharesAmount) if tc.expectPass { require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) } else { diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index 60cf3840e7c6..684df919dbb9 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -32,8 +32,8 @@ type Validator struct { Description Description `json:"description"` // description terms for the validator BondHeight int64 `json:"bond_height"` // earliest height as a bonded validator - UnbondingHeight int64 `json:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding - UnbondingMinTime time.Time `json:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding + UnbondingHeight int64 `json:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding + UnbondingCompletionTime time.Time `json:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding Commission Commission `json:"commission"` // commission parameters } @@ -41,17 +41,17 @@ type Validator struct { // NewValidator - initialize a new validator func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator { return Validator{ - OperatorAddr: operator, - ConsPubKey: pubKey, - Jailed: false, - Status: sdk.Unbonded, - Tokens: sdk.ZeroInt(), - DelegatorShares: sdk.ZeroDec(), - Description: description, - BondHeight: int64(0), - UnbondingHeight: int64(0), - UnbondingMinTime: time.Unix(0, 0).UTC(), - Commission: NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), + OperatorAddr: operator, + ConsPubKey: pubKey, + Jailed: false, + Status: sdk.Unbonded, + Tokens: sdk.ZeroInt(), + DelegatorShares: sdk.ZeroDec(), + Description: description, + BondHeight: int64(0), + UnbondingHeight: int64(0), + UnbondingCompletionTime: time.Unix(0, 0).UTC(), + Commission: NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), } } @@ -94,7 +94,7 @@ func (v Validator) HumanReadableString() (string, error) { resp += fmt.Sprintf("Description: %s\n", v.Description) resp += fmt.Sprintf("Bond Height: %d\n", v.BondHeight) resp += fmt.Sprintf("Unbonding Height: %d\n", v.UnbondingHeight) - resp += fmt.Sprintf("Minimum Unbonding Time: %v\n", v.UnbondingMinTime) + resp += fmt.Sprintf("Minimum Unbonding Time: %v\n", v.UnbondingCompletionTime) resp += fmt.Sprintf("Commission: {%s}\n", v.Commission) return resp, nil @@ -115,8 +115,8 @@ type bechValidator struct { Description Description `json:"description"` // description terms for the validator BondHeight int64 `json:"bond_height"` // earliest height as a bonded validator - UnbondingHeight int64 `json:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding - UnbondingMinTime time.Time `json:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding + UnbondingHeight int64 `json:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding + UnbondingCompletionTime time.Time `json:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding Commission Commission `json:"commission"` // commission parameters } @@ -129,17 +129,17 @@ func (v Validator) MarshalJSON() ([]byte, error) { } return codec.Cdc.MarshalJSON(bechValidator{ - OperatorAddr: v.OperatorAddr, - ConsPubKey: bechConsPubKey, - Jailed: v.Jailed, - Status: v.Status, - Tokens: v.Tokens, - DelegatorShares: v.DelegatorShares, - Description: v.Description, - BondHeight: v.BondHeight, - UnbondingHeight: v.UnbondingHeight, - UnbondingMinTime: v.UnbondingMinTime, - Commission: v.Commission, + OperatorAddr: v.OperatorAddr, + ConsPubKey: bechConsPubKey, + Jailed: v.Jailed, + Status: v.Status, + Tokens: v.Tokens, + DelegatorShares: v.DelegatorShares, + Description: v.Description, + BondHeight: v.BondHeight, + UnbondingHeight: v.UnbondingHeight, + UnbondingCompletionTime: v.UnbondingCompletionTime, + Commission: v.Commission, }) } @@ -154,17 +154,17 @@ func (v *Validator) UnmarshalJSON(data []byte) error { return err } *v = Validator{ - OperatorAddr: bv.OperatorAddr, - ConsPubKey: consPubKey, - Jailed: bv.Jailed, - Tokens: bv.Tokens, - Status: bv.Status, - DelegatorShares: bv.DelegatorShares, - Description: bv.Description, - BondHeight: bv.BondHeight, - UnbondingHeight: bv.UnbondingHeight, - UnbondingMinTime: bv.UnbondingMinTime, - Commission: bv.Commission, + OperatorAddr: bv.OperatorAddr, + ConsPubKey: consPubKey, + Jailed: bv.Jailed, + Tokens: bv.Tokens, + Status: bv.Status, + DelegatorShares: bv.DelegatorShares, + Description: bv.Description, + BondHeight: bv.BondHeight, + UnbondingHeight: bv.UnbondingHeight, + UnbondingCompletionTime: bv.UnbondingCompletionTime, + Commission: bv.Commission, } return nil }