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

Fix the TestEndToEnd_Slasher_MinimalConfig test #12116

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 testing/endtoend/evaluators/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//container/slice:go_default_library",
"//crypto/bls:go_default_library",
"//encoding/bytesutil:go_default_library",
"//encoding/ssz/detect:go_default_library",
"//math:go_default_library",
Expand Down
74 changes: 55 additions & 19 deletions testing/endtoend/evaluators/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/container/slice"
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
e2e "github.com/prysmaticlabs/prysm/v3/testing/endtoend/params"
Expand Down Expand Up @@ -64,13 +65,27 @@ func validatorsSlashed(_ *e2eTypes.EvaluationContext, conns ...*grpc.ClientConn)
conn := conns[0]
ctx := context.Background()
client := eth.NewBeaconChainClient(conn)
req := &eth.GetValidatorActiveSetChangesRequest{}
changes, err := client.GetValidatorActiveSetChanges(ctx, req)
if err != nil {
return err

actualSlashedIndices := 0

for _, slashedIndex := range slashedIndices {
req := &eth.GetValidatorRequest{
QueryFilter: &eth.GetValidatorRequest_Index{
Index: primitives.ValidatorIndex(slashedIndex),
},
}
valResp, err := client.GetValidator(ctx, req)
if err != nil {
return err
}

if valResp.Slashed {
actualSlashedIndices++
}
}
if len(changes.SlashedIndices) != len(slashedIndices) {
return fmt.Errorf("expected %d indices to be slashed, received %d", len(slashedIndices), len(changes.SlashedIndices))

if actualSlashedIndices != len(slashedIndices) {
return fmt.Errorf("expected %d indices to be slashed, received %d", len(slashedIndices), actualSlashedIndices)
}
return nil
}
Expand Down Expand Up @@ -241,11 +256,40 @@ func proposeDoubleBlock(_ *e2eTypes.EvaluationContext, conns ...*grpc.ClientConn
valClient = eth.NewBeaconNodeValidatorClient(conns[1])
}

b, err := generateSignedBeaconBlock(chainHead, proposerIndex, valClient, privKeys, "bad state root")
if err != nil {
return err
}
if _, err = valClient.ProposeBeaconBlock(ctx, b); err == nil {
return errors.New("expected block to fail processing")
}

b, err = generateSignedBeaconBlock(chainHead, proposerIndex, valClient, privKeys, "bad state root 2")
if err != nil {
return err
}
if _, err = valClient.ProposeBeaconBlock(ctx, b); err == nil {
return errors.New("expected block to fail processing")
}

slashedIndices = append(slashedIndices, uint64(proposerIndex))
return nil
}

func generateSignedBeaconBlock(
chainHead *eth.ChainHead,
proposerIndex primitives.ValidatorIndex,
valClient eth.BeaconNodeValidatorClient,
privKeys []bls.SecretKey,
stateRoot string,
) (*eth.GenericSignedBeaconBlock, error) {
ctx := context.Background()

hashLen := 32
blk := &eth.BeaconBlock{
Slot: chainHead.HeadSlot + 1,
ParentRoot: chainHead.HeadBlockRoot,
StateRoot: bytesutil.PadTo([]byte("bad state root"), hashLen),
StateRoot: bytesutil.PadTo([]byte(stateRoot), hashLen),
ProposerIndex: proposerIndex,
Body: &eth.BeaconBlockBody{
Eth1Data: &eth.Eth1Data{
Expand All @@ -269,11 +313,11 @@ func proposeDoubleBlock(_ *e2eTypes.EvaluationContext, conns ...*grpc.ClientConn
}
resp, err := valClient.DomainData(ctx, req)
if err != nil {
return errors.Wrap(err, "could not get domain data")
return nil, errors.Wrap(err, "could not get domain data")
}
signingRoot, err := signing.ComputeSigningRoot(blk, resp.SignatureDomain)
if err != nil {
return errors.Wrap(err, "could not compute signing root")
return nil, errors.Wrap(err, "could not compute signing root")
}
sig := privKeys[proposerIndex].Sign(signingRoot[:]).Marshal()
signedBlk := &eth.SignedBeaconBlock{
Expand All @@ -285,15 +329,7 @@ func proposeDoubleBlock(_ *e2eTypes.EvaluationContext, conns ...*grpc.ClientConn
// Only broadcasting the attestation to one node also helps test slashing propagation.
wb, err := blocks.NewSignedBeaconBlock(signedBlk)
if err != nil {
return err
}
b, err := wb.PbGenericBlock()
if err != nil {
return err
return nil, err
}
if _, err = valClient.ProposeBeaconBlock(ctx, b); err == nil {
return errors.New("expected block to fail processing")
}
slashedIndices = append(slashedIndices, uint64(proposerIndex))
return nil
return wb.PbGenericBlock()
}
2 changes: 1 addition & 1 deletion testing/endtoend/minimal_slashing_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestEndToEnd_Slasher_MinimalConfig(t *testing.T) {
"--slasher",
},
ValidatorFlags: []string{},
EpochsToRun: 4,
EpochsToRun: 6,
TestSync: false,
TestFeature: false,
TestDeposits: false,
Expand Down