Merge branch 'develop' into release/v0.25.0
This commit is contained in:
commit
1538ab8de9
6
Makefile
6
Makefile
|
@ -169,13 +169,13 @@ test_sim_gaia_nondeterminism:
|
|||
|
||||
test_sim_gaia_fast:
|
||||
@echo "Running quick Gaia simulation. This may take several minutes..."
|
||||
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=400 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=9 -v -timeout 24h
|
||||
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=500 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=9 -v -timeout 24h
|
||||
|
||||
test_sim_gaia_multi_seed:
|
||||
@echo "Running multi-seed Gaia simulation. This may take awhile!"
|
||||
@bash scripts/multisim.sh 10
|
||||
@bash scripts/multisim.sh 25
|
||||
|
||||
SIM_NUM_BLOCKS ?= 210
|
||||
SIM_NUM_BLOCKS ?= 500
|
||||
SIM_BLOCK_SIZE ?= 200
|
||||
SIM_COMMIT ?= true
|
||||
test_sim_gaia_benchmark:
|
||||
|
|
|
@ -18,6 +18,7 @@ FEATURES
|
|||
* Gaia REST API (`gaiacli advanced rest-server`)
|
||||
|
||||
* Gaia CLI (`gaiacli`)
|
||||
* [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations
|
||||
|
||||
* Gaia
|
||||
|
||||
|
@ -35,6 +36,8 @@ IMPROVEMENTS
|
|||
* Gaia
|
||||
|
||||
* SDK
|
||||
- #2573 [x/distribution] add accum invariance
|
||||
- #2610 [x/stake] Block redelegation to and from the same validator
|
||||
|
||||
* Tendermint
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -141,7 +142,7 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {
|
|||
var logger log.Logger
|
||||
logger = log.NewNopLogger()
|
||||
var db dbm.DB
|
||||
dir := os.TempDir()
|
||||
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
|
||||
db, _ = dbm.NewGoLevelDB("Simulation", dir)
|
||||
defer func() {
|
||||
db.Close()
|
||||
|
@ -183,7 +184,13 @@ func TestFullGaiaSimulation(t *testing.T) {
|
|||
} else {
|
||||
logger = log.NewNopLogger()
|
||||
}
|
||||
db := dbm.NewMemDB()
|
||||
var db dbm.DB
|
||||
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
|
||||
db, _ = dbm.NewGoLevelDB("Simulation", dir)
|
||||
defer func() {
|
||||
db.Close()
|
||||
os.RemoveAll(dir)
|
||||
}()
|
||||
app := NewGaiaApp(logger, db, nil)
|
||||
require.Equal(t, "GaiaApp", app.Name())
|
||||
|
||||
|
@ -198,7 +205,11 @@ func TestFullGaiaSimulation(t *testing.T) {
|
|||
commit,
|
||||
)
|
||||
if commit {
|
||||
fmt.Println("Database Size", db.Stats()["database.size"])
|
||||
// for memdb:
|
||||
// fmt.Println("Database Size", db.Stats()["database.size"])
|
||||
fmt.Println("GoLevelDB Stats")
|
||||
fmt.Println(db.Stats()["leveldb.stats"])
|
||||
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
|
||||
}
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
|
|
@ -285,6 +285,12 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
|||
validator = executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||
require.Equal(t, "1.0000000000", validator.Tokens.String())
|
||||
|
||||
validatorUbds := executeGetValidatorUnbondingDelegations(t,
|
||||
fmt.Sprintf("gaiacli query unbonding-delegations-from %s --output=json %v",
|
||||
sdk.ValAddress(barAddr), flags))
|
||||
require.Len(t, validatorUbds, 1)
|
||||
require.Equal(t, "1", validatorUbds[0].Balance.Amount.String())
|
||||
|
||||
params := executeGetParams(t, fmt.Sprintf("gaiacli query parameters --output=json %v", flags))
|
||||
require.True(t, defaultParams.Equal(params))
|
||||
|
||||
|
@ -693,6 +699,24 @@ func executeGetValidator(t *testing.T, cmdStr string) stake.Validator {
|
|||
return validator
|
||||
}
|
||||
|
||||
func executeGetValidatorUnbondingDelegations(t *testing.T, cmdStr string) []stake.UnbondingDelegation {
|
||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||
var ubds []stake.UnbondingDelegation
|
||||
cdc := app.MakeCodec()
|
||||
err := cdc.UnmarshalJSON([]byte(out), &ubds)
|
||||
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||
return ubds
|
||||
}
|
||||
|
||||
func executeGetValidatorRedelegations(t *testing.T, cmdStr string) []stake.Redelegation {
|
||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||
var reds []stake.Redelegation
|
||||
cdc := app.MakeCodec()
|
||||
err := cdc.UnmarshalJSON([]byte(out), &reds)
|
||||
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||
return reds
|
||||
}
|
||||
|
||||
func executeGetPool(t *testing.T, cmdStr string) stake.Pool {
|
||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||
var pool stake.Pool
|
||||
|
|
|
@ -28,10 +28,11 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
storeAcc = "acc"
|
||||
storeGov = "gov"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
storeAcc = "acc"
|
||||
storeGov = "gov"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
queryRouteStake = "stake"
|
||||
)
|
||||
|
||||
// rootCmd is the entry point for this binary
|
||||
|
@ -70,21 +71,23 @@ func main() {
|
|||
authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)),
|
||||
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
|
||||
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryPool(storeStake, cdc),
|
||||
govcmd.GetCmdQueryProposal(storeGov, cdc),
|
||||
govcmd.GetCmdQueryProposals(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposit(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposits(storeGov, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||
govcmd.GetCmdQueryVote(storeGov, cdc),
|
||||
govcmd.GetCmdQueryVotes(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposit(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposits(storeGov, cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
|
||||
)...)
|
||||
|
||||
//Add query commands
|
||||
|
|
|
@ -285,7 +285,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va
|
|||
gaiacli query unbonding-delegations <account_cosmos>
|
||||
```
|
||||
|
||||
You can also get previous unbonding-delegation(s) status by adding the `--height` flag.
|
||||
Additionally, as you can get all the unbonding-delegations from a particular validator:
|
||||
|
||||
```bash
|
||||
gaiacli query unbonding-delegations-from <account_cosmosval>
|
||||
```
|
||||
|
||||
To get previous unbonding-delegation(s) status on past blocks, try adding the `--height` flag.
|
||||
|
||||
#### Redelegate Tokens
|
||||
|
||||
|
@ -321,7 +327,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va
|
|||
gaiacli query redelegations <account_cosmos>
|
||||
```
|
||||
|
||||
You can also get previous redelegation(s) status by adding the `--height` flag.
|
||||
Additionally, as you can get all the outgoing redelegations from a particular validator:
|
||||
|
||||
```bash
|
||||
gaiacli query redelegations-from <account_cosmosval>
|
||||
```
|
||||
|
||||
To get previous redelegation(s) status on past blocks, try adding the `--height` flag.
|
||||
|
||||
### Governance
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@ func main() {
|
|||
client.GetCommands(
|
||||
stakecmd.GetCmdQueryValidator("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidators("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryDelegation("stake", cdc),
|
||||
stakecmd.GetCmdQueryDelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryPool("stake", cdc),
|
||||
|
|
|
@ -114,6 +114,80 @@ func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command.
|
||||
func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbonding-delegations-from [operator-addr]",
|
||||
Short: "Query all unbonding delegatations from a validator",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: valAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/validatorUnbondingDelegations", queryRoute),
|
||||
bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryValidatorRedelegations implements the query all redelegatations from a validator command.
|
||||
func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "redelegations-from [operator-addr]",
|
||||
Short: "Query all outgoing redelegatations from a validator",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: valAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/validatorRedelegations", queryRoute),
|
||||
bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryDelegation the query delegation command.
|
||||
func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
@ -139,6 +213,7 @@ func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
}
|
||||
|
||||
// parse out the delegation
|
||||
|
||||
delegation, err := types.UnmarshalDelegation(cdc, key, res)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -292,7 +367,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra.
|
|||
return err
|
||||
}
|
||||
|
||||
// parse out the validators
|
||||
// parse out the unbonding delegations
|
||||
var ubds []stake.UnbondingDelegation
|
||||
for _, kv := range resKVs {
|
||||
ubd := types.MustUnmarshalUBD(cdc, kv.Key, kv.Value)
|
||||
|
|
|
@ -541,6 +541,10 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
|
|||
func (k Keeper) BeginRedelegation(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
valSrcAddr, valDstAddr sdk.ValAddress, sharesAmount sdk.Dec) (types.Redelegation, sdk.Error) {
|
||||
|
||||
if bytes.Equal(valSrcAddr, valDstAddr) {
|
||||
return types.Redelegation{}, types.ErrSelfRedelegation(k.Codespace())
|
||||
}
|
||||
|
||||
// check if there is already a redelgation in progress from src to dst
|
||||
// TODO quick fix, instead we should use an index, see https://github.com/cosmos/cosmos-sdk/issues/1402
|
||||
_, found := k.GetRedelegation(ctx, delAddr, valSrcAddr, valDstAddr)
|
||||
|
|
|
@ -581,6 +581,32 @@ func TestRedelegation(t *testing.T) {
|
|||
require.Equal(t, 0, len(redelegations))
|
||||
}
|
||||
|
||||
func TestRedelegateToSameValidator(t *testing.T) {
|
||||
|
||||
ctx, _, keeper := CreateTestInput(t, false, 0)
|
||||
pool := keeper.GetPool(ctx)
|
||||
pool.LooseTokens = sdk.NewDec(30)
|
||||
|
||||
// create a validator with a self-delegation
|
||||
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
|
||||
validator, pool, issuedShares := validator.AddTokensFromDel(pool, sdk.NewInt(10))
|
||||
require.Equal(t, int64(10), issuedShares.RoundInt64())
|
||||
keeper.SetPool(ctx, pool)
|
||||
validator = TestingUpdateValidator(keeper, ctx, validator)
|
||||
pool = keeper.GetPool(ctx)
|
||||
val0AccAddr := sdk.AccAddress(addrVals[0].Bytes())
|
||||
selfDelegation := types.Delegation{
|
||||
DelegatorAddr: val0AccAddr,
|
||||
ValidatorAddr: addrVals[0],
|
||||
Shares: issuedShares,
|
||||
}
|
||||
keeper.SetDelegation(ctx, selfDelegation)
|
||||
|
||||
_, err := keeper.BeginRedelegation(ctx, val0AccAddr, addrVals[0], addrVals[0], sdk.NewDec(5))
|
||||
require.Error(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestRedelegateSelfDelegation(t *testing.T) {
|
||||
|
||||
ctx, _, keeper := CreateTestInput(t, false, 0)
|
||||
|
|
|
@ -155,6 +155,10 @@ func ErrNoRedelegation(codespace sdk.CodespaceType) sdk.Error {
|
|||
return sdk.NewError(codespace, CodeInvalidDelegation, "no redelegation found")
|
||||
}
|
||||
|
||||
func ErrSelfRedelegation(codespace sdk.CodespaceType) sdk.Error {
|
||||
return sdk.NewError(codespace, CodeInvalidDelegation, "cannot redelegate to the same validator")
|
||||
}
|
||||
|
||||
func ErrBadRedelegationDst(codespace sdk.CodespaceType) sdk.Error {
|
||||
return sdk.NewError(codespace, CodeInvalidDelegation, "redelegation validator not found")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue