From 5a559f75c5ea38d1f4924b9e9978ca60f95ded73 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Mon, 22 Oct 2018 23:55:49 -0400 Subject: [PATCH 1/2] simulation stop early with no proposers --- x/distribution/keeper/allocation.go | 1 + x/distribution/keeper/hooks.go | 1 - x/mock/simulation/random_simulate_blocks.go | 6 ++++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index debf0eb620..ddb351e4ed 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -13,6 +13,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s // get the proposer of this block proposerValidator := k.stakeKeeper.ValidatorByConsAddr(ctx, proposer) + proposerDist := k.GetValidatorDistInfo(ctx, proposerValidator.GetOperator()) // get the fees which have been getting collected through all the diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index a3540c7609..f02b12b8d9 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -104,7 +104,6 @@ func (h Hooks) OnDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valA func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) { h.k.onValidatorModified(ctx, addr) } - func (h Hooks) OnValidatorBonded(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) { h.k.onValidatorModified(ctx, addr) } diff --git a/x/mock/simulation/random_simulate_blocks.go b/x/mock/simulation/random_simulate_blocks.go index bccb42285f..72f2ea1f0c 100644 --- a/x/mock/simulation/random_simulate_blocks.go +++ b/x/mock/simulation/random_simulate_blocks.go @@ -176,6 +176,12 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, app.Commit() } + if header.ProposerAddress == nil { + fmt.Printf("\nSimulation stopped early as all validators have been unbonded, there is nobody left propose a block!\n") + stopEarly = true + break + } + // Generate a random RequestBeginBlock with the current validator set for the next block request = RandomRequestBeginBlock(r, validators, livenessTransitionMatrix, evidenceFraction, pastTimes, pastVoteInfos, event, header) From 8999ee8797fabe633f0c3061845b5ac9c0d2f569 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 23 Oct 2018 00:53:06 -0400 Subject: [PATCH 2/2] re-enable simulation parameters --- cmd/gaia/app/sim_test.go | 20 ++++++++++---------- x/mock/simulation/random_simulate_blocks.go | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index bad7473095..d39edb91b3 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -14,7 +14,7 @@ import ( "github.com/tendermint/tendermint/libs/log" sdk "github.com/cosmos/cosmos-sdk/types" - // authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation" banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation" distr "github.com/cosmos/cosmos-sdk/x/distribution" distributionsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation" @@ -104,19 +104,19 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage { func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation { return []simulation.WeightedOperation{ - //{5, authsim.SimulateDeductFee(app.accountMapper, app.feeCollectionKeeper)}, + {5, authsim.SimulateDeductFee(app.accountMapper, app.feeCollectionKeeper)}, {100, banksim.SingleInputSendMsg(app.accountMapper, app.bankKeeper)}, - // {50, distributionsim.SimulateMsgSetWithdrawAddress(app.accountMapper, app.distrKeeper)}, + {50, distributionsim.SimulateMsgSetWithdrawAddress(app.accountMapper, app.distrKeeper)}, {50, distributionsim.SimulateMsgWithdrawDelegatorRewardsAll(app.accountMapper, app.distrKeeper)}, {50, distributionsim.SimulateMsgWithdrawDelegatorReward(app.accountMapper, app.distrKeeper)}, - // {50, distributionsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountMapper, app.distrKeeper)}, - //{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, app.stakeKeeper)}, - //{100, govsim.SimulateMsgDeposit(app.govKeeper, app.stakeKeeper)}, - //{100, stakesim.SimulateMsgCreateValidator(app.accountMapper, app.stakeKeeper)}, - //{5, stakesim.SimulateMsgEditValidator(app.stakeKeeper)}, + {50, distributionsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountMapper, app.distrKeeper)}, + {5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, app.stakeKeeper)}, + {100, govsim.SimulateMsgDeposit(app.govKeeper, app.stakeKeeper)}, + {100, stakesim.SimulateMsgCreateValidator(app.accountMapper, app.stakeKeeper)}, + {5, stakesim.SimulateMsgEditValidator(app.stakeKeeper)}, {100, stakesim.SimulateMsgDelegate(app.accountMapper, app.stakeKeeper)}, - //{100, stakesim.SimulateMsgBeginUnbonding(app.accountMapper, app.stakeKeeper)}, - //{100, stakesim.SimulateMsgBeginRedelegate(app.accountMapper, app.stakeKeeper)}, + {100, stakesim.SimulateMsgBeginUnbonding(app.accountMapper, app.stakeKeeper)}, + {100, stakesim.SimulateMsgBeginRedelegate(app.accountMapper, app.stakeKeeper)}, {100, slashingsim.SimulateMsgUnjail(app.slashingKeeper)}, } } diff --git a/x/mock/simulation/random_simulate_blocks.go b/x/mock/simulation/random_simulate_blocks.go index 72f2ea1f0c..4c9b91d722 100644 --- a/x/mock/simulation/random_simulate_blocks.go +++ b/x/mock/simulation/random_simulate_blocks.go @@ -233,7 +233,7 @@ func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T, event f assertAllInvariants(t, app, invariants, fmt.Sprintf("operation: %v", logUpdate), displayLogs) } if opCount%50 == 0 { - fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ", header.Height, totalNumBlocks, opCount, blocksize) + fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ", header.Height, totalNumBlocks, opCount, blocksize) } } opCount++