From e8a936ff9d002b226657c0fece251ce55defc731 Mon Sep 17 00:00:00 2001 From: rkapka Date: Wed, 19 Apr 2023 14:01:38 +0200 Subject: [PATCH 1/3] Add support for non-blinded blocks to `ProduceBlindedBlock` --- beacon-chain/rpc/eth/validator/validator.go | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/beacon-chain/rpc/eth/validator/validator.go b/beacon-chain/rpc/eth/validator/validator.go index fd53e41e571f..2c4f6feda970 100644 --- a/beacon-chain/rpc/eth/validator/validator.go +++ b/beacon-chain/rpc/eth/validator/validator.go @@ -533,9 +533,22 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB if optimistic { return nil, status.Errorf(codes.Unavailable, "The node is currently optimistic and cannot serve validators") } - bellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedBellatrix) + bellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Bellatrix) + if ok { + blk, err := migration.V1Alpha1BeaconBlockBellatrixToV2Blinded(bellatrixBlock.Bellatrix) + if err != nil { + return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) + } + return ðpbv2.ProduceBlindedBlockResponse{ + Version: ethpbv2.Version_BELLATRIX, + Data: ðpbv2.BlindedBeaconBlockContainer{ + Block: ðpbv2.BlindedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: blk}, + }, + }, nil + } + blindedBellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedBellatrix) if ok { - blk, err := migration.V1Alpha1BeaconBlockBlindedBellatrixToV2Blinded(bellatrixBlock.BlindedBellatrix) + blk, err := migration.V1Alpha1BeaconBlockBlindedBellatrixToV2Blinded(blindedBellatrixBlock.BlindedBellatrix) if err != nil { return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) } @@ -546,9 +559,22 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB }, }, nil } - capellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedCapella) + capellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Capella) + if ok { + blk, err := migration.V1Alpha1BeaconBlockCapellaToV2Blinded(capellaBlock.Capella) + if err != nil { + return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) + } + return ðpbv2.ProduceBlindedBlockResponse{ + Version: ethpbv2.Version_CAPELLA, + Data: ðpbv2.BlindedBeaconBlockContainer{ + Block: ðpbv2.BlindedBeaconBlockContainer_CapellaBlock{CapellaBlock: blk}, + }, + }, nil + } + blindedCapellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedCapella) if ok { - blk, err := migration.V1Alpha1BeaconBlockBlindedCapellaToV2Blinded(capellaBlock.BlindedCapella) + blk, err := migration.V1Alpha1BeaconBlockBlindedCapellaToV2Blinded(blindedCapellaBlock.BlindedCapella) if err != nil { return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) } From fb0e8dbb9169f298f90040e5532cf537ec2afd93 Mon Sep 17 00:00:00 2001 From: rkapka Date: Thu, 20 Apr 2023 18:00:39 +0200 Subject: [PATCH 2/3] return errors --- beacon-chain/rpc/eth/validator/validator.go | 37 ++++++------------- .../rpc/eth/validator/validator_test.go | 9 +++++ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/beacon-chain/rpc/eth/validator/validator.go b/beacon-chain/rpc/eth/validator/validator.go index 4b678f0d8c0a..af5f5a042ffb 100644 --- a/beacon-chain/rpc/eth/validator/validator.go +++ b/beacon-chain/rpc/eth/validator/validator.go @@ -482,6 +482,9 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB ctx, span := trace.StartSpan(ctx, "validator.ProduceBlindedBlock") defer span.End() + if !vs.V1Alpha1Server.BlockBuilder.Configured() { + return nil, status.Error(codes.Internal, "Block builder not configured") + } if err := rpchelpers.ValidateSync(ctx, vs.SyncChecker, vs.HeadFetcher, vs.TimeFetcher, vs.OptimisticModeFetcher); err != nil { // We simply return the error because it's already a gRPC error. return nil, err @@ -533,22 +536,13 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB if optimistic { return nil, status.Errorf(codes.Unavailable, "The node is currently optimistic and cannot serve validators") } - bellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Bellatrix) + _, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Bellatrix) if ok { - blk, err := migration.V1Alpha1BeaconBlockBellatrixToV2Blinded(bellatrixBlock.Bellatrix) - if err != nil { - return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) - } - return ðpbv2.ProduceBlindedBlockResponse{ - Version: ethpbv2.Version_BELLATRIX, - Data: ðpbv2.BlindedBeaconBlockContainer{ - Block: ðpbv2.BlindedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: blk}, - }, - }, nil + return nil, status.Error(codes.Internal, "Prepared beacon block is not blinded") } - blindedBellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedBellatrix) + bellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedBellatrix) if ok { - blk, err := migration.V1Alpha1BeaconBlockBlindedBellatrixToV2Blinded(blindedBellatrixBlock.BlindedBellatrix) + blk, err := migration.V1Alpha1BeaconBlockBlindedBellatrixToV2Blinded(bellatrixBlock.BlindedBellatrix) if err != nil { return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) } @@ -559,22 +553,13 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB }, }, nil } - capellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Capella) + _, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Capella) if ok { - blk, err := migration.V1Alpha1BeaconBlockCapellaToV2Blinded(capellaBlock.Capella) - if err != nil { - return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) - } - return ðpbv2.ProduceBlindedBlockResponse{ - Version: ethpbv2.Version_CAPELLA, - Data: ðpbv2.BlindedBeaconBlockContainer{ - Block: ðpbv2.BlindedBeaconBlockContainer_CapellaBlock{CapellaBlock: blk}, - }, - }, nil + return nil, status.Error(codes.Internal, "Prepared beacon block is not blinded") } - blindedCapellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedCapella) + capellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedCapella) if ok { - blk, err := migration.V1Alpha1BeaconBlockBlindedCapellaToV2Blinded(blindedCapellaBlock.BlindedCapella) + blk, err := migration.V1Alpha1BeaconBlockBlindedCapellaToV2Blinded(capellaBlock.BlindedCapella) if err != nil { return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err) } diff --git a/beacon-chain/rpc/eth/validator/validator_test.go b/beacon-chain/rpc/eth/validator/validator_test.go index eeb4c7d34cff..d239ebc7b29a 100644 --- a/beacon-chain/rpc/eth/validator/validator_test.go +++ b/beacon-chain/rpc/eth/validator/validator_test.go @@ -2271,6 +2271,7 @@ func TestProduceBlindedBlock(t *testing.T) { SlashingsPool: slashings.NewPool(), ExitPool: voluntaryexits.NewPool(), StateGen: stategen.New(db, doublylinkedtree.New()), + BlockBuilder: &builderTest.MockBuilderService{HasConfigured: true}, } proposerSlashings := make([]*ethpbalpha.ProposerSlashing, params.BeaconConfig().MaxProposerSlashings) @@ -2379,6 +2380,7 @@ func TestProduceBlindedBlock(t *testing.T) { ExitPool: voluntaryexits.NewPool(), StateGen: stategen.New(db, doublylinkedtree.New()), SyncCommitteePool: synccommittee.NewStore(), + BlockBuilder: &builderTest.MockBuilderService{HasConfigured: true}, } proposerSlashings := make([]*ethpbalpha.ProposerSlashing, params.BeaconConfig().MaxProposerSlashings) @@ -3074,6 +3076,13 @@ func TestProduceBlindedBlock(t *testing.T) { _, err = v1Server.ProduceBlindedBlock(ctx, req) require.ErrorContains(t, " block was not a supported blinded block type", err) }) + t.Run("builder not configured", func(t *testing.T) { + v1Server := &Server{ + V1Alpha1Server: &v1alpha1validator.Server{BlockBuilder: &builderTest.MockBuilderService{HasConfigured: false}}, + } + _, err := v1Server.ProduceBlindedBlock(context.Background(), nil) + require.ErrorContains(t, "Block builder not configured", err) + }) } func TestProduceBlindedBlockSSZ(t *testing.T) { From 8a30593387ea83740772cfff3f0006907f04b0ce Mon Sep 17 00:00:00 2001 From: rkapka Date: Thu, 20 Apr 2023 18:34:27 +0200 Subject: [PATCH 3/3] fix tests --- beacon-chain/rpc/eth/validator/validator_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beacon-chain/rpc/eth/validator/validator_test.go b/beacon-chain/rpc/eth/validator/validator_test.go index d239ebc7b29a..fa53d3c7eb02 100644 --- a/beacon-chain/rpc/eth/validator/validator_test.go +++ b/beacon-chain/rpc/eth/validator/validator_test.go @@ -2920,7 +2920,7 @@ func TestProduceBlindedBlock(t *testing.T) { assert.DeepEqual(t, expectedBits, blk.Body.SyncAggregate.SyncCommitteeBits) assert.DeepEqual(t, aggregatedSig, blk.Body.SyncAggregate.SyncCommitteeSignature) }) - t.Run("Unsupported Block Type", func(t *testing.T) { + t.Run("full block", func(t *testing.T) { db := dbutil.SetupDB(t) ctx := context.Background() @@ -3056,7 +3056,7 @@ func TestProduceBlindedBlock(t *testing.T) { SyncCommitteePool: synccommittee.NewStore(), ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(), BlockBuilder: &builderTest.MockBuilderService{ - HasConfigured: false, + HasConfigured: true, }, } @@ -3074,7 +3074,7 @@ func TestProduceBlindedBlock(t *testing.T) { Graffiti: graffiti[:], } _, err = v1Server.ProduceBlindedBlock(ctx, req) - require.ErrorContains(t, " block was not a supported blinded block type", err) + require.ErrorContains(t, "Prepared beacon block is not blinded", err) }) t.Run("builder not configured", func(t *testing.T) { v1Server := &Server{ @@ -3911,6 +3911,7 @@ func TestProduceBlindedBlock_SyncNotReady(t *testing.T) { HeadFetcher: chainService, TimeFetcher: chainService, OptimisticModeFetcher: chainService, + V1Alpha1Server: &v1alpha1validator.Server{BlockBuilder: &builderTest.MockBuilderService{HasConfigured: true}}, } _, err = vs.ProduceBlindedBlock(context.Background(), ðpbv1.ProduceBlockRequest{}) assert.ErrorContains(t, "Syncing to latest head, not ready to respond", err)