Skip to content

Commit da955a3

Browse files
committed
Implement Gloas fork support in consensus-types/blocks
1 parent ec109f8 commit da955a3

File tree

15 files changed

+362
-31
lines changed

15 files changed

+362
-31
lines changed

beacon-chain/blockchain/kzg/validation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func TestVerifyCellKZGProofBatchFromBlobData(t *testing.T) {
366366
randBlob := random.GetRandBlob(123)
367367
var blob Blob
368368
copy(blob[:], randBlob[:])
369-
369+
370370
// Create invalid commitment (wrong size)
371371
invalidCommitment := make([]byte, 32) // Should be 48 bytes
372372
cellProofs := make([][]byte, numberOfColumns)
@@ -456,10 +456,10 @@ func TestVerifyCellKZGProofBatchFromBlobData(t *testing.T) {
456456
copy(blob[:], randBlob[:])
457457
commitment, err := BlobToKZGCommitment(&blob)
458458
require.NoError(t, err)
459-
459+
460460
blobs[i] = blob[:]
461461
commitments[i] = commitment[:]
462-
462+
463463
// Add cell proofs - make some invalid in the second blob
464464
for j := uint64(0); j < numberOfColumns; j++ {
465465
if i == 1 && j == 64 {

beacon-chain/rpc/eth/beacon/handlers_equivocation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ func TestBlocks_NewSignedBeaconBlock_EquivocationFix(t *testing.T) {
1717
var block structs.SignedBeaconBlock
1818
err := json.Unmarshal([]byte(rpctesting.Phase0Block), &block)
1919
require.NoError(t, err)
20-
20+
2121
// Convert to generic format
2222
genericBlock, err := block.ToGeneric()
2323
require.NoError(t, err)
24-
24+
2525
// Test the FIX: pass genericBlock.Block instead of genericBlock
2626
// This is what our fix changed in handlers.go line 704 and 858
2727
_, err = blocks.NewSignedBeaconBlock(genericBlock.Block)
2828
require.NoError(t, err, "NewSignedBeaconBlock should work with genericBlock.Block")
29-
29+
3030
// Test the BROKEN version: pass genericBlock directly (this should fail)
3131
_, err = blocks.NewSignedBeaconBlock(genericBlock)
3232
if err == nil {
3333
t.Errorf("NewSignedBeaconBlock should fail with whole genericBlock but succeeded")
3434
}
35-
}
35+
}

beacon-chain/rpc/prysm/v1alpha1/beacon/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestServer_GetBeaconConfig(t *testing.T) {
1919
conf := params.BeaconConfig()
2020
confType := reflect.TypeOf(conf).Elem()
2121
numFields := confType.NumField()
22-
22+
2323
// Count only exported fields, as unexported fields are not included in the config
2424
exportedFields := 0
2525
for i := 0; i < numFields; i++ {
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+
// SignedExecutionPayloadHeader returns the signed execution payload header in the block.
1293+
func (b *BeaconBlockBody) SignedExecutionPayloadHeader() (*eth.SignedExecutionPayloadHeader, error) {
1294+
if b.version >= version.Gloas {
1295+
return b.signedExecutionPayloadHeader, nil
1296+
}
1297+
return nil, consensus_types.ErrNotSupported("SignedExecutionPayloadHeader", 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
}

0 commit comments

Comments
 (0)