mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
fixing electra attestation inconsistencies (#14331)
* fixing electra attestation inconsistencies * adding dependencies * removing helper circular dependency * adding error * simplifying function * improving get committee index function * fixing more instances of GetData().committeeIndex and fixing tests * Update proto/prysm/v1alpha1/attestation.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing feedback and fixing linting * removing unused functions and associated tests * fixing test error checks * removing helpers.VerifyAttestationBitfieldLengths to reduce beaconCommitteeFromState calls * small optimizations * fixing linting --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -332,6 +332,7 @@ go_library(
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/eth/ext:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@com_github_grpc_ecosystem_grpc_gateway_v2//protoc-gen-openapiv2/options:options_go_proto",
|
||||
"@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
@@ -21,6 +24,7 @@ type Att interface {
|
||||
GetData() *AttestationData
|
||||
CommitteeBitsVal() bitfield.Bitfield
|
||||
GetSignature() []byte
|
||||
GetCommitteeIndex() (primitives.CommitteeIndex, error)
|
||||
}
|
||||
|
||||
// IndexedAtt defines common functionality for all indexed attestation types.
|
||||
@@ -123,6 +127,14 @@ func (a *Attestation) CommitteeBitsVal() bitfield.Bitfield {
|
||||
return cb
|
||||
}
|
||||
|
||||
// GetCommitteeIndex --
|
||||
func (a *Attestation) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
|
||||
if a == nil || a.Data == nil {
|
||||
return 0, errors.New("nil attestation data")
|
||||
}
|
||||
return a.Data.CommitteeIndex, nil
|
||||
}
|
||||
|
||||
// Version --
|
||||
func (a *PendingAttestation) Version() int {
|
||||
return version.Phase0
|
||||
@@ -156,6 +168,14 @@ func (a *PendingAttestation) GetSignature() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCommitteeIndex --
|
||||
func (a *PendingAttestation) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
|
||||
if a == nil || a.Data == nil {
|
||||
return 0, errors.New("nil attestation data")
|
||||
}
|
||||
return a.Data.CommitteeIndex, nil
|
||||
}
|
||||
|
||||
// Version --
|
||||
func (a *AttestationElectra) Version() int {
|
||||
return version.Electra
|
||||
@@ -184,6 +204,24 @@ func (a *AttestationElectra) CommitteeBitsVal() bitfield.Bitfield {
|
||||
return a.CommitteeBits
|
||||
}
|
||||
|
||||
// GetCommitteeIndex --
|
||||
func (a *AttestationElectra) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
|
||||
if a == nil || a.Data == nil {
|
||||
return 0, errors.New("nil attestation data")
|
||||
}
|
||||
if len(a.CommitteeBits) == 0 {
|
||||
return 0, errors.New("no committee bits found in attestation")
|
||||
}
|
||||
if a.Data.CommitteeIndex != 0 {
|
||||
return 0, fmt.Errorf("attestation data's committee index must be 0 but was %d", a.Data.CommitteeIndex)
|
||||
}
|
||||
indices := a.CommitteeBits.BitIndices()
|
||||
if len(indices) != 1 {
|
||||
return 0, fmt.Errorf("exactly 1 committee index must be set but %d were set", len(indices))
|
||||
}
|
||||
return primitives.CommitteeIndex(uint64(indices[0])), nil
|
||||
}
|
||||
|
||||
// Version --
|
||||
func (a *IndexedAttestation) Version() int {
|
||||
return version.Phase0
|
||||
|
||||
Reference in New Issue
Block a user