Skip to content

Commit 8ecec5d

Browse files
committed
Implement Gloas fork support in consensus-types/blocks
1 parent d809ceb commit 8ecec5d

File tree

12 files changed

+353
-29
lines changed

12 files changed

+353
-29
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added
2+
3+
- Implement Gloas fork support in consensus-types/blocks with factory methods, getters, setters, and proto handling

consensus-types/blocks/factory.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func NewSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) {
8282
return initBlindedSignedBlockFromProtoFulu(b)
8383
case *eth.GenericSignedBeaconBlock_BlindedFulu:
8484
return initBlindedSignedBlockFromProtoFulu(b.BlindedFulu)
85+
case *eth.SignedBeaconBlockGloas:
86+
return initSignedBlockFromProtoGloas(b)
8587
default:
8688
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", i)
8789
}
@@ -138,6 +140,8 @@ func NewBeaconBlock(i interface{}) (interfaces.ReadOnlyBeaconBlock, error) {
138140
return initBlindedBlockFromProtoFulu(b)
139141
case *eth.GenericBeaconBlock_BlindedFulu:
140142
return initBlindedBlockFromProtoFulu(b.BlindedFulu)
143+
case *eth.BeaconBlockGloas:
144+
return initBlockFromProtoGloas(b)
141145
default:
142146
return nil, errors.Wrapf(errUnsupportedBeaconBlock, "unable to create block from type %T", i)
143147
}
@@ -168,6 +172,8 @@ func NewBeaconBlockBody(i interface{}) (interfaces.ReadOnlyBeaconBlockBody, erro
168172
return initBlockBodyFromProtoElectra(b)
169173
case *eth.BlindedBeaconBlockBodyElectra:
170174
return initBlindedBlockBodyFromProtoElectra(b)
175+
case *eth.BeaconBlockBodyGloas:
176+
return initBlockBodyFromProtoGloas(b)
171177
default:
172178
return nil, errors.Wrapf(errUnsupportedBeaconBlockBody, "unable to create block body from type %T", i)
173179
}
@@ -260,6 +266,12 @@ func BuildSignedBeaconBlock(blk interfaces.ReadOnlyBeaconBlock, signature []byte
260266
return nil, errIncorrectBlockVersion
261267
}
262268
return NewSignedBeaconBlock(&eth.SignedBeaconBlockFulu{Block: pb, Signature: signature})
269+
case version.Gloas:
270+
pb, ok := pb.(*eth.BeaconBlockGloas)
271+
if !ok {
272+
return nil, errIncorrectBlockVersion
273+
}
274+
return NewSignedBeaconBlock(&eth.SignedBeaconBlockGloas{Block: pb, Signature: signature})
263275
default:
264276
return nil, errUnsupportedBeaconBlock
265277
}
@@ -629,6 +641,8 @@ func BuildSignedBeaconBlockFromExecutionPayload(blk interfaces.ReadOnlySignedBea
629641
},
630642
Signature: sig[:],
631643
}
644+
case version.Gloas:
645+
return nil, errors.Wrap(errUnsupportedBeaconBlock, "gloas blocks are not supported in this function")
632646
default:
633647
return nil, errors.New("Block not of known type")
634648
}

consensus-types/blocks/getters.go

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func (b *SignedBeaconBlock) Copy() (interfaces.SignedBeaconBlock, error) {
8080
return initBlindedSignedBlockFromProtoFulu(pb.(*eth.SignedBlindedBeaconBlockFulu).Copy())
8181
}
8282
return initSignedBlockFromProtoFulu(pb.(*eth.SignedBeaconBlockFulu).Copy())
83+
case version.Gloas:
84+
return initSignedBlockFromProtoGloas(eth.CopySignedBeaconBlockGloas(pb.(*eth.SignedBeaconBlockGloas)))
8385
default:
8486
return nil, errIncorrectBlockVersion
8587
}
@@ -157,14 +159,17 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
157159
return &eth.GenericSignedBeaconBlock{
158160
Block: &eth.GenericSignedBeaconBlock_Fulu{Fulu: bc},
159161
}, nil
162+
case version.Gloas:
163+
// Gloas doesn't support GenericSignedBeaconBlock yet
164+
return nil, errors.New("Gloas blocks don't support GenericSignedBeaconBlock conversion")
160165
default:
161166
return nil, errIncorrectBlockVersion
162167
}
163168
}
164169

165170
// ToBlinded converts a non-blinded block to its blinded equivalent.
166171
func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, error) {
167-
if b.version < version.Bellatrix {
172+
if b.version < version.Bellatrix || b.version > version.Gloas {
168173
return nil, ErrUnsupportedVersion
169174
}
170175
if b.IsBlinded() {
@@ -376,7 +381,7 @@ func (b *SignedBeaconBlock) Version() int {
376381

377382
// IsBlinded metadata on whether a block is blinded
378383
func (b *SignedBeaconBlock) IsBlinded() bool {
379-
return b.version >= version.Bellatrix && b.block.body.executionPayload == nil
384+
return b.version < version.Gloas && b.version >= version.Bellatrix && b.block.body.executionPayload == nil
380385
}
381386

382387
// Header converts the underlying protobuf object from blinded block to header format.
@@ -437,6 +442,8 @@ func (b *SignedBeaconBlock) MarshalSSZ() ([]byte, error) {
437442
return pb.(*eth.SignedBlindedBeaconBlockFulu).MarshalSSZ()
438443
}
439444
return pb.(*eth.SignedBeaconBlockFulu).MarshalSSZ()
445+
case version.Gloas:
446+
return pb.(*eth.SignedBeaconBlockGloas).MarshalSSZ()
440447
default:
441448
return []byte{}, errIncorrectBlockVersion
442449
}
@@ -479,6 +486,8 @@ func (b *SignedBeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
479486
return pb.(*eth.SignedBlindedBeaconBlockFulu).MarshalSSZTo(dst)
480487
}
481488
return pb.(*eth.SignedBeaconBlockFulu).MarshalSSZTo(dst)
489+
case version.Gloas:
490+
return pb.(*eth.SignedBeaconBlockGloas).MarshalSSZTo(dst)
482491
default:
483492
return []byte{}, errIncorrectBlockVersion
484493
}
@@ -526,6 +535,8 @@ func (b *SignedBeaconBlock) SizeSSZ() int {
526535
return pb.(*eth.SignedBlindedBeaconBlockFulu).SizeSSZ()
527536
}
528537
return pb.(*eth.SignedBeaconBlockFulu).SizeSSZ()
538+
case version.Gloas:
539+
return pb.(*eth.SignedBeaconBlockGloas).SizeSSZ()
529540
default:
530541
panic(incorrectBlockVersion)
531542
}
@@ -666,6 +677,16 @@ func (b *SignedBeaconBlock) UnmarshalSSZ(buf []byte) error {
666677
return err
667678
}
668679
}
680+
case version.Gloas:
681+
pb := &eth.SignedBeaconBlockGloas{}
682+
if err := pb.UnmarshalSSZ(buf); err != nil {
683+
return err
684+
}
685+
var err error
686+
newBlock, err = initSignedBlockFromProtoGloas(pb)
687+
if err != nil {
688+
return err
689+
}
669690
default:
670691
return errIncorrectBlockVersion
671692
}
@@ -705,7 +726,7 @@ func (b *BeaconBlock) IsNil() bool {
705726

706727
// IsBlinded checks if the beacon block is a blinded block.
707728
func (b *BeaconBlock) IsBlinded() bool {
708-
return b.version >= version.Bellatrix && b.body.executionPayload == nil
729+
return b.version < version.Gloas && b.version >= version.Bellatrix && b.body.executionPayload == nil
709730
}
710731

711732
// Version of the underlying protobuf object.
@@ -749,6 +770,9 @@ func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
749770
return pb.(*eth.BlindedBeaconBlockFulu).HashTreeRoot()
750771
}
751772
return pb.(*eth.BeaconBlockElectra).HashTreeRoot()
773+
case version.Gloas:
774+
return pb.(*eth.BeaconBlockGloas).HashTreeRoot()
775+
752776
default:
753777
return [field_params.RootLength]byte{}, errIncorrectBlockVersion
754778
}
@@ -790,6 +814,8 @@ func (b *BeaconBlock) HashTreeRootWith(h *ssz.Hasher) error {
790814
return pb.(*eth.BlindedBeaconBlockFulu).HashTreeRootWith(h)
791815
}
792816
return pb.(*eth.BeaconBlockElectra).HashTreeRootWith(h)
817+
case version.Gloas:
818+
return pb.(*eth.BeaconBlockGloas).HashTreeRootWith(h)
793819
default:
794820
return errIncorrectBlockVersion
795821
}
@@ -832,6 +858,8 @@ func (b *BeaconBlock) MarshalSSZ() ([]byte, error) {
832858
return pb.(*eth.BlindedBeaconBlockFulu).MarshalSSZ()
833859
}
834860
return pb.(*eth.BeaconBlockElectra).MarshalSSZ()
861+
case version.Gloas:
862+
return pb.(*eth.BeaconBlockGloas).MarshalSSZ()
835863
default:
836864
return []byte{}, errIncorrectBlockVersion
837865
}
@@ -874,6 +902,8 @@ func (b *BeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
874902
return pb.(*eth.BlindedBeaconBlockFulu).MarshalSSZTo(dst)
875903
}
876904
return pb.(*eth.BeaconBlockElectra).MarshalSSZTo(dst)
905+
case version.Gloas:
906+
return pb.(*eth.BeaconBlockGloas).MarshalSSZTo(dst)
877907
default:
878908
return []byte{}, errIncorrectBlockVersion
879909
}
@@ -921,6 +951,8 @@ func (b *BeaconBlock) SizeSSZ() int {
921951
return pb.(*eth.BlindedBeaconBlockFulu).SizeSSZ()
922952
}
923953
return pb.(*eth.BeaconBlockElectra).SizeSSZ()
954+
case version.Gloas:
955+
return pb.(*eth.BeaconBlockGloas).SizeSSZ()
924956
default:
925957
panic(incorrectBodyVersion)
926958
}
@@ -1061,6 +1093,16 @@ func (b *BeaconBlock) UnmarshalSSZ(buf []byte) error {
10611093
return err
10621094
}
10631095
}
1096+
case version.Gloas:
1097+
pb := &eth.BeaconBlockGloas{}
1098+
if err := pb.UnmarshalSSZ(buf); err != nil {
1099+
return err
1100+
}
1101+
var err error
1102+
newBlock, err = initBlockFromProtoGloas(pb)
1103+
if err != nil {
1104+
return err
1105+
}
10641106
default:
10651107
return errIncorrectBlockVersion
10661108
}
@@ -1239,6 +1281,22 @@ func (b *BeaconBlockBody) ExecutionRequests() (*enginev1.ExecutionRequests, erro
12391281
return b.executionRequests, nil
12401282
}
12411283

1284+
// PayloadAttestations returns the payload attestations in the block.
1285+
func (b *BeaconBlockBody) PayloadAttestations() ([]*eth.PayloadAttestation, error) {
1286+
if b.version >= version.Gloas {
1287+
return b.payloadAttestations, nil
1288+
}
1289+
return nil, consensus_types.ErrNotSupported("PayloadAttestations", b.version)
1290+
}
1291+
1292+
// SignedExecutionPayloadBid returns the signed execution payload header in the block.
1293+
func (b *BeaconBlockBody) SignedExecutionPayloadBid() (*eth.SignedExecutionPayloadBid, error) {
1294+
if b.version >= version.Gloas {
1295+
return b.signedExecutionPayloadBid, nil
1296+
}
1297+
return nil, consensus_types.ErrNotSupported("SignedExecutionPayloadBid", b.version)
1298+
}
1299+
12421300
// Version returns the version of the beacon block body
12431301
func (b *BeaconBlockBody) Version() int {
12441302
return b.version
@@ -1280,12 +1338,14 @@ func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error)
12801338
return pb.(*eth.BlindedBeaconBlockBodyElectra).HashTreeRoot()
12811339
}
12821340
return pb.(*eth.BeaconBlockBodyElectra).HashTreeRoot()
1341+
case version.Gloas:
1342+
return pb.(*eth.BeaconBlockBodyGloas).HashTreeRoot()
12831343
default:
12841344
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
12851345
}
12861346
}
12871347

12881348
// IsBlinded checks if the beacon block body is a blinded block body.
12891349
func (b *BeaconBlockBody) IsBlinded() bool {
1290-
return b.version >= version.Bellatrix && b.executionPayload == nil
1350+
return b.version < version.Gloas && b.version >= version.Bellatrix && b.executionPayload == nil
12911351
}

consensus-types/blocks/proto.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) { // nolint:gocognit
185185
Block: block,
186186
Signature: b.signature[:],
187187
}, nil
188+
case version.Gloas:
189+
var block *eth.BeaconBlockGloas
190+
if blockMessage != nil {
191+
var ok bool
192+
block, ok = blockMessage.(*eth.BeaconBlockGloas)
193+
if !ok {
194+
return nil, errIncorrectBlockVersion
195+
}
196+
}
197+
return &eth.SignedBeaconBlockGloas{
198+
Block: block,
199+
Signature: b.signature[:],
200+
}, nil
188201
default:
189202
return nil, errors.New("unsupported signed beacon block version")
190203
}
@@ -399,6 +412,22 @@ func (b *BeaconBlock) Proto() (proto.Message, error) { // nolint:gocognit
399412
StateRoot: b.stateRoot[:],
400413
Body: body,
401414
}, nil
415+
case version.Gloas:
416+
var body *eth.BeaconBlockBodyGloas
417+
if bodyMessage != nil {
418+
var ok bool
419+
body, ok = bodyMessage.(*eth.BeaconBlockBodyGloas)
420+
if !ok {
421+
return nil, errIncorrectBodyVersion
422+
}
423+
}
424+
return &eth.BeaconBlockGloas{
425+
Slot: b.slot,
426+
ProposerIndex: b.proposerIndex,
427+
ParentRoot: b.parentRoot[:],
428+
StateRoot: b.stateRoot[:],
429+
Body: body,
430+
}, nil
402431
default:
403432
return nil, fmt.Errorf("unsupported beacon block version: %s", version.String(b.version))
404433
}
@@ -668,6 +697,21 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
668697
BlobKzgCommitments: b.blobKzgCommitments,
669698
ExecutionRequests: b.executionRequests,
670699
}, nil
700+
case version.Gloas:
701+
return &eth.BeaconBlockBodyGloas{
702+
RandaoReveal: b.randaoReveal[:],
703+
Eth1Data: b.eth1Data,
704+
Graffiti: b.graffiti[:],
705+
ProposerSlashings: b.proposerSlashings,
706+
AttesterSlashings: b.attesterSlashingsElectra,
707+
Attestations: b.attestationsElectra,
708+
Deposits: b.deposits,
709+
VoluntaryExits: b.voluntaryExits,
710+
SyncAggregate: b.syncAggregate,
711+
BlsToExecutionChanges: b.blsToExecutionChanges,
712+
SignedExecutionPayloadBid: b.signedExecutionPayloadBid,
713+
PayloadAttestations: b.payloadAttestations,
714+
}, nil
671715
default:
672716
return nil, errors.New("unsupported beacon block body version")
673717
}
@@ -1477,3 +1521,67 @@ func initBlindedBlockBodyFromProtoFulu(pb *eth.BlindedBeaconBlockBodyElectra) (*
14771521
}
14781522
return b, nil
14791523
}
1524+
1525+
// ----------------------------------------------------------------------------
1526+
// Gloas
1527+
// ----------------------------------------------------------------------------
1528+
1529+
func initSignedBlockFromProtoGloas(pb *eth.SignedBeaconBlockGloas) (*SignedBeaconBlock, error) {
1530+
if pb == nil {
1531+
return nil, errNilBlock
1532+
}
1533+
1534+
block, err := initBlockFromProtoGloas(pb.Block)
1535+
if err != nil {
1536+
return nil, err
1537+
}
1538+
b := &SignedBeaconBlock{
1539+
version: version.Gloas,
1540+
block: block,
1541+
signature: bytesutil.ToBytes96(pb.Signature),
1542+
}
1543+
return b, nil
1544+
}
1545+
1546+
func initBlockFromProtoGloas(pb *eth.BeaconBlockGloas) (*BeaconBlock, error) {
1547+
if pb == nil {
1548+
return nil, errNilBlock
1549+
}
1550+
1551+
body, err := initBlockBodyFromProtoGloas(pb.Body)
1552+
if err != nil {
1553+
return nil, err
1554+
}
1555+
b := &BeaconBlock{
1556+
version: version.Gloas,
1557+
slot: pb.Slot,
1558+
proposerIndex: pb.ProposerIndex,
1559+
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
1560+
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
1561+
body: body,
1562+
}
1563+
return b, nil
1564+
}
1565+
1566+
func initBlockBodyFromProtoGloas(pb *eth.BeaconBlockBodyGloas) (*BeaconBlockBody, error) {
1567+
if pb == nil {
1568+
return nil, errNilBlockBody
1569+
}
1570+
1571+
b := &BeaconBlockBody{
1572+
version: version.Gloas,
1573+
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
1574+
eth1Data: pb.Eth1Data,
1575+
graffiti: bytesutil.ToBytes32(pb.Graffiti),
1576+
proposerSlashings: pb.ProposerSlashings,
1577+
attesterSlashingsElectra: pb.AttesterSlashings,
1578+
attestationsElectra: pb.Attestations,
1579+
deposits: pb.Deposits,
1580+
voluntaryExits: pb.VoluntaryExits,
1581+
syncAggregate: pb.SyncAggregate,
1582+
signedExecutionPayloadBid: pb.SignedExecutionPayloadBid,
1583+
blsToExecutionChanges: pb.BlsToExecutionChanges,
1584+
payloadAttestations: pb.PayloadAttestations,
1585+
}
1586+
return b, nil
1587+
}

consensus-types/blocks/setters.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,21 @@ func (b *SignedBeaconBlock) SetExecutionRequests(req *enginev1.ExecutionRequests
182182
b.block.body.executionRequests = req
183183
return nil
184184
}
185+
186+
// SetPayloadAttestations sets the payload attestations in the block.
187+
func (b *SignedBeaconBlock) SetPayloadAttestations(pa []*eth.PayloadAttestation) error {
188+
if b.version < version.Gloas {
189+
return consensus_types.ErrNotSupported("SetPayloadAttestations", b.version)
190+
}
191+
b.block.body.payloadAttestations = pa
192+
return nil
193+
}
194+
195+
// SetSignedExecutionPayloadBid sets the signed execution payload header in the block.
196+
func (b *SignedBeaconBlock) SetSignedExecutionPayloadBid(header *eth.SignedExecutionPayloadBid) error {
197+
if b.version < version.Gloas {
198+
return consensus_types.ErrNotSupported("SetSignedExecutionPayloadBid", b.version)
199+
}
200+
b.block.body.signedExecutionPayloadBid = header
201+
return nil
202+
}

0 commit comments

Comments
 (0)