From 48672c4c0b25da30a0d448a7ee2effbf64792b6b Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 4 Oct 2018 18:22:51 +0200 Subject: [PATCH] More comments, update sim for NextValSet --- PENDING.md | 5 ++--- x/mock/simulation/random_simulate_blocks.go | 8 ++++++-- x/slashing/keeper.go | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/PENDING.md b/PENDING.md index d556264ed..7799a4a72 100644 --- a/PENDING.md +++ b/PENDING.md @@ -28,10 +28,9 @@ BREAKING CHANGES * [x/stake, x/slashing] [#1305](https://github.com/cosmos/cosmos-sdk/issues/1305) - Rename "revoked" to "jailed" * [x/stake] [#1676] Revoked and jailed validators put into the unbonding state * [x/stake] [#1877] Redelegations/unbonding-delegation from unbonding validator have reduced time - * [x/stake] \#2040 Validator operator type has now changed to `sdk.ValAddress` - * A new bech32 prefix has been introduced for Tendermint signing keys and - addresses, `cosmosconspub` and `cosmoscons` respectively. * [x/slashing] \#1789 Slashing changes for Tendermint validator set offset (NextValSet) + * [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator + operator type has now changed to `sdk.ValAddress` * [x/stake] [\#2221](https://github.com/cosmos/cosmos-sdk/issues/2221) New Bech32 prefixes have been introduced for a validator's consensus address and public key: `cosmosvalcons` and `cosmosvalconspub` respectively. Also, existing Bech32 prefixes have been diff --git a/x/mock/simulation/random_simulate_blocks.go b/x/mock/simulation/random_simulate_blocks.go index 51705cbef..0fc9c21a9 100644 --- a/x/mock/simulation/random_simulate_blocks.go +++ b/x/mock/simulation/random_simulate_blocks.go @@ -77,6 +77,9 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, } validators := initChain(r, accs, setups, app, appStateFn) + // Second variable to keep pending validator set (delayed one block since TM 0.24) + // Initially this is the same as the initial validator set + nextValidators := validators header := abci.Header{Height: 0, Time: timestamp} opCount := 0 @@ -160,8 +163,9 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, // Generate a random RequestBeginBlock with the current validator set for the next block request = RandomRequestBeginBlock(r, validators, livenessTransitionMatrix, evidenceFraction, pastTimes, pastVoteInfos, event, header) - // Update the validator set - validators = updateValidators(tb, r, validators, res.ValidatorUpdates, event) + // Update the validator set, which will be reflected in the application on the next block + validators = nextValidators + nextValidators = updateValidators(tb, r, validators, res.ValidatorUpdates, event) } if stopEarly { DisplayEvents(events) diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 73d411367..a745a52d3 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -63,6 +63,9 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio logger.Info(fmt.Sprintf("Fraction slashed capped by slashing period from %v to %v", fraction, revisedFraction)) // We need to retrieve the stake distribution which signed the block, so we subtract ValidatorUpdateDelay from the evidence height. + // Note that this *can* result in a "distributionHeight" of -1, + // i.e. at the end of the pre-genesis block (none) = at the beginning of the genesis block. + // That's fine since this is just used to filter unbonding delegations & redelegations. distributionHeight := infractionHeight - ValidatorUpdateDelay // Slash validator @@ -128,6 +131,9 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p pubkey.Address(), minHeight, k.MinSignedPerWindow(ctx))) // We need to retrieve the stake distribution which signed the block, so we subtract ValidatorUpdateDelay from the evidence height, // and subtract an additional 1 since this is the LastCommit. + // Note that this *can* result in a "distributionHeight" of -1 or -2, + // i.e. at the end of the pre-genesis block (none) = at the beginning of the genesis block. + // That's fine since this is just used to filter unbonding delegations & redelegations. distributionHeight := height - ValidatorUpdateDelay - 1 k.validatorSet.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx)) k.validatorSet.Jail(ctx, consAddr)