diff --git a/beacon-chain/rpc/eth/beacon/blinded_blocks.go b/beacon-chain/rpc/eth/beacon/blinded_blocks.go index 537360a84b79..bb82a1c00620 100644 --- a/beacon-chain/rpc/eth/beacon/blinded_blocks.go +++ b/beacon-chain/rpc/eth/beacon/blinded_blocks.go @@ -142,32 +142,25 @@ func (bs *Server) SubmitBlindedBlock(ctx context.Context, req *ethpbv2.SignedBli ctx, span := trace.StartSpan(ctx, "beacon.SubmitBlindedBlock") defer span.End() - capellaBlkContainer, ok := req.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_CapellaBlock) - if ok { - if err := bs.submitBlindedCapellaBlock(ctx, capellaBlkContainer.CapellaBlock, req.Signature); err != nil { + switch blkContainer := req.Message.(type) { + case *ethpbv2.SignedBlindedBeaconBlockContainer_CapellaBlock: + if err := bs.submitBlindedCapellaBlock(ctx, blkContainer.CapellaBlock, req.Signature); err != nil { return nil, err } - } - - bellatrixBlkContainer, ok := req.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_BellatrixBlock) - if ok { - if err := bs.submitBlindedBellatrixBlock(ctx, bellatrixBlkContainer.BellatrixBlock, req.Signature); err != nil { + case *ethpbv2.SignedBlindedBeaconBlockContainer_BellatrixBlock: + if err := bs.submitBlindedBellatrixBlock(ctx, blkContainer.BellatrixBlock, req.Signature); err != nil { return nil, err } - } - - // At the end we check forks that don't have blinded blocks. - phase0BlkContainer, ok := req.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_Phase0Block) - if ok { - if err := bs.submitPhase0Block(ctx, phase0BlkContainer.Phase0Block, req.Signature); err != nil { + case *ethpbv2.SignedBlindedBeaconBlockContainer_Phase0Block: + if err := bs.submitPhase0Block(ctx, blkContainer.Phase0Block, req.Signature); err != nil { return nil, err } - } - altairBlkContainer, ok := req.Message.(*ethpbv2.SignedBlindedBeaconBlockContainer_AltairBlock) - if ok { - if err := bs.submitAltairBlock(ctx, altairBlkContainer.AltairBlock, req.Signature); err != nil { + case *ethpbv2.SignedBlindedBeaconBlockContainer_AltairBlock: + if err := bs.submitAltairBlock(ctx, blkContainer.AltairBlock, req.Signature); err != nil { return nil, err } + default: + return nil, status.Errorf(codes.InvalidArgument, "Unsupported block container type %T", blkContainer) } return &emptypb.Empty{}, nil diff --git a/beacon-chain/rpc/eth/beacon/blocks.go b/beacon-chain/rpc/eth/beacon/blocks.go index 8455fe477f4d..f208a80401dd 100644 --- a/beacon-chain/rpc/eth/beacon/blocks.go +++ b/beacon-chain/rpc/eth/beacon/blocks.go @@ -220,29 +220,25 @@ func (bs *Server) SubmitBlock(ctx context.Context, req *ethpbv2.SignedBeaconBloc ctx, span := trace.StartSpan(ctx, "beacon.SubmitBlock") defer span.End() - phase0BlkContainer, ok := req.Message.(*ethpbv2.SignedBeaconBlockContainer_Phase0Block) - if ok { - if err := bs.submitPhase0Block(ctx, phase0BlkContainer.Phase0Block, req.Signature); err != nil { + switch blkContainer := req.Message.(type) { + case *ethpbv2.SignedBeaconBlockContainer_Phase0Block: + if err := bs.submitPhase0Block(ctx, blkContainer.Phase0Block, req.Signature); err != nil { return nil, err } - } - altairBlkContainer, ok := req.Message.(*ethpbv2.SignedBeaconBlockContainer_AltairBlock) - if ok { - if err := bs.submitAltairBlock(ctx, altairBlkContainer.AltairBlock, req.Signature); err != nil { + case *ethpbv2.SignedBeaconBlockContainer_AltairBlock: + if err := bs.submitAltairBlock(ctx, blkContainer.AltairBlock, req.Signature); err != nil { return nil, err } - } - bellatrixBlkContainer, ok := req.Message.(*ethpbv2.SignedBeaconBlockContainer_BellatrixBlock) - if ok { - if err := bs.submitBellatrixBlock(ctx, bellatrixBlkContainer.BellatrixBlock, req.Signature); err != nil { + case *ethpbv2.SignedBeaconBlockContainer_BellatrixBlock: + if err := bs.submitBellatrixBlock(ctx, blkContainer.BellatrixBlock, req.Signature); err != nil { return nil, err } - } - capellaBlkContainer, ok := req.Message.(*ethpbv2.SignedBeaconBlockContainer_CapellaBlock) - if ok { - if err := bs.submitCapellaBlock(ctx, capellaBlkContainer.CapellaBlock, req.Signature); err != nil { + case *ethpbv2.SignedBeaconBlockContainer_CapellaBlock: + if err := bs.submitCapellaBlock(ctx, blkContainer.CapellaBlock, req.Signature); err != nil { return nil, err } + default: + return nil, status.Errorf(codes.InvalidArgument, "Unsupported block container type %T", blkContainer) } return &emptypb.Empty{}, nil diff --git a/beacon-chain/rpc/eth/beacon/blocks_test.go b/beacon-chain/rpc/eth/beacon/blocks_test.go index ba59d33bde36..d0f16139bbfd 100644 --- a/beacon-chain/rpc/eth/beacon/blocks_test.go +++ b/beacon-chain/rpc/eth/beacon/blocks_test.go @@ -6,6 +6,7 @@ import ( "reflect" "testing" + "github.com/prysmaticlabs/go-bitfield" mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" @@ -43,13 +44,6 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) ( b := util.NewBeaconBlock() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} root, err := b.Block.HashTreeRoot() require.NoError(t, err) blks[i], err = blocks.NewSignedBeaconBlock(b) @@ -86,13 +80,12 @@ func fillDBTestBlocksAltair(ctx context.Context, t *testing.T, beaconDB db.Datab b := util.NewBeaconBlockAltair() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} + syncCommitteeBits := bitfield.NewBitvector512() + syncCommitteeBits.SetBitAt(100, true) + b.Block.Body.SyncAggregate = ðpbalpha.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: bytesutil.PadTo([]byte("signature"), 96), + } root, err := b.Block.HashTreeRoot() require.NoError(t, err) signedB, err := blocks.NewSignedBeaconBlock(b) @@ -128,13 +121,28 @@ func fillDBTestBlocksBellatrix(ctx context.Context, t *testing.T, beaconDB db.Da b := util.NewBeaconBlockBellatrix() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} + syncCommitteeBits := bitfield.NewBitvector512() + syncCommitteeBits.SetBitAt(100, true) + b.Block.Body.SyncAggregate = ðpbalpha.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: bytesutil.PadTo([]byte("signature"), 96), + } + b.Block.Body.ExecutionPayload = &enginev1.ExecutionPayload{ + ParentHash: bytesutil.PadTo([]byte("parent_hash"), 32), + FeeRecipient: bytesutil.PadTo([]byte("fee_recipient"), 20), + StateRoot: bytesutil.PadTo([]byte("state_root"), 32), + ReceiptsRoot: bytesutil.PadTo([]byte("receipts_root"), 32), + LogsBloom: bytesutil.PadTo([]byte("logs_bloom"), 256), + PrevRandao: bytesutil.PadTo([]byte("prev_randao"), 32), + BlockNumber: 123, + GasLimit: 123, + GasUsed: 123, + Timestamp: 123, + ExtraData: bytesutil.PadTo([]byte("extra_data"), 32), + BaseFeePerGas: bytesutil.PadTo([]byte("base_fee_per_gas"), 32), + BlockHash: bytesutil.PadTo([]byte("block_hash"), 32), + Transactions: [][]byte{[]byte("transaction1"), []byte("transaction2")}, + } root, err := b.Block.HashTreeRoot() require.NoError(t, err) signedB, err := blocks.NewSignedBeaconBlock(b) @@ -170,13 +178,42 @@ func fillDBTestBlocksCapella(ctx context.Context, t *testing.T, beaconDB db.Data b := util.NewBeaconBlockCapella() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} + syncCommitteeBits := bitfield.NewBitvector512() + syncCommitteeBits.SetBitAt(100, true) + b.Block.Body.SyncAggregate = ðpbalpha.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: bytesutil.PadTo([]byte("signature"), 96), + } + b.Block.Body.ExecutionPayload = &enginev1.ExecutionPayloadCapella{ + ParentHash: bytesutil.PadTo([]byte("parent_hash"), 32), + FeeRecipient: bytesutil.PadTo([]byte("fee_recipient"), 20), + StateRoot: bytesutil.PadTo([]byte("state_root"), 32), + ReceiptsRoot: bytesutil.PadTo([]byte("receipts_root"), 32), + LogsBloom: bytesutil.PadTo([]byte("logs_bloom"), 256), + PrevRandao: bytesutil.PadTo([]byte("prev_randao"), 32), + BlockNumber: 123, + GasLimit: 123, + GasUsed: 123, + Timestamp: 123, + ExtraData: bytesutil.PadTo([]byte("extra_data"), 32), + BaseFeePerGas: bytesutil.PadTo([]byte("base_fee_per_gas"), 32), + BlockHash: bytesutil.PadTo([]byte("block_hash"), 32), + Transactions: [][]byte{[]byte("transaction1"), []byte("transaction2")}, + Withdrawals: []*enginev1.Withdrawal{ + { + Index: 1, + ValidatorIndex: 1, + Address: bytesutil.PadTo([]byte("address1"), 20), + Amount: 1, + }, + { + Index: 2, + ValidatorIndex: 2, + Address: bytesutil.PadTo([]byte("address2"), 20), + Amount: 2, + }, + }, + } root, err := b.Block.HashTreeRoot() require.NoError(t, err) signedB, err := blocks.NewSignedBeaconBlock(b) @@ -212,13 +249,28 @@ func fillDBTestBlocksBellatrixBlinded(ctx context.Context, t *testing.T, beaconD b := util.NewBlindedBeaconBlockBellatrix() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} + syncCommitteeBits := bitfield.NewBitvector512() + syncCommitteeBits.SetBitAt(100, true) + b.Block.Body.SyncAggregate = ðpbalpha.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: bytesutil.PadTo([]byte("signature"), 96), + } + b.Block.Body.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeader{ + ParentHash: bytesutil.PadTo([]byte("parent_hash"), 32), + FeeRecipient: bytesutil.PadTo([]byte("fee_recipient"), 20), + StateRoot: bytesutil.PadTo([]byte("state_root"), 32), + ReceiptsRoot: bytesutil.PadTo([]byte("receipts_root"), 32), + LogsBloom: bytesutil.PadTo([]byte("logs_bloom"), 256), + PrevRandao: bytesutil.PadTo([]byte("prev_randao"), 32), + BlockNumber: 123, + GasLimit: 123, + GasUsed: 123, + Timestamp: 123, + ExtraData: bytesutil.PadTo([]byte("extra_data"), 32), + BaseFeePerGas: bytesutil.PadTo([]byte("base_fee_per_gas"), 32), + BlockHash: bytesutil.PadTo([]byte("block_hash"), 32), + TransactionsRoot: bytesutil.PadTo([]byte("transactions_root"), 32), + } root, err := b.Block.HashTreeRoot() require.NoError(t, err) signedB, err := blocks.NewSignedBeaconBlock(b) @@ -254,13 +306,29 @@ func fillDBTestBlocksCapellaBlinded(ctx context.Context, t *testing.T, beaconDB b := util.NewBlindedBeaconBlockCapella() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - att1 := util.NewAttestation() - att1.Data.Slot = i - att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() - att2.Data.Slot = i - att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} + syncCommitteeBits := bitfield.NewBitvector512() + syncCommitteeBits.SetBitAt(100, true) + b.Block.Body.SyncAggregate = ðpbalpha.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: bytesutil.PadTo([]byte("signature"), 96), + } + b.Block.Body.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderCapella{ + ParentHash: bytesutil.PadTo([]byte("parent_hash"), 32), + FeeRecipient: bytesutil.PadTo([]byte("fee_recipient"), 20), + StateRoot: bytesutil.PadTo([]byte("state_root"), 32), + ReceiptsRoot: bytesutil.PadTo([]byte("receipts_root"), 32), + LogsBloom: bytesutil.PadTo([]byte("logs_bloom"), 256), + PrevRandao: bytesutil.PadTo([]byte("prev_randao"), 32), + BlockNumber: 123, + GasLimit: 123, + GasUsed: 123, + Timestamp: 123, + ExtraData: bytesutil.PadTo([]byte("extra_data"), 32), + BaseFeePerGas: bytesutil.PadTo([]byte("base_fee_per_gas"), 32), + BlockHash: bytesutil.PadTo([]byte("block_hash"), 32), + TransactionsRoot: bytesutil.PadTo([]byte("transactions_root"), 32), + WithdrawalsRoot: bytesutil.PadTo([]byte("withdrawals_root"), 32), + } root, err := b.Block.HashTreeRoot() require.NoError(t, err) signedB, err := blocks.NewSignedBeaconBlock(b)