From dfcc05c7f873a69d03f54380e5fc3399f2bb49b8 Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 20 Jul 2023 15:07:55 +1000 Subject: [PATCH 1/2] Add helpers to versioned signed blinded beacon block --- api/versionedsignedblindedbeaconblock.go | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/api/versionedsignedblindedbeaconblock.go b/api/versionedsignedblindedbeaconblock.go index ad3ca0b7..978d3c64 100644 --- a/api/versionedsignedblindedbeaconblock.go +++ b/api/versionedsignedblindedbeaconblock.go @@ -214,3 +214,95 @@ func (v *VersionedSignedBlindedBeaconBlock) ProposerSlashings() ([]*phase0.Propo return nil, errors.New("unknown version") } } + +// ProposerIndex returns the proposer index of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) ProposerIndex() (phase0.ValidatorIndex, error) { + switch v.Version { + case spec.DataVersionBellatrix: + if v.Bellatrix == nil || v.Bellatrix.Message == nil { + return 0, errors.New("no bellatrix block") + } + return v.Bellatrix.Message.ProposerIndex, nil + case spec.DataVersionCapella: + if v.Capella == nil || v.Capella.Message == nil { + return 0, errors.New("no capella block") + } + return v.Capella.Message.ProposerIndex, nil + case spec.DataVersionDeneb: + if v.Deneb == nil || v.Deneb.Message == nil { + return 0, errors.New("no deneb block") + } + return v.Deneb.Message.ProposerIndex, nil + default: + return 0, errors.New("unknown version") + } +} + +// BlockHash returns the hash of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) BlockHash() (phase0.Hash32, error) { + switch v.Version { + case spec.DataVersionBellatrix: + if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { + return phase0.Hash32{}, errors.New("no bellatrix block") + } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockHash, nil + case spec.DataVersionCapella: + if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { + return phase0.Hash32{}, errors.New("no capella block") + } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockHash, nil + case spec.DataVersionDeneb: + if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayloadHeader == nil { + return phase0.Hash32{}, errors.New("no deneb block") + } + return v.Deneb.Message.Body.ExecutionPayloadHeader.BlockHash, nil + default: + return phase0.Hash32{}, errors.New("unknown version") + } +} + +// BlockNumber returns the block number of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) BlockNumber() (uint64, error) { + switch v.Version { + case spec.DataVersionBellatrix: + if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { + return 0, errors.New("no bellatrix block") + } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockNumber, nil + case spec.DataVersionCapella: + if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { + return 0, errors.New("no capella block") + } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockNumber, nil + case spec.DataVersionDeneb: + if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayloadHeader == nil { + return 0, errors.New("no deneb block") + } + return v.Deneb.Message.Body.ExecutionPayloadHeader.BlockNumber, nil + default: + return 0, errors.New("unknown version") + } +} + +// Signature returns the signature of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) Signature() (phase0.BLSSignature, error) { + switch v.Version { + case spec.DataVersionBellatrix: + if v.Bellatrix == nil { + return phase0.BLSSignature{}, errors.New("no bellatrix block") + } + return v.Bellatrix.Signature, nil + case spec.DataVersionCapella: + if v.Capella == nil { + return phase0.BLSSignature{}, errors.New("no capella block") + } + return v.Capella.Signature, nil + case spec.DataVersionDeneb: + if v.Deneb == nil { + return phase0.BLSSignature{}, errors.New("no deneb block") + } + return v.Deneb.Signature, nil + default: + return phase0.BLSSignature{}, errors.New("unknown version") + } +} From 605ed5d1b4c2aad9f44d99d34b50053f4d4ebfe2 Mon Sep 17 00:00:00 2001 From: avalonche Date: Fri, 21 Jul 2023 13:46:03 +1000 Subject: [PATCH 2/2] renaming --- api/versionedsignedblindedbeaconblock.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/versionedsignedblindedbeaconblock.go b/api/versionedsignedblindedbeaconblock.go index 978d3c64..3ffe788a 100644 --- a/api/versionedsignedblindedbeaconblock.go +++ b/api/versionedsignedblindedbeaconblock.go @@ -238,8 +238,8 @@ func (v *VersionedSignedBlindedBeaconBlock) ProposerIndex() (phase0.ValidatorInd } } -// BlockHash returns the hash of the beacon block. -func (v *VersionedSignedBlindedBeaconBlock) BlockHash() (phase0.Hash32, error) { +// ExecutionBlockHash returns the hash of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) ExecutionBlockHash() (phase0.Hash32, error) { switch v.Version { case spec.DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { @@ -261,8 +261,8 @@ func (v *VersionedSignedBlindedBeaconBlock) BlockHash() (phase0.Hash32, error) { } } -// BlockNumber returns the block number of the beacon block. -func (v *VersionedSignedBlindedBeaconBlock) BlockNumber() (uint64, error) { +// ExecutionBlockNumber returns the block number of the beacon block. +func (v *VersionedSignedBlindedBeaconBlock) ExecutionBlockNumber() (uint64, error) { switch v.Version { case spec.DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil {