Fix the TestEndToEnd_Slasher_MinimalConfig test (#12116)

* WIP

* WIP

* WIP

---------

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
Patrice Vignola
2023-03-15 12:15:46 -07:00
committed by GitHub
parent 2669c93375
commit 3802761088
3 changed files with 57 additions and 20 deletions

View File

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

View File

@@ -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"
@@ -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
}
@@ -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{
@@ -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{
@@ -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
return nil, err
}
b, err := wb.PbGenericBlock()
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
return wb.PbGenericBlock()
}

View File

@@ -24,7 +24,7 @@ func TestEndToEnd_Slasher_MinimalConfig(t *testing.T) {
"--slasher",
},
ValidatorFlags: []string{},
EpochsToRun: 4,
EpochsToRun: 6,
TestSync: false,
TestFeature: false,
TestDeposits: false,