Skip to content

Commit 6333253

Browse files
committed
Implement Gloas fork support in consensus-types/blocks
1 parent 5c286ed commit 6333253

File tree

20 files changed

+821
-43
lines changed

20 files changed

+821
-43
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/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ go_test(
5353
"roblob_test.go",
5454
"roblock_test.go",
5555
"rodatacolumn_test.go",
56+
"setters_test.go",
5657
],
5758
embed = [":go_default_library"],
5859
deps = [

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/factory_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ func Test_NewSignedBeaconBlock(t *testing.T) {
161161
assert.Equal(t, version.Deneb, b.Version())
162162
assert.Equal(t, true, b.IsBlinded())
163163
})
164+
t.Run("SignedBeaconBlockGloas", func(t *testing.T) {
165+
pb := &eth.SignedBeaconBlockGloas{
166+
Block: &eth.BeaconBlockGloas{
167+
Body: &eth.BeaconBlockBodyGloas{},
168+
},
169+
Signature: []byte("sig"),
170+
}
171+
b, err := NewSignedBeaconBlock(pb)
172+
require.NoError(t, err)
173+
assert.Equal(t, version.Gloas, b.Version())
174+
assert.Equal(t, false, b.IsBlinded())
175+
})
164176
t.Run("nil", func(t *testing.T) {
165177
_, err := NewSignedBeaconBlock(nil)
166178
assert.ErrorContains(t, "received nil object", err)
@@ -276,6 +288,13 @@ func Test_NewBeaconBlock(t *testing.T) {
276288
assert.Equal(t, version.Deneb, b.Version())
277289
assert.Equal(t, true, b.IsBlinded())
278290
})
291+
t.Run("BeaconBlockGloas", func(t *testing.T) {
292+
pb := &eth.BeaconBlockGloas{Body: &eth.BeaconBlockBodyGloas{}}
293+
b, err := NewBeaconBlock(pb)
294+
require.NoError(t, err)
295+
assert.Equal(t, version.Gloas, b.Version())
296+
assert.Equal(t, false, b.IsBlinded())
297+
})
279298
t.Run("nil", func(t *testing.T) {
280299
_, err := NewBeaconBlock(nil)
281300
assert.ErrorContains(t, "received nil object", err)
@@ -354,6 +373,15 @@ func Test_NewBeaconBlockBody(t *testing.T) {
354373
assert.Equal(t, version.Deneb, b.version)
355374
assert.Equal(t, true, b.IsBlinded())
356375
})
376+
t.Run("BeaconBlockBodyGloas", func(t *testing.T) {
377+
pb := &eth.BeaconBlockBodyGloas{}
378+
i, err := NewBeaconBlockBody(pb)
379+
require.NoError(t, err)
380+
b, ok := i.(*BeaconBlockBody)
381+
require.Equal(t, true, ok)
382+
assert.Equal(t, version.Gloas, b.version)
383+
assert.Equal(t, false, b.IsBlinded())
384+
})
357385
t.Run("nil", func(t *testing.T) {
358386
_, err := NewBeaconBlockBody(nil)
359387
assert.ErrorContains(t, "received nil object", err)
@@ -425,6 +453,14 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
425453
assert.Equal(t, version.Deneb, sb.Version())
426454
assert.Equal(t, true, sb.IsBlinded())
427455
})
456+
t.Run("Gloas", func(t *testing.T) {
457+
b := &BeaconBlock{version: version.Gloas, body: &BeaconBlockBody{version: version.Gloas}}
458+
sb, err := BuildSignedBeaconBlock(b, sig[:])
459+
require.NoError(t, err)
460+
assert.DeepEqual(t, sig, sb.Signature())
461+
assert.Equal(t, version.Gloas, sb.Version())
462+
assert.Equal(t, false, sb.IsBlinded())
463+
})
428464
}
429465

430466
func TestBuildSignedBeaconBlockFromExecutionPayload(t *testing.T) {
@@ -535,4 +571,12 @@ func TestBuildSignedBeaconBlockFromExecutionPayload(t *testing.T) {
535571
require.DeepEqual(t, uint64(123), payload.ExcessBlobGas)
536572
require.DeepEqual(t, uint64(321), payload.BlobGasUsed)
537573
})
574+
t.Run("gloas unsupported", func(t *testing.T) {
575+
blk := &SignedBeaconBlock{
576+
version: version.Gloas,
577+
block: &BeaconBlock{version: version.Gloas, body: &BeaconBlockBody{version: version.Gloas}},
578+
}
579+
_, err := BuildSignedBeaconBlockFromExecutionPayload(blk, nil)
580+
require.ErrorIs(t, err, errNonBlindedSignedBeaconBlock)
581+
})
538582
}

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
}

0 commit comments

Comments
 (0)