mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
EIP-7549: Add aggregate attestation interfaces (#14029)
* interfaces move * build fix * remove annoying warning * more build fixes * review
This commit is contained in:
@@ -1077,13 +1077,13 @@ func (b *BeaconBlockBody) ProposerSlashings() []*eth.ProposerSlashing {
|
||||
}
|
||||
|
||||
// AttesterSlashings returns the attester slashings in the block.
|
||||
func (b *BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
|
||||
var slashings []interfaces.AttesterSlashing
|
||||
func (b *BeaconBlockBody) AttesterSlashings() []eth.AttSlashing {
|
||||
var slashings []eth.AttSlashing
|
||||
if b.version < version.Electra {
|
||||
if b.attesterSlashings == nil {
|
||||
return nil
|
||||
}
|
||||
slashings = make([]interfaces.AttesterSlashing, len(b.attesterSlashings))
|
||||
slashings = make([]eth.AttSlashing, len(b.attesterSlashings))
|
||||
for i, s := range b.attesterSlashings {
|
||||
slashings[i] = s
|
||||
}
|
||||
@@ -1091,7 +1091,7 @@ func (b *BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
|
||||
if b.attesterSlashingsElectra == nil {
|
||||
return nil
|
||||
}
|
||||
slashings = make([]interfaces.AttesterSlashing, len(b.attesterSlashingsElectra))
|
||||
slashings = make([]eth.AttSlashing, len(b.attesterSlashingsElectra))
|
||||
for i, s := range b.attesterSlashingsElectra {
|
||||
slashings[i] = s
|
||||
}
|
||||
@@ -1100,13 +1100,13 @@ func (b *BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
|
||||
}
|
||||
|
||||
// Attestations returns the stored attestations in the block.
|
||||
func (b *BeaconBlockBody) Attestations() []interfaces.Attestation {
|
||||
var atts []interfaces.Attestation
|
||||
func (b *BeaconBlockBody) Attestations() []eth.Att {
|
||||
var atts []eth.Att
|
||||
if b.version < version.Electra {
|
||||
if b.attestations == nil {
|
||||
return nil
|
||||
}
|
||||
atts = make([]interfaces.Attestation, len(b.attestations))
|
||||
atts = make([]eth.Att, len(b.attestations))
|
||||
for i, a := range b.attestations {
|
||||
atts[i] = a
|
||||
}
|
||||
@@ -1114,7 +1114,7 @@ func (b *BeaconBlockBody) Attestations() []interfaces.Attestation {
|
||||
if b.attestationsElectra == nil {
|
||||
return nil
|
||||
}
|
||||
atts = make([]interfaces.Attestation, len(b.attestationsElectra))
|
||||
atts = make([]eth.Att, len(b.attestationsElectra))
|
||||
for i, a := range b.attestationsElectra {
|
||||
atts[i] = a
|
||||
}
|
||||
|
||||
@@ -356,14 +356,14 @@ func Test_BeaconBlockBody_ProposerSlashings(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_BeaconBlockBody_AttesterSlashings(t *testing.T) {
|
||||
as := make([]interfaces.AttesterSlashing, 0)
|
||||
as := make([]eth.AttSlashing, 0)
|
||||
bb := &SignedBeaconBlock{block: &BeaconBlock{body: &BeaconBlockBody{}}}
|
||||
require.NoError(t, bb.SetAttesterSlashings(as))
|
||||
assert.DeepSSZEqual(t, as, bb.Block().Body().AttesterSlashings())
|
||||
}
|
||||
|
||||
func Test_BeaconBlockBody_Attestations(t *testing.T) {
|
||||
a := make([]interfaces.Attestation, 0)
|
||||
a := make([]eth.Att, 0)
|
||||
bb := &SignedBeaconBlock{block: &BeaconBlock{body: &BeaconBlockBody{}}}
|
||||
require.NoError(t, bb.SetAttestations(a))
|
||||
assert.DeepSSZEqual(t, a, bb.Block().Body().Attestations())
|
||||
|
||||
@@ -66,7 +66,7 @@ func (b *SignedBeaconBlock) SetProposerSlashings(p []*eth.ProposerSlashing) {
|
||||
|
||||
// SetAttesterSlashings sets the attester slashings in the block.
|
||||
// This function is not thread safe, it is only used during block creation.
|
||||
func (b *SignedBeaconBlock) SetAttesterSlashings(slashings []interfaces.AttesterSlashing) error {
|
||||
func (b *SignedBeaconBlock) SetAttesterSlashings(slashings []eth.AttSlashing) error {
|
||||
if b.version < version.Electra {
|
||||
blockSlashings := make([]*eth.AttesterSlashing, 0, len(slashings))
|
||||
for _, slashing := range slashings {
|
||||
@@ -93,7 +93,7 @@ func (b *SignedBeaconBlock) SetAttesterSlashings(slashings []interfaces.Attester
|
||||
|
||||
// SetAttestations sets the attestations in the block.
|
||||
// This function is not thread safe, it is only used during block creation.
|
||||
func (b *SignedBeaconBlock) SetAttestations(atts []interfaces.Attestation) error {
|
||||
func (b *SignedBeaconBlock) SetAttestations(atts []eth.Att) error {
|
||||
if b.version < version.Electra {
|
||||
blockAtts := make([]*eth.Attestation, 0, len(atts))
|
||||
for _, att := range atts {
|
||||
|
||||
@@ -20,7 +20,6 @@ go_library(
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@ package interfaces
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
|
||||
@@ -61,8 +60,8 @@ type ReadOnlyBeaconBlockBody interface {
|
||||
Eth1Data() *ethpb.Eth1Data
|
||||
Graffiti() [field_params.RootLength]byte
|
||||
ProposerSlashings() []*ethpb.ProposerSlashing
|
||||
AttesterSlashings() []AttesterSlashing
|
||||
Attestations() []Attestation
|
||||
AttesterSlashings() []ethpb.AttSlashing
|
||||
Attestations() []ethpb.Att
|
||||
Deposits() []*ethpb.Deposit
|
||||
VoluntaryExits() []*ethpb.SignedVoluntaryExit
|
||||
SyncAggregate() (*ethpb.SyncAggregate, error)
|
||||
@@ -87,8 +86,8 @@ type SignedBeaconBlock interface {
|
||||
SetSyncAggregate(*ethpb.SyncAggregate) error
|
||||
SetVoluntaryExits([]*ethpb.SignedVoluntaryExit)
|
||||
SetDeposits([]*ethpb.Deposit)
|
||||
SetAttestations([]Attestation) error
|
||||
SetAttesterSlashings([]AttesterSlashing) error
|
||||
SetAttestations([]ethpb.Att) error
|
||||
SetAttesterSlashings([]ethpb.AttSlashing) error
|
||||
SetProposerSlashings([]*ethpb.ProposerSlashing)
|
||||
SetGraffiti([]byte)
|
||||
SetEth1Data(*ethpb.Eth1Data)
|
||||
@@ -138,39 +137,3 @@ type ExecutionDataElectra interface {
|
||||
DepositReceipts() []*enginev1.DepositReceipt
|
||||
WithdrawalRequests() []*enginev1.ExecutionLayerWithdrawalRequest
|
||||
}
|
||||
|
||||
type Attestation interface {
|
||||
proto.Message
|
||||
ssz.Marshaler
|
||||
ssz.Unmarshaler
|
||||
ssz.HashRoot
|
||||
Version() int
|
||||
GetAggregationBits() bitfield.Bitlist
|
||||
GetData() *ethpb.AttestationData
|
||||
GetCommitteeBitsVal() bitfield.Bitfield
|
||||
GetSignature() []byte
|
||||
}
|
||||
|
||||
type AttesterSlashing interface {
|
||||
proto.Message
|
||||
ssz.Marshaler
|
||||
ssz.Unmarshaler
|
||||
ssz.HashRoot
|
||||
Version() int
|
||||
GetFirstAttestation() ethpb.IndexedAtt
|
||||
GetSecondAttestation() ethpb.IndexedAtt
|
||||
}
|
||||
|
||||
// TODO: this is ugly. The proper way to do this is to create a Copy() function on the interface and implement it. But this results in a circular dependency.
|
||||
// CopyAttestation copies the provided attestation object.
|
||||
func CopyAttestation(att Attestation) Attestation {
|
||||
a, ok := att.(*ethpb.Attestation)
|
||||
if ok {
|
||||
return ethpb.CopyAttestation(a)
|
||||
}
|
||||
ae, ok := att.(*ethpb.AttestationElectra)
|
||||
if ok {
|
||||
return ethpb.CopyAttestationElectra(ae)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ go_library(
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/validator-client:go_default_library",
|
||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
|
||||
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -191,7 +192,7 @@ func (BeaconBlockBody) ProposerSlashings() []*eth.ProposerSlashing {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
|
||||
func (BeaconBlockBody) AttesterSlashings() []eth.AttSlashing {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -247,7 +248,7 @@ func (b *BeaconBlockBody) SetProposerSlashings([]*eth.ProposerSlashing) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (b *BeaconBlockBody) SetAttesterSlashings([]interfaces.AttesterSlashing) {
|
||||
func (b *BeaconBlockBody) SetAttesterSlashings([]ethpb.AttesterSlashing) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -280,7 +281,7 @@ func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (b *BeaconBlockBody) Attestations() []interfaces.Attestation {
|
||||
func (b *BeaconBlockBody) Attestations() []eth.Att {
|
||||
panic("implement me")
|
||||
}
|
||||
func (b *BeaconBlockBody) Consolidations() []*eth.SignedConsolidation {
|
||||
|
||||
Reference in New Issue
Block a user