Update state machine, contd.

This commit is contained in:
Christopher Goes 2018-08-13 17:52:58 +02:00
parent 2445718295
commit 8b7d6e0979
2 changed files with 31 additions and 3 deletions

View File

@ -54,6 +54,16 @@ and `SlashedSoFar` of `0`:
```golang ```golang
onValidatorBonded(address sdk.ValAddress) onValidatorBonded(address sdk.ValAddress)
slashingPeriod := SlashingPeriod{
ValidatorAddr : address,
StartHeight : CurrentHeight,
EndHeight : 0,
SlashedSoFar : 0,
}
setSlashingPeriod(slashingPeriod)
return
``` ```
#### Validator Unbonded #### Validator Unbonded
@ -62,6 +72,12 @@ When a validator is unbonded, we update the in-progress `SlashingPeriod` with th
```golang ```golang
onValidatorUnbonded(address sdk.ValAddress) onValidatorUnbonded(address sdk.ValAddress)
slashingPeriod = getSlashingPeriod(address, CurrentHeight)
slashingPeriod.EndHeight = CurrentHeight
setSlashingPeriod(slashingPeriod)
return
``` ```
#### Validator Slashed #### 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`: (which may be `0`), and update the `SlashingPeriod` with the increased `SlashedSoFar`:
```golang ```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 ### State Cleanup

View File

@ -64,9 +64,11 @@ When the validator voluntarily unjails themselves (and possibly changes signing
Slashing periods are indexed in the store as follows: 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 ```go
type SlashingPeriod struct { type SlashingPeriod struct {