From 48457309555631884af7b4e85fee5eab9653f7e8 Mon Sep 17 00:00:00 2001 From: nisdas Date: Fri, 2 Dec 2022 18:31:33 +0800 Subject: [PATCH] add check and test case --- .../sync/validate_bls_to_execution_change.go | 6 +++ .../validate_bls_to_execution_change_test.go | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/beacon-chain/sync/validate_bls_to_execution_change.go b/beacon-chain/sync/validate_bls_to_execution_change.go index fba805906ba3..c55dfa1331a4 100644 --- a/beacon-chain/sync/validate_bls_to_execution_change.go +++ b/beacon-chain/sync/validate_bls_to_execution_change.go @@ -8,6 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/monitoring/tracing" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v3/runtime/version" "go.opencensus.io/trace" ) @@ -45,6 +46,11 @@ func (s *Service) validateBlsToExecutionChange(ctx context.Context, pid peer.ID, if err != nil { return pubsub.ValidationIgnore, err } + // Ignore messages if our current head state doesn't support + // capella. + if st.Version() < version.Capella { + return pubsub.ValidationIgnore, nil + } // Validate that the execution change object is valid. _, err = blocks.ValidateBLSToExecutionChange(st, blsChange) if err != nil { diff --git a/beacon-chain/sync/validate_bls_to_execution_change_test.go b/beacon-chain/sync/validate_bls_to_execution_change_test.go index 7a743fc5e6e7..1f5443996edc 100644 --- a/beacon-chain/sync/validate_bls_to_execution_change_test.go +++ b/beacon-chain/sync/validate_bls_to_execution_change_test.go @@ -147,6 +147,43 @@ func TestService_ValidateBlsToExecutionChange(t *testing.T) { }}, want: pubsub.ValidationIgnore, }, + { + name: "Non-capella Head state", + svc: NewService(context.Background(), + WithP2P(mockp2p.NewTestP2P(t)), + WithInitialSync(&mockSync.Sync{IsSyncing: false}), + WithChainService(chainService), + WithStateNotifier(chainService.StateNotifier()), + WithOperationNotifier(chainService.OperationNotifier()), + WithBlsToExecPool(blstoexec.NewPool()), + ), + setupSvc: func(s *Service, msg *ethpb.SignedBLSToExecutionChange, topic string) (*Service, string) { + s.cfg.stateGen = stategen.New(beaconDB, doublylinkedtree.New()) + s.cfg.beaconDB = beaconDB + s.initCaches() + st, _ := util.DeterministicGenesisStateBellatrix(t, 128) + s.cfg.chain = &mockChain.ChainService{ + ValidatorsRoot: [32]byte{'A'}, + Genesis: time.Now().Add(-time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Duration(10)), + State: st, + } + + return s, topic + }, + args: args{ + ctx: context.Background(), + pid: "random", + topic: fmt.Sprintf(defaultTopic, fakeDigest), + msg: ðpb.SignedBLSToExecutionChange{ + Message: ðpb.BLSToExecutionChange{ + ValidatorIndex: 0, + FromBlsPubkey: make([]byte, 48), + ToExecutionAddress: make([]byte, 20), + }, + Signature: emptySig[:], + }}, + want: pubsub.ValidationIgnore, + }, { name: "Non-existent Validator Index", svc: NewService(context.Background(),