Capella beacon block (#11566)

* in progress

* done, no tests yet

* fix ToBlinded()

* Revert "Auxiliary commit to revert individual files from 2e356b6f5b15d409ac15e825c744528591c13739"

This reverts commit 081ab74e88fb7d0e3f6a81e00fe5e89483b41f90.

* tests

* fix tests

* one more fix

* and one more

* review

* fix proto_test

* another fix

* do not return error when nil object is wrapped

* allow nil payload in body.Proto()

* correctly assert error

* nil checks in body.Execution()

* simplify PR

* Revert "Auxiliary commit to revert individual files from 5736c1f22f2d2f309b9303c13d0fb6b1679c6ecb"

This reverts commit 1ff3a4c864923f5c180aa015aa087a2814498b42.

* fix slice sizes in cloner tests

* better payload tests

* review

Co-authored-by: terencechain <terence@prysmaticlabs.com>
This commit is contained in:
Radosław Kapka
2022-10-31 12:58:30 -05:00
committed by GitHub
parent 26b46301d2
commit ffac232d89
16 changed files with 1801 additions and 158 deletions

View File

@@ -81,6 +81,113 @@ func TestWrapExecutionPayloadHeader_SSZ(t *testing.T) {
assert.NoError(t, wsb.UnmarshalSSZ(encoded))
}
func TestWrapExecutionPayloadCapella(t *testing.T) {
data := &enginev1.ExecutionPayloadCapella{
ParentHash: []byte("parenthash"),
FeeRecipient: []byte("feerecipient"),
StateRoot: []byte("stateroot"),
ReceiptsRoot: []byte("receiptsroot"),
LogsBloom: []byte("logsbloom"),
PrevRandao: []byte("prevrandao"),
BlockNumber: 11,
GasLimit: 22,
GasUsed: 33,
Timestamp: 44,
ExtraData: []byte("extradata"),
BaseFeePerGas: []byte("basefeepergas"),
BlockHash: []byte("blockhash"),
Transactions: [][]byte{[]byte("transaction")},
Withdrawals: []*enginev1.Withdrawal{{
WithdrawalIndex: 55,
ValidatorIndex: 66,
ExecutionAddress: []byte("executionaddress"),
Amount: 77,
}},
}
payload, err := blocks.WrappedExecutionPayloadCapella(data)
require.NoError(t, err)
assert.DeepEqual(t, data, payload.Proto())
}
func TestWrapExecutionPayloadHeaderCapella(t *testing.T) {
data := &enginev1.ExecutionPayloadHeaderCapella{
ParentHash: []byte("parenthash"),
FeeRecipient: []byte("feerecipient"),
StateRoot: []byte("stateroot"),
ReceiptsRoot: []byte("receiptsroot"),
LogsBloom: []byte("logsbloom"),
PrevRandao: []byte("prevrandao"),
BlockNumber: 11,
GasLimit: 22,
GasUsed: 33,
Timestamp: 44,
ExtraData: []byte("extradata"),
BaseFeePerGas: []byte("basefeepergas"),
BlockHash: []byte("blockhash"),
TransactionsRoot: []byte("transactionsroot"),
WithdrawalsRoot: []byte("withdrawalsroot"),
}
payload, err := blocks.WrappedExecutionPayloadHeaderCapella(data)
require.NoError(t, err)
assert.DeepEqual(t, data, payload.Proto())
}
func TestWrapExecutionPayloadCapella_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayloadCapella(nil)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayloadCapella{GasUsed: 54}
payload, err := blocks.WrappedExecutionPayloadCapella(data)
require.NoError(t, err)
assert.Equal(t, false, payload.IsNil())
}
func TestWrapExecutionPayloadHeaderCapella_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayloadHeaderCapella(nil)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayloadHeaderCapella{GasUsed: 54}
payload, err := blocks.WrappedExecutionPayloadHeaderCapella(data)
require.NoError(t, err)
assert.Equal(t, false, payload.IsNil())
}
func TestWrapExecutionPayloadCapella_SSZ(t *testing.T) {
payload := createWrappedPayloadCapella(t)
rt, err := payload.HashTreeRoot()
assert.NoError(t, err)
assert.NotEmpty(t, rt)
var b []byte
b, err = payload.MarshalSSZTo(b)
assert.NoError(t, err)
assert.NotEqual(t, 0, len(b))
encoded, err := payload.MarshalSSZ()
require.NoError(t, err)
assert.NotEqual(t, 0, payload.SizeSSZ())
assert.NoError(t, payload.UnmarshalSSZ(encoded))
}
func TestWrapExecutionPayloadHeaderCapella_SSZ(t *testing.T) {
payload := createWrappedPayloadHeaderCapella(t)
rt, err := payload.HashTreeRoot()
assert.NoError(t, err)
assert.NotEmpty(t, rt)
var b []byte
b, err = payload.MarshalSSZTo(b)
assert.NoError(t, err)
assert.NotEqual(t, 0, len(b))
encoded, err := payload.MarshalSSZ()
require.NoError(t, err)
assert.NotEqual(t, 0, payload.SizeSSZ())
assert.NoError(t, payload.UnmarshalSSZ(encoded))
}
func createWrappedPayload(t testing.TB) interfaces.ExecutionData {
wsb, err := blocks.WrappedExecutionPayload(&enginev1.ExecutionPayload{
ParentHash: make([]byte, fieldparams.RootLength),
@@ -122,3 +229,47 @@ func createWrappedPayloadHeader(t testing.TB) interfaces.ExecutionData {
require.NoError(t, err)
return wsb
}
func createWrappedPayloadCapella(t testing.TB) interfaces.ExecutionData {
payload, err := blocks.WrappedExecutionPayloadCapella(&enginev1.ExecutionPayloadCapella{
ParentHash: make([]byte, fieldparams.RootLength),
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
PrevRandao: make([]byte, fieldparams.RootLength),
BlockNumber: 0,
GasLimit: 0,
GasUsed: 0,
Timestamp: 0,
ExtraData: make([]byte, 0),
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
Transactions: make([][]byte, 0),
Withdrawals: make([]*enginev1.Withdrawal, 0),
})
require.NoError(t, err)
return payload
}
func createWrappedPayloadHeaderCapella(t testing.TB) interfaces.ExecutionData {
payload, err := blocks.WrappedExecutionPayloadHeaderCapella(&enginev1.ExecutionPayloadHeaderCapella{
ParentHash: make([]byte, fieldparams.RootLength),
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
PrevRandao: make([]byte, fieldparams.RootLength),
BlockNumber: 0,
GasLimit: 0,
GasUsed: 0,
Timestamp: 0,
ExtraData: make([]byte, 0),
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
TransactionsRoot: make([]byte, fieldparams.RootLength),
WithdrawalsRoot: make([]byte, fieldparams.RootLength),
})
require.NoError(t, err)
return payload
}

View File

@@ -47,6 +47,14 @@ func NewSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) {
return initBlindedSignedBlockFromProtoBellatrix(b.BlindedBellatrix)
case *eth.SignedBlindedBeaconBlockBellatrix:
return initBlindedSignedBlockFromProtoBellatrix(b)
case *eth.GenericSignedBeaconBlock_Capella:
return initSignedBlockFromProtoCapella(b.Capella)
case *eth.SignedBeaconBlockCapella:
return initSignedBlockFromProtoCapella(b)
case *eth.GenericSignedBeaconBlock_BlindedCapella:
return initBlindedSignedBlockFromProtoCapella(b.BlindedCapella)
case *eth.SignedBlindedBeaconBlockCapella:
return initBlindedSignedBlockFromProtoCapella(b)
default:
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", i)
}
@@ -73,6 +81,14 @@ func NewBeaconBlock(i interface{}) (interfaces.BeaconBlock, error) {
return initBlindedBlockFromProtoBellatrix(b.BlindedBellatrix)
case *eth.BlindedBeaconBlockBellatrix:
return initBlindedBlockFromProtoBellatrix(b)
case *eth.GenericBeaconBlock_Capella:
return initBlockFromProtoCapella(b.Capella)
case *eth.BeaconBlockCapella:
return initBlockFromProtoCapella(b)
case *eth.GenericBeaconBlock_BlindedCapella:
return initBlindedBlockFromProtoCapella(b.BlindedCapella)
case *eth.BlindedBeaconBlockCapella:
return initBlindedBlockFromProtoCapella(b)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlock, "unable to create block from type %T", i)
}
@@ -91,6 +107,10 @@ func NewBeaconBlockBody(i interface{}) (interfaces.BeaconBlockBody, error) {
return initBlockBodyFromProtoBellatrix(b)
case *eth.BlindedBeaconBlockBodyBellatrix:
return initBlindedBlockBodyFromProtoBellatrix(b)
case *eth.BeaconBlockBodyCapella:
return initBlockBodyFromProtoCapella(b)
case *eth.BlindedBeaconBlockBodyCapella:
return initBlindedBlockBodyFromProtoCapella(b)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlockBody, "unable to create block body from type %T", i)
}
@@ -131,6 +151,19 @@ func BuildSignedBeaconBlock(blk interfaces.BeaconBlock, signature []byte) (inter
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockBellatrix{Block: pb, Signature: signature})
case version.Capella:
if blk.IsBlinded() {
pb, ok := pb.(*eth.BlindedBeaconBlockCapella)
if !ok {
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBlindedBeaconBlockCapella{Block: pb, Signature: signature})
}
pb, ok := pb.(*eth.BeaconBlockCapella)
if !ok {
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockCapella{Block: pb, Signature: signature})
default:
return nil, errUnsupportedBeaconBlock
}
@@ -139,7 +172,7 @@ func BuildSignedBeaconBlock(blk interfaces.BeaconBlock, signature []byte) (inter
// BuildSignedBeaconBlockFromExecutionPayload takes a signed, blinded beacon block and converts into
// a full, signed beacon block by specifying an execution payload.
func BuildSignedBeaconBlockFromExecutionPayload(
blk interfaces.SignedBeaconBlock, payload *enginev1.ExecutionPayload,
blk interfaces.SignedBeaconBlock, payload interface{},
) (interfaces.SignedBeaconBlock, error) {
if err := BeaconBlockIsNil(blk); err != nil {
return nil, err
@@ -153,16 +186,26 @@ func BuildSignedBeaconBlockFromExecutionPayload(
return nil, errors.Wrap(err, "could not get execution payload header")
default:
}
wrappedPayload, err := WrappedExecutionPayload(payload)
if err != nil {
return nil, err
var wrappedPayload interfaces.ExecutionData
var wrapErr error
switch p := payload.(type) {
case *enginev1.ExecutionPayload:
wrappedPayload, wrapErr = WrappedExecutionPayload(p)
case *enginev1.ExecutionPayloadCapella:
wrappedPayload, wrapErr = WrappedExecutionPayloadCapella(p)
default:
return nil, fmt.Errorf("%T is not a type of execution payload", p)
}
if wrapErr != nil {
return nil, wrapErr
}
empty, err := IsEmptyExecutionData(wrappedPayload)
if err != nil {
return nil, err
}
if !empty {
payloadRoot, err := payload.HashTreeRoot()
payloadRoot, err := wrappedPayload.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "could not hash tree root execution payload")
}
@@ -187,26 +230,61 @@ func BuildSignedBeaconBlockFromExecutionPayload(
randaoReveal := b.Body().RandaoReveal()
graffiti := b.Body().Graffiti()
sig := blk.Signature()
bellatrixFullBlock := &eth.SignedBeaconBlockBellatrix{
Block: &eth.BeaconBlockBellatrix{
Slot: b.Slot(),
ProposerIndex: b.ProposerIndex(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &eth.BeaconBlockBodyBellatrix{
RandaoReveal: randaoReveal[:],
Eth1Data: b.Body().Eth1Data(),
Graffiti: graffiti[:],
ProposerSlashings: b.Body().ProposerSlashings(),
AttesterSlashings: b.Body().AttesterSlashings(),
Attestations: b.Body().Attestations(),
Deposits: b.Body().Deposits(),
VoluntaryExits: b.Body().VoluntaryExits(),
SyncAggregate: syncAgg,
ExecutionPayload: payload,
var fullBlock interface{}
switch p := payload.(type) {
case *enginev1.ExecutionPayload:
fullBlock = &eth.SignedBeaconBlockBellatrix{
Block: &eth.BeaconBlockBellatrix{
Slot: b.Slot(),
ProposerIndex: b.ProposerIndex(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &eth.BeaconBlockBodyBellatrix{
RandaoReveal: randaoReveal[:],
Eth1Data: b.Body().Eth1Data(),
Graffiti: graffiti[:],
ProposerSlashings: b.Body().ProposerSlashings(),
AttesterSlashings: b.Body().AttesterSlashings(),
Attestations: b.Body().Attestations(),
Deposits: b.Body().Deposits(),
VoluntaryExits: b.Body().VoluntaryExits(),
SyncAggregate: syncAgg,
ExecutionPayload: p,
},
},
},
Signature: sig[:],
Signature: sig[:],
}
case *enginev1.ExecutionPayloadCapella:
blsToExecutionChanges, err := b.Body().BLSToExecutionChanges()
if err != nil {
return nil, err
}
fullBlock = &eth.SignedBeaconBlockCapella{
Block: &eth.BeaconBlockCapella{
Slot: b.Slot(),
ProposerIndex: b.ProposerIndex(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &eth.BeaconBlockBodyCapella{
RandaoReveal: randaoReveal[:],
Eth1Data: b.Body().Eth1Data(),
Graffiti: graffiti[:],
ProposerSlashings: b.Body().ProposerSlashings(),
AttesterSlashings: b.Body().AttesterSlashings(),
Attestations: b.Body().Attestations(),
Deposits: b.Body().Deposits(),
VoluntaryExits: b.Body().VoluntaryExits(),
SyncAggregate: syncAgg,
ExecutionPayload: p,
BlsToExecutionChanges: blsToExecutionChanges,
},
},
Signature: sig[:],
}
default:
return nil, fmt.Errorf("%T is not a type of execution payload", p)
}
return NewSignedBeaconBlock(bellatrixFullBlock)
return NewSignedBeaconBlock(fullBlock)
}

View File

@@ -85,6 +85,42 @@ func Test_NewSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Bellatrix, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("GenericSignedBeaconBlock_Capella", func(t *testing.T) {
pb := &eth.GenericSignedBeaconBlock_Capella{
Capella: &eth.SignedBeaconBlockCapella{
Block: &eth.BeaconBlockCapella{
Body: &eth.BeaconBlockBodyCapella{}}}}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
})
t.Run("SignedBeaconBlockCapella", func(t *testing.T) {
pb := &eth.SignedBeaconBlockCapella{
Block: &eth.BeaconBlockCapella{
Body: &eth.BeaconBlockBodyCapella{}}}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
})
t.Run("GenericSignedBeaconBlock_BlindedCapella", func(t *testing.T) {
pb := &eth.GenericSignedBeaconBlock_BlindedCapella{
BlindedCapella: &eth.SignedBlindedBeaconBlockCapella{
Block: &eth.BlindedBeaconBlockCapella{
Body: &eth.BlindedBeaconBlockBodyCapella{}}}}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("SignedBlindedBeaconBlockCapella", func(t *testing.T) {
pb := &eth.SignedBlindedBeaconBlockCapella{
Block: &eth.BlindedBeaconBlockCapella{
Body: &eth.BlindedBeaconBlockBodyCapella{}}}
b, err := NewSignedBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("nil", func(t *testing.T) {
_, err := NewSignedBeaconBlock(nil)
assert.ErrorContains(t, "received nil object", err)
@@ -146,6 +182,32 @@ func Test_NewBeaconBlock(t *testing.T) {
assert.Equal(t, version.Bellatrix, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("GenericBeaconBlock_Capella", func(t *testing.T) {
pb := &eth.GenericBeaconBlock_Capella{Capella: &eth.BeaconBlockCapella{Body: &eth.BeaconBlockBodyCapella{}}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
})
t.Run("BeaconBlockCapella", func(t *testing.T) {
pb := &eth.BeaconBlockCapella{Body: &eth.BeaconBlockBodyCapella{}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
})
t.Run("GenericBeaconBlock_BlindedCapella", func(t *testing.T) {
pb := &eth.GenericBeaconBlock_BlindedCapella{BlindedCapella: &eth.BlindedBeaconBlockCapella{Body: &eth.BlindedBeaconBlockBodyCapella{}}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("BlindedBeaconBlockCapella", func(t *testing.T) {
pb := &eth.BlindedBeaconBlockCapella{Body: &eth.BlindedBeaconBlockBodyCapella{}}
b, err := NewBeaconBlock(pb)
require.NoError(t, err)
assert.Equal(t, version.Capella, b.Version())
assert.Equal(t, true, b.IsBlinded())
})
t.Run("nil", func(t *testing.T) {
_, err := NewBeaconBlock(nil)
assert.ErrorContains(t, "received nil object", err)
@@ -190,6 +252,23 @@ func Test_NewBeaconBlockBody(t *testing.T) {
assert.Equal(t, version.Bellatrix, b.version)
assert.Equal(t, true, b.isBlinded)
})
t.Run("BeaconBlockBodyCapella", func(t *testing.T) {
pb := &eth.BeaconBlockBodyCapella{}
i, err := NewBeaconBlockBody(pb)
require.NoError(t, err)
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Capella, b.version)
})
t.Run("BlindedBeaconBlockBodyCapella", func(t *testing.T) {
pb := &eth.BlindedBeaconBlockBodyCapella{}
i, err := NewBeaconBlockBody(pb)
require.NoError(t, err)
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Capella, b.version)
assert.Equal(t, true, b.isBlinded)
})
t.Run("nil", func(t *testing.T) {
_, err := NewBeaconBlockBody(nil)
assert.ErrorContains(t, "received nil object", err)
@@ -231,6 +310,21 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Bellatrix, sb.Version())
assert.Equal(t, true, sb.IsBlinded())
})
t.Run("Capella", func(t *testing.T) {
b := &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Capella, sb.Version())
})
t.Run("CapellaBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella, isBlinded: true}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Capella, sb.Version())
assert.Equal(t, true, sb.IsBlinded())
})
}
func TestBuildSignedBeaconBlockFromExecutionPayload(t *testing.T) {

View File

@@ -1,11 +1,14 @@
package blocks
import (
"fmt"
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
@@ -60,6 +63,13 @@ func (b *SignedBeaconBlock) Copy() (interfaces.SignedBeaconBlock, error) {
}
cp := eth.CopySignedBeaconBlockBellatrix(pb.(*eth.SignedBeaconBlockBellatrix))
return initSignedBlockFromProtoBellatrix(cp)
case version.Capella:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockCapella(pb.(*eth.SignedBlindedBeaconBlockCapella))
return initBlindedSignedBlockFromProtoCapella(cp)
}
cp := eth.CopySignedBeaconBlockCapella(pb.(*eth.SignedBeaconBlockCapella))
return initSignedBlockFromProtoCapella(cp)
default:
return nil, errIncorrectBlockVersion
}
@@ -89,6 +99,15 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_Bellatrix{Bellatrix: pb.(*eth.SignedBeaconBlockBellatrix)},
}, nil
case version.Capella:
if b.IsBlinded() {
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_BlindedCapella{BlindedCapella: pb.(*eth.SignedBlindedBeaconBlockCapella)},
}, nil
}
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_Capella{Capella: pb.(*eth.SignedBeaconBlockCapella)},
}, nil
default:
return nil, errIncorrectBlockVersion
}
@@ -143,9 +162,33 @@ func (b *SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconB
return pb.(*eth.SignedBlindedBeaconBlockBellatrix), nil
}
// PbCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, error) {
if b.version != version.Capella || b.IsBlinded() {
return nil, errNotSupported("PbCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockCapella), nil
}
// PbBlindedCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedCapellaBlock() (*eth.SignedBlindedBeaconBlockCapella, error) {
if b.version != version.Capella || !b.IsBlinded() {
return nil, errNotSupported("PbBlindedCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBlindedBeaconBlockCapella), nil
}
// ToBlinded converts a non-blinded block to its blinded equivalent.
func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
if b.version != version.Bellatrix {
if b.version < version.Bellatrix {
return nil, ErrUnsupportedVersion
}
if b.IsBlinded() {
@@ -158,32 +201,66 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
if err != nil {
return nil, err
}
header, err := PayloadToHeader(payload)
if err != nil {
return nil, err
}
return initBlindedSignedBlockFromProtoBellatrix(
&eth.SignedBlindedBeaconBlockBellatrix{
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashings,
Attestations: b.block.body.attestations,
Deposits: b.block.body.deposits,
VoluntaryExits: b.block.body.voluntaryExits,
SyncAggregate: b.block.body.syncAggregate,
ExecutionPayloadHeader: header,
switch p := payload.Proto().(type) {
case *enginev1.ExecutionPayload:
header, err := PayloadToHeader(payload)
if err != nil {
return nil, err
}
return initBlindedSignedBlockFromProtoBellatrix(
&eth.SignedBlindedBeaconBlockBellatrix{
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashings,
Attestations: b.block.body.attestations,
Deposits: b.block.body.deposits,
VoluntaryExits: b.block.body.voluntaryExits,
SyncAggregate: b.block.body.syncAggregate,
ExecutionPayloadHeader: header,
},
},
},
Signature: b.signature[:],
})
Signature: b.signature[:],
})
case *enginev1.ExecutionPayloadCapella:
header, err := PayloadToHeaderCapella(payload)
if err != nil {
return nil, err
}
return initBlindedSignedBlockFromProtoCapella(
&eth.SignedBlindedBeaconBlockCapella{
Block: &eth.BlindedBeaconBlockCapella{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyCapella{
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashings,
Attestations: b.block.body.attestations,
Deposits: b.block.body.deposits,
VoluntaryExits: b.block.body.voluntaryExits,
SyncAggregate: b.block.body.syncAggregate,
ExecutionPayloadHeader: header,
BlsToExecutionChanges: b.block.body.blsToExecutionChanges,
},
},
Signature: b.signature[:],
})
default:
return nil, fmt.Errorf("%T is not an execution payload header", p)
}
}
// Version of the underlying protobuf object.
@@ -233,6 +310,11 @@ func (b *SignedBeaconBlock) MarshalSSZ() ([]byte, error) {
return pb.(*eth.SignedBlindedBeaconBlockBellatrix).MarshalSSZ()
}
return pb.(*eth.SignedBeaconBlockBellatrix).MarshalSSZ()
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockCapella).MarshalSSZ()
}
return pb.(*eth.SignedBeaconBlockCapella).MarshalSSZ()
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -255,6 +337,11 @@ func (b *SignedBeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
return pb.(*eth.SignedBlindedBeaconBlockBellatrix).MarshalSSZTo(dst)
}
return pb.(*eth.SignedBeaconBlockBellatrix).MarshalSSZTo(dst)
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockCapella).MarshalSSZTo(dst)
}
return pb.(*eth.SignedBeaconBlockCapella).MarshalSSZTo(dst)
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -281,6 +368,11 @@ func (b *SignedBeaconBlock) SizeSSZ() int {
return pb.(*eth.SignedBlindedBeaconBlockBellatrix).SizeSSZ()
}
return pb.(*eth.SignedBeaconBlockBellatrix).SizeSSZ()
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockCapella).SizeSSZ()
}
return pb.(*eth.SignedBeaconBlockCapella).SizeSSZ()
default:
panic(incorrectBlockVersion)
}
@@ -332,6 +424,28 @@ func (b *SignedBeaconBlock) UnmarshalSSZ(buf []byte) error {
return err
}
}
case version.Capella:
if b.IsBlinded() {
pb := &eth.SignedBlindedBeaconBlockCapella{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlindedSignedBlockFromProtoCapella(pb)
if err != nil {
return err
}
} else {
pb := &eth.SignedBeaconBlockCapella{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initSignedBlockFromProtoCapella(pb)
if err != nil {
return err
}
}
default:
return errIncorrectBlockVersion
}
@@ -395,6 +509,11 @@ func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
return pb.(*eth.BlindedBeaconBlockBellatrix).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBellatrix).HashTreeRoot()
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockCapella).HashTreeRoot()
}
return pb.(*eth.BeaconBlockCapella).HashTreeRoot()
default:
return [field_params.RootLength]byte{}, errIncorrectBlockVersion
}
@@ -416,6 +535,11 @@ func (b *BeaconBlock) HashTreeRootWith(h *ssz.Hasher) error {
return pb.(*eth.BlindedBeaconBlockBellatrix).HashTreeRootWith(h)
}
return pb.(*eth.BeaconBlockBellatrix).HashTreeRootWith(h)
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockCapella).HashTreeRootWith(h)
}
return pb.(*eth.BeaconBlockCapella).HashTreeRootWith(h)
default:
return errIncorrectBlockVersion
}
@@ -438,6 +562,11 @@ func (b *BeaconBlock) MarshalSSZ() ([]byte, error) {
return pb.(*eth.BlindedBeaconBlockBellatrix).MarshalSSZ()
}
return pb.(*eth.BeaconBlockBellatrix).MarshalSSZ()
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockCapella).MarshalSSZ()
}
return pb.(*eth.BeaconBlockCapella).MarshalSSZ()
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -460,6 +589,11 @@ func (b *BeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
return pb.(*eth.BlindedBeaconBlockBellatrix).MarshalSSZTo(dst)
}
return pb.(*eth.BeaconBlockBellatrix).MarshalSSZTo(dst)
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockCapella).MarshalSSZTo(dst)
}
return pb.(*eth.BeaconBlockCapella).MarshalSSZTo(dst)
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -486,6 +620,11 @@ func (b *BeaconBlock) SizeSSZ() int {
return pb.(*eth.BlindedBeaconBlockBellatrix).SizeSSZ()
}
return pb.(*eth.BeaconBlockBellatrix).SizeSSZ()
case version.Capella:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockCapella).SizeSSZ()
}
return pb.(*eth.BeaconBlockCapella).SizeSSZ()
default:
panic(incorrectBodyVersion)
}
@@ -537,6 +676,28 @@ func (b *BeaconBlock) UnmarshalSSZ(buf []byte) error {
return err
}
}
case version.Capella:
if b.IsBlinded() {
pb := &eth.BlindedBeaconBlockCapella{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlindedBlockFromProtoCapella(pb)
if err != nil {
return err
}
} else {
pb := &eth.BeaconBlockCapella{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlockFromProtoCapella(pb)
if err != nil {
return err
}
}
default:
return errIncorrectBlockVersion
}
@@ -560,6 +721,11 @@ func (b *BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, erro
return &validatorpb.SignRequest_BlindedBlockBellatrix{BlindedBlockBellatrix: pb.(*eth.BlindedBeaconBlockBellatrix)}, nil
}
return &validatorpb.SignRequest_BlockBellatrix{BlockBellatrix: pb.(*eth.BeaconBlockBellatrix)}, nil
case version.Capella:
if b.IsBlinded() {
return &validatorpb.SignRequest_BlindedBlockCapella{BlindedBlockCapella: pb.(*eth.BlindedBeaconBlockCapella)}, nil
}
return &validatorpb.SignRequest_BlockCapella{BlockCapella: pb.(*eth.BeaconBlockCapella)}, nil
default:
return nil, errIncorrectBlockVersion
}
@@ -625,14 +791,58 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
return nil, errNotSupported("Execution", b.version)
case version.Bellatrix:
if b.isBlinded {
return WrappedExecutionPayloadHeader(b.executionPayloadHeader)
var ph *enginev1.ExecutionPayloadHeader
var ok bool
if b.executionPayloadHeader != nil {
ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeader)
if !ok {
return nil, errPayloadHeaderWrongType
}
}
return WrappedExecutionPayloadHeader(ph)
}
return WrappedExecutionPayload(b.executionPayload)
var p *enginev1.ExecutionPayload
var ok bool
if b.executionPayload != nil {
p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayload)
if !ok {
return nil, errPayloadWrongType
}
}
return WrappedExecutionPayload(p)
case version.Capella:
if b.isBlinded {
var ph *enginev1.ExecutionPayloadHeaderCapella
var ok bool
if b.executionPayloadHeader != nil {
ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderCapella)
if !ok {
return nil, errPayloadHeaderWrongType
}
return WrappedExecutionPayloadHeaderCapella(ph)
}
}
var p *enginev1.ExecutionPayloadCapella
var ok bool
if b.executionPayload != nil {
p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadCapella)
if !ok {
return nil, errPayloadWrongType
}
}
return WrappedExecutionPayloadCapella(p)
default:
return nil, errIncorrectBlockVersion
}
}
func (b *BeaconBlockBody) BLSToExecutionChanges() ([]*eth.SignedBLSToExecutionChange, error) {
if b.version < version.Capella {
return nil, errNotSupported("BLSToExecutionChanges", b.version)
}
return b.blsToExecutionChanges, nil
}
// HashTreeRoot returns the ssz root of the block body.
func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) {
pb, err := b.Proto()
@@ -649,6 +859,11 @@ func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error)
return pb.(*eth.BlindedBeaconBlockBodyBellatrix).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyBellatrix).HashTreeRoot()
case version.Capella:
if b.isBlinded {
return pb.(*eth.BlindedBeaconBlockBodyCapella).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyCapella).HashTreeRoot()
default:
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
}

View File

@@ -309,6 +309,14 @@ func Test_BeaconBlockBody_SyncAggregate(t *testing.T) {
assert.Equal(t, result, sa)
}
func Test_BeaconBlockBody_BLSToExecutionChanges(t *testing.T) {
changes := []*eth.SignedBLSToExecutionChange{{}}
bb := &BeaconBlockBody{version: version.Capella, blsToExecutionChanges: changes}
result, err := bb.BLSToExecutionChanges()
require.NoError(t, err)
assert.DeepSSZEqual(t, result, changes)
}
func Test_BeaconBlockBody_HashTreeRoot(t *testing.T) {
pb := hydrateBeaconBlockBody()
expectedHTR, err := pb.HashTreeRoot()

View File

@@ -3,6 +3,7 @@ package blocks
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"google.golang.org/protobuf/proto"
@@ -73,6 +74,33 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
Block: block,
Signature: b.signature[:],
}, nil
case version.Capella:
if b.IsBlinded() {
var block *eth.BlindedBeaconBlockCapella
if blockMessage != nil {
var ok bool
block, ok = blockMessage.(*eth.BlindedBeaconBlockCapella)
if !ok {
return nil, errIncorrectBlockVersion
}
}
return &eth.SignedBlindedBeaconBlockCapella{
Block: block,
Signature: b.signature[:],
}, nil
}
var block *eth.BeaconBlockCapella
if blockMessage != nil {
var ok bool
block, ok = blockMessage.(*eth.BeaconBlockCapella)
if !ok {
return nil, errIncorrectBlockVersion
}
}
return &eth.SignedBeaconBlockCapella{
Block: block,
Signature: b.signature[:],
}, nil
default:
return nil, errors.New("unsupported signed beacon block version")
}
@@ -155,6 +183,39 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
StateRoot: b.stateRoot[:],
Body: body,
}, nil
case version.Capella:
if b.IsBlinded() {
var body *eth.BlindedBeaconBlockBodyCapella
if bodyMessage != nil {
var ok bool
body, ok = bodyMessage.(*eth.BlindedBeaconBlockBodyCapella)
if !ok {
return nil, errIncorrectBodyVersion
}
}
return &eth.BlindedBeaconBlockCapella{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
}
var body *eth.BeaconBlockBodyCapella
if bodyMessage != nil {
var ok bool
body, ok = bodyMessage.(*eth.BeaconBlockBodyCapella)
if !ok {
return nil, errIncorrectBodyVersion
}
}
return &eth.BeaconBlockCapella{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
default:
return nil, errors.New("unsupported beacon block version")
}
@@ -192,6 +253,14 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
}, nil
case version.Bellatrix:
if b.isBlinded {
var ph *enginev1.ExecutionPayloadHeader
var ok bool
if b.executionPayloadHeader != nil {
ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeader)
if !ok {
return nil, errPayloadHeaderWrongType
}
}
return &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
@@ -202,9 +271,17 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayloadHeader: b.executionPayloadHeader,
ExecutionPayloadHeader: ph,
}, nil
}
var p *enginev1.ExecutionPayload
var ok bool
if b.executionPayload != nil {
p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayload)
if !ok {
return nil, errPayloadWrongType
}
}
return &eth.BeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
@@ -215,7 +292,52 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayload: b.executionPayload,
ExecutionPayload: p,
}, nil
case version.Capella:
if b.isBlinded {
var ph *enginev1.ExecutionPayloadHeaderCapella
var ok bool
if b.executionPayloadHeader != nil {
ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderCapella)
if !ok {
return nil, errPayloadHeaderWrongType
}
}
return &eth.BlindedBeaconBlockBodyCapella{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayloadHeader: ph,
BlsToExecutionChanges: b.blsToExecutionChanges,
}, nil
}
var p *enginev1.ExecutionPayloadCapella
var ok bool
if b.executionPayload != nil {
p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadCapella)
if !ok {
return nil, errPayloadWrongType
}
}
return &eth.BeaconBlockBodyCapella{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayload: p,
BlsToExecutionChanges: b.blsToExecutionChanges,
}, nil
default:
return nil, errors.New("unsupported beacon block body version")
@@ -273,6 +395,23 @@ func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*Sig
return b, nil
}
func initSignedBlockFromProtoCapella(pb *eth.SignedBeaconBlockCapella) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
block, err := initBlockFromProtoCapella(pb.Block)
if err != nil {
return nil, err
}
b := &SignedBeaconBlock{
version: version.Capella,
block: block,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBellatrix) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
@@ -290,6 +429,23 @@ func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBe
return b, nil
}
func initBlindedSignedBlockFromProtoCapella(pb *eth.SignedBlindedBeaconBlockCapella) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
block, err := initBlindedBlockFromProtoCapella(pb.Block)
if err != nil {
return nil, err
}
b := &SignedBeaconBlock{
version: version.Capella,
block: block,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
@@ -370,6 +526,46 @@ func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*B
return b, nil
}
func initBlockFromProtoCapella(pb *eth.BeaconBlockCapella) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
body, err := initBlockBodyFromProtoCapella(pb.Body)
if err != nil {
return nil, err
}
b := &BeaconBlock{
version: version.Capella,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
}
func initBlindedBlockFromProtoCapella(pb *eth.BlindedBeaconBlockCapella) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
body, err := initBlindedBlockBodyFromProtoCapella(pb.Body)
if err != nil {
return nil, err
}
b := &BeaconBlock{
version: version.Capella,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
}
func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
@@ -416,6 +612,11 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
return nil, errNilBlockBody
}
p, err := WrappedExecutionPayload(pb.ExecutionPayload)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: false,
@@ -428,7 +629,7 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayload: pb.ExecutionPayload,
executionPayload: p,
}
return b, nil
}
@@ -438,6 +639,11 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
return nil, errNilBlockBody
}
ph, err := WrappedExecutionPayloadHeader(pb.ExecutionPayloadHeader)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
@@ -450,7 +656,63 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayloadHeader: pb.ExecutionPayloadHeader,
executionPayloadHeader: ph,
}
return b, nil
}
func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
}
p, err := WrappedExecutionPayloadCapella(pb.ExecutionPayload)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Capella,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayload: p,
blsToExecutionChanges: pb.BlsToExecutionChanges,
}
return b, nil
}
func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
}
ph, err := WrappedExecutionPayloadHeaderCapella(pb.ExecutionPayloadHeader)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Capella,
isBlinded: true,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayloadHeader: ph,
blsToExecutionChanges: pb.BlsToExecutionChanges,
}
return b, nil
}

View File

@@ -12,16 +12,19 @@ import (
)
type fields struct {
root [32]byte
sig [96]byte
deposits []*eth.Deposit
atts []*eth.Attestation
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
voluntaryExits []*eth.SignedVoluntaryExit
syncAggregate *eth.SyncAggregate
execPayload *enginev1.ExecutionPayload
execPayloadHeader *enginev1.ExecutionPayloadHeader
root [32]byte
sig [96]byte
deposits []*eth.Deposit
atts []*eth.Attestation
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
voluntaryExits []*eth.SignedVoluntaryExit
syncAggregate *eth.SyncAggregate
execPayload *enginev1.ExecutionPayload
execPayloadHeader *enginev1.ExecutionPayloadHeader
execPayloadCapella *enginev1.ExecutionPayloadCapella
execPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella
blsToExecutionChanges []*eth.SignedBLSToExecutionChange
}
func Test_SignedBeaconBlock_Proto(t *testing.T) {
@@ -114,7 +117,7 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
body: bodyBellatrix(t),
},
signature: f.sig,
}
@@ -148,7 +151,7 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
body: bodyBlindedBellatrix(t),
},
signature: f.sig,
}
@@ -163,6 +166,74 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("Capella", func(t *testing.T) {
expectedBlock := &eth.SignedBeaconBlockCapella{
Block: &eth.BeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbCapella(),
},
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Capella,
block: &BeaconBlock{
version: version.Capella,
slot: 128,
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyCapella(t),
},
signature: f.sig,
}
result, err := block.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.SignedBeaconBlockCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("CapellaBlind", func(t *testing.T) {
expectedBlock := &eth.SignedBlindedBeaconBlockCapella{
Block: &eth.BlindedBeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedCapella(),
},
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Capella,
block: &BeaconBlock{
version: version.Capella,
slot: 128,
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedCapella(t),
},
signature: f.sig,
}
result, err := block.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.SignedBlindedBeaconBlockCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
}
func Test_BeaconBlock_Proto(t *testing.T) {
@@ -236,7 +307,7 @@ func Test_BeaconBlock_Proto(t *testing.T) {
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
body: bodyBellatrix(t),
}
result, err := block.Proto()
@@ -263,7 +334,7 @@ func Test_BeaconBlock_Proto(t *testing.T) {
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
body: bodyBlindedBellatrix(t),
}
result, err := block.Proto()
@@ -276,6 +347,60 @@ func Test_BeaconBlock_Proto(t *testing.T) {
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("Capella", func(t *testing.T) {
expectedBlock := &eth.BeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbCapella(),
}
block := &BeaconBlock{
version: version.Capella,
slot: 128,
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyCapella(t),
}
result, err := block.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BeaconBlockCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("CapellaBlind", func(t *testing.T) {
expectedBlock := &eth.BlindedBeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedCapella(),
}
block := &BeaconBlock{
version: version.Capella,
slot: 128,
proposerIndex: 128,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedCapella(t),
}
result, err := block.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BlindedBeaconBlockCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
}
func Test_BeaconBlockBody_Proto(t *testing.T) {
@@ -308,7 +433,7 @@ func Test_BeaconBlockBody_Proto(t *testing.T) {
})
t.Run("Bellatrix", func(t *testing.T) {
expectedBody := bodyPbBellatrix()
body := bodyBellatrix()
body := bodyBellatrix(t)
result, err := body.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BeaconBlockBodyBellatrix)
@@ -321,7 +446,7 @@ func Test_BeaconBlockBody_Proto(t *testing.T) {
})
t.Run("BellatrixBlind", func(t *testing.T) {
expectedBody := bodyPbBlindedBellatrix()
body := bodyBlindedBellatrix()
body := bodyBlindedBellatrix(t)
result, err := body.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BlindedBeaconBlockBodyBellatrix)
@@ -332,6 +457,56 @@ func Test_BeaconBlockBody_Proto(t *testing.T) {
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("Capella", func(t *testing.T) {
expectedBody := bodyPbCapella()
body := bodyCapella(t)
result, err := body.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BeaconBlockBodyCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBody.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("CapellaBlind", func(t *testing.T) {
expectedBody := bodyPbBlindedCapella()
body := bodyBlindedCapella(t)
result, err := body.Proto()
require.NoError(t, err)
resultBlock, ok := result.(*eth.BlindedBeaconBlockBodyCapella)
require.Equal(t, true, ok)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBody.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
})
t.Run("Bellatrix - wrong payload type", func(t *testing.T) {
body := bodyBellatrix(t)
body.executionPayload = &executionPayloadHeader{}
_, err := body.Proto()
require.ErrorIs(t, err, errPayloadWrongType)
})
t.Run("BellatrixBlind - wrong payload type", func(t *testing.T) {
body := bodyBlindedBellatrix(t)
body.executionPayloadHeader = &executionPayload{}
_, err := body.Proto()
require.ErrorIs(t, err, errPayloadHeaderWrongType)
})
t.Run("Capella - wrong payload type", func(t *testing.T) {
body := bodyCapella(t)
body.executionPayload = &executionPayloadHeaderCapella{}
_, err := body.Proto()
require.ErrorIs(t, err, errPayloadWrongType)
})
t.Run("CapellaBlind - wrong payload type", func(t *testing.T) {
body := bodyBlindedCapella(t)
body.executionPayloadHeader = &executionPayloadCapella{}
_, err := body.Proto()
require.ErrorIs(t, err, errPayloadHeaderWrongType)
})
}
func Test_initSignedBlockFromProtoPhase0(t *testing.T) {
@@ -422,6 +597,50 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initSignedBlockFromProtoCapella(t *testing.T) {
f := getFields()
expectedBlock := &eth.SignedBeaconBlockCapella{
Block: &eth.BeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbCapella(),
},
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoCapella(expectedBlock)
require.NoError(t, err)
resultHTR, err := resultBlock.block.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlindedSignedBlockFromProtoCapella(t *testing.T) {
f := getFields()
expectedBlock := &eth.SignedBlindedBeaconBlockCapella{
Block: &eth.BlindedBeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedCapella(),
},
Signature: f.sig[:],
}
resultBlock, err := initBlindedSignedBlockFromProtoCapella(expectedBlock)
require.NoError(t, err)
resultHTR, err := resultBlock.block.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlockFromProtoPhase0(t *testing.T) {
f := getFields()
expectedBlock := &eth.BeaconBlock{
@@ -494,6 +713,42 @@ func Test_initBlockFromProtoBlindedBellatrix(t *testing.T) {
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func Test_initBlockFromProtoCapella(t *testing.T) {
f := getFields()
expectedBlock := &eth.BeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbCapella(),
}
resultBlock, err := initBlockFromProtoCapella(expectedBlock)
require.NoError(t, err)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func Test_initBlockFromProtoBlindedCapella(t *testing.T) {
f := getFields()
expectedBlock := &eth.BlindedBeaconBlockCapella{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedCapella(),
}
resultBlock, err := initBlindedBlockFromProtoCapella(expectedBlock)
require.NoError(t, err)
resultHTR, err := resultBlock.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBlock.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func Test_initBlockBodyFromProtoPhase0(t *testing.T) {
expectedBody := bodyPbPhase0()
resultBody, err := initBlockBodyFromProtoPhase0(expectedBody)
@@ -538,6 +793,28 @@ func Test_initBlockBodyFromProtoBlindedBellatrix(t *testing.T) {
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func Test_initBlockBodyFromProtoCapella(t *testing.T) {
expectedBody := bodyPbCapella()
resultBody, err := initBlockBodyFromProtoCapella(expectedBody)
require.NoError(t, err)
resultHTR, err := resultBody.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBody.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func Test_initBlockBodyFromProtoBlindedCapella(t *testing.T) {
expectedBody := bodyPbBlindedCapella()
resultBody, err := initBlindedBlockBodyFromProtoCapella(expectedBody)
require.NoError(t, err)
resultHTR, err := resultBody.HashTreeRoot()
require.NoError(t, err)
expectedHTR, err := expectedBody.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
}
func bodyPbPhase0() *eth.BeaconBlockBody {
f := getFields()
return &eth.BeaconBlockBody{
@@ -615,6 +892,48 @@ func bodyPbBlindedBellatrix() *eth.BlindedBeaconBlockBodyBellatrix {
}
}
func bodyPbCapella() *eth.BeaconBlockBodyCapella {
f := getFields()
return &eth.BeaconBlockBodyCapella{
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.root[:],
},
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
Deposits: f.deposits,
VoluntaryExits: f.voluntaryExits,
SyncAggregate: f.syncAggregate,
ExecutionPayload: f.execPayloadCapella,
BlsToExecutionChanges: f.blsToExecutionChanges,
}
}
func bodyPbBlindedCapella() *eth.BlindedBeaconBlockBodyCapella {
f := getFields()
return &eth.BlindedBeaconBlockBodyCapella{
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.root[:],
},
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
Deposits: f.deposits,
VoluntaryExits: f.voluntaryExits,
SyncAggregate: f.syncAggregate,
ExecutionPayloadHeader: f.execPayloadHeaderCapella,
BlsToExecutionChanges: f.blsToExecutionChanges,
}
}
func bodyPhase0() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
@@ -654,8 +973,10 @@ func bodyAltair() *BeaconBlockBody {
}
}
func bodyBellatrix() *BeaconBlockBody {
func bodyBellatrix(t *testing.T) *BeaconBlockBody {
f := getFields()
p, err := WrappedExecutionPayload(f.execPayload)
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Bellatrix,
randaoReveal: f.sig,
@@ -671,12 +992,14 @@ func bodyBellatrix() *BeaconBlockBody {
deposits: f.deposits,
voluntaryExits: f.voluntaryExits,
syncAggregate: f.syncAggregate,
executionPayload: f.execPayload,
executionPayload: p,
}
}
func bodyBlindedBellatrix() *BeaconBlockBody {
func bodyBlindedBellatrix(t *testing.T) *BeaconBlockBody {
f := getFields()
ph, err := WrappedExecutionPayloadHeader(f.execPayloadHeader)
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
@@ -693,7 +1016,56 @@ func bodyBlindedBellatrix() *BeaconBlockBody {
deposits: f.deposits,
voluntaryExits: f.voluntaryExits,
syncAggregate: f.syncAggregate,
executionPayloadHeader: f.execPayloadHeader,
executionPayloadHeader: ph,
}
}
func bodyCapella(t *testing.T) *BeaconBlockBody {
f := getFields()
p, err := WrappedExecutionPayloadCapella(f.execPayloadCapella)
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Capella,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.root[:],
},
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
deposits: f.deposits,
voluntaryExits: f.voluntaryExits,
syncAggregate: f.syncAggregate,
executionPayload: p,
blsToExecutionChanges: f.blsToExecutionChanges,
}
}
func bodyBlindedCapella(t *testing.T) *BeaconBlockBody {
f := getFields()
ph, err := WrappedExecutionPayloadHeaderCapella(f.execPayloadHeaderCapella)
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Capella,
isBlinded: true,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.root[:],
},
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
deposits: f.deposits,
voluntaryExits: f.voluntaryExits,
syncAggregate: f.syncAggregate,
executionPayloadHeader: ph,
blsToExecutionChanges: f.blsToExecutionChanges,
}
}
@@ -850,17 +1222,72 @@ func getFields() fields {
BlockHash: root[:],
TransactionsRoot: root[:],
}
execPayloadCapella := &enginev1.ExecutionPayloadCapella{
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
Transactions: [][]byte{
[]byte("transaction1"),
[]byte("transaction2"),
[]byte("transaction8"),
},
Withdrawals: []*enginev1.Withdrawal{
{
WithdrawalIndex: 128,
ExecutionAddress: b20,
Amount: 128,
},
},
}
execPayloadHeaderCapella := &enginev1.ExecutionPayloadHeaderCapella{
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
TransactionsRoot: root[:],
WithdrawalsRoot: root[:],
}
blsToExecutionChanges := []*eth.SignedBLSToExecutionChange{{
Message: &eth.BLSToExecutionChange{
ValidatorIndex: 128,
FromBlsPubkey: b48,
ToExecutionAddress: b20,
},
Signature: sig[:],
}}
return fields{
root: root,
sig: sig,
deposits: deposits,
atts: atts,
proposerSlashings: []*eth.ProposerSlashing{proposerSlashing},
attesterSlashings: []*eth.AttesterSlashing{attesterSlashing},
voluntaryExits: []*eth.SignedVoluntaryExit{voluntaryExit},
syncAggregate: syncAggregate,
execPayload: execPayload,
execPayloadHeader: execPayloadHeader,
root: root,
sig: sig,
deposits: deposits,
atts: atts,
proposerSlashings: []*eth.ProposerSlashing{proposerSlashing},
attesterSlashings: []*eth.AttesterSlashing{attesterSlashing},
voluntaryExits: []*eth.SignedVoluntaryExit{voluntaryExit},
syncAggregate: syncAggregate,
execPayload: execPayload,
execPayloadHeader: execPayloadHeader,
execPayloadCapella: execPayloadCapella,
execPayloadHeaderCapella: execPayloadHeaderCapella,
blsToExecutionChanges: blsToExecutionChanges,
}
}

View File

@@ -22,6 +22,10 @@ func NewSignedBeaconBlockFromGeneric(gb *eth.GenericSignedBeaconBlock) (interfac
return blocks.NewSignedBeaconBlock(bb.Bellatrix)
case *eth.GenericSignedBeaconBlock_BlindedBellatrix:
return blocks.NewSignedBeaconBlock(bb.BlindedBellatrix)
case *eth.GenericSignedBeaconBlock_Capella:
return blocks.NewSignedBeaconBlock(bb.Capella)
case *eth.GenericSignedBeaconBlock_BlindedCapella:
return blocks.NewSignedBeaconBlock(bb.BlindedCapella)
default:
return nil, errors.Wrapf(blocks.ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", gb)
}

View File

@@ -12,6 +12,7 @@ type blockMutator struct {
Phase0 func(beaconBlock *eth.SignedBeaconBlock)
Altair func(beaconBlock *eth.SignedBeaconBlockAltair)
Bellatrix func(beaconBlock *eth.SignedBeaconBlockBellatrix)
Capella func(beaconBlock *eth.SignedBeaconBlockCapella)
}
func (m blockMutator) apply(b interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
@@ -37,6 +38,13 @@ func (m blockMutator) apply(b interfaces.SignedBeaconBlock) (interfaces.SignedBe
}
m.Bellatrix(bb)
return blocks.NewSignedBeaconBlock(bb)
case version.Capella:
bb, err := b.PbCapellaBlock()
if err != nil {
return nil, err
}
m.Capella(bb)
return blocks.NewSignedBeaconBlock(bb)
default:
return nil, blocks.ErrUnsupportedSignedBeaconBlock
}
@@ -48,6 +56,7 @@ func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) (interfaces.
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.StateRoot = sr[:] },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.StateRoot = sr[:] },
Bellatrix: func(bb *eth.SignedBeaconBlockBellatrix) { bb.Block.StateRoot = sr[:] },
Capella: func(bb *eth.SignedBeaconBlockCapella) { bb.Block.StateRoot = sr[:] },
}.apply(b)
}
@@ -57,6 +66,7 @@ func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) (interfaces
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ParentRoot = pr[:] },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ParentRoot = pr[:] },
Bellatrix: func(bb *eth.SignedBeaconBlockBellatrix) { bb.Block.ParentRoot = pr[:] },
Capella: func(bb *eth.SignedBeaconBlockCapella) { bb.Block.ParentRoot = pr[:] },
}.apply(b)
}
@@ -66,6 +76,7 @@ func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) (interfaces.Sign
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.Slot = s },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.Slot = s },
Bellatrix: func(bb *eth.SignedBeaconBlockBellatrix) { bb.Block.Slot = s },
Capella: func(bb *eth.SignedBeaconBlockCapella) { bb.Block.Slot = s },
}.apply(b)
}
@@ -75,5 +86,6 @@ func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex)
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ProposerIndex = idx },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ProposerIndex = idx },
Bellatrix: func(bb *eth.SignedBeaconBlockBellatrix) { bb.Block.ProposerIndex = idx },
Capella: func(bb *eth.SignedBeaconBlockCapella) { bb.Block.ProposerIndex = idx },
}.apply(b)
}

View File

@@ -7,7 +7,6 @@ import (
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
engine "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
)
@@ -18,6 +17,11 @@ var (
_ = interfaces.BeaconBlockBody(&BeaconBlockBody{})
)
var (
errPayloadWrongType = errors.New("execution payload has wrong type")
errPayloadHeaderWrongType = errors.New("execution payload header has wrong type")
)
const (
incorrectBlockVersion = "incorrect beacon block version"
incorrectBodyVersion = "incorrect beacon block body version"
@@ -49,8 +53,9 @@ type BeaconBlockBody struct {
deposits []*eth.Deposit
voluntaryExits []*eth.SignedVoluntaryExit
syncAggregate *eth.SyncAggregate
executionPayload *engine.ExecutionPayload
executionPayloadHeader *engine.ExecutionPayloadHeader
executionPayload interfaces.ExecutionData
executionPayloadHeader interfaces.ExecutionData
blsToExecutionChanges []*eth.SignedBLSToExecutionChange
}
// BeaconBlock is the main beacon block structure. It can represent any block type.

View File

@@ -24,6 +24,8 @@ type SignedBeaconBlock interface {
ToBlinded() (SignedBeaconBlock, error)
PbBellatrixBlock() (*ethpb.SignedBeaconBlockBellatrix, error)
PbBlindedBellatrixBlock() (*ethpb.SignedBlindedBeaconBlockBellatrix, error)
PbCapellaBlock() (*ethpb.SignedBeaconBlockCapella, error)
PbBlindedCapellaBlock() (*ethpb.SignedBlindedBeaconBlockCapella, error)
ssz.Marshaler
ssz.Unmarshaler
Version() int
@@ -66,6 +68,7 @@ type BeaconBlockBody interface {
HashTreeRoot() ([field_params.RootLength]byte, error)
Proto() (proto.Message, error)
Execution() (ExecutionData, error)
BLSToExecutionChanges() ([]*ethpb.SignedBLSToExecutionChange, error)
}
// ExecutionData represents execution layer information that is contained

View File

@@ -54,6 +54,14 @@ func (SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconBloc
panic("implement me")
}
func (SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBlindedCapellaBlock() (*eth.SignedBlindedBeaconBlockCapella, error) {
panic("implement me")
}
func (SignedBeaconBlock) MarshalSSZTo(_ []byte) ([]byte, error) {
panic("implement me")
}
@@ -211,6 +219,10 @@ func (BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
panic("implement me")
}
func (BeaconBlockBody) BLSToExecutionChanges() ([]*eth.SignedBLSToExecutionChange, error) {
panic("implement me")
}
var _ interfaces.SignedBeaconBlock = &SignedBeaconBlock{}
var _ interfaces.BeaconBlock = &BeaconBlock{}
var _ interfaces.BeaconBlockBody = &BeaconBlockBody{}