mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
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:
@@ -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 ð.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 ð.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 ð.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 ð.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 ð.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 ð.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 ð.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 ð.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user