diff --git a/Makefile b/Makefile index b36ef61d4d..9d4ad0a255 100644 --- a/Makefile +++ b/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: diff --git a/PENDING.md b/PENDING.md index a43485bebd..0b99b9193f 100644 --- a/PENDING.md +++ b/PENDING.md @@ -38,6 +38,8 @@ IMPROVEMENTS * SDK - #2573 [x/distribution] add accum invariance - \#1924 [simulation] Use a transition matrix for block size + - #2610 [x/stake] Block redelegation to and from the same validator + * Tendermint diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index 384afbf6db..9f94a82f7c 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -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) } diff --git a/docs/sdk/clients.md b/docs/sdk/clients.md index f784dd238d..01deeae417 100644 --- a/docs/sdk/clients.md +++ b/docs/sdk/clients.md @@ -286,8 +286,8 @@ A redelegation is a type delegation that allows you to bond illiquid tokens from ```bash gaiacli tx redelegate begin \ - --address-validator-source= \ - --address-validator-dest= \ + --addr-validator-source= \ + --addr-validator-dest= \ --shares-percent=50 \ --from= \ --chain-id= @@ -311,8 +311,8 @@ Once you begin an redelegation, you can see it's information by using the follow ```bash gaiacli query redelegation \ --address-delegator= \ - --address-validator-source= \ - --address-validator-dest= \ + --addr-validator-source= \ + --addr-validator-dest= \ ``` Or if you want to check all your current unbonding-delegations with disctinct validators: diff --git a/docs/validators/validator-setup.md b/docs/validators/validator-setup.md index 43a3b06728..217a0d341c 100644 --- a/docs/validators/validator-setup.md +++ b/docs/validators/validator-setup.md @@ -32,7 +32,7 @@ Don't use more `steak` thank you have! You can always get more by using the [Fau gaiacli tx create-validator \ --amount=5steak \ --pubkey=$(gaiad tendermint show-validator) \ - --address-validator= + --from= --moniker="choose a moniker" \ --chain-id= \ --name= \ diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index a5d08d4892..97acc24042 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -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) diff --git a/x/stake/keeper/delegation_test.go b/x/stake/keeper/delegation_test.go index 24476ca3cc..fcf2f42067 100644 --- a/x/stake/keeper/delegation_test.go +++ b/x/stake/keeper/delegation_test.go @@ -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) diff --git a/x/stake/types/errors.go b/x/stake/types/errors.go index e8c85800fe..d76eb39c15 100644 --- a/x/stake/types/errors.go +++ b/x/stake/types/errors.go @@ -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") }