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

Return errors from ProduceBlindedBlock #12309

Merged
merged 8 commits into from
Apr 21, 2023
11 changes: 11 additions & 0 deletions beacon-chain/rpc/eth/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -533,6 +536,10 @@ 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")
}
_, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Bellatrix)
if ok {
return nil, status.Error(codes.Internal, "Prepared beacon block is not blinded")
}
bellatrixBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedBellatrix)
if ok {
blk, err := migration.V1Alpha1BeaconBlockBlindedBellatrixToV2Blinded(bellatrixBlock.BlindedBellatrix)
Expand All @@ -546,6 +553,10 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB
},
}, nil
}
_, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Capella)
if ok {
return nil, status.Error(codes.Internal, "Prepared beacon block is not blinded")
}
capellaBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedCapella)
if ok {
blk, err := migration.V1Alpha1BeaconBlockBlindedCapellaToV2Blinded(capellaBlock.BlindedCapella)
Expand Down
16 changes: 13 additions & 3 deletions beacon-chain/rpc/eth/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2918,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()

Expand Down Expand Up @@ -3054,7 +3056,7 @@ func TestProduceBlindedBlock(t *testing.T) {
SyncCommitteePool: synccommittee.NewStore(),
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
BlockBuilder: &builderTest.MockBuilderService{
HasConfigured: false,
HasConfigured: true,
},
}

Expand All @@ -3072,7 +3074,14 @@ 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{
V1Alpha1Server: &v1alpha1validator.Server{BlockBuilder: &builderTest.MockBuilderService{HasConfigured: false}},
}
_, err := v1Server.ProduceBlindedBlock(context.Background(), nil)
require.ErrorContains(t, "Block builder not configured", err)
})
}

Expand Down Expand Up @@ -3902,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(), &ethpbv1.ProduceBlockRequest{})
assert.ErrorContains(t, "Syncing to latest head, not ready to respond", err)
Expand Down