diff --git a/docs/spec/slashing/state-machine.md b/docs/spec/slashing/state-machine.md index 22987bb6e0..77b41f9b5d 100644 --- a/docs/spec/slashing/state-machine.md +++ b/docs/spec/slashing/state-machine.md @@ -54,6 +54,16 @@ and `SlashedSoFar` of `0`: ```golang onValidatorBonded(address sdk.ValAddress) + + slashingPeriod := SlashingPeriod{ + ValidatorAddr : address, + StartHeight : CurrentHeight, + EndHeight : 0, + SlashedSoFar : 0, + } + setSlashingPeriod(slashingPeriod) + + return ``` #### Validator Unbonded @@ -62,6 +72,12 @@ When a validator is unbonded, we update the in-progress `SlashingPeriod` with th ```golang onValidatorUnbonded(address sdk.ValAddress) + + slashingPeriod = getSlashingPeriod(address, CurrentHeight) + slashingPeriod.EndHeight = CurrentHeight + setSlashingPeriod(slashingPeriod) + + return ``` #### Validator Slashed @@ -71,7 +87,17 @@ address and the time of infraction, cap the fraction slashed as `max(SlashFracti (which may be `0`), and update the `SlashingPeriod` with the increased `SlashedSoFar`: ```golang -beforeValidatorSlashed(address sdk.ValAddress, fraction sdk.Rat) +beforeValidatorSlashed(address sdk.ValAddress, fraction sdk.Rat, infractionHeight int64) + + slashingPeriod = getSlashingPeriod(address, infractionHeight) + totalToSlash = max(slashingPeriod.SlashedSoFar, fraction) + slashingPeriod.SlashedSoFar = totalToSlash + setSlashingPeriod(slashingPeriod) + + remainderToSlash = slashingPeriod.SlashedSoFar - totalToSlash + fraction = remainderToSlash + + continue with slashing ``` ### State Cleanup diff --git a/docs/spec/slashing/state.md b/docs/spec/slashing/state.md index f4412067bf..07bf3261cf 100644 --- a/docs/spec/slashing/state.md +++ b/docs/spec/slashing/state.md @@ -64,9 +64,11 @@ When the validator voluntarily unjails themselves (and possibly changes signing Slashing periods are indexed in the store as follows: -- SlashingPeriod: ` 0x03 | ValTendermintAddr -> amino(slashingPeriod) ` +- SlashingPeriod: ` 0x03 | ValTendermintAddr | StartHeight -> amino(slashingPeriod) ` -This allows us to look up slashing period by validator address, the only lookup necessary. +This allows us to look up slashing period by validator address, the only lookup necessary, +and iterate over start height to efficiently retrieve the most recent slashing period(s) +or those beginning after a given height. ```go type SlashingPeriod struct {