Skip to content

Commit

Permalink
Merge branch 'develop' into dev/sim_blocksize
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Oct 30, 2018
2 parents 100f888 + 0d8325b commit 4cde804
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())

Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions docs/sdk/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<account_cosmosval> \
--address-validator-dest=<account_cosmosval> \
--addr-validator-source=<account_cosmosval> \
--addr-validator-dest=<account_cosmosval> \
--shares-percent=50 \
--from=<key_name> \
--chain-id=<chain_id>
Expand All @@ -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=<account_cosmos> \
--address-validator-source=<account_cosmosval> \
--address-validator-dest=<account_cosmosval> \
--addr-validator-source=<account_cosmosval> \
--addr-validator-dest=<account_cosmosval> \
```

Or if you want to check all your current unbonding-delegations with disctinct validators:
Expand Down
2 changes: 1 addition & 1 deletion docs/validators/validator-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<account_cosmosval>
--from=<account_cosmosval>
--moniker="choose a moniker" \
--chain-id=<chain_id> \
--name=<key_name> \
Expand Down
4 changes: 4 additions & 0 deletions x/stake/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions x/stake/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions x/stake/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 4cde804

Please sign in to comment.