mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Compare commits
18 Commits
terence_re
...
unify-slas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a03981e29 | ||
|
|
952d0f2aa3 | ||
|
|
b9d65da9b5 | ||
|
|
ecd87610e5 | ||
|
|
3557f78746 | ||
|
|
d386571766 | ||
|
|
aeda04290e | ||
|
|
d393d3f0fd | ||
|
|
a9dfbd19f7 | ||
|
|
b5f0465fb4 | ||
|
|
0df4a695df | ||
|
|
bfc6b49058 | ||
|
|
9f59201e93 | ||
|
|
26ff9b15fc | ||
|
|
b4c42013d2 | ||
|
|
99a1c517bd | ||
|
|
dbb9bb2a1e | ||
|
|
f61efb3c61 |
@@ -52,7 +52,6 @@ go_test(
|
||||
"endtoend_setup_test.go",
|
||||
"endtoend_test.go",
|
||||
"minimal_e2e_test.go",
|
||||
"minimal_slashing_e2e_test.go",
|
||||
"slasher_simulator_e2e_test.go",
|
||||
],
|
||||
args = ["-test.v"],
|
||||
|
||||
@@ -40,8 +40,12 @@ func e2eMinimal(t *testing.T, cfgo ...types.E2EConfigOpt) *testRunner {
|
||||
ev.HealthzCheck,
|
||||
ev.MetricsCheck,
|
||||
ev.ValidatorsAreActive,
|
||||
ev.InjectDoubleVoteOnEpoch(2),
|
||||
ev.InjectDoubleBlockOnEpoch(2),
|
||||
ev.ValidatorsParticipatingAtEpoch(2),
|
||||
ev.FinalizationOccurs(3),
|
||||
ev.ValidatorsSlashedAfterEpoch(4),
|
||||
ev.SlashedValidatorsLoseBalanceAfterEpoch(5),
|
||||
ev.VerifyBlockGraffiti,
|
||||
ev.PeersCheck,
|
||||
ev.ProposeVoluntaryExit,
|
||||
@@ -62,6 +66,7 @@ func e2eMinimal(t *testing.T, cfgo ...types.E2EConfigOpt) *testRunner {
|
||||
}
|
||||
testConfig := &types.E2EConfig{
|
||||
BeaconFlags: []string{
|
||||
"--slasher",
|
||||
fmt.Sprintf("--slots-per-archive-point=%d", params.BeaconConfig().SlotsPerEpoch*16),
|
||||
fmt.Sprintf("--tracing-endpoint=http://%s", tracingEndpoint),
|
||||
"--enable-tracing",
|
||||
|
||||
@@ -3,6 +3,7 @@ package evaluators
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
@@ -57,6 +58,7 @@ var SlashedValidatorsLoseBalanceAfterEpoch = func(n types.Epoch) e2eTypes.Evalua
|
||||
}
|
||||
}
|
||||
|
||||
var slashedIndicesLock sync.RWMutex
|
||||
var slashedIndices []uint64
|
||||
|
||||
func validatorsSlashed(conns ...*grpc.ClientConn) error {
|
||||
@@ -68,8 +70,16 @@ func validatorsSlashed(conns ...*grpc.ClientConn) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slashedIndicesLock.RLock()
|
||||
defer slashedIndicesLock.RUnlock()
|
||||
if len(changes.SlashedIndices) != len(slashedIndices) {
|
||||
return fmt.Errorf("expected %d indices to be slashed, received %d", len(slashedIndices), len(changes.SlashedIndices))
|
||||
return fmt.Errorf(
|
||||
"expected %d (%v) indices to be slashed, received %d (%v)",
|
||||
len(slashedIndices),
|
||||
slashedIndices,
|
||||
len(changes.SlashedIndices),
|
||||
changes.SlashedIndices,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -79,7 +89,9 @@ func validatorsLoseBalance(conns ...*grpc.ClientConn) error {
|
||||
ctx := context.Background()
|
||||
client := eth.NewBeaconChainClient(conn)
|
||||
|
||||
for i, slashedIndex := range slashedIndices {
|
||||
slashedIndicesLock.RLock()
|
||||
defer slashedIndicesLock.RUnlock()
|
||||
for _, slashedIndex := range slashedIndices {
|
||||
req := ð.GetValidatorRequest{
|
||||
QueryFilter: ð.GetValidatorRequest_Index{
|
||||
Index: types.ValidatorIndex(slashedIndex),
|
||||
@@ -95,7 +107,7 @@ func validatorsLoseBalance(conns ...*grpc.ClientConn) error {
|
||||
if valResp.EffectiveBalance >= slashedBal {
|
||||
return fmt.Errorf(
|
||||
"expected slashed validator %d to balance less than %d, received %d",
|
||||
i,
|
||||
slashedIndex,
|
||||
slashedBal,
|
||||
valResp.EffectiveBalance,
|
||||
)
|
||||
@@ -167,6 +179,8 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error {
|
||||
return errors.Wrap(err, "could not compute signing root")
|
||||
}
|
||||
|
||||
slashedIndicesLock.Lock()
|
||||
defer slashedIndicesLock.Unlock()
|
||||
valsToSlash := uint64(2)
|
||||
for i := uint64(0); i < valsToSlash && i < uint64(len(committee)); i++ {
|
||||
if len(slice.IntersectionUint64(slashedIndices, []uint64{uint64(committee[i])})) > 0 {
|
||||
@@ -285,6 +299,8 @@ func proposeDoubleBlock(conns ...*grpc.ClientConn) error {
|
||||
if _, err = valClient.ProposeBlock(ctx, signedBlk); err == nil {
|
||||
return errors.New("expected block to fail processing")
|
||||
}
|
||||
slashedIndicesLock.Lock()
|
||||
slashedIndices = append(slashedIndices, uint64(proposerIndex))
|
||||
slashedIndicesLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,19 +62,37 @@ func validatorsAreActive(conns ...*grpc.ClientConn) error {
|
||||
return errors.Wrap(err, "failed to get validators")
|
||||
}
|
||||
|
||||
expectedCount := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
receivedCount := uint64(len(validators.ValidatorList))
|
||||
if expectedCount != receivedCount {
|
||||
return fmt.Errorf("expected validator count to be %d, recevied %d", expectedCount, receivedCount)
|
||||
}
|
||||
|
||||
effBalanceLowCount := 0
|
||||
exitEpochWrongCount := 0
|
||||
withdrawEpochWrongCount := 0
|
||||
|
||||
validatorSlashedSoFar := make(map[ethtypes.ValidatorIndex]bool)
|
||||
slashedIndicesLock.RLock()
|
||||
for _, valIdx := range slashedIndices {
|
||||
validatorSlashedSoFar[ethtypes.ValidatorIndex(valIdx)] = true
|
||||
}
|
||||
slashedIndicesLock.RUnlock()
|
||||
|
||||
expectedCount := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
receivedCount := uint64(len(validators.ValidatorList))
|
||||
|
||||
// Subtract the slashed indices from the expected active number of validators.
|
||||
expectedCount -= uint64(len(slashedIndices))
|
||||
|
||||
// Although we may have triggered slashed validator indices, sometimes the slashing itself does not
|
||||
// trigger until some time later. We account for this discrepancy in the check below.
|
||||
if receivedCount != expectedCount && receivedCount != expectedCount-uint64(len(slashedIndices)) {
|
||||
return fmt.Errorf("received incorrect active validator count %d", receivedCount)
|
||||
}
|
||||
for _, item := range validators.ValidatorList {
|
||||
// Ignore exited validators in the computation.
|
||||
if valExited && item.Index == exitedIndex {
|
||||
continue
|
||||
}
|
||||
// Ignore slashed validators in the computation.
|
||||
if validatorSlashedSoFar[item.Index] {
|
||||
continue
|
||||
}
|
||||
if item.Validator.EffectiveBalance < params.BeaconConfig().MaxEffectiveBalance {
|
||||
effBalanceLowCount++
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package endtoend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
ev "github.com/prysmaticlabs/prysm/testing/endtoend/evaluators"
|
||||
e2eParams "github.com/prysmaticlabs/prysm/testing/endtoend/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/endtoend/types"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestEndToEnd_Slasher_MinimalConfig(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.E2ETestConfig().Copy())
|
||||
require.NoError(t, e2eParams.Init(t, e2eParams.StandardBeaconCount))
|
||||
|
||||
tracingPort := e2eParams.TestParams.Ports.JaegerTracingPort
|
||||
tracingEndpoint := fmt.Sprintf("127.0.0.1:%d", tracingPort)
|
||||
|
||||
testConfig := &types.E2EConfig{
|
||||
BeaconFlags: []string{
|
||||
"--slasher",
|
||||
},
|
||||
ValidatorFlags: []string{},
|
||||
EpochsToRun: 4,
|
||||
TestSync: false,
|
||||
TestFeature: false,
|
||||
TestDeposits: false,
|
||||
Evaluators: []types.Evaluator{
|
||||
ev.PeersConnect,
|
||||
ev.HealthzCheck,
|
||||
ev.ValidatorsSlashedAfterEpoch(4),
|
||||
ev.SlashedValidatorsLoseBalanceAfterEpoch(4),
|
||||
ev.InjectDoubleVoteOnEpoch(2),
|
||||
ev.InjectDoubleBlockOnEpoch(2),
|
||||
},
|
||||
EvalInterceptor: defaultInterceptor,
|
||||
TracingSinkEndpoint: tracingEndpoint,
|
||||
}
|
||||
|
||||
newTestRunner(t, testConfig).run()
|
||||
}
|
||||
Reference in New Issue
Block a user