Skip to content

Commit

Permalink
adding ssz handling to produce block endpoint for deneb (#12632)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-prysm authored and prestonvanloon committed Aug 24, 2023
1 parent 41623ce commit bb0296f
Show file tree
Hide file tree
Showing 8 changed files with 1,364 additions and 697 deletions.
4 changes: 2 additions & 2 deletions beacon-chain/rpc/eth/beacon/blinded_blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func TestServer_GetBlindedBlock(t *testing.T) {
require.NoError(t, err)
resp, err := bs.GetBlindedBlock(ctx, &ethpbv1.BlockRequest{})
require.NoError(t, err)
capellaBlock, ok := resp.Data.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_DenebBlock)
denebBlock, ok := resp.Data.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_DenebBlock)
require.Equal(t, true, ok)
assert.DeepEqual(t, expected, capellaBlock.DenebBlock)
assert.DeepEqual(t, expected, denebBlock.DenebBlock)
assert.Equal(t, ethpbv2.Version_DENEB, resp.Version)
})
t.Run("execution optimistic", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/eth/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ go_test(
"//network/http:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/migration:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/assert:go_default_library",
"//testing/mock:go_default_library",
Expand Down
82 changes: 82 additions & 0 deletions beacon-chain/rpc/eth/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,27 @@ func (vs *Server) ProduceBlockV2(ctx context.Context, req *ethpbv1.ProduceBlockR
},
}, nil
}
_, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedDeneb)
if ok {
return nil, status.Error(codes.Internal, "Prepared Deneb beacon block contents are blinded")
}
denebBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Deneb)
if ok {
blockAndBlobs, err := migration.V1Alpha1BeaconBlockDenebAndBlobsToV2(denebBlock.Deneb)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not prepare beacon block contents: %v", err)
}
return &ethpbv2.ProduceBlockResponseV2{
Version: ethpbv2.Version_DENEB,
Data: &ethpbv2.BeaconBlockContainerV2{
Block: &ethpbv2.BeaconBlockContainerV2_DenebContents{
DenebContents: &ethpbv2.BeaconBlockContentsDeneb{
Block: blockAndBlobs.Block,
BlobSidecars: blockAndBlobs.BlobSidecars,
}},
},
}, nil
}
return nil, status.Error(codes.InvalidArgument, "Unsupported block type")
}

Expand Down Expand Up @@ -492,6 +513,27 @@ func (vs *Server) ProduceBlockV2SSZ(ctx context.Context, req *ethpbv1.ProduceBlo
Data: sszBlock,
}, nil
}

_, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedDeneb)
if ok {
return nil, status.Error(codes.Internal, "Prepared Deneb beacon blockcontent is blinded")
}
denebBlockcontent, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Deneb)
if ok {
blockContent, err := migration.V1Alpha1BeaconBlockDenebAndBlobsToV2(denebBlockcontent.Deneb)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err)
}
sszBlock, err := blockContent.MarshalSSZ()
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not marshal block into SSZ format: %v", err)
}
return &ethpbv2.SSZContainer{
Version: ethpbv2.Version_DENEB,
Data: sszBlock,
}, nil
}

return nil, status.Error(codes.InvalidArgument, "Unsupported block type")
}

Expand Down Expand Up @@ -593,6 +635,27 @@ func (vs *Server) ProduceBlindedBlock(ctx context.Context, req *ethpbv1.ProduceB
},
}, nil
}
_, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Deneb)
if ok {
return nil, status.Error(codes.Internal, "Prepared Deneb beacon block contents are not blinded")
}
denebBlock, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedDeneb)
if ok {
blockAndBlobs, err := migration.V1Alpha1BlindedBlockAndBlobsDenebToV2Blinded(denebBlock.BlindedDeneb)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not prepare beacon block contents: %v", err)
}
return &ethpbv2.ProduceBlindedBlockResponse{
Version: ethpbv2.Version_DENEB,
Data: &ethpbv2.BlindedBeaconBlockContainer{
Block: &ethpbv2.BlindedBeaconBlockContainer_DenebContents{
DenebContents: &ethpbv2.BlindedBeaconBlockContentsDeneb{
BlindedBlock: blockAndBlobs.BlindedBlock,
BlindedBlobSidecars: blockAndBlobs.BlindedBlobSidecars,
}},
},
}, nil
}
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("block was not a supported blinded block type, validator may not be registered if using a relay. received: %T", v1alpha1resp.Block))
}

Expand Down Expand Up @@ -700,6 +763,25 @@ func (vs *Server) ProduceBlindedBlockSSZ(ctx context.Context, req *ethpbv1.Produ
Data: sszBlock,
}, nil
}
_, ok = v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_Deneb)
if ok {
return nil, status.Error(codes.Internal, "Prepared Deneb beacon block content is not blinded")
}
denebBlockcontent, ok := v1alpha1resp.Block.(*ethpbalpha.GenericBeaconBlock_BlindedDeneb)
if ok {
blockContent, err := migration.V1Alpha1BlindedBlockAndBlobsDenebToV2Blinded(denebBlockcontent.BlindedDeneb)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not prepare beacon block: %v", err)
}
sszBlock, err := blockContent.MarshalSSZ()
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not marshal block into SSZ format: %v", err)
}
return &ethpbv2.SSZContainer{
Version: ethpbv2.Version_DENEB,
Data: sszBlock,
}, nil
}
return nil, status.Error(codes.InvalidArgument, "Unsupported block type")
}

Expand Down
Loading

0 comments on commit bb0296f

Please sign in to comment.