Skip to content

Commit

Permalink
Merge PR #2430: Aggressive slashing simulation & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored Oct 5, 2018
1 parent b7cb2e4 commit 482537e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ BREAKING CHANGES
* [x/gov] [#2195] Governance uses BFT Time
* [x/gov] \#2256 Removed slashing for governance non-voting validators
* [simulation] \#2162 Added back correct supply invariants
* [x/slashing] \#2430 Simulate more slashes, check if validator is jailed before jailing

* SDK
* [core] \#2219 Update to Tendermint 0.24.0
Expand Down
9 changes: 5 additions & 4 deletions scripts/multisim.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/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

echo "Running multi-seed simulation with seeds ${seeds[@]}"
Expand Down Expand Up @@ -28,7 +28,7 @@ for seed in ${seeds[@]}; do
sim $seed &
pids[${i}]=$!
i=$(($i+1))
sleep 5 # start in order, nicer logs
sleep 10 # start in order, nicer logs
done

echo "Simulation processes spawned, waiting for completion..."
Expand All @@ -40,11 +40,12 @@ for pid in ${pids[*]}; do
wait $pid
last=$?
seed=${seeds[${i}]}
if [ $last -ne 0 ]; then
if [ $last -ne 0 ]
then
echo "Simulation with seed $seed failed!"
code=1
else
echo "Simulation with seed $seed OK!"
echo "Simulation with seed $seed OK"
fi
i=$(($i+1))
done
Expand Down
2 changes: 1 addition & 1 deletion x/mock/simulation/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
numKeys int = 250

// 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
onOperation bool = false
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
k.validatorSet.Jail(ctx, consAddr)
}

// Set validator jail duration
// Set or updated validator jail duration
signInfo, found := k.getValidatorSigningInfo(ctx, consAddr)
if !found {
panic(fmt.Sprintf("Expected signing info for validator %s but not found", consAddr))
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
b := make([]byte, 8)
// 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...)
}

Expand Down
6 changes: 3 additions & 3 deletions x/slashing/slashing_period.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k Keeper) capBySlashingPeriod(ctx sdk.Context, address sdk.ConsAddress, fr

// Sanity check
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
Expand Down Expand Up @@ -43,7 +43,7 @@ func (k Keeper) getValidatorSlashingPeriodForHeight(ctx sdk.Context, address sdk
end := sdk.PrefixEndBytes(GetValidatorSlashingPeriodKey(address, height))
iterator := store.ReverseIterator(start, end)
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())
return
Expand All @@ -68,7 +68,7 @@ func (k Keeper) unmarshalSlashingPeriodKeyValue(key []byte, value []byte) Valida
var slashingPeriodValue ValidatorSlashingPeriodValue
k.cdc.MustUnmarshalBinary(value, &slashingPeriodValue)
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{
ValidatorAddr: address,
StartHeight: startHeight,
Expand Down

0 comments on commit 482537e

Please sign in to comment.