Skip to content

Commit

Permalink
Add ePBS stuff to consensus-types: block
Browse files Browse the repository at this point in the history
  • Loading branch information
potuz committed Apr 26, 2024
1 parent 55bfb0d commit 6415688
Show file tree
Hide file tree
Showing 28 changed files with 1,271 additions and 406 deletions.
3 changes: 3 additions & 0 deletions consensus-types/blocks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ go_test(
srcs = [
"execution_test.go",
"factory_test.go",
"getters_epbs_test.go",
"getters_test.go",
"kzg_test.go",
"proto_epbs_test.go",
"proto_test.go",
"roblob_test.go",
"roblock_test.go",
"setters_test.go",
],
embed = [":go_default_library"],
deps = [
Expand Down
19 changes: 19 additions & 0 deletions consensus-types/blocks/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func NewSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) {
return initBlindedSignedBlockFromProtoDeneb(b)
case *eth.GenericSignedBeaconBlock_BlindedDeneb:
return initBlindedSignedBlockFromProtoDeneb(b.BlindedDeneb)
case *eth.GenericSignedBeaconBlock_Epbs:
return initSignedBlockFromProtoEPBS(b.Epbs)
case *eth.SignedBeaconBlockEpbs:
return initSignedBlockFromProtoEPBS(b)
default:
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", i)
}
Expand Down Expand Up @@ -109,6 +113,10 @@ func NewBeaconBlock(i interface{}) (interfaces.ReadOnlyBeaconBlock, error) {
return initBlindedBlockFromProtoDeneb(b)
case *eth.GenericBeaconBlock_BlindedDeneb:
return initBlindedBlockFromProtoDeneb(b.BlindedDeneb)
case *eth.GenericBeaconBlock_Epbs:
return initBlockFromProtoEpbs(b.Epbs)
case *eth.BeaconBlockEpbs:
return initBlockFromProtoEpbs(b)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlock, "unable to create block from type %T", i)
}
Expand All @@ -135,6 +143,8 @@ func NewBeaconBlockBody(i interface{}) (interfaces.ReadOnlyBeaconBlockBody, erro
return initBlockBodyFromProtoDeneb(b)
case *eth.BlindedBeaconBlockBodyDeneb:
return initBlindedBlockBodyFromProtoDeneb(b)
case *eth.BeaconBlockBodyEpbs:
return initBlockBodyFromProtoEpbs(b)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlockBody, "unable to create block body from type %T", i)
}
Expand Down Expand Up @@ -201,6 +211,12 @@ func BuildSignedBeaconBlock(blk interfaces.ReadOnlyBeaconBlock, signature []byte
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockDeneb{Block: pb, Signature: signature})
case version.EPBS:
pb, ok := pb.(*eth.BeaconBlockEpbs)
if !ok {
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockEpbs{Block: pb, Signature: signature})
default:
return nil, errUnsupportedBeaconBlock
}
Expand All @@ -217,6 +233,9 @@ func BuildSignedBeaconBlockFromExecutionPayload(
if !blk.IsBlinded() {
return nil, errNonBlindedSignedBeaconBlock
}
if blk.Version() >= version.EPBS {
return nil, errors.Wrap(errUnsupportedBeaconBlock, "post epbs blocks no longer need to be unblind")
}
b := blk.Block()
payloadHeader, err := b.Body().Execution()
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions consensus-types/blocks/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ func Test_NewSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Deneb, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("GenericSignedBeaconBlock_Epbs", func(t *testing.T) {
pb := &eth.GenericSignedBeaconBlock_Epbs{
Epbs: &eth.SignedBeaconBlockEpbs{
Block: &eth.BeaconBlockEpbs{
Body: &eth.BeaconBlockBodyEpbs{},
},
},
}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.EPBS, b.Version())
})
t.Run("SignedBeaconBlockEpbs", func(t *testing.T) {
pb := &eth.SignedBeaconBlockEpbs{
Block: &eth.BeaconBlockEpbs{
Body: &eth.BeaconBlockBodyEpbs{}}}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.EPBS, b.Version())
})
t.Run("nil", func(t *testing.T) {
_, err := NewSignedBeaconBlock(nil)
assert.ErrorContains(t, "received nil object", err)
Expand Down Expand Up @@ -277,6 +297,18 @@ func Test_NewBeaconBlock(t *testing.T) {
assert.Equal(t, version.Deneb, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("GenericBeaconBlock_Epbs", func(t *testing.T) {
pb := &eth.GenericBeaconBlock_Epbs{Epbs: &eth.BeaconBlockEpbs{Body: &eth.BeaconBlockBodyEpbs{}}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.EPBS, b.Version())
})
t.Run("BeaconBlockEpbs", func(t *testing.T) {
pb := &eth.BeaconBlockEpbs{Body: &eth.BeaconBlockBodyEpbs{}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.EPBS, b.Version())
})
t.Run("nil", func(t *testing.T) {
_, err := NewBeaconBlock(nil)
assert.ErrorContains(t, "received nil object", err)
Expand Down Expand Up @@ -355,6 +387,14 @@ func Test_NewBeaconBlockBody(t *testing.T) {
assert.Equal(t, version.Deneb, b.version)
assert.Equal(t, true, b.IsBlinded())
})
t.Run("BeaconBlockBodyEpbs", func(t *testing.T) {
pb := &eth.BeaconBlockBodyEpbs{}
i, err := NewBeaconBlockBody(pb)
require.NoError(t, err)
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.EPBS, b.version)
})
t.Run("nil", func(t *testing.T) {
_, err := NewBeaconBlockBody(nil)
assert.ErrorContains(t, "received nil object", err)
Expand Down Expand Up @@ -426,6 +466,13 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Deneb, sb.Version())
assert.Equal(t, true, sb.IsBlinded())
})
t.Run("Epbs", func(t *testing.T) {
b := &BeaconBlock{version: version.EPBS, body: &BeaconBlockBody{version: version.EPBS}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.EPBS, sb.Version())
})
}

func TestBuildSignedBeaconBlockFromExecutionPayload(t *testing.T) {
Expand Down
Loading

0 comments on commit 6415688

Please sign in to comment.