mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
Update light-client consensus types (#14652)
* update diff * deps * changelog * remove `SetNextSyncCommitteeBranchElectra`
This commit is contained in:
@@ -59,6 +59,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
|
||||
- Non-blocking payload attribute event handling in beacon api [pr](https://github.com/prysmaticlabs/prysm/pull/14644).
|
||||
- Updated light client protobufs. [PR](https://github.com/prysmaticlabs/prysm/pull/14650)
|
||||
- Added `Eth-Consensus-Version` header to `ListAttestationsV2` and `GetAggregateAttestationV2` endpoints.
|
||||
- Updated light client consensus types. [PR](https://github.com/prysmaticlabs/prysm/pull/14652)
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ const (
|
||||
SyncCommitteeBranchDepth = 5 // SyncCommitteeBranchDepth defines the number of leaves in a merkle proof of a sync committee.
|
||||
SyncCommitteeBranchDepthElectra = 6 // SyncCommitteeBranchDepthElectra defines the number of leaves in a merkle proof of a sync committee.
|
||||
FinalityBranchDepth = 6 // FinalityBranchDepth defines the number of leaves in a merkle proof of the finalized checkpoint root.
|
||||
FinalityBranchDepthElectra = 7 // FinalityBranchDepthElectra defines the number of leaves in a merkle proof of the finalized checkpoint root.
|
||||
PendingDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
||||
PendingPartialWithdrawalsLimit = 134217728 // Maximum number of pending partial withdrawals in the beacon state.
|
||||
PendingConsolidationsLimit = 262144 // Maximum number of pending consolidations in the beacon state.
|
||||
|
||||
@@ -37,6 +37,7 @@ const (
|
||||
SyncCommitteeBranchDepth = 5 // SyncCommitteeBranchDepth defines the number of leaves in a merkle proof of a sync committee.
|
||||
SyncCommitteeBranchDepthElectra = 6 // SyncCommitteeBranchDepthElectra defines the number of leaves in a merkle proof of a sync committee.
|
||||
FinalityBranchDepth = 6 // FinalityBranchDepth defines the number of leaves in a merkle proof of the finalized checkpoint root.
|
||||
FinalityBranchDepthElectra = 7 // FinalityBranchDepthElectra defines the number of leaves in a merkle proof of the finalized checkpoint root.
|
||||
PendingDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
||||
PendingPartialWithdrawalsLimit = 64 // Maximum number of pending partial withdrawals in the beacon state.
|
||||
PendingConsolidationsLimit = 64 // Maximum number of pending consolidations in the beacon state.
|
||||
|
||||
@@ -5,15 +5,18 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type LightClientExecutionBranch = [fieldparams.ExecutionBranchDepth][fieldparams.RootLength]byte
|
||||
type LightClientSyncCommitteeBranch = [fieldparams.SyncCommitteeBranchDepth][fieldparams.RootLength]byte
|
||||
type LightClientSyncCommitteeBranchElectra = [fieldparams.SyncCommitteeBranchDepthElectra][fieldparams.RootLength]byte
|
||||
type LightClientFinalityBranch = [fieldparams.FinalityBranchDepth][fieldparams.RootLength]byte
|
||||
type LightClientFinalityBranchElectra = [fieldparams.FinalityBranchDepthElectra][fieldparams.RootLength]byte
|
||||
|
||||
type LightClientHeader interface {
|
||||
ssz.Marshaler
|
||||
Proto() proto.Message
|
||||
Version() int
|
||||
Beacon() *pb.BeaconBlockHeader
|
||||
Execution() (ExecutionData, error)
|
||||
@@ -31,29 +34,41 @@ type LightClientBootstrap interface {
|
||||
|
||||
type LightClientUpdate interface {
|
||||
ssz.Marshaler
|
||||
Proto() proto.Message
|
||||
Version() int
|
||||
AttestedHeader() LightClientHeader
|
||||
SetAttestedHeader(header LightClientHeader) error
|
||||
NextSyncCommittee() *pb.SyncCommittee
|
||||
SetNextSyncCommittee(sc *pb.SyncCommittee)
|
||||
NextSyncCommitteeBranch() (LightClientSyncCommitteeBranch, error)
|
||||
SetNextSyncCommitteeBranch(branch [][]byte) error
|
||||
NextSyncCommitteeBranchElectra() (LightClientSyncCommitteeBranchElectra, error)
|
||||
FinalizedHeader() LightClientHeader
|
||||
FinalityBranch() LightClientFinalityBranch
|
||||
SetFinalizedHeader(header LightClientHeader) error
|
||||
FinalityBranch() (LightClientFinalityBranch, error)
|
||||
FinalityBranchElectra() (LightClientFinalityBranchElectra, error)
|
||||
SetFinalityBranch(branch [][]byte) error
|
||||
SyncAggregate() *pb.SyncAggregate
|
||||
SetSyncAggregate(sa *pb.SyncAggregate)
|
||||
SignatureSlot() primitives.Slot
|
||||
SetSignatureSlot(slot primitives.Slot)
|
||||
}
|
||||
|
||||
type LightClientFinalityUpdate interface {
|
||||
ssz.Marshaler
|
||||
Proto() proto.Message
|
||||
Version() int
|
||||
AttestedHeader() LightClientHeader
|
||||
FinalizedHeader() LightClientHeader
|
||||
FinalityBranch() LightClientFinalityBranch
|
||||
FinalityBranch() (LightClientFinalityBranch, error)
|
||||
FinalityBranchElectra() (LightClientFinalityBranchElectra, error)
|
||||
SyncAggregate() *pb.SyncAggregate
|
||||
SignatureSlot() primitives.Slot
|
||||
}
|
||||
|
||||
type LightClientOptimisticUpdate interface {
|
||||
ssz.Marshaler
|
||||
Proto() proto.Message
|
||||
Version() int
|
||||
AttestedHeader() LightClientHeader
|
||||
SyncAggregate() *pb.SyncAggregate
|
||||
|
||||
@@ -14,6 +14,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
@@ -21,6 +22,7 @@ go_library(
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewWrappedBootstrapAltair(p *pb.LightClientBootstrapAltair) (interfaces.Lig
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
header, err := NewWrappedHeaderAltair(p.Header)
|
||||
header, err := NewWrappedHeader(p.Header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func NewWrappedBootstrapCapella(p *pb.LightClientBootstrapCapella) (interfaces.L
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
header, err := NewWrappedHeaderCapella(p.Header)
|
||||
header, err := NewWrappedHeader(p.Header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func NewWrappedBootstrapDeneb(p *pb.LightClientBootstrapDeneb) (interfaces.Light
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
header, err := NewWrappedHeaderDeneb(p.Header)
|
||||
header, err := NewWrappedHeader(p.Header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func NewWrappedBootstrapElectra(p *pb.LightClientBootstrapElectra) (interfaces.L
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
header, err := NewWrappedHeaderDeneb(p.Header)
|
||||
header, err := NewWrappedHeader(p.Header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -23,11 +23,72 @@ func NewWrappedFinalityUpdate(m proto.Message) (interfaces.LightClientFinalityUp
|
||||
return NewWrappedFinalityUpdateCapella(t)
|
||||
case *pb.LightClientFinalityUpdateDeneb:
|
||||
return NewWrappedFinalityUpdateDeneb(t)
|
||||
case *pb.LightClientFinalityUpdateElectra:
|
||||
return NewWrappedFinalityUpdateElectra(t)
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot construct light client finality update from type %T", t)
|
||||
}
|
||||
}
|
||||
|
||||
func NewFinalityUpdateFromUpdate(update interfaces.LightClientUpdate) (interfaces.LightClientFinalityUpdate, error) {
|
||||
switch t := update.(type) {
|
||||
case *updateAltair:
|
||||
return &finalityUpdateAltair{
|
||||
p: &pb.LightClientFinalityUpdateAltair{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
FinalizedHeader: t.p.FinalizedHeader,
|
||||
FinalityBranch: t.p.FinalityBranch,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
finalizedHeader: t.finalizedHeader,
|
||||
finalityBranch: t.finalityBranch,
|
||||
}, nil
|
||||
case *updateCapella:
|
||||
return &finalityUpdateCapella{
|
||||
p: &pb.LightClientFinalityUpdateCapella{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
FinalizedHeader: t.p.FinalizedHeader,
|
||||
FinalityBranch: t.p.FinalityBranch,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
finalizedHeader: t.finalizedHeader,
|
||||
finalityBranch: t.finalityBranch,
|
||||
}, nil
|
||||
case *updateDeneb:
|
||||
return &finalityUpdateDeneb{
|
||||
p: &pb.LightClientFinalityUpdateDeneb{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
FinalizedHeader: t.p.FinalizedHeader,
|
||||
FinalityBranch: t.p.FinalityBranch,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
finalizedHeader: t.finalizedHeader,
|
||||
finalityBranch: t.finalityBranch,
|
||||
}, nil
|
||||
case *updateElectra:
|
||||
return &finalityUpdateElectra{
|
||||
p: &pb.LightClientFinalityUpdateElectra{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
FinalizedHeader: t.p.FinalizedHeader,
|
||||
FinalityBranch: t.p.FinalityBranch,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
finalizedHeader: t.finalizedHeader,
|
||||
finalityBranch: t.finalityBranch,
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported type %T", t)
|
||||
}
|
||||
}
|
||||
|
||||
type finalityUpdateAltair struct {
|
||||
p *pb.LightClientFinalityUpdateAltair
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
@@ -41,11 +102,11 @@ func NewWrappedFinalityUpdateAltair(p *pb.LightClientFinalityUpdateAltair) (inte
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderAltair(p.AttestedHeader)
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderAltair(p.FinalizedHeader)
|
||||
finalizedHeader, err := NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -78,6 +139,10 @@ func (u *finalityUpdateAltair) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *finalityUpdateAltair) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *finalityUpdateAltair) Version() int {
|
||||
return version.Altair
|
||||
}
|
||||
@@ -90,8 +155,12 @@ func (u *finalityUpdateAltair) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *finalityUpdateAltair) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *finalityUpdateAltair) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *finalityUpdateAltair) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", u.Version())
|
||||
}
|
||||
|
||||
func (u *finalityUpdateAltair) SyncAggregate() *pb.SyncAggregate {
|
||||
@@ -115,11 +184,11 @@ func NewWrappedFinalityUpdateCapella(p *pb.LightClientFinalityUpdateCapella) (in
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderCapella(p.AttestedHeader)
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderCapella(p.FinalizedHeader)
|
||||
finalizedHeader, err := NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -152,6 +221,10 @@ func (u *finalityUpdateCapella) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *finalityUpdateCapella) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *finalityUpdateCapella) Version() int {
|
||||
return version.Capella
|
||||
}
|
||||
@@ -164,8 +237,12 @@ func (u *finalityUpdateCapella) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *finalityUpdateCapella) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *finalityUpdateCapella) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *finalityUpdateCapella) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", u.Version())
|
||||
}
|
||||
|
||||
func (u *finalityUpdateCapella) SyncAggregate() *pb.SyncAggregate {
|
||||
@@ -189,11 +266,11 @@ func NewWrappedFinalityUpdateDeneb(p *pb.LightClientFinalityUpdateDeneb) (interf
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderDeneb(p.AttestedHeader)
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderDeneb(p.FinalizedHeader)
|
||||
finalizedHeader, err := NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -226,6 +303,10 @@ func (u *finalityUpdateDeneb) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *finalityUpdateDeneb) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *finalityUpdateDeneb) Version() int {
|
||||
return version.Deneb
|
||||
}
|
||||
@@ -238,8 +319,12 @@ func (u *finalityUpdateDeneb) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *finalityUpdateDeneb) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *finalityUpdateDeneb) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *finalityUpdateDeneb) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", u.Version())
|
||||
}
|
||||
|
||||
func (u *finalityUpdateDeneb) SyncAggregate() *pb.SyncAggregate {
|
||||
@@ -249,3 +334,86 @@ func (u *finalityUpdateDeneb) SyncAggregate() *pb.SyncAggregate {
|
||||
func (u *finalityUpdateDeneb) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
type finalityUpdateElectra struct {
|
||||
p *pb.LightClientFinalityUpdateElectra
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
finalizedHeader interfaces.LightClientHeader
|
||||
finalityBranch interfaces.LightClientFinalityBranchElectra
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientFinalityUpdate = &finalityUpdateElectra{}
|
||||
|
||||
func NewWrappedFinalityUpdateElectra(p *pb.LightClientFinalityUpdateElectra) (interfaces.LightClientFinalityUpdate, error) {
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
finalityBranch, err := createBranch[interfaces.LightClientFinalityBranchElectra](
|
||||
"finality",
|
||||
p.FinalityBranch,
|
||||
fieldparams.FinalityBranchDepthElectra,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &finalityUpdateElectra{
|
||||
p: p,
|
||||
attestedHeader: attestedHeader,
|
||||
finalizedHeader: finalizedHeader,
|
||||
finalityBranch: finalityBranch,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
return u.p.MarshalSSZTo(dst)
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) MarshalSSZ() ([]byte, error) {
|
||||
return u.p.MarshalSSZ()
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) Version() int {
|
||||
return version.Electra
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return interfaces.LightClientFinalityBranch{}, consensustypes.ErrNotSupported("FinalityBranch", u.Version())
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *finalityUpdateElectra) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/config/params"
|
||||
consensustypes "github.com/prysmaticlabs/prysm/v5/consensus-types"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
||||
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/v5/time/slots"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -22,6 +24,9 @@ func NewWrappedHeader(m proto.Message) (interfaces.LightClientHeader, error) {
|
||||
case *pb.LightClientHeaderCapella:
|
||||
return NewWrappedHeaderCapella(t)
|
||||
case *pb.LightClientHeaderDeneb:
|
||||
if slots.ToEpoch(t.Beacon.Slot) >= params.BeaconConfig().ElectraForkEpoch {
|
||||
return NewWrappedHeaderElectra(t)
|
||||
}
|
||||
return NewWrappedHeaderDeneb(t)
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot construct light client header from type %T", t)
|
||||
@@ -53,6 +58,10 @@ func (h *headerAltair) SizeSSZ() int {
|
||||
return h.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (h *headerAltair) Proto() proto.Message {
|
||||
return h.p
|
||||
}
|
||||
|
||||
func (h *headerAltair) Version() int {
|
||||
return version.Altair
|
||||
}
|
||||
@@ -62,11 +71,11 @@ func (h *headerAltair) Beacon() *pb.BeaconBlockHeader {
|
||||
}
|
||||
|
||||
func (h *headerAltair) Execution() (interfaces.ExecutionData, error) {
|
||||
return nil, consensustypes.ErrNotSupported("Execution", version.Altair)
|
||||
return nil, consensustypes.ErrNotSupported("Execution", h.Version())
|
||||
}
|
||||
|
||||
func (h *headerAltair) ExecutionBranch() (interfaces.LightClientExecutionBranch, error) {
|
||||
return interfaces.LightClientExecutionBranch{}, consensustypes.ErrNotSupported("ExecutionBranch", version.Altair)
|
||||
return interfaces.LightClientExecutionBranch{}, consensustypes.ErrNotSupported("ExecutionBranch", h.Version())
|
||||
}
|
||||
|
||||
type headerCapella struct {
|
||||
@@ -114,6 +123,10 @@ func (h *headerCapella) SizeSSZ() int {
|
||||
return h.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (h *headerCapella) Proto() proto.Message {
|
||||
return h.p
|
||||
}
|
||||
|
||||
func (h *headerCapella) Version() int {
|
||||
return version.Capella
|
||||
}
|
||||
@@ -175,6 +188,10 @@ func (h *headerDeneb) SizeSSZ() int {
|
||||
return h.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (h *headerDeneb) Proto() proto.Message {
|
||||
return h.p
|
||||
}
|
||||
|
||||
func (h *headerDeneb) Version() int {
|
||||
return version.Deneb
|
||||
}
|
||||
@@ -190,3 +207,68 @@ func (h *headerDeneb) Execution() (interfaces.ExecutionData, error) {
|
||||
func (h *headerDeneb) ExecutionBranch() (interfaces.LightClientExecutionBranch, error) {
|
||||
return h.executionBranch, nil
|
||||
}
|
||||
|
||||
type headerElectra struct {
|
||||
p *pb.LightClientHeaderDeneb
|
||||
execution interfaces.ExecutionData
|
||||
executionBranch interfaces.LightClientExecutionBranch
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientHeader = &headerElectra{}
|
||||
|
||||
func NewWrappedHeaderElectra(p *pb.LightClientHeaderDeneb) (interfaces.LightClientHeader, error) {
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
execution, err := blocks.WrappedExecutionPayloadHeaderDeneb(p.Execution)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
branch, err := createBranch[interfaces.LightClientExecutionBranch](
|
||||
"execution",
|
||||
p.ExecutionBranch,
|
||||
fieldparams.ExecutionBranchDepth,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &headerElectra{
|
||||
p: p,
|
||||
execution: execution,
|
||||
executionBranch: branch,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *headerElectra) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
return h.p.MarshalSSZTo(dst)
|
||||
}
|
||||
|
||||
func (h *headerElectra) MarshalSSZ() ([]byte, error) {
|
||||
return h.p.MarshalSSZ()
|
||||
}
|
||||
|
||||
func (h *headerElectra) SizeSSZ() int {
|
||||
return h.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (h *headerElectra) Proto() proto.Message {
|
||||
return h.p
|
||||
}
|
||||
|
||||
func (h *headerElectra) Version() int {
|
||||
return version.Electra
|
||||
}
|
||||
|
||||
func (h *headerElectra) Beacon() *pb.BeaconBlockHeader {
|
||||
return h.p.Beacon
|
||||
}
|
||||
|
||||
func (h *headerElectra) Execution() (interfaces.ExecutionData, error) {
|
||||
return h.execution, nil
|
||||
}
|
||||
|
||||
func (h *headerElectra) ExecutionBranch() (interfaces.LightClientExecutionBranch, error) {
|
||||
return h.executionBranch, nil
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
||||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
||||
)
|
||||
|
||||
type branchConstraint interface {
|
||||
~interfaces.LightClientExecutionBranch | ~interfaces.LightClientSyncCommitteeBranch | ~interfaces.LightClientFinalityBranch
|
||||
[4][fieldparams.RootLength]byte | [5][fieldparams.RootLength]byte | [6][fieldparams.RootLength]byte | [7][fieldparams.RootLength]byte
|
||||
}
|
||||
|
||||
func createBranch[T branchConstraint](name string, input [][]byte, depth int) (T, error) {
|
||||
|
||||
@@ -27,12 +27,55 @@ func NewWrappedOptimisticUpdate(m proto.Message) (interfaces.LightClientOptimist
|
||||
}
|
||||
}
|
||||
|
||||
type OptimisticUpdateAltair struct {
|
||||
func NewOptimisticUpdateFromUpdate(update interfaces.LightClientUpdate) (interfaces.LightClientOptimisticUpdate, error) {
|
||||
switch t := update.(type) {
|
||||
case *updateAltair:
|
||||
return &optimisticUpdateAltair{
|
||||
p: &pb.LightClientOptimisticUpdateAltair{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
}, nil
|
||||
case *updateCapella:
|
||||
return &optimisticUpdateCapella{
|
||||
p: &pb.LightClientOptimisticUpdateCapella{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
}, nil
|
||||
case *updateDeneb:
|
||||
return &optimisticUpdateDeneb{
|
||||
p: &pb.LightClientOptimisticUpdateDeneb{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
}, nil
|
||||
case *updateElectra:
|
||||
return &optimisticUpdateDeneb{
|
||||
p: &pb.LightClientOptimisticUpdateDeneb{
|
||||
AttestedHeader: t.p.AttestedHeader,
|
||||
SyncAggregate: t.p.SyncAggregate,
|
||||
SignatureSlot: t.p.SignatureSlot,
|
||||
},
|
||||
attestedHeader: t.attestedHeader,
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported type %T", t)
|
||||
}
|
||||
}
|
||||
|
||||
type optimisticUpdateAltair struct {
|
||||
p *pb.LightClientOptimisticUpdateAltair
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientOptimisticUpdate = &OptimisticUpdateAltair{}
|
||||
var _ interfaces.LightClientOptimisticUpdate = &optimisticUpdateAltair{}
|
||||
|
||||
func NewWrappedOptimisticUpdateAltair(p *pb.LightClientOptimisticUpdateAltair) (interfaces.LightClientOptimisticUpdate, error) {
|
||||
if p == nil {
|
||||
@@ -43,46 +86,50 @@ func NewWrappedOptimisticUpdateAltair(p *pb.LightClientOptimisticUpdateAltair) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &OptimisticUpdateAltair{
|
||||
return &optimisticUpdateAltair{
|
||||
p: p,
|
||||
attestedHeader: attestedHeader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
func (u *optimisticUpdateAltair) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
return u.p.MarshalSSZTo(dst)
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) MarshalSSZ() ([]byte, error) {
|
||||
func (u *optimisticUpdateAltair) MarshalSSZ() ([]byte, error) {
|
||||
return u.p.MarshalSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) SizeSSZ() int {
|
||||
func (u *optimisticUpdateAltair) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) Version() int {
|
||||
func (u *optimisticUpdateAltair) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *optimisticUpdateAltair) Version() int {
|
||||
return version.Altair
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) AttestedHeader() interfaces.LightClientHeader {
|
||||
func (u *optimisticUpdateAltair) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) SyncAggregate() *pb.SyncAggregate {
|
||||
func (u *optimisticUpdateAltair) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateAltair) SignatureSlot() primitives.Slot {
|
||||
func (u *optimisticUpdateAltair) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
type OptimisticUpdateCapella struct {
|
||||
type optimisticUpdateCapella struct {
|
||||
p *pb.LightClientOptimisticUpdateCapella
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientOptimisticUpdate = &OptimisticUpdateCapella{}
|
||||
var _ interfaces.LightClientOptimisticUpdate = &optimisticUpdateCapella{}
|
||||
|
||||
func NewWrappedOptimisticUpdateCapella(p *pb.LightClientOptimisticUpdateCapella) (interfaces.LightClientOptimisticUpdate, error) {
|
||||
if p == nil {
|
||||
@@ -93,46 +140,50 @@ func NewWrappedOptimisticUpdateCapella(p *pb.LightClientOptimisticUpdateCapella)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &OptimisticUpdateCapella{
|
||||
return &optimisticUpdateCapella{
|
||||
p: p,
|
||||
attestedHeader: attestedHeader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
func (u *optimisticUpdateCapella) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
return u.p.MarshalSSZTo(dst)
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) MarshalSSZ() ([]byte, error) {
|
||||
func (u *optimisticUpdateCapella) MarshalSSZ() ([]byte, error) {
|
||||
return u.p.MarshalSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) SizeSSZ() int {
|
||||
func (u *optimisticUpdateCapella) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) Version() int {
|
||||
func (u *optimisticUpdateCapella) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *optimisticUpdateCapella) Version() int {
|
||||
return version.Capella
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) AttestedHeader() interfaces.LightClientHeader {
|
||||
func (u *optimisticUpdateCapella) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) SyncAggregate() *pb.SyncAggregate {
|
||||
func (u *optimisticUpdateCapella) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateCapella) SignatureSlot() primitives.Slot {
|
||||
func (u *optimisticUpdateCapella) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
type OptimisticUpdateDeneb struct {
|
||||
type optimisticUpdateDeneb struct {
|
||||
p *pb.LightClientOptimisticUpdateDeneb
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientOptimisticUpdate = &OptimisticUpdateDeneb{}
|
||||
var _ interfaces.LightClientOptimisticUpdate = &optimisticUpdateDeneb{}
|
||||
|
||||
func NewWrappedOptimisticUpdateDeneb(p *pb.LightClientOptimisticUpdateDeneb) (interfaces.LightClientOptimisticUpdate, error) {
|
||||
if p == nil {
|
||||
@@ -143,36 +194,40 @@ func NewWrappedOptimisticUpdateDeneb(p *pb.LightClientOptimisticUpdateDeneb) (in
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &OptimisticUpdateDeneb{
|
||||
return &optimisticUpdateDeneb{
|
||||
p: p,
|
||||
attestedHeader: attestedHeader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
func (u *optimisticUpdateDeneb) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
return u.p.MarshalSSZTo(dst)
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) MarshalSSZ() ([]byte, error) {
|
||||
func (u *optimisticUpdateDeneb) MarshalSSZ() ([]byte, error) {
|
||||
return u.p.MarshalSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) SizeSSZ() int {
|
||||
func (u *optimisticUpdateDeneb) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) Version() int {
|
||||
func (u *optimisticUpdateDeneb) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *optimisticUpdateDeneb) Version() int {
|
||||
return version.Deneb
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) AttestedHeader() interfaces.LightClientHeader {
|
||||
func (u *optimisticUpdateDeneb) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) SyncAggregate() *pb.SyncAggregate {
|
||||
func (u *optimisticUpdateDeneb) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *OptimisticUpdateDeneb) SignatureSlot() primitives.Slot {
|
||||
func (u *optimisticUpdateDeneb) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
@@ -23,11 +23,17 @@ func NewWrappedUpdate(m proto.Message) (interfaces.LightClientUpdate, error) {
|
||||
return NewWrappedUpdateCapella(t)
|
||||
case *pb.LightClientUpdateDeneb:
|
||||
return NewWrappedUpdateDeneb(t)
|
||||
case *pb.LightClientUpdateElectra:
|
||||
return NewWrappedUpdateElectra(t)
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot construct light client update from type %T", t)
|
||||
}
|
||||
}
|
||||
|
||||
// In addition to the proto object being wrapped, we store some fields that have to be
|
||||
// constructed from the proto, so that we don't have to reconstruct them every time
|
||||
// in getters.
|
||||
|
||||
type updateAltair struct {
|
||||
p *pb.LightClientUpdateAltair
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
@@ -42,14 +48,20 @@ func NewWrappedUpdateAltair(p *pb.LightClientUpdateAltair) (interfaces.LightClie
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderAltair(p.AttestedHeader)
|
||||
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderAltair(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var finalizedHeader interfaces.LightClientHeader
|
||||
if p.FinalizedHeader != nil {
|
||||
finalizedHeader, err = NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
scBranch, err := createBranch[interfaces.LightClientSyncCommitteeBranch](
|
||||
"sync committee",
|
||||
p.NextSyncCommitteeBranch,
|
||||
@@ -88,6 +100,10 @@ func (u *updateAltair) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *updateAltair) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *updateAltair) Version() int {
|
||||
return version.Altair
|
||||
}
|
||||
@@ -96,14 +112,40 @@ func (u *updateAltair) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetAttestedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderAltair)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderAltair{})
|
||||
}
|
||||
u.p.AttestedHeader = proto
|
||||
u.attestedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) NextSyncCommittee() *pb.SyncCommittee {
|
||||
return u.p.NextSyncCommittee
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetNextSyncCommittee(sc *pb.SyncCommittee) {
|
||||
u.p.NextSyncCommittee = sc
|
||||
}
|
||||
|
||||
func (u *updateAltair) NextSyncCommitteeBranch() (interfaces.LightClientSyncCommitteeBranch, error) {
|
||||
return u.nextSyncCommitteeBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetNextSyncCommitteeBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientSyncCommitteeBranch]("sync committee", branch, fieldparams.SyncCommitteeBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.nextSyncCommitteeBranch = b
|
||||
|
||||
u.p.NextSyncCommitteeBranch = branch
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) {
|
||||
return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Altair)
|
||||
}
|
||||
@@ -112,18 +154,53 @@ func (u *updateAltair) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *updateAltair) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *updateAltair) SetFinalizedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderAltair)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderAltair{})
|
||||
}
|
||||
u.p.FinalizedHeader = proto
|
||||
u.finalizedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetFinalityBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientFinalityBranch]("finality", branch, fieldparams.FinalityBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.finalityBranch = b
|
||||
u.p.FinalityBranch = branch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateAltair) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", version.Altair)
|
||||
}
|
||||
|
||||
func (u *updateAltair) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetSyncAggregate(sa *pb.SyncAggregate) {
|
||||
u.p.SyncAggregate = sa
|
||||
}
|
||||
|
||||
func (u *updateAltair) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
func (u *updateAltair) SetSignatureSlot(slot primitives.Slot) {
|
||||
u.p.SignatureSlot = slot
|
||||
}
|
||||
|
||||
// In addition to the proto object being wrapped, we store some fields that have to be
|
||||
// constructed from the proto, so that we don't have to reconstruct them every time
|
||||
// in getters.
|
||||
type updateCapella struct {
|
||||
p *pb.LightClientUpdateCapella
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
@@ -138,14 +215,20 @@ func NewWrappedUpdateCapella(p *pb.LightClientUpdateCapella) (interfaces.LightCl
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderCapella(p.AttestedHeader)
|
||||
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderCapella(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var finalizedHeader interfaces.LightClientHeader
|
||||
if p.FinalizedHeader != nil {
|
||||
finalizedHeader, err = NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
scBranch, err := createBranch[interfaces.LightClientSyncCommitteeBranch](
|
||||
"sync committee",
|
||||
p.NextSyncCommitteeBranch,
|
||||
@@ -184,6 +267,10 @@ func (u *updateCapella) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *updateCapella) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *updateCapella) Version() int {
|
||||
return version.Capella
|
||||
}
|
||||
@@ -192,14 +279,40 @@ func (u *updateCapella) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetAttestedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderCapella)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderCapella{})
|
||||
}
|
||||
u.p.AttestedHeader = proto
|
||||
u.attestedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) NextSyncCommittee() *pb.SyncCommittee {
|
||||
return u.p.NextSyncCommittee
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetNextSyncCommittee(sc *pb.SyncCommittee) {
|
||||
u.p.NextSyncCommittee = sc
|
||||
}
|
||||
|
||||
func (u *updateCapella) NextSyncCommitteeBranch() (interfaces.LightClientSyncCommitteeBranch, error) {
|
||||
return u.nextSyncCommitteeBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetNextSyncCommitteeBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientSyncCommitteeBranch]("sync committee", branch, fieldparams.SyncCommitteeBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.nextSyncCommitteeBranch = b
|
||||
|
||||
u.p.NextSyncCommitteeBranch = branch
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) {
|
||||
return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Capella)
|
||||
}
|
||||
@@ -208,18 +321,53 @@ func (u *updateCapella) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *updateCapella) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *updateCapella) SetFinalizedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderCapella)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderCapella{})
|
||||
}
|
||||
u.p.FinalizedHeader = proto
|
||||
u.finalizedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetFinalityBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientFinalityBranch]("finality", branch, fieldparams.FinalityBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.finalityBranch = b
|
||||
u.p.FinalityBranch = branch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateCapella) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", u.Version())
|
||||
}
|
||||
|
||||
func (u *updateCapella) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetSyncAggregate(sa *pb.SyncAggregate) {
|
||||
u.p.SyncAggregate = sa
|
||||
}
|
||||
|
||||
func (u *updateCapella) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
func (u *updateCapella) SetSignatureSlot(slot primitives.Slot) {
|
||||
u.p.SignatureSlot = slot
|
||||
}
|
||||
|
||||
// In addition to the proto object being wrapped, we store some fields that have to be
|
||||
// constructed from the proto, so that we don't have to reconstruct them every time
|
||||
// in getters.
|
||||
type updateDeneb struct {
|
||||
p *pb.LightClientUpdateDeneb
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
@@ -234,14 +382,20 @@ func NewWrappedUpdateDeneb(p *pb.LightClientUpdateDeneb) (interfaces.LightClient
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderDeneb(p.AttestedHeader)
|
||||
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderDeneb(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var finalizedHeader interfaces.LightClientHeader
|
||||
if p.FinalizedHeader != nil {
|
||||
finalizedHeader, err = NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
scBranch, err := createBranch[interfaces.LightClientSyncCommitteeBranch](
|
||||
"sync committee",
|
||||
p.NextSyncCommitteeBranch,
|
||||
@@ -280,6 +434,10 @@ func (u *updateDeneb) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *updateDeneb) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *updateDeneb) Version() int {
|
||||
return version.Deneb
|
||||
}
|
||||
@@ -288,14 +446,40 @@ func (u *updateDeneb) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetAttestedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderDeneb)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderDeneb{})
|
||||
}
|
||||
u.p.AttestedHeader = proto
|
||||
u.attestedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) NextSyncCommittee() *pb.SyncCommittee {
|
||||
return u.p.NextSyncCommittee
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetNextSyncCommittee(sc *pb.SyncCommittee) {
|
||||
u.p.NextSyncCommittee = sc
|
||||
}
|
||||
|
||||
func (u *updateDeneb) NextSyncCommitteeBranch() (interfaces.LightClientSyncCommitteeBranch, error) {
|
||||
return u.nextSyncCommitteeBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetNextSyncCommitteeBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientSyncCommitteeBranch]("sync committee", branch, fieldparams.SyncCommitteeBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.nextSyncCommitteeBranch = b
|
||||
|
||||
u.p.NextSyncCommitteeBranch = branch
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) {
|
||||
return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Deneb)
|
||||
}
|
||||
@@ -304,24 +488,59 @@ func (u *updateDeneb) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *updateDeneb) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *updateDeneb) SetFinalizedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderDeneb)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderDeneb{})
|
||||
}
|
||||
u.p.FinalizedHeader = proto
|
||||
u.finalizedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetFinalityBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientFinalityBranch]("finality", branch, fieldparams.FinalityBranchDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.finalityBranch = b
|
||||
u.p.FinalityBranch = branch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateDeneb) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return interfaces.LightClientFinalityBranchElectra{}, consensustypes.ErrNotSupported("FinalityBranchElectra", u.Version())
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetSyncAggregate(sa *pb.SyncAggregate) {
|
||||
u.p.SyncAggregate = sa
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
func (u *updateDeneb) SetSignatureSlot(slot primitives.Slot) {
|
||||
u.p.SignatureSlot = slot
|
||||
}
|
||||
|
||||
// In addition to the proto object being wrapped, we store some fields that have to be
|
||||
// constructed from the proto, so that we don't have to reconstruct them every time
|
||||
// in getters.
|
||||
type updateElectra struct {
|
||||
p *pb.LightClientUpdateElectra
|
||||
attestedHeader interfaces.LightClientHeader
|
||||
nextSyncCommitteeBranch interfaces.LightClientSyncCommitteeBranchElectra
|
||||
finalizedHeader interfaces.LightClientHeader
|
||||
finalityBranch interfaces.LightClientFinalityBranch
|
||||
finalityBranch interfaces.LightClientFinalityBranchElectra
|
||||
}
|
||||
|
||||
var _ interfaces.LightClientUpdate = &updateElectra{}
|
||||
@@ -330,14 +549,20 @@ func NewWrappedUpdateElectra(p *pb.LightClientUpdateElectra) (interfaces.LightCl
|
||||
if p == nil {
|
||||
return nil, consensustypes.ErrNilObjectWrapped
|
||||
}
|
||||
attestedHeader, err := NewWrappedHeaderDeneb(p.AttestedHeader)
|
||||
|
||||
attestedHeader, err := NewWrappedHeader(p.AttestedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalizedHeader, err := NewWrappedHeaderDeneb(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var finalizedHeader interfaces.LightClientHeader
|
||||
if p.FinalizedHeader != nil {
|
||||
finalizedHeader, err = NewWrappedHeader(p.FinalizedHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
scBranch, err := createBranch[interfaces.LightClientSyncCommitteeBranchElectra](
|
||||
"sync committee",
|
||||
p.NextSyncCommitteeBranch,
|
||||
@@ -346,10 +571,11 @@ func NewWrappedUpdateElectra(p *pb.LightClientUpdateElectra) (interfaces.LightCl
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalityBranch, err := createBranch[interfaces.LightClientFinalityBranch](
|
||||
|
||||
finalityBranch, err := createBranch[interfaces.LightClientFinalityBranchElectra](
|
||||
"finality",
|
||||
p.FinalityBranch,
|
||||
fieldparams.FinalityBranchDepth,
|
||||
fieldparams.FinalityBranchDepthElectra,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -376,6 +602,10 @@ func (u *updateElectra) SizeSSZ() int {
|
||||
return u.p.SizeSSZ()
|
||||
}
|
||||
|
||||
func (u *updateElectra) Proto() proto.Message {
|
||||
return u.p
|
||||
}
|
||||
|
||||
func (u *updateElectra) Version() int {
|
||||
return version.Electra
|
||||
}
|
||||
@@ -384,14 +614,40 @@ func (u *updateElectra) AttestedHeader() interfaces.LightClientHeader {
|
||||
return u.attestedHeader
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetAttestedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderDeneb)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderDeneb{})
|
||||
}
|
||||
u.p.AttestedHeader = proto
|
||||
u.attestedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateElectra) NextSyncCommittee() *pb.SyncCommittee {
|
||||
return u.p.NextSyncCommittee
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetNextSyncCommittee(sc *pb.SyncCommittee) {
|
||||
u.p.NextSyncCommittee = sc
|
||||
}
|
||||
|
||||
func (u *updateElectra) NextSyncCommitteeBranch() (interfaces.LightClientSyncCommitteeBranch, error) {
|
||||
return [5][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranch", version.Electra)
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetNextSyncCommitteeBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientSyncCommitteeBranchElectra]("sync committee", branch, fieldparams.SyncCommitteeBranchDepthElectra)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.nextSyncCommitteeBranch = b
|
||||
|
||||
u.p.NextSyncCommitteeBranch = branch
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateElectra) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) {
|
||||
return u.nextSyncCommitteeBranch, nil
|
||||
}
|
||||
@@ -400,14 +656,46 @@ func (u *updateElectra) FinalizedHeader() interfaces.LightClientHeader {
|
||||
return u.finalizedHeader
|
||||
}
|
||||
|
||||
func (u *updateElectra) FinalityBranch() interfaces.LightClientFinalityBranch {
|
||||
return u.finalityBranch
|
||||
func (u *updateElectra) SetFinalizedHeader(header interfaces.LightClientHeader) error {
|
||||
proto, ok := header.Proto().(*pb.LightClientHeaderDeneb)
|
||||
if !ok {
|
||||
return fmt.Errorf("header type %T is not %T", proto, &pb.LightClientHeaderDeneb{})
|
||||
}
|
||||
u.p.FinalizedHeader = proto
|
||||
u.finalizedHeader = header
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateElectra) FinalityBranch() (interfaces.LightClientFinalityBranch, error) {
|
||||
return interfaces.LightClientFinalityBranch{}, consensustypes.ErrNotSupported("FinalityBranch", u.Version())
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetFinalityBranch(branch [][]byte) error {
|
||||
b, err := createBranch[interfaces.LightClientFinalityBranchElectra]("finality", branch, fieldparams.FinalityBranchDepthElectra)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.finalityBranch = b
|
||||
u.p.FinalityBranch = branch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *updateElectra) FinalityBranchElectra() (interfaces.LightClientFinalityBranchElectra, error) {
|
||||
return u.finalityBranch, nil
|
||||
}
|
||||
|
||||
func (u *updateElectra) SyncAggregate() *pb.SyncAggregate {
|
||||
return u.p.SyncAggregate
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetSyncAggregate(sa *pb.SyncAggregate) {
|
||||
u.p.SyncAggregate = sa
|
||||
}
|
||||
|
||||
func (u *updateElectra) SignatureSlot() primitives.Slot {
|
||||
return u.p.SignatureSlot
|
||||
}
|
||||
|
||||
func (u *updateElectra) SetSignatureSlot(slot primitives.Slot) {
|
||||
u.p.SignatureSlot = slot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user