Merge PR #2430: Aggressive slashing simulation & fixes

This commit is contained in:
Christopher Goes 2018-10-05 19:42:52 +02:00 committed by GitHub
parent b7cb2e4252
commit 482537e6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 10 deletions

View File

@ -42,6 +42,7 @@ BREAKING CHANGES
* [x/gov] [#2195] Governance uses BFT Time * [x/gov] [#2195] Governance uses BFT Time
* [x/gov] \#2256 Removed slashing for governance non-voting validators * [x/gov] \#2256 Removed slashing for governance non-voting validators
* [simulation] \#2162 Added back correct supply invariants * [simulation] \#2162 Added back correct supply invariants
* [x/slashing] \#2430 Simulate more slashes, check if validator is jailed before jailing
* SDK * SDK
* [core] \#2219 Update to Tendermint 0.24.0 * [core] \#2219 Update to Tendermint 0.24.0

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
seeds=(1 2 4 7 9 20 32 123 4728 37827 981928 87821 891823782 989182 89182391) seeds=(1 2 4 7 9 20 32 123 124 582 1893 2989 3012 4728 37827 981928 87821 891823782 989182 89182391)
blocks=$1 blocks=$1
echo "Running multi-seed simulation with seeds ${seeds[@]}" echo "Running multi-seed simulation with seeds ${seeds[@]}"
@ -28,7 +28,7 @@ for seed in ${seeds[@]}; do
sim $seed & sim $seed &
pids[${i}]=$! pids[${i}]=$!
i=$(($i+1)) i=$(($i+1))
sleep 5 # start in order, nicer logs sleep 10 # start in order, nicer logs
done done
echo "Simulation processes spawned, waiting for completion..." echo "Simulation processes spawned, waiting for completion..."
@ -40,11 +40,12 @@ for pid in ${pids[*]}; do
wait $pid wait $pid
last=$? last=$?
seed=${seeds[${i}]} seed=${seeds[${i}]}
if [ $last -ne 0 ]; then if [ $last -ne 0 ]
then
echo "Simulation with seed $seed failed!" echo "Simulation with seed $seed failed!"
code=1 code=1
else else
echo "Simulation with seed $seed OK!" echo "Simulation with seed $seed OK"
fi fi
i=$(($i+1)) i=$(($i+1))
done done

View File

@ -14,7 +14,7 @@ const (
numKeys int = 250 numKeys int = 250
// Chance that double-signing evidence is found on a given block // Chance that double-signing evidence is found on a given block
evidenceFraction float64 = 0.01 evidenceFraction float64 = 0.5
// TODO Remove in favor of binary search for invariant violation // TODO Remove in favor of binary search for invariant violation
onOperation bool = false onOperation bool = false

View File

@ -77,7 +77,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
k.validatorSet.Jail(ctx, consAddr) k.validatorSet.Jail(ctx, consAddr)
} }
// Set validator jail duration // Set or updated validator jail duration
signInfo, found := k.getValidatorSigningInfo(ctx, consAddr) signInfo, found := k.getValidatorSigningInfo(ctx, consAddr)
if !found { if !found {
panic(fmt.Sprintf("Expected signing info for validator %s but not found", consAddr)) panic(fmt.Sprintf("Expected signing info for validator %s but not found", consAddr))

View File

@ -35,7 +35,7 @@ func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte { func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
b := make([]byte, 8) b := make([]byte, 8)
// this needs to be height + 1 because the slashing period for genesis validators starts at height -1 // this needs to be height + 1 because the slashing period for genesis validators starts at height -1
binary.LittleEndian.PutUint64(b, uint64(startHeight+1)) binary.BigEndian.PutUint64(b, uint64(startHeight+1))
return append(GetValidatorSlashingPeriodPrefix(v), b...) return append(GetValidatorSlashingPeriodPrefix(v), b...)
} }

View File

@ -15,7 +15,7 @@ func (k Keeper) capBySlashingPeriod(ctx sdk.Context, address sdk.ConsAddress, fr
// Sanity check // Sanity check
if slashingPeriod.EndHeight > 0 && slashingPeriod.EndHeight < infractionHeight { if slashingPeriod.EndHeight > 0 && slashingPeriod.EndHeight < infractionHeight {
panic(fmt.Sprintf("slashing period ended before infraction: infraction height %d, slashing period ended at %d", infractionHeight, slashingPeriod.EndHeight)) panic(fmt.Sprintf("slashing period ended before infraction: validator %s, infraction height %d, slashing period ended at %d", address, infractionHeight, slashingPeriod.EndHeight))
} }
// Calculate the updated total slash amount // Calculate the updated total slash amount
@ -43,7 +43,7 @@ func (k Keeper) getValidatorSlashingPeriodForHeight(ctx sdk.Context, address sdk
end := sdk.PrefixEndBytes(GetValidatorSlashingPeriodKey(address, height)) end := sdk.PrefixEndBytes(GetValidatorSlashingPeriodKey(address, height))
iterator := store.ReverseIterator(start, end) iterator := store.ReverseIterator(start, end)
if !iterator.Valid() { if !iterator.Valid() {
panic("expected to find slashing period, but none was found") panic(fmt.Sprintf("expected to find slashing period for validator %s before height %d, but none was found", address, height))
} }
slashingPeriod = k.unmarshalSlashingPeriodKeyValue(iterator.Key(), iterator.Value()) slashingPeriod = k.unmarshalSlashingPeriodKeyValue(iterator.Key(), iterator.Value())
return return
@ -68,7 +68,7 @@ func (k Keeper) unmarshalSlashingPeriodKeyValue(key []byte, value []byte) Valida
var slashingPeriodValue ValidatorSlashingPeriodValue var slashingPeriodValue ValidatorSlashingPeriodValue
k.cdc.MustUnmarshalBinary(value, &slashingPeriodValue) k.cdc.MustUnmarshalBinary(value, &slashingPeriodValue)
address := sdk.ConsAddress(key[1 : 1+sdk.AddrLen]) address := sdk.ConsAddress(key[1 : 1+sdk.AddrLen])
startHeight := int64(binary.LittleEndian.Uint64(key[1+sdk.AddrLen:1+sdk.AddrLen+8]) - 1) startHeight := int64(binary.BigEndian.Uint64(key[1+sdk.AddrLen:1+sdk.AddrLen+8]) - 1)
return ValidatorSlashingPeriod{ return ValidatorSlashingPeriod{
ValidatorAddr: address, ValidatorAddr: address,
StartHeight: startHeight, StartHeight: startHeight,