From a7a283fdcfac5586fdad9f1f9c8e51e65a75bfd1 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Wed, 20 Nov 2024 23:00:49 +0530 Subject: [PATCH 1/4] update diff --- config/fieldparams/mainnet.go | 1 + config/fieldparams/minimal.go | 1 + consensus-types/interfaces/light_client.go | 20 +- consensus-types/light-client/bootstrap.go | 8 +- .../light-client/finality_update.go | 192 +++++++++- consensus-types/light-client/header.go | 86 ++++- consensus-types/light-client/helpers.go | 3 +- .../light-client/optimistic_update.go | 115 ++++-- consensus-types/light-client/update.go | 358 ++++++++++++++++-- 9 files changed, 705 insertions(+), 79 deletions(-) diff --git a/config/fieldparams/mainnet.go b/config/fieldparams/mainnet.go index 3eb5e90b53ee..c745aac44a5c 100644 --- a/config/fieldparams/mainnet.go +++ b/config/fieldparams/mainnet.go @@ -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. diff --git a/config/fieldparams/minimal.go b/config/fieldparams/minimal.go index db99c2dd91b4..eb9d1af88f7a 100644 --- a/config/fieldparams/minimal.go +++ b/config/fieldparams/minimal.go @@ -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. diff --git a/consensus-types/interfaces/light_client.go b/consensus-types/interfaces/light_client.go index 217a086497d4..b0d0dadaa2e4 100644 --- a/consensus-types/interfaces/light_client.go +++ b/consensus-types/interfaces/light_client.go @@ -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,42 @@ 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) + SetNextSyncCommitteeBranchElectra(branch [][]byte) 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 diff --git a/consensus-types/light-client/bootstrap.go b/consensus-types/light-client/bootstrap.go index 33d8b2c78f70..1de819266d03 100644 --- a/consensus-types/light-client/bootstrap.go +++ b/consensus-types/light-client/bootstrap.go @@ -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 } diff --git a/consensus-types/light-client/finality_update.go b/consensus-types/light-client/finality_update.go index 37de560e60ed..51cbd2408033 100644 --- a/consensus-types/light-client/finality_update.go +++ b/consensus-types/light-client/finality_update.go @@ -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 +} diff --git a/consensus-types/light-client/header.go b/consensus-types/light-client/header.go index 496a48424c7e..4ed8ce0de91d 100644 --- a/consensus-types/light-client/header.go +++ b/consensus-types/light-client/header.go @@ -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 +} diff --git a/consensus-types/light-client/helpers.go b/consensus-types/light-client/helpers.go index c2fc9b05922c..8a6313b42943 100644 --- a/consensus-types/light-client/helpers.go +++ b/consensus-types/light-client/helpers.go @@ -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) { diff --git a/consensus-types/light-client/optimistic_update.go b/consensus-types/light-client/optimistic_update.go index f1f43d12cfa4..dd15ba02267e 100644 --- a/consensus-types/light-client/optimistic_update.go +++ b/consensus-types/light-client/optimistic_update.go @@ -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 } diff --git a/consensus-types/light-client/update.go b/consensus-types/light-client/update.go index 66a3403f1896..84a299361309 100644 --- a/consensus-types/light-client/update.go +++ b/consensus-types/light-client/update.go @@ -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,34 +112,99 @@ 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) } +func (u *updateAltair) SetNextSyncCommitteeBranchElectra([][]byte) error { + return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Altair) +} + 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 +219,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 +271,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,34 +283,99 @@ 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) } +func (u *updateCapella) SetNextSyncCommitteeBranchElectra([][]byte) error { + return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Capella) +} + 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 +390,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 +442,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,40 +454,105 @@ 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) } +func (u *updateDeneb) SetNextSyncCommitteeBranchElectra([][]byte) error { + return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Deneb) +} + 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 +561,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 +583,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 +614,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,30 +626,92 @@ 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 { + return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranch", version.Electra) +} + func (u *updateElectra) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) { return u.nextSyncCommitteeBranch, nil } +func (u *updateElectra) SetNextSyncCommitteeBranchElectra(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) 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 +} From 8fc2253157959e83a0cca1cce1f39de05c93df3d Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Wed, 20 Nov 2024 23:04:36 +0530 Subject: [PATCH 2/4] deps --- consensus-types/light-client/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/consensus-types/light-client/BUILD.bazel b/consensus-types/light-client/BUILD.bazel index 151f22b522f9..78432c8eecba 100644 --- a/consensus-types/light-client/BUILD.bazel +++ b/consensus-types/light-client/BUILD.bazel @@ -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", ], ) From 07a6343a6a4ded88e0a8840f7f688636108d8b9a Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Wed, 20 Nov 2024 23:24:09 +0530 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98206ce591b1..c0f81fd1ffd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Rename instances of "deposit receipts" to "deposit requests". - 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) +- Updated light client consensus types. [PR](https://github.com/prysmaticlabs/prysm/pull/14652) ### Deprecated From 3ef38d78c4a52e1f052fd2f51b0a7ccd1db97981 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Thu, 21 Nov 2024 14:24:44 +0530 Subject: [PATCH 4/4] remove `SetNextSyncCommitteeBranchElectra` --- consensus-types/interfaces/light_client.go | 1 - consensus-types/light-client/update.go | 24 ++++------------------ 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/consensus-types/interfaces/light_client.go b/consensus-types/interfaces/light_client.go index b0d0dadaa2e4..078cc135ecdb 100644 --- a/consensus-types/interfaces/light_client.go +++ b/consensus-types/interfaces/light_client.go @@ -43,7 +43,6 @@ type LightClientUpdate interface { NextSyncCommitteeBranch() (LightClientSyncCommitteeBranch, error) SetNextSyncCommitteeBranch(branch [][]byte) error NextSyncCommitteeBranchElectra() (LightClientSyncCommitteeBranchElectra, error) - SetNextSyncCommitteeBranchElectra(branch [][]byte) error FinalizedHeader() LightClientHeader SetFinalizedHeader(header LightClientHeader) error FinalityBranch() (LightClientFinalityBranch, error) diff --git a/consensus-types/light-client/update.go b/consensus-types/light-client/update.go index 84a299361309..aff6a953d336 100644 --- a/consensus-types/light-client/update.go +++ b/consensus-types/light-client/update.go @@ -150,10 +150,6 @@ func (u *updateAltair) NextSyncCommitteeBranchElectra() (interfaces.LightClientS return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Altair) } -func (u *updateAltair) SetNextSyncCommitteeBranchElectra([][]byte) error { - return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Altair) -} - func (u *updateAltair) FinalizedHeader() interfaces.LightClientHeader { return u.finalizedHeader } @@ -321,10 +317,6 @@ func (u *updateCapella) NextSyncCommitteeBranchElectra() (interfaces.LightClient return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Capella) } -func (u *updateCapella) SetNextSyncCommitteeBranchElectra([][]byte) error { - return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Capella) -} - func (u *updateCapella) FinalizedHeader() interfaces.LightClientHeader { return u.finalizedHeader } @@ -492,10 +484,6 @@ func (u *updateDeneb) NextSyncCommitteeBranchElectra() (interfaces.LightClientSy return [6][32]byte{}, consensustypes.ErrNotSupported("NextSyncCommitteeBranchElectra", version.Deneb) } -func (u *updateDeneb) SetNextSyncCommitteeBranchElectra([][]byte) error { - return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranchElectra", version.Deneb) -} - func (u *updateDeneb) FinalizedHeader() interfaces.LightClientHeader { return u.finalizedHeader } @@ -649,14 +637,6 @@ func (u *updateElectra) NextSyncCommitteeBranch() (interfaces.LightClientSyncCom } func (u *updateElectra) SetNextSyncCommitteeBranch(branch [][]byte) error { - return consensustypes.ErrNotSupported("SetNextSyncCommitteeBranch", version.Electra) -} - -func (u *updateElectra) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) { - return u.nextSyncCommitteeBranch, nil -} - -func (u *updateElectra) SetNextSyncCommitteeBranchElectra(branch [][]byte) error { b, err := createBranch[interfaces.LightClientSyncCommitteeBranchElectra]("sync committee", branch, fieldparams.SyncCommitteeBranchDepthElectra) if err != nil { return err @@ -668,6 +648,10 @@ func (u *updateElectra) SetNextSyncCommitteeBranchElectra(branch [][]byte) error return nil } +func (u *updateElectra) NextSyncCommitteeBranchElectra() (interfaces.LightClientSyncCommitteeBranchElectra, error) { + return u.nextSyncCommitteeBranch, nil +} + func (u *updateElectra) FinalizedHeader() interfaces.LightClientHeader { return u.finalizedHeader }