mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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:
@@ -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",
|
||||
|
||||
@@ -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 := ð.GetValidatorActiveSetChangesRequest{}
|
||||
changes, err := client.GetValidatorActiveSetChanges(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
actualSlashedIndices := 0
|
||||
|
||||
for _, slashedIndex := range slashedIndices {
|
||||
req := ð.GetValidatorRequest{
|
||||
QueryFilter: ð.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 := ð.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: ð.BeaconBlockBody{
|
||||
Eth1Data: ð.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 := ð.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()
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestEndToEnd_Slasher_MinimalConfig(t *testing.T) {
|
||||
"--slasher",
|
||||
},
|
||||
ValidatorFlags: []string{},
|
||||
EpochsToRun: 4,
|
||||
EpochsToRun: 6,
|
||||
TestSync: false,
|
||||
TestFeature: false,
|
||||
TestDeposits: false,
|
||||
|
||||
Reference in New Issue
Block a user