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

Add proposer suppot for Electra #13987

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions consensus-types/blocks/testing/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func NewSignedBeaconBlockFromGeneric(gb *eth.GenericSignedBeaconBlock) (interfac
return blocks.NewSignedBeaconBlock(bb.Deneb.Block)
case *eth.GenericSignedBeaconBlock_BlindedDeneb:
return blocks.NewSignedBeaconBlock(bb.BlindedDeneb)
case *eth.GenericSignedBeaconBlock_Electra:
return blocks.NewSignedBeaconBlock(bb.Electra.Block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to remember to do blinded as well

// Generic Signed Beacon Block Deneb can't be used here as it is not a block, but block content with blobs
default:
return nil, errors.Wrapf(blocks.ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", gb)
Expand Down
7 changes: 7 additions & 0 deletions testing/util/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,13 @@ func HydrateSignedBeaconBlockContentsDeneb(b *ethpb.SignedBeaconBlockContentsDen
return b
}

// HydrateSignedBeaconBlockContentsElectra hydrates a signed beacon block with correct field length sizes
// to comply with fssz marshalling and unmarshalling rules.
func HydrateSignedBeaconBlockContentsElectra(b *ethpb.SignedBeaconBlockContentsElectra) *ethpb.SignedBeaconBlockContentsElectra {
b.Block = HydrateSignedBeaconBlockElectra(b.Block)
return b
}

// HydrateV2SignedBeaconBlockDeneb hydrates a v2 signed beacon block with correct field length sizes
// to comply with fssz marshalling and unmarshalling rules.
func HydrateV2SignedBeaconBlockDeneb(b *v2.SignedBeaconBlockDeneb) *v2.SignedBeaconBlockDeneb {
Expand Down
5 changes: 5 additions & 0 deletions testing/util/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func NewBlindedBeaconBlockDeneb() *ethpb.SignedBlindedBeaconBlockDeneb {
return HydrateSignedBlindedBeaconBlockDeneb(&ethpb.SignedBlindedBeaconBlockDeneb{})
}

// NewBeaconBlockContentsElectra creates a beacon block with minimum marshalable fields.
func NewBeaconBlockContentsElectra() *ethpb.SignedBeaconBlockContentsElectra {
return HydrateSignedBeaconBlockContentsElectra(&ethpb.SignedBeaconBlockContentsElectra{})
}

// NewBlindedBeaconBlockElectra creates a blinded beacon block with minimum marshalable fields.
func NewBlindedBeaconBlockElectra() *ethpb.SignedBlindedBeaconBlockElectra {
return HydrateSignedBlindedBeaconBlockElectra(&ethpb.SignedBlindedBeaconBlockElectra{})
Expand Down
60 changes: 47 additions & 13 deletions validator/client/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/validator/client/iface"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"google.golang.org/protobuf/proto"
)

const (
Expand Down Expand Up @@ -127,25 +128,26 @@ func (v *validator) ProposeBlock(ctx context.Context, slot primitives.Slot, pubK
}

var genericSignedBlock *ethpb.GenericSignedBeaconBlock
// Special handling for Deneb blocks and later version because of blob side cars.
if blk.Version() >= version.Deneb && !blk.IsBlinded() {
pb, err := blk.Proto()
if err != nil {
log.WithError(err).Error("Failed to get deneb block")
return
}
denebBlock, ok := pb.(*ethpb.SignedBeaconBlockDeneb)
if !ok {
log.WithError(err).Error("Failed to get deneb block - assertion failure")
return
}
genericSignedBlock = &ethpb.GenericSignedBeaconBlock{
Block: &ethpb.GenericSignedBeaconBlock_Deneb{
Deneb: &ethpb.SignedBeaconBlockContentsDeneb{
Block: denebBlock,
KzgProofs: b.GetDeneb().KzgProofs,
Blobs: b.GetDeneb().Blobs,
},
},
switch blk.Version() {
case version.Deneb:
genericSignedBlock, err = buildGenericSignedBlockDenebWithBlobs(pb, b)
if err != nil {
log.WithError(err).Error("Failed to build generic signed block")
return
}
case version.Electra:
genericSignedBlock, err = buildGenericSignedBlockElectraWithBlobs(pb, b)
if err != nil {
log.WithError(err).Error("Failed to build generic signed block")
return
}
}
} else {
genericSignedBlock, err = blk.PbGenericBlock()
Expand Down Expand Up @@ -230,6 +232,38 @@ func (v *validator) ProposeBlock(ctx context.Context, slot primitives.Slot, pubK
}
}

func buildGenericSignedBlockDenebWithBlobs(pb proto.Message, b *ethpb.GenericBeaconBlock) (*ethpb.GenericSignedBeaconBlock, error) {
denebBlock, ok := pb.(*ethpb.SignedBeaconBlockDeneb)
if !ok {
return nil, errors.New("could cast to deneb block")
}
return &ethpb.GenericSignedBeaconBlock{
Block: &ethpb.GenericSignedBeaconBlock_Deneb{
Deneb: &ethpb.SignedBeaconBlockContentsDeneb{
Block: denebBlock,
KzgProofs: b.GetDeneb().KzgProofs,
Blobs: b.GetDeneb().Blobs,
},
},
}, nil
}

func buildGenericSignedBlockElectraWithBlobs(pb proto.Message, b *ethpb.GenericBeaconBlock) (*ethpb.GenericSignedBeaconBlock, error) {
electraBlock, ok := pb.(*ethpb.SignedBeaconBlockElectra)
if !ok {
return nil, errors.New("could cast to electra block")
}
return &ethpb.GenericSignedBeaconBlock{
Block: &ethpb.GenericSignedBeaconBlock_Electra{
Electra: &ethpb.SignedBeaconBlockContentsElectra{
Block: electraBlock,
KzgProofs: b.GetElectra().KzgProofs,
Blobs: b.GetElectra().Blobs,
},
},
}, nil
}

// ProposeExit performs a voluntary exit on a validator.
// The exit is signed by the validator before being sent to the beacon node for broadcasting.
func ProposeExit(
Expand Down
13 changes: 13 additions & 0 deletions validator/client/propose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,19 @@ func testProposeBlock(t *testing.T, graffiti []byte) {
},
},
},
{
name: "electra block",
version: version.Electra,
block: &ethpb.GenericBeaconBlock{
Block: &ethpb.GenericBeaconBlock_Electra{
Electra: func() *ethpb.BeaconBlockContentsElectra {
blk := util.NewBeaconBlockContentsElectra()
blk.Block.Block.Body.Graffiti = graffiti
return &ethpb.BeaconBlockContentsElectra{Block: blk.Block.Block, KzgProofs: blk.KzgProofs, Blobs: blk.Blobs}
}(),
},
},
},
}

for _, tt := range tests {
Expand Down
Loading