Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Aggressive slashing simulation & fixes #2430

Merged
merged 58 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
77a0041
Work in progress
cwgoes Sep 11, 2018
af1cb43
Isolate iteration issue
cwgoes Sep 11, 2018
546b5f3
Merge branch 'develop' into cwgoes/fix-slashing-period-fetch
cwgoes Sep 12, 2018
19080d0
pulling in issue code
rigelrozanski Sep 25, 2018
6c78ac7
Merge remote-tracking branch 'origin/develop' into rigel/stake-refactor
rigelrozanski Sep 26, 2018
1aa65e4
replace ensureValidatorFound with mustGetValidator
rigelrozanski Sep 26, 2018
8d394f6
split up keeper/validator.go
rigelrozanski Sep 26, 2018
8373329
move validatorByPowerIndexExists from keeper to test file
rigelrozanski Sep 26, 2018
b6575bb
reorganizing
rigelrozanski Sep 26, 2018
52c413f
GetValidatorsByPower -> GetBondedValidatorsByPower
rigelrozanski Sep 26, 2018
7debae0
remove duplicate SetValidator in handleMsgEditValidator
rigelrozanski Sep 26, 2018
e838a02
Added missing by-power index at validator creation
rigelrozanski Sep 26, 2018
0e91227
removed codebase use of UpdateValidator
rigelrozanski Sep 26, 2018
cd9a9fb
SetParams now doesnt update validator set as happens at endblock
rigelrozanski Sep 26, 2018
76f18fd
got non-test code compiling
rigelrozanski Sep 26, 2018
eec5f42
Merge branch 'develop' into rigel/stake-refactor
cwgoes Sep 27, 2018
54098df
Remove old code, minor cleanup of existing work
cwgoes Sep 27, 2018
2fa6b1c
Merge branch 'develop' into rigel/stake-refactor
cwgoes Sep 27, 2018
b1d6384
Merge branch 'cwgoes/update-tendermint-upstream' into rigel/stake-ref…
cwgoes Sep 27, 2018
e2200a2
Fixes from merge
cwgoes Sep 27, 2018
174b321
Pseudocode to real-ish code
cwgoes Sep 27, 2018
715ad04
Remove cliff validator key (no longer used)
cwgoes Sep 27, 2018
ba3c1f5
GetTendermintUpdates continued
cwgoes Sep 28, 2018
ebc59ae
Works with simulation
cwgoes Sep 28, 2018
09c43d5
Merge branch 'develop' into rigel/stake-refactor
cwgoes Oct 1, 2018
cfb12da
Refactor testcases in progress
cwgoes Oct 1, 2018
77c2cc8
Testcase fixes in progress
cwgoes Oct 1, 2018
123bc06
Minor fixes
cwgoes Oct 1, 2018
6d4af75
Testcase fixes contd...
cwgoes Oct 1, 2018
d8f2656
Fix slashing tests (just adding stake.EndBlocker calls)
cwgoes Oct 1, 2018
a12cda1
Fix more testcases
cwgoes Oct 1, 2018
0c1ddec
Unit tests as far as the eye can see
cwgoes Oct 1, 2018
c7cac2d
Update PENDING.md
cwgoes Oct 1, 2018
de0decc
Merge branch 'cwgoes/update-tendermint-upstream' into rigel/stake-ref…
cwgoes Oct 1, 2018
7d82281
Address review comments, round one
cwgoes Oct 2, 2018
b96faf6
dep update, rename to clarify that function applies state changes
cwgoes Oct 2, 2018
dbd2c0a
Split up function for clarity
cwgoes Oct 2, 2018
54d5ce8
Remove jailed validators from the power store entirely
cwgoes Oct 2, 2018
413fa42
Remove redundant bonded validator store
cwgoes Oct 2, 2018
1c1183a
Fix simulator bug
cwgoes Oct 2, 2018
951cacc
Change key name to reflect usage
cwgoes Oct 2, 2018
8e67f6d
updateValidator -> testingUpdateValidator
cwgoes Oct 3, 2018
94b0ca9
'make format'
cwgoes Oct 3, 2018
5893e23
Address @rigelrozanski comments
cwgoes Oct 3, 2018
4102f76
Validator might already be jailed
cwgoes Oct 3, 2018
a1c9cd8
Update PENDING.md
cwgoes Oct 3, 2018
3902cf2
Merge branch 'cwgoes/fix-slashing-period-fetch' into cwgoes/aggressiv…
cwgoes Oct 3, 2018
b119a54
Use a KVStoreReversePrefixIterator instead
cwgoes Oct 3, 2018
1ad577b
Merge branch 'develop' into rigel/stake-refactor
cwgoes Oct 3, 2018
4a4e9d1
Merge branch 'rigel/stake-refactor' into cwgoes/aggressive-slashing-s…
cwgoes Oct 3, 2018
00e050d
Merge branch 'develop' into cwgoes/aggressive-slashing-simulation
cwgoes Oct 3, 2018
9a4249e
Undo accidental merge changes
cwgoes Oct 3, 2018
9d87707
Merge branch 'develop' into cwgoes/aggressive-slashing-simulation
cwgoes Oct 4, 2018
4c60529
Merge branch 'cwgoes/nextvalset' into cwgoes/aggressive-slashing-simu…
cwgoes Oct 5, 2018
a4277ed
Merge branch 'cwgoes/nextvalset' into cwgoes/aggressive-slashing-simu…
cwgoes Oct 5, 2018
c50a29b
Height must be stored big-endian (duh)
cwgoes Oct 5, 2018
c629be9
Big endian, more simulation seeds
cwgoes Oct 5, 2018
7e59454
More sleep on the multi-sim
cwgoes Oct 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should randomize this. Also .5 seems a bit too high lol.

Setting a high evidence fraction isn't sufficient tho, since it executes a different code path than liveness (Or in this bloxk) slashes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't block this PR, it lgtm!


// 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