Compare commits

...

18 Commits

Author SHA1 Message Date
Raul Jordan
1a03981e29 Merge branch 'develop' into unify-slasher-e2e 2022-06-29 17:01:21 -04:00
Raul Jordan
952d0f2aa3 Merge branch 'unify-slasher-e2e' of github.com:prysmaticlabs/prysm into unify-slasher-e2e 2022-06-27 16:39:43 -04:00
Raul Jordan
b9d65da9b5 check 2022-06-27 16:39:37 -04:00
prylabs-bulldozer[bot]
ecd87610e5 Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 19:54:33 +00:00
Raul Jordan
3557f78746 test param fixes 2022-06-27 15:11:00 -04:00
prylabs-bulldozer[bot]
d386571766 Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 18:27:56 +00:00
prylabs-bulldozer[bot]
aeda04290e Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 16:32:44 +00:00
prylabs-bulldozer[bot]
d393d3f0fd Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 15:25:39 +00:00
prylabs-bulldozer[bot]
a9dfbd19f7 Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 14:19:49 +00:00
prylabs-bulldozer[bot]
b5f0465fb4 Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 13:34:45 +00:00
prylabs-bulldozer[bot]
0df4a695df Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 11:19:45 +00:00
prylabs-bulldozer[bot]
bfc6b49058 Merge refs/heads/develop into unify-slasher-e2e 2022-06-27 10:50:22 +00:00
prylabs-bulldozer[bot]
9f59201e93 Merge refs/heads/develop into unify-slasher-e2e 2022-06-25 03:57:57 +00:00
Raul Jordan
26ff9b15fc Merge branch 'unify-slasher-e2e' of github.com:prysmaticlabs/prysm into unify-slasher-e2e 2022-06-24 12:25:41 -06:00
Raul Jordan
b4c42013d2 ignore slashed in evaluator 2022-06-24 12:25:07 -06:00
prylabs-bulldozer[bot]
99a1c517bd Merge refs/heads/develop into unify-slasher-e2e 2022-06-24 18:07:36 +00:00
prylabs-bulldozer[bot]
dbb9bb2a1e Merge refs/heads/develop into unify-slasher-e2e 2022-06-24 17:22:43 +00:00
Raul Jordan
f61efb3c61 unify slasher e2e test 2022-06-24 11:15:42 -06:00
5 changed files with 48 additions and 54 deletions

View File

@@ -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"],

View File

@@ -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",

View File

@@ -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 := &eth.GetValidatorRequest{
QueryFilter: &eth.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
}

View File

@@ -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++
}

View File

@@ -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()
}