Skip to content

Commit 5bbdebe

Browse files
Add Gloas consensus type block package (#15618)
Co-authored-by: Bastin <[email protected]>
1 parent 26100e0 commit 5bbdebe

File tree

21 files changed

+933
-44
lines changed

21 files changed

+933
-44
lines changed

beacon-chain/blockchain/process_block_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,6 +2805,10 @@ func TestProcessLightClientUpdate(t *testing.T) {
28052805
require.NoError(t, s.cfg.BeaconDB.SaveHeadBlockRoot(ctx, [32]byte{1, 2}))
28062806

28072807
for _, testVersion := range version.All()[1:] {
2808+
if testVersion == version.Gloas {
2809+
// TODO(16027): Unskip light client tests for Gloas
2810+
continue
2811+
}
28082812
t.Run(version.String(testVersion), func(t *testing.T) {
28092813
l := util.NewTestLightClient(t, testVersion)
28102814

beacon-chain/core/blocks/payload.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func IsExecutionEnabled(st state.ReadOnlyBeaconState, body interfaces.ReadOnlyBe
9090
if st == nil || body == nil {
9191
return false, errors.New("nil state or block body")
9292
}
93+
if st.Version() >= version.Capella {
94+
return true, nil
95+
}
9396
if IsPreBellatrixVersion(st.Version()) {
9497
return false, nil
9598
}

beacon-chain/core/blocks/payload_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,12 @@ func Test_IsExecutionBlockCapella(t *testing.T) {
260260

261261
func Test_IsExecutionEnabled(t *testing.T) {
262262
tests := []struct {
263-
name string
264-
payload *enginev1.ExecutionPayload
265-
header interfaces.ExecutionData
266-
useAltairSt bool
267-
want bool
263+
name string
264+
payload *enginev1.ExecutionPayload
265+
header interfaces.ExecutionData
266+
useAltairSt bool
267+
useCapellaSt bool
268+
want bool
268269
}{
269270
{
270271
name: "use older than bellatrix state",
@@ -331,6 +332,17 @@ func Test_IsExecutionEnabled(t *testing.T) {
331332
}(),
332333
want: true,
333334
},
335+
{
336+
name: "capella state always enabled",
337+
payload: emptyPayload(),
338+
header: func() interfaces.ExecutionData {
339+
h, err := emptyPayloadHeader()
340+
require.NoError(t, err)
341+
return h
342+
}(),
343+
useCapellaSt: true,
344+
want: true,
345+
},
334346
}
335347
for _, tt := range tests {
336348
t.Run(tt.name, func(t *testing.T) {
@@ -342,6 +354,8 @@ func Test_IsExecutionEnabled(t *testing.T) {
342354
require.NoError(t, err)
343355
if tt.useAltairSt {
344356
st, _ = util.DeterministicGenesisStateAltair(t, 1)
357+
} else if tt.useCapellaSt {
358+
st, _ = util.DeterministicGenesisStateCapella(t, 1)
345359
}
346360
got, err := blocks.IsExecutionEnabled(st, body)
347361
require.NoError(t, err)

beacon-chain/db/kv/lightclient_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ func TestStore_LightClientUpdate_CanSaveRetrieve(t *testing.T) {
216216
db := setupDB(t)
217217
ctx := t.Context()
218218
for _, testVersion := range version.All()[1:] {
219+
if testVersion == version.Gloas {
220+
// TODO(16027): Unskip light client tests for Gloas
221+
continue
222+
}
219223
t.Run(version.String(testVersion), func(t *testing.T) {
220224
update, err := createUpdate(t, testVersion)
221225
require.NoError(t, err)
@@ -572,6 +576,10 @@ func TestStore_LightClientBootstrap_CanSaveRetrieve(t *testing.T) {
572576
require.IsNil(t, retrievedBootstrap)
573577
})
574578
for _, testVersion := range version.All()[1:] {
579+
if testVersion == version.Gloas {
580+
// TODO(16027): Unskip light client tests for Gloas
581+
continue
582+
}
575583
t.Run(version.String(testVersion), func(t *testing.T) {
576584
bootstrap, err := createDefaultLightClientBootstrap(primitives.Slot(uint64(params.BeaconConfig().VersionToForkEpochMap()[testVersion]) * uint64(params.BeaconConfig().SlotsPerEpoch)))
577585
require.NoError(t, err)

beacon-chain/light-client/lightclient_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func TestLightClient_NewLightClientOptimisticUpdateFromBeaconState(t *testing.T)
3333
params.OverrideBeaconConfig(cfg)
3434

3535
for _, testVersion := range version.All()[1:] {
36+
if testVersion == version.Gloas {
37+
// TODO(16027): Unskip light client tests for Gloas
38+
continue
39+
}
3640
t.Run(version.String(testVersion), func(t *testing.T) {
3741
l := util.NewTestLightClient(t, testVersion)
3842

beacon-chain/rpc/eth/light-client/handlers_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func TestLightClientHandler_GetLightClientBootstrap(t *testing.T) {
4747
params.OverrideBeaconConfig(cfg)
4848

4949
for _, testVersion := range version.All()[1:] {
50+
if testVersion == version.Gloas {
51+
// TODO(16027): Unskip light client tests for Gloas
52+
continue
53+
}
5054
t.Run(version.String(testVersion), func(t *testing.T) {
5155
l := util.NewTestLightClient(t, testVersion)
5256

@@ -178,6 +182,10 @@ func TestLightClientHandler_GetLightClientByRange(t *testing.T) {
178182

179183
t.Run("can save retrieve", func(t *testing.T) {
180184
for _, testVersion := range version.All()[1:] {
185+
if testVersion == version.Gloas {
186+
// TODO(16027): Unskip light client tests for Gloas
187+
continue
188+
}
181189
t.Run(version.String(testVersion), func(t *testing.T) {
182190

183191
slot := primitives.Slot(params.BeaconConfig().VersionToForkEpochMap()[testVersion] * primitives.Epoch(config.SlotsPerEpoch)).Add(1)
@@ -732,6 +740,10 @@ func TestLightClientHandler_GetLightClientFinalityUpdate(t *testing.T) {
732740
})
733741

734742
for _, testVersion := range version.All()[1:] {
743+
if testVersion == version.Gloas {
744+
// TODO(16027): Unskip light client tests for Gloas
745+
continue
746+
}
735747
t.Run(version.String(testVersion), func(t *testing.T) {
736748
ctx := t.Context()
737749

@@ -827,6 +839,10 @@ func TestLightClientHandler_GetLightClientOptimisticUpdate(t *testing.T) {
827839
})
828840

829841
for _, testVersion := range version.All()[1:] {
842+
if testVersion == version.Gloas {
843+
// TODO(16027): Unskip light client tests for Gloas
844+
continue
845+
}
830846
t.Run(version.String(testVersion), func(t *testing.T) {
831847
ctx := t.Context()
832848
l := util.NewTestLightClient(t, testVersion)
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func NewSignedBeaconBlock(i any) (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 any) (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 any) (interfaces.ReadOnlyBeaconBlockBody, error) {
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
}

consensus-types/blocks/factory_test.go

Lines changed: 53 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,21 @@ 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 execution unsupported", func(t *testing.T) {
575+
base := &SignedBeaconBlock{
576+
version: version.Gloas,
577+
block: &BeaconBlock{version: version.Gloas, body: &BeaconBlockBody{version: version.Gloas}},
578+
}
579+
blinded := &testBlindedSignedBeaconBlock{SignedBeaconBlock: base}
580+
_, err := BuildSignedBeaconBlockFromExecutionPayload(blinded, nil)
581+
require.ErrorContains(t, "Execution is not supported for gloas", err)
582+
})
583+
}
584+
585+
type testBlindedSignedBeaconBlock struct {
586+
*SignedBeaconBlock
587+
}
588+
589+
func (b *testBlindedSignedBeaconBlock) IsBlinded() bool {
590+
return true
538591
}

0 commit comments

Comments
 (0)