From 549eba0d549c0c29358e542f3b9c8ded7be60848 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 7 Sep 2018 06:56:05 +0200 Subject: [PATCH] Add height offsets --- x/slashing/keeper.go | 10 ++++++++-- x/slashing/params.go | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 081e1c1e58..4567f538bb 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -62,8 +62,11 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio revisedFraction := k.capBySlashingPeriod(ctx, address, fraction, infractionHeight) 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. + distributionHeight := infractionHeight - ValidatorUpdateDelay + // Slash validator - k.validatorSet.Slash(ctx, pubkey, infractionHeight, power, revisedFraction) + k.validatorSet.Slash(ctx, pubkey, distributionHeight, power, revisedFraction) // Jail validator k.validatorSet.Jail(ctx, pubkey) @@ -123,7 +126,10 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p // Downtime confirmed: slash and jail the validator logger.Info(fmt.Sprintf("Validator %s past min height of %d and below signed blocks threshold of %d", pubkey.Address(), minHeight, k.MinSignedPerWindow(ctx))) - k.validatorSet.Slash(ctx, pubkey, height, power, k.SlashFractionDowntime(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. + distributionHeight := height - ValidatorUpdateDelay - 1 + k.validatorSet.Slash(ctx, pubkey, distributionHeight, power, k.SlashFractionDowntime(ctx)) k.validatorSet.Jail(ctx, pubkey) signInfo.JailedUntil = ctx.BlockHeader().Time.Add(k.DowntimeUnbondDuration(ctx)) } else { diff --git a/x/slashing/params.go b/x/slashing/params.go index 6e18e5f481..467af3c113 100644 --- a/x/slashing/params.go +++ b/x/slashing/params.go @@ -15,6 +15,12 @@ const ( DowntimeUnbondDurationKey = "slashing/DowntimeUnbondDuration" SlashFractionDoubleSignKey = "slashing/SlashFractionDoubleSign" SlashFractionDowntimeKey = "slashing/SlashFractionDowntime" + + // Delay, in blocks, between when validator updates are returned to Tendermint and when they are applied + // For example, if this is 0, the validator set at the end of a block will sign the next block, or + // if this is 1, the validator set at the end of a block will sign the block after the next. + // Constant as this should not change without a hard fork. + ValidatorUpdateDelay int64 = 1 ) // MaxEvidenceAge - Max age for evidence - 21 days (3 weeks)