From 0fbb27d8e3f6cd91c3f5229b8aa4da2894773b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kapka?= Date: Thu, 23 May 2024 01:14:08 +0900 Subject: [PATCH] EIP-7549: Add aggregate attestation interfaces (#14029) * interfaces move * build fix * remove annoying warning * more build fixes * review --- beacon-chain/blockchain/head_test.go | 7 +- .../blockchain/process_attestation.go | 3 +- .../blockchain/process_attestation_test.go | 3 +- beacon-chain/blockchain/process_block.go | 2 +- beacon-chain/blockchain/process_block_test.go | 2 +- .../blockchain/receive_attestation.go | 7 +- .../blockchain/receive_attestation_test.go | 5 +- beacon-chain/blockchain/receive_block.go | 6 +- beacon-chain/blockchain/setup_test.go | 3 +- beacon-chain/blockchain/testing/mock.go | 4 +- beacon-chain/core/altair/attestation.go | 2 +- beacon-chain/core/blocks/attestation.go | 8 +- beacon-chain/core/blocks/attestation_test.go | 9 +- beacon-chain/core/blocks/attester_slashing.go | 23 ++- .../core/blocks/attester_slashing_test.go | 13 +- .../core/blocks/block_operations_fuzz_test.go | 3 +- .../core/blocks/block_regression_test.go | 3 +- beacon-chain/core/blocks/signature.go | 8 +- beacon-chain/core/feed/operation/BUILD.bazel | 1 - beacon-chain/core/feed/operation/events.go | 5 +- beacon-chain/core/helpers/BUILD.bazel | 1 - beacon-chain/core/helpers/attestation.go | 7 +- beacon-chain/core/helpers/attestation_test.go | 3 +- beacon-chain/core/helpers/beacon_committee.go | 4 +- beacon-chain/monitor/process_attestation.go | 6 +- beacon-chain/monitor/process_block.go | 19 +-- .../operations/attestations/BUILD.bazel | 3 +- .../operations/attestations/kv/BUILD.bazel | 3 +- .../operations/attestations/kv/aggregated.go | 34 ++--- .../attestations/kv/aggregated_test.go | 39 +++-- .../operations/attestations/kv/block.go | 14 +- .../operations/attestations/kv/block_test.go | 7 +- .../operations/attestations/kv/forkchoice.go | 17 ++- .../attestations/kv/forkchoice_test.go | 7 +- beacon-chain/operations/attestations/kv/kv.go | 18 +-- .../operations/attestations/kv/seen_bits.go | 6 +- .../attestations/kv/unaggregated.go | 21 ++- .../attestations/kv/unaggregated_test.go | 29 ++-- beacon-chain/operations/attestations/pool.go | 38 ++--- .../attestations/prepare_forkchoice.go | 12 +- .../attestations/prepare_forkchoice_test.go | 25 ++-- .../attestations/prune_expired_test.go | 7 +- beacon-chain/operations/slashings/BUILD.bazel | 2 - .../operations/slashings/mock/BUILD.bazel | 1 - .../operations/slashings/mock/mock.go | 9 +- beacon-chain/operations/slashings/service.go | 17 ++- .../slashings/service_attester_test.go | 13 +- beacon-chain/operations/slashings/types.go | 9 +- beacon-chain/p2p/BUILD.bazel | 1 - beacon-chain/p2p/broadcaster.go | 5 +- beacon-chain/p2p/interfaces.go | 3 +- beacon-chain/p2p/testing/BUILD.bazel | 1 - beacon-chain/p2p/testing/fuzz_p2p.go | 3 +- beacon-chain/p2p/testing/mock_broadcaster.go | 5 +- beacon-chain/p2p/testing/p2p.go | 3 +- .../rpc/eth/beacon/handlers_pool_test.go | 7 +- beacon-chain/rpc/eth/rewards/handlers_test.go | 4 +- beacon-chain/rpc/eth/validator/BUILD.bazel | 2 - beacon-chain/rpc/eth/validator/handlers.go | 5 +- .../rpc/eth/validator/handlers_test.go | 7 +- .../rpc/prysm/v1alpha1/beacon/attestations.go | 10 +- .../v1alpha1/beacon/attestations_test.go | 12 +- .../v1alpha1/validator/aggregator_test.go | 5 +- .../rpc/prysm/v1alpha1/validator/proposer.go | 2 +- .../validator/proposer_attestations.go | 22 +-- .../validator/proposer_attestations_test.go | 5 +- .../v1alpha1/validator/proposer_deposits.go | 5 +- .../v1alpha1/validator/proposer_slashings.go | 5 +- .../validator/proposer_slashings_test.go | 3 +- .../prysm/v1alpha1/validator/proposer_test.go | 31 ++-- .../validator/proposer_utils_bench_test.go | 3 +- beacon-chain/slasher/BUILD.bazel | 2 - beacon-chain/slasher/chunks.go | 7 +- beacon-chain/slasher/detect_attestations.go | 19 ++- beacon-chain/slasher/helpers.go | 13 +- beacon-chain/slasher/process_slashings.go | 15 +- .../slasher/process_slashings_test.go | 7 +- beacon-chain/slasher/receive.go | 3 +- .../subscriber_beacon_aggregate_proof_test.go | 5 +- beacon-chain/sync/subscriber_handlers.go | 9 +- beacon-chain/sync/validate_aggregate_proof.go | 5 +- .../sync/validate_attester_slashing.go | 4 +- .../sync/validate_beacon_attestation.go | 11 +- consensus-types/blocks/getters.go | 16 +-- consensus-types/blocks/getters_test.go | 4 +- consensus-types/blocks/setters.go | 4 +- consensus-types/interfaces/BUILD.bazel | 1 - consensus-types/interfaces/beacon_block.go | 45 +----- consensus-types/mock/BUILD.bazel | 1 + consensus-types/mock/block.go | 7 +- proto/prysm/v1alpha1/attestation.go | 136 ++++++++++++++++-- proto/prysm/v1alpha1/attestation/BUILD.bazel | 2 - .../aggregation/attestations/BUILD.bazel | 2 - .../aggregation/attestations/attestations.go | 7 +- .../aggregation/attestations/maxcover.go | 9 +- .../aggregation/attestations/maxcover_test.go | 61 ++++---- .../aggregation/testing/BUILD.bazel | 1 - .../aggregation/testing/bitlistutils.go | 5 +- .../v1alpha1/attestation/attestation_utils.go | 5 +- .../attestation/attestation_utils_test.go | 3 +- .../validator-client/keymanager.proto | 1 - testing/slasher/simulator/BUILD.bazel | 1 - testing/slasher/simulator/simulator.go | 3 +- .../shared/common/forkchoice/builder.go | 2 +- 104 files changed, 530 insertions(+), 523 deletions(-) diff --git a/beacon-chain/blockchain/head_test.go b/beacon-chain/blockchain/head_test.go index d1e5b1c1de..4bdda69e9d 100644 --- a/beacon-chain/blockchain/head_test.go +++ b/beacon-chain/blockchain/head_test.go @@ -13,7 +13,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/blstoexec" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpbv1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" @@ -313,7 +312,7 @@ func TestSaveOrphanedAtts(t *testing.T) { require.NoError(t, service.saveOrphanedOperations(ctx, r3, r4)) require.Equal(t, 3, service.cfg.AttPool.AggregatedAttestationCount()) - wantAtts := []interfaces.Attestation{ + wantAtts := []ethpb.Att{ blk3.Block.Body.Attestations[0], blk2.Block.Body.Attestations[0], blk1.Block.Body.Attestations[0], @@ -390,7 +389,7 @@ func TestSaveOrphanedOps(t *testing.T) { require.NoError(t, service.saveOrphanedOperations(ctx, r3, r4)) require.Equal(t, 3, service.cfg.AttPool.AggregatedAttestationCount()) - wantAtts := []interfaces.Attestation{ + wantAtts := []ethpb.Att{ blk3.Block.Body.Attestations[0], blk2.Block.Body.Attestations[0], blk1.Block.Body.Attestations[0], @@ -518,7 +517,7 @@ func TestSaveOrphanedAtts_DoublyLinkedTrie(t *testing.T) { require.NoError(t, service.saveOrphanedOperations(ctx, r3, r4)) require.Equal(t, 3, service.cfg.AttPool.AggregatedAttestationCount()) - wantAtts := []interfaces.Attestation{ + wantAtts := []ethpb.Att{ blk3.Block.Body.Attestations[0], blk2.Block.Body.Attestations[0], blk1.Block.Body.Attestations[0], diff --git a/beacon-chain/blockchain/process_attestation.go b/beacon-chain/blockchain/process_attestation.go index c645f9ccee..a0949e8699 100644 --- a/beacon-chain/blockchain/process_attestation.go +++ b/beacon-chain/blockchain/process_attestation.go @@ -6,7 +6,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation" @@ -37,7 +36,7 @@ import ( // // # Update latest messages for attesting indices // update_latest_messages(store, indexed_attestation.attesting_indices, attestation) -func (s *Service) OnAttestation(ctx context.Context, a interfaces.Attestation, disparity time.Duration) error { +func (s *Service) OnAttestation(ctx context.Context, a ethpb.Att, disparity time.Duration) error { ctx, span := trace.StartSpan(ctx, "blockChain.onAttestation") defer span.End() diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index 9b0f722051..47e411eacc 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -74,7 +73,7 @@ func TestStore_OnAttestation_ErrorConditions(t *testing.T) { tests := []struct { name string - a interfaces.Attestation + a ethpb.Att wantedErr string }{ { diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index 5ced8b1623..575b1f2529 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -387,7 +387,7 @@ func (s *Service) handleBlockAttestations(ctx context.Context, blk interfaces.Re // InsertSlashingsToForkChoiceStore inserts attester slashing indices to fork choice store. // To call this function, it's caller's responsibility to ensure the slashing object is valid. // This function requires a write lock on forkchoice. -func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashings []interfaces.AttesterSlashing) { +func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashings []ethpb.AttSlashing) { for _, slashing := range slashings { indices := blocks.SlashableAttesterIndices(slashing) for _, index := range indices { diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index fbc15a824a..d4ca7a9ba6 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -824,7 +824,7 @@ func TestRemoveBlockAttestationsInPool(t *testing.T) { require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: r[:]})) require.NoError(t, service.cfg.BeaconDB.SaveGenesisBlockRoot(ctx, r)) - atts := make([]interfaces.Attestation, len(b.Block.Body.Attestations)) + atts := make([]ethpb.Att, len(b.Block.Body.Attestations)) for i, a := range b.Block.Body.Attestations { atts[i] = a } diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 1d5a5763f3..89f344383c 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -10,7 +10,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -32,7 +31,7 @@ type AttestationStateFetcher interface { // AttestationReceiver interface defines the methods of chain service receive and processing new attestations. type AttestationReceiver interface { AttestationStateFetcher - VerifyLmdFfgConsistency(ctx context.Context, att interfaces.Attestation) error + VerifyLmdFfgConsistency(ctx context.Context, att ethpb.Att) error InForkchoice([32]byte) bool } @@ -52,7 +51,7 @@ func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Chec } // VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other. -func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a interfaces.Attestation) error { +func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a ethpb.Att) error { r, err := s.TargetRootForEpoch([32]byte(a.GetData().BeaconBlockRoot), a.GetData().Target.Epoch) if err != nil { return err @@ -207,7 +206,7 @@ func (s *Service) processAttestations(ctx context.Context, disparity time.Durati // 1. Validate attestation, update validator's latest vote // 2. Apply fork choice to the processed attestation // 3. Save latest head info -func (s *Service) receiveAttestationNoPubsub(ctx context.Context, att interfaces.Attestation, disparity time.Duration) error { +func (s *Service) receiveAttestationNoPubsub(ctx context.Context, att ethpb.Att, disparity time.Duration) error { ctx, span := trace.StartSpan(ctx, "beacon-chain.blockchain.receiveAttestationNoPubsub") defer span.End() diff --git a/beacon-chain/blockchain/receive_attestation_test.go b/beacon-chain/blockchain/receive_attestation_test.go index dd1ce2cabc..94c27f1fb8 100644 --- a/beacon-chain/blockchain/receive_attestation_test.go +++ b/beacon-chain/blockchain/receive_attestation_test.go @@ -10,7 +10,6 @@ import ( forkchoicetypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -84,7 +83,7 @@ func TestProcessAttestations_Ok(t *testing.T) { state, blkRoot, err := prepareForkchoiceState(ctx, 0, tRoot, tRoot, params.BeaconConfig().ZeroHash, ojc, ofc) require.NoError(t, err) require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot)) - attsToSave := make([]interfaces.Attestation, len(atts)) + attsToSave := make([]ethpb.Att, len(atts)) for i, a := range atts { attsToSave[i] = a } @@ -126,7 +125,7 @@ func TestService_ProcessAttestationsAndUpdateHead(t *testing.T) { // Generate attestations for this block in Slot 1 atts, err := util.GenerateAttestations(copied, pks, 1, 1, false) require.NoError(t, err) - attsToSave := make([]interfaces.Attestation, len(atts)) + attsToSave := make([]ethpb.Att, len(atts)) for i, a := range atts { attsToSave[i] = a } diff --git a/beacon-chain/blockchain/receive_block.go b/beacon-chain/blockchain/receive_block.go index f4b05f6c35..884e257f32 100644 --- a/beacon-chain/blockchain/receive_block.go +++ b/beacon-chain/blockchain/receive_block.go @@ -52,7 +52,7 @@ type BlobReceiver interface { // SlashingReceiver interface defines the methods of chain service for receiving validated slashing over the wire. type SlashingReceiver interface { - ReceiveAttesterSlashing(ctx context.Context, slashing interfaces.AttesterSlashing) + ReceiveAttesterSlashing(ctx context.Context, slashing ethpb.AttSlashing) } // ReceiveBlock is a function that defines the operations (minus pubsub) @@ -295,10 +295,10 @@ func (s *Service) HasBlock(ctx context.Context, root [32]byte) bool { } // ReceiveAttesterSlashing receives an attester slashing and inserts it to forkchoice -func (s *Service) ReceiveAttesterSlashing(ctx context.Context, slashing interfaces.AttesterSlashing) { +func (s *Service) ReceiveAttesterSlashing(ctx context.Context, slashing ethpb.AttSlashing) { s.cfg.ForkChoiceStore.Lock() defer s.cfg.ForkChoiceStore.Unlock() - s.InsertSlashingsToForkChoiceStore(ctx, []interfaces.AttesterSlashing{slashing}) + s.InsertSlashingsToForkChoiceStore(ctx, []ethpb.AttSlashing{slashing}) } // prunePostBlockOperationPools only runs on new head otherwise should return a nil. diff --git a/beacon-chain/blockchain/setup_test.go b/beacon-chain/blockchain/setup_test.go index 97c6d00f7d..f305ea6e95 100644 --- a/beacon-chain/blockchain/setup_test.go +++ b/beacon-chain/blockchain/setup_test.go @@ -20,7 +20,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v5/beacon-chain/startup" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" "google.golang.org/protobuf/proto" @@ -50,7 +49,7 @@ func (mb *mockBroadcaster) Broadcast(_ context.Context, _ proto.Message) error { return nil } -func (mb *mockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, _ interfaces.Attestation) error { +func (mb *mockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, _ ethpb.Att) error { mb.broadcastCalled = true return nil } diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index e85868c448..d0da4f0cd0 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -414,7 +414,7 @@ func (*ChainService) HeadGenesisValidatorsRoot() [32]byte { } // VerifyLmdFfgConsistency mocks VerifyLmdFfgConsistency and always returns nil. -func (*ChainService) VerifyLmdFfgConsistency(_ context.Context, a interfaces.Attestation) error { +func (*ChainService) VerifyLmdFfgConsistency(_ context.Context, a ethpb.Att) error { if !bytes.Equal(a.GetData().BeaconBlockRoot, a.GetData().Target.Root) { return errors.New("LMD and FFG miss matched") } @@ -495,7 +495,7 @@ func (s *ChainService) UpdateHead(ctx context.Context, slot primitives.Slot) { } // ReceiveAttesterSlashing mocks the same method in the chain service. -func (*ChainService) ReceiveAttesterSlashing(context.Context, interfaces.AttesterSlashing) {} +func (*ChainService) ReceiveAttesterSlashing(context.Context, ethpb.AttSlashing) {} // IsFinalized mocks the same method in the chain service. func (s *ChainService) IsFinalized(_ context.Context, blockRoot [32]byte) bool { diff --git a/beacon-chain/core/altair/attestation.go b/beacon-chain/core/altair/attestation.go index 336edf57a7..e2d6305a4b 100644 --- a/beacon-chain/core/altair/attestation.go +++ b/beacon-chain/core/altair/attestation.go @@ -48,7 +48,7 @@ func ProcessAttestationsNoVerifySignature( func ProcessAttestationNoVerifySignature( ctx context.Context, beaconState state.BeaconState, - att interfaces.Attestation, + att ethpb.Att, totalBalance uint64, ) (state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "altair.ProcessAttestationNoVerifySignature") diff --git a/beacon-chain/core/blocks/attestation.go b/beacon-chain/core/blocks/attestation.go index 2afafcb6a1..5b9c0c83ef 100644 --- a/beacon-chain/core/blocks/attestation.go +++ b/beacon-chain/core/blocks/attestation.go @@ -46,7 +46,7 @@ func ProcessAttestationsNoVerifySignature( func VerifyAttestationNoVerifySignature( ctx context.Context, beaconState state.ReadOnlyBeaconState, - att interfaces.Attestation, + att ethpb.Att, ) error { ctx, span := trace.StartSpan(ctx, "core.VerifyAttestationNoVerifySignature") defer span.End() @@ -133,7 +133,7 @@ func VerifyAttestationNoVerifySignature( return errors.New("committee index must be 0 post-Electra") } - committeeIndices := att.GetCommitteeBitsVal().BitIndices() + committeeIndices := att.CommitteeBitsVal().BitIndices() committees := make([][]primitives.ValidatorIndex, len(committeeIndices)) participantsCount := 0 var err error @@ -164,7 +164,7 @@ func VerifyAttestationNoVerifySignature( func ProcessAttestationNoVerifySignature( ctx context.Context, beaconState state.BeaconState, - att interfaces.Attestation, + att ethpb.Att, ) (state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerifySignature") defer span.End() @@ -202,7 +202,7 @@ func ProcessAttestationNoVerifySignature( // VerifyAttestationSignature converts and attestation into an indexed attestation and verifies // the signature in that attestation. -func VerifyAttestationSignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, att interfaces.Attestation) error { +func VerifyAttestationSignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, att ethpb.Att) error { if err := helpers.ValidateNilAttestation(att); err != nil { return err } diff --git a/beacon-chain/core/blocks/attestation_test.go b/beacon-chain/core/blocks/attestation_test.go index 10ca47b178..2ebc36a231 100644 --- a/beacon-chain/core/blocks/attestation_test.go +++ b/beacon-chain/core/blocks/attestation_test.go @@ -11,7 +11,6 @@ import ( state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -464,7 +463,7 @@ func TestValidateIndexedAttestation_BadAttestationsSignatureSet(t *testing.T) { sig := keys[0].Sign([]byte{'t', 'e', 's', 't'}) list := bitfield.Bitlist{0b11111} - var atts []interfaces.Attestation + var atts []ethpb.Att for i := uint64(0); i < 1000; i++ { atts = append(atts, ðpb.Attestation{ Data: ðpb.AttestationData{ @@ -480,7 +479,7 @@ func TestValidateIndexedAttestation_BadAttestationsSignatureSet(t *testing.T) { _, err := blocks.AttestationSignatureBatch(context.Background(), beaconState, atts) assert.ErrorContains(t, want, err) - atts = []interfaces.Attestation{} + atts = []ethpb.Att{} list = bitfield.Bitlist{0b10000} for i := uint64(0); i < 1000; i++ { atts = append(atts, ðpb.Attestation{ @@ -621,7 +620,7 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing } att2.Signature = bls.AggregateSignatures(sigs).Marshal() - set, err := blocks.AttestationSignatureBatch(ctx, st, []interfaces.Attestation{att1, att2}) + set, err := blocks.AttestationSignatureBatch(ctx, st, []ethpb.Att{att1, att2}) require.NoError(t, err) verified, err := set.Verify() require.NoError(t, err) @@ -685,6 +684,6 @@ func TestRetrieveAttestationSignatureSet_AcrossFork(t *testing.T) { } att2.Signature = bls.AggregateSignatures(sigs).Marshal() - _, err = blocks.AttestationSignatureBatch(ctx, st, []interfaces.Attestation{att1, att2}) + _, err = blocks.AttestationSignatureBatch(ctx, st, []ethpb.Att{att1, att2}) require.NoError(t, err) } diff --git a/beacon-chain/core/blocks/attester_slashing.go b/beacon-chain/core/blocks/attester_slashing.go index b6392b6fcb..f1b96e8a15 100644 --- a/beacon-chain/core/blocks/attester_slashing.go +++ b/beacon-chain/core/blocks/attester_slashing.go @@ -7,7 +7,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -39,7 +38,7 @@ import ( func ProcessAttesterSlashings( ctx context.Context, beaconState state.BeaconState, - slashings []interfaces.AttesterSlashing, + slashings []ethpb.AttSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error) { var err error @@ -56,7 +55,7 @@ func ProcessAttesterSlashings( func ProcessAttesterSlashing( ctx context.Context, beaconState state.BeaconState, - slashing interfaces.AttesterSlashing, + slashing ethpb.AttSlashing, slashFunc slashValidatorFunc, ) (state.BeaconState, error) { if err := VerifyAttesterSlashing(ctx, beaconState, slashing); err != nil { @@ -91,18 +90,18 @@ func ProcessAttesterSlashing( } // VerifyAttesterSlashing validates the attestation data in both attestations in the slashing object. -func VerifyAttesterSlashing(ctx context.Context, beaconState state.ReadOnlyBeaconState, slashing interfaces.AttesterSlashing) error { +func VerifyAttesterSlashing(ctx context.Context, beaconState state.ReadOnlyBeaconState, slashing ethpb.AttSlashing) error { if slashing == nil { return errors.New("nil slashing") } - if slashing.GetFirstAttestation() == nil || slashing.GetSecondAttestation() == nil { + if slashing.FirstAttestation() == nil || slashing.SecondAttestation() == nil { return errors.New("nil attestation") } - if slashing.GetFirstAttestation().GetData() == nil || slashing.GetSecondAttestation().GetData() == nil { + if slashing.FirstAttestation().GetData() == nil || slashing.SecondAttestation().GetData() == nil { return errors.New("nil attestation data") } - att1 := slashing.GetFirstAttestation() - att2 := slashing.GetSecondAttestation() + att1 := slashing.FirstAttestation() + att2 := slashing.SecondAttestation() data1 := att1.GetData() data2 := att2.GetData() if !IsSlashableAttestationData(data1, data2) { @@ -144,11 +143,11 @@ func IsSlashableAttestationData(data1, data2 *ethpb.AttestationData) bool { } // SlashableAttesterIndices returns the intersection of attester indices from both attestations in this slashing. -func SlashableAttesterIndices(slashing interfaces.AttesterSlashing) []uint64 { - if slashing == nil || slashing.GetFirstAttestation() == nil || slashing.GetSecondAttestation() == nil { +func SlashableAttesterIndices(slashing ethpb.AttSlashing) []uint64 { + if slashing == nil || slashing.FirstAttestation() == nil || slashing.SecondAttestation() == nil { return nil } - indices1 := slashing.GetFirstAttestation().GetAttestingIndices() - indices2 := slashing.GetSecondAttestation().GetAttestingIndices() + indices1 := slashing.FirstAttestation().GetAttestingIndices() + indices2 := slashing.SecondAttestation().GetAttestingIndices() return slice.IntersectionUint64(indices1, indices2) } diff --git a/beacon-chain/core/blocks/attester_slashing_test.go b/beacon-chain/core/blocks/attester_slashing_test.go index 295146c77c..75c5b7efa0 100644 --- a/beacon-chain/core/blocks/attester_slashing_test.go +++ b/beacon-chain/core/blocks/attester_slashing_test.go @@ -9,7 +9,6 @@ import ( v "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/validators" state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -58,7 +57,7 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) { AttesterSlashings: slashings, }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } @@ -97,7 +96,7 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T) }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } @@ -153,7 +152,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } @@ -226,7 +225,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) { }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } @@ -299,7 +298,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) { }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } @@ -372,7 +371,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusCapella(t *testing.T) { }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } diff --git a/beacon-chain/core/blocks/block_operations_fuzz_test.go b/beacon-chain/core/blocks/block_operations_fuzz_test.go index 8d2ac1fbbb..28db7d8c4f 100644 --- a/beacon-chain/core/blocks/block_operations_fuzz_test.go +++ b/beacon-chain/core/blocks/block_operations_fuzz_test.go @@ -10,7 +10,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -217,7 +216,7 @@ func TestFuzzProcessAttesterSlashings_10000(t *testing.T) { fuzzer.Fuzz(a) s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) - r, err := ProcessAttesterSlashings(ctx, s, []interfaces.AttesterSlashing{a}, v.SlashValidator) + r, err := ProcessAttesterSlashings(ctx, s, []ethpb.AttSlashing{a}, v.SlashValidator) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and slashing: %v", r, err, state, a) } diff --git a/beacon-chain/core/blocks/block_regression_test.go b/beacon-chain/core/blocks/block_regression_test.go index 807cea81b4..96339adba9 100644 --- a/beacon-chain/core/blocks/block_regression_test.go +++ b/beacon-chain/core/blocks/block_regression_test.go @@ -8,7 +8,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing" v "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -92,7 +91,7 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) { }, } - ss := make([]interfaces.AttesterSlashing, len(b.Block.Body.AttesterSlashings)) + ss := make([]ethpb.AttSlashing, len(b.Block.Body.AttesterSlashings)) for i, s := range b.Block.Body.AttesterSlashings { ss[i] = s } diff --git a/beacon-chain/core/blocks/signature.go b/beacon-chain/core/blocks/signature.go index 720e025d41..b142441605 100644 --- a/beacon-chain/core/blocks/signature.go +++ b/beacon-chain/core/blocks/signature.go @@ -179,7 +179,7 @@ func randaoSigningData(ctx context.Context, beaconState state.ReadOnlyBeaconStat func createAttestationSignatureBatch( ctx context.Context, beaconState state.ReadOnlyBeaconState, - atts []interfaces.Attestation, + atts []ethpb.Att, domain []byte, ) (*bls.SignatureBatch, error) { if len(atts) == 0 { @@ -233,7 +233,7 @@ func createAttestationSignatureBatch( // AttestationSignatureBatch retrieves all the related attestation signature data such as the relevant public keys, // signatures and attestation signing data and collate it into a signature batch object. -func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []interfaces.Attestation) (*bls.SignatureBatch, error) { +func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []ethpb.Att) (*bls.SignatureBatch, error) { if len(atts) == 0 { return bls.NewSet(), nil } @@ -243,8 +243,8 @@ func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBe dt := params.BeaconConfig().DomainBeaconAttester // Split attestations by fork. Note: the signature domain will differ based on the fork. - var preForkAtts []interfaces.Attestation - var postForkAtts []interfaces.Attestation + var preForkAtts []ethpb.Att + var postForkAtts []ethpb.Att for _, a := range atts { if slots.ToEpoch(a.GetData().Slot) < fork.Epoch { preForkAtts = append(preForkAtts, a) diff --git a/beacon-chain/core/feed/operation/BUILD.bazel b/beacon-chain/core/feed/operation/BUILD.bazel index b159265e19..0d475e92d8 100644 --- a/beacon-chain/core/feed/operation/BUILD.bazel +++ b/beacon-chain/core/feed/operation/BUILD.bazel @@ -11,7 +11,6 @@ go_library( deps = [ "//async/event:go_default_library", "//consensus-types/blocks:go_default_library", - "//consensus-types/interfaces:go_default_library", "//proto/prysm/v1alpha1:go_default_library", ], ) diff --git a/beacon-chain/core/feed/operation/events.go b/beacon-chain/core/feed/operation/events.go index 2a4bf6942f..86287da922 100644 --- a/beacon-chain/core/feed/operation/events.go +++ b/beacon-chain/core/feed/operation/events.go @@ -3,7 +3,6 @@ package operation import ( "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) @@ -38,7 +37,7 @@ const ( // UnAggregatedAttReceivedData is the data sent with UnaggregatedAttReceived events. type UnAggregatedAttReceivedData struct { // Attestation is the unaggregated attestation object. - Attestation interfaces.Attestation + Attestation ethpb.Att } // AggregatedAttReceivedData is the data sent with AggregatedAttReceived events. @@ -76,5 +75,5 @@ type ProposerSlashingReceivedData struct { // AttesterSlashingReceivedData is the data sent with AttesterSlashingReceived events. type AttesterSlashingReceivedData struct { - AttesterSlashing interfaces.AttesterSlashing + AttesterSlashing ethpb.AttSlashing } diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 1912d6c299..c8b45a534c 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -73,7 +73,6 @@ go_test( "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//container/slice:go_default_library", "//crypto/hash:go_default_library", diff --git a/beacon-chain/core/helpers/attestation.go b/beacon-chain/core/helpers/attestation.go index bb620ba179..0e9baf9932 100644 --- a/beacon-chain/core/helpers/attestation.go +++ b/beacon-chain/core/helpers/attestation.go @@ -7,7 +7,6 @@ import ( "time" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/hash" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -22,7 +21,7 @@ var ( // ValidateNilAttestation checks if any composite field of input attestation is nil. // Access to these nil fields will result in run time panic, // it is recommended to run these checks as first line of defense. -func ValidateNilAttestation(attestation interfaces.Attestation) error { +func ValidateNilAttestation(attestation ethpb.Att) error { if attestation == nil { return errors.New("attestation can't be nil") } @@ -72,7 +71,7 @@ func IsAggregator(committeeCount uint64, slotSig []byte) (bool, error) { // IsAggregated returns true if the attestation is an aggregated attestation, // false otherwise. -func IsAggregated(attestation interfaces.Attestation) bool { +func IsAggregated(attestation ethpb.Att) bool { return attestation.GetAggregationBits().Count() > 1 } @@ -91,7 +90,7 @@ func IsAggregated(attestation interfaces.Attestation) bool { // committees_since_epoch_start = committees_per_slot * slots_since_epoch_start // // return uint64((committees_since_epoch_start + committee_index) % ATTESTATION_SUBNET_COUNT) -func ComputeSubnetForAttestation(activeValCount uint64, att interfaces.Attestation) uint64 { +func ComputeSubnetForAttestation(activeValCount uint64, att ethpb.Att) uint64 { return ComputeSubnetFromCommitteeAndSlot(activeValCount, att.GetData().CommitteeIndex, att.GetData().Slot) } diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index 6ffb5f4476..e4a84ae422 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -239,7 +238,7 @@ func TestVerifyCheckpointEpoch_Ok(t *testing.T) { func TestValidateNilAttestation(t *testing.T) { tests := []struct { name string - attestation interfaces.Attestation + attestation ethpb.Att errString string }{ { diff --git a/beacon-chain/core/helpers/beacon_committee.go b/beacon-chain/core/helpers/beacon_committee.go index 86134ca4d0..d1371a9537 100644 --- a/beacon-chain/core/helpers/beacon_committee.go +++ b/beacon-chain/core/helpers/beacon_committee.go @@ -15,12 +15,12 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" "github.com/prysmaticlabs/prysm/v5/crypto/hash" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/math" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" ) @@ -257,7 +257,7 @@ func VerifyBitfieldLength(bf bitfield.Bitfield, committeeSize uint64) error { // VerifyAttestationBitfieldLengths verifies that an attestations aggregation bitfields is // a valid length matching the size of the committee. -func VerifyAttestationBitfieldLengths(ctx context.Context, state state.ReadOnlyBeaconState, att interfaces.Attestation) error { +func VerifyAttestationBitfieldLengths(ctx context.Context, state state.ReadOnlyBeaconState, att ethpb.Att) error { committee, err := BeaconCommitteeFromState(ctx, state, att.GetData().Slot, att.GetData().CommitteeIndex) if err != nil { return errors.Wrap(err, "could not retrieve beacon committees") diff --git a/beacon-chain/monitor/process_attestation.go b/beacon-chain/monitor/process_attestation.go index 9f596eea61..7191aebdd1 100644 --- a/beacon-chain/monitor/process_attestation.go +++ b/beacon-chain/monitor/process_attestation.go @@ -33,7 +33,7 @@ func (s *Service) canUpdateAttestedValidator(idx primitives.ValidatorIndex, slot } // attestingIndices returns the indices of validators that participated in the given aggregated attestation. -func attestingIndices(ctx context.Context, state state.BeaconState, att interfaces.Attestation) ([]uint64, error) { +func attestingIndices(ctx context.Context, state state.BeaconState, att ethpb.Att) ([]uint64, error) { committee, err := helpers.BeaconCommitteeFromState(ctx, state, att.GetData().Slot, att.GetData().CommitteeIndex) if err != nil { return nil, err @@ -63,7 +63,7 @@ func (s *Service) processAttestations(ctx context.Context, state state.BeaconSta } // processIncludedAttestation logs in the event for the tracked validators' and their latest attestation gets processed. -func (s *Service) processIncludedAttestation(ctx context.Context, state state.BeaconState, att interfaces.Attestation) { +func (s *Service) processIncludedAttestation(ctx context.Context, state state.BeaconState, att ethpb.Att) { attestingIndices, err := attestingIndices(ctx, state, att) if err != nil { log.WithError(err).Error("Could not get attesting indices") @@ -161,7 +161,7 @@ func (s *Service) processIncludedAttestation(ctx context.Context, state state.Be } // processUnaggregatedAttestation logs when the beacon node observes an unaggregated attestation from tracked validator. -func (s *Service) processUnaggregatedAttestation(ctx context.Context, att interfaces.Attestation) { +func (s *Service) processUnaggregatedAttestation(ctx context.Context, att ethpb.Att) { s.RLock() defer s.RUnlock() root := bytesutil.ToBytes32(att.GetData().BeaconBlockRoot) diff --git a/beacon-chain/monitor/process_block.go b/beacon-chain/monitor/process_block.go index d1661a3dfb..2edd14e2e9 100644 --- a/beacon-chain/monitor/process_block.go +++ b/beacon-chain/monitor/process_block.go @@ -121,17 +121,20 @@ func (s *Service) processSlashings(blk interfaces.ReadOnlyBeaconBlock) { for _, slashing := range blk.Body().AttesterSlashings() { for _, idx := range blocks.SlashableAttesterIndices(slashing) { if s.trackedIndex(primitives.ValidatorIndex(idx)) { + data1 := slashing.FirstAttestation().GetData() + data2 := slashing.SecondAttestation().GetData() + log.WithFields(logrus.Fields{ "attesterIndex": idx, "blockInclusionSlot": blk.Slot(), - "attestationSlot1": slashing.GetFirstAttestation().GetData().Slot, - "beaconBlockRoot1": fmt.Sprintf("%#x", bytesutil.Trunc(slashing.GetFirstAttestation().GetData().BeaconBlockRoot)), - "sourceEpoch1": slashing.GetFirstAttestation().GetData().Source.Epoch, - "targetEpoch1": slashing.GetFirstAttestation().GetData().Target.Epoch, - "attestationSlot2": slashing.GetSecondAttestation().GetData().Slot, - "beaconBlockRoot2": fmt.Sprintf("%#x", bytesutil.Trunc(slashing.GetSecondAttestation().GetData().BeaconBlockRoot)), - "sourceEpoch2": slashing.GetSecondAttestation().GetData().Source.Epoch, - "targetEpoch2": slashing.GetSecondAttestation().GetData().Target.Epoch, + "attestationSlot1": data1.Slot, + "beaconBlockRoot1": fmt.Sprintf("%#x", bytesutil.Trunc(data1.BeaconBlockRoot)), + "sourceEpoch1": data1.Source.Epoch, + "targetEpoch1": data1.Target.Epoch, + "attestationSlot2": data2.Slot, + "beaconBlockRoot2": fmt.Sprintf("%#x", bytesutil.Trunc(data2.BeaconBlockRoot)), + "sourceEpoch2": data2.Source.Epoch, + "targetEpoch2": data2.Target.Epoch, }).Info("Attester slashing was included") } } diff --git a/beacon-chain/operations/attestations/BUILD.bazel b/beacon-chain/operations/attestations/BUILD.bazel index 96f11a78f7..5b4cc57b38 100644 --- a/beacon-chain/operations/attestations/BUILD.bazel +++ b/beacon-chain/operations/attestations/BUILD.bazel @@ -20,9 +20,9 @@ go_library( "//cache/lru:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/hash:go_default_library", + "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library", "//time:go_default_library", "//time/slots:go_default_library", @@ -49,7 +49,6 @@ go_test( "//beacon-chain/operations/attestations/kv:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/operations/attestations/kv/BUILD.bazel b/beacon-chain/operations/attestations/kv/BUILD.bazel index a2daf64e83..807bc29200 100644 --- a/beacon-chain/operations/attestations/kv/BUILD.bazel +++ b/beacon-chain/operations/attestations/kv/BUILD.bazel @@ -15,9 +15,9 @@ go_library( deps = [ "//beacon-chain/core/helpers:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/hash:go_default_library", + "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", "@com_github_pkg_errors//:go_default_library", @@ -39,7 +39,6 @@ go_test( embed = [":go_default_library"], deps = [ "//config/fieldparams:go_default_library", - "//consensus-types/interfaces:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", diff --git a/beacon-chain/operations/attestations/kv/aggregated.go b/beacon-chain/operations/attestations/kv/aggregated.go index 8c11767db2..b0571cb6ab 100644 --- a/beacon-chain/operations/attestations/kv/aggregated.go +++ b/beacon-chain/operations/attestations/kv/aggregated.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations" log "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -28,11 +28,11 @@ func (c *AttCaches) AggregateUnaggregatedAttestations(ctx context.Context) error return c.aggregateUnaggregatedAtts(ctx, unaggregatedAtts) } -func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedAtts []interfaces.Attestation) error { +func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedAtts []ethpb.Att) error { _, span := trace.StartSpan(ctx, "operations.attestations.kv.aggregateUnaggregatedAtts") defer span.End() - attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(unaggregatedAtts)) + attsByDataRoot := make(map[[32]byte][]ethpb.Att, len(unaggregatedAtts)) for _, att := range unaggregatedAtts { attDataRoot, err := att.GetData().HashTreeRoot() if err != nil { @@ -66,12 +66,12 @@ func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedA // aggregateParallel aggregates attestations in parallel for `atts` and saves them in the pool, // returns the unaggregated attestations that weren't able to aggregate. // Given `n` CPU cores, it creates a channel of size `n` and spawns `n` goroutines to aggregate attestations -func (c *AttCaches) aggregateParallel(atts map[[32]byte][]interfaces.Attestation, leftOver map[[32]byte]bool) map[[32]byte]bool { +func (c *AttCaches) aggregateParallel(atts map[[32]byte][]ethpb.Att, leftOver map[[32]byte]bool) map[[32]byte]bool { var leftoverLock sync.Mutex wg := sync.WaitGroup{} n := runtime.GOMAXPROCS(0) // defaults to the value of runtime.NumCPU - ch := make(chan []interfaces.Attestation, n) + ch := make(chan []ethpb.Att, n) wg.Add(n) for i := 0; i < n; i++ { go func() { @@ -87,7 +87,7 @@ func (c *AttCaches) aggregateParallel(atts map[[32]byte][]interfaces.Attestation continue } if helpers.IsAggregated(aggregated) { - if err := c.SaveAggregatedAttestations([]interfaces.Attestation{aggregated}); err != nil { + if err := c.SaveAggregatedAttestations([]ethpb.Att{aggregated}); err != nil { log.WithError(err).Error("could not save aggregated attestation") continue } @@ -116,7 +116,7 @@ func (c *AttCaches) aggregateParallel(atts map[[32]byte][]interfaces.Attestation } // SaveAggregatedAttestation saves an aggregated attestation in cache. -func (c *AttCaches) SaveAggregatedAttestation(att interfaces.Attestation) error { +func (c *AttCaches) SaveAggregatedAttestation(att ethpb.Att) error { if err := helpers.ValidateNilAttestation(att); err != nil { return err } @@ -143,12 +143,12 @@ func (c *AttCaches) SaveAggregatedAttestation(att interfaces.Attestation) error if err != nil { return errors.Wrap(err, "could not tree hash attestation") } - copiedAtt := interfaces.CopyAttestation(att) + copiedAtt := att.Copy() c.aggregatedAttLock.Lock() defer c.aggregatedAttLock.Unlock() atts, ok := c.aggregatedAtt[r] if !ok { - atts := []interfaces.Attestation{copiedAtt} + atts := []ethpb.Att{copiedAtt} c.aggregatedAtt[r] = atts return nil } @@ -163,7 +163,7 @@ func (c *AttCaches) SaveAggregatedAttestation(att interfaces.Attestation) error } // SaveAggregatedAttestations saves a list of aggregated attestations in cache. -func (c *AttCaches) SaveAggregatedAttestations(atts []interfaces.Attestation) error { +func (c *AttCaches) SaveAggregatedAttestations(atts []ethpb.Att) error { for _, att := range atts { if err := c.SaveAggregatedAttestation(att); err != nil { log.WithError(err).Debug("Could not save aggregated attestation") @@ -176,11 +176,11 @@ func (c *AttCaches) SaveAggregatedAttestations(atts []interfaces.Attestation) er } // AggregatedAttestations returns the aggregated attestations in cache. -func (c *AttCaches) AggregatedAttestations() []interfaces.Attestation { +func (c *AttCaches) AggregatedAttestations() []ethpb.Att { c.aggregatedAttLock.RLock() defer c.aggregatedAttLock.RUnlock() - atts := make([]interfaces.Attestation, 0) + atts := make([]ethpb.Att, 0) for _, a := range c.aggregatedAtt { atts = append(atts, a...) @@ -191,11 +191,11 @@ func (c *AttCaches) AggregatedAttestations() []interfaces.Attestation { // AggregatedAttestationsBySlotIndex returns the aggregated attestations in cache, // filtered by committee index and slot. -func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation { +func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []ethpb.Att { _, span := trace.StartSpan(ctx, "operations.attestations.kv.AggregatedAttestationsBySlotIndex") defer span.End() - atts := make([]interfaces.Attestation, 0) + atts := make([]ethpb.Att, 0) c.aggregatedAttLock.RLock() defer c.aggregatedAttLock.RUnlock() @@ -209,7 +209,7 @@ func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot } // DeleteAggregatedAttestation deletes the aggregated attestations in cache. -func (c *AttCaches) DeleteAggregatedAttestation(att interfaces.Attestation) error { +func (c *AttCaches) DeleteAggregatedAttestation(att ethpb.Att) error { if err := helpers.ValidateNilAttestation(att); err != nil { return err } @@ -232,7 +232,7 @@ func (c *AttCaches) DeleteAggregatedAttestation(att interfaces.Attestation) erro return nil } - filtered := make([]interfaces.Attestation, 0) + filtered := make([]ethpb.Att, 0) for _, a := range attList { if c, err := att.GetAggregationBits().Contains(a.GetAggregationBits()); err != nil { return err @@ -250,7 +250,7 @@ func (c *AttCaches) DeleteAggregatedAttestation(att interfaces.Attestation) erro } // HasAggregatedAttestation checks if the input attestations has already existed in cache. -func (c *AttCaches) HasAggregatedAttestation(att interfaces.Attestation) (bool, error) { +func (c *AttCaches) HasAggregatedAttestation(att ethpb.Att) (bool, error) { if err := helpers.ValidateNilAttestation(att); err != nil { return false, err } diff --git a/beacon-chain/operations/attestations/kv/aggregated_test.go b/beacon-chain/operations/attestations/kv/aggregated_test.go index 37a8e5013d..5f2ddd40a1 100644 --- a/beacon-chain/operations/attestations/kv/aggregated_test.go +++ b/beacon-chain/operations/attestations/kv/aggregated_test.go @@ -9,7 +9,6 @@ import ( "github.com/pkg/errors" fssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -31,7 +30,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { att6 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}) att7 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}) att8 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}) - atts := []interfaces.Attestation{att1, att2, att3, att4, att5, att6, att7, att8} + atts := []ethpb.Att{att1, att2, att3, att4, att5, att6, att7, att8} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) require.NoError(t, cache.AggregateUnaggregatedAttestations(context.Background())) @@ -42,7 +41,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { tests := []struct { name string - att interfaces.Attestation + att ethpb.Att count int wantErrString string }{ @@ -119,13 +118,13 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { tests := []struct { name string - atts []interfaces.Attestation + atts []ethpb.Att count int wantErrString string }{ { name: "no duplicates", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, @@ -154,13 +153,13 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) { tests := []struct { name string - atts []interfaces.Attestation + atts []ethpb.Att count int wantErrString string }{ { name: "the first attestation is bad", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, @@ -192,7 +191,7 @@ func TestKV_Aggregated_AggregatedAttestations(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveAggregatedAttestation(att)) @@ -247,13 +246,13 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11010}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11010}}) att4 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b10101}}) - atts := []interfaces.Attestation{att1, att2, att3, att4} + atts := []ethpb.Att{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) require.NoError(t, cache.DeleteAggregatedAttestation(att1)) require.NoError(t, cache.DeleteAggregatedAttestation(att3)) returned := cache.AggregatedAttestations() - wanted := []interfaces.Attestation{att2} + wanted := []ethpb.Att{att2} assert.DeepEqual(t, wanted, returned) }) @@ -263,14 +262,14 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110111}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110100}}) att4 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110101}}) - atts := []interfaces.Attestation{att1, att2, att3, att4} + atts := []ethpb.Att{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) assert.Equal(t, 2, cache.AggregatedAttestationCount(), "Unexpected number of atts") require.NoError(t, cache.DeleteAggregatedAttestation(att4)) returned := cache.AggregatedAttestations() - wanted := []interfaces.Attestation{att1, att2} + wanted := []ethpb.Att{att1, att2} sort.Slice(returned, func(i, j int) bool { return string(returned[i].GetAggregationBits()) < string(returned[j].GetAggregationBits()) }) @@ -281,7 +280,7 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { tests := []struct { name string - existing []interfaces.Attestation + existing []ethpb.Att input *ethpb.Attestation want bool err error @@ -320,7 +319,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "single attestation in cache with exact match", - existing: []interfaces.Attestation{ðpb.Attestation{ + existing: []ethpb.Att{ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), @@ -335,7 +334,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "single attestation in cache with subset aggregation", - existing: []interfaces.Attestation{ðpb.Attestation{ + existing: []ethpb.Att{ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), @@ -350,7 +349,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "single attestation in cache with superset aggregation", - existing: []interfaces.Attestation{ðpb.Attestation{ + existing: []ethpb.Att{ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), @@ -365,7 +364,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "multiple attestations with same data in cache with overlapping aggregation, input is subset", - existing: []interfaces.Attestation{ + existing: []ethpb.Att{ ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, @@ -388,7 +387,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "multiple attestations with same data in cache with overlapping aggregation and input is superset", - existing: []interfaces.Attestation{ + existing: []ethpb.Att{ ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, @@ -411,7 +410,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "multiple attestations with different data in cache", - existing: []interfaces.Attestation{ + existing: []ethpb.Att{ ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, @@ -434,7 +433,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "attestations with different bitlist lengths", - existing: []interfaces.Attestation{ + existing: []ethpb.Att{ ðpb.Attestation{ Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, diff --git a/beacon-chain/operations/attestations/kv/block.go b/beacon-chain/operations/attestations/kv/block.go index 797deb6913..49cc90b279 100644 --- a/beacon-chain/operations/attestations/kv/block.go +++ b/beacon-chain/operations/attestations/kv/block.go @@ -2,11 +2,11 @@ package kv import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) // SaveBlockAttestation saves an block attestation in cache. -func (c *AttCaches) SaveBlockAttestation(att interfaces.Attestation) error { +func (c *AttCaches) SaveBlockAttestation(att ethpb.Att) error { if att == nil { return nil } @@ -19,7 +19,7 @@ func (c *AttCaches) SaveBlockAttestation(att interfaces.Attestation) error { defer c.blockAttLock.Unlock() atts, ok := c.blockAtt[r] if !ok { - atts = make([]interfaces.Attestation, 0, 1) + atts = make([]ethpb.Att, 0, 1) } // Ensure that this attestation is not already fully contained in an existing attestation. @@ -31,14 +31,14 @@ func (c *AttCaches) SaveBlockAttestation(att interfaces.Attestation) error { } } - c.blockAtt[r] = append(atts, interfaces.CopyAttestation(att)) + c.blockAtt[r] = append(atts, att.Copy()) return nil } // BlockAttestations returns the block attestations in cache. -func (c *AttCaches) BlockAttestations() []interfaces.Attestation { - atts := make([]interfaces.Attestation, 0) +func (c *AttCaches) BlockAttestations() []ethpb.Att { + atts := make([]ethpb.Att, 0) c.blockAttLock.RLock() defer c.blockAttLock.RUnlock() @@ -50,7 +50,7 @@ func (c *AttCaches) BlockAttestations() []interfaces.Attestation { } // DeleteBlockAttestation deletes a block attestation in cache. -func (c *AttCaches) DeleteBlockAttestation(att interfaces.Attestation) error { +func (c *AttCaches) DeleteBlockAttestation(att ethpb.Att) error { if att == nil { return nil } diff --git a/beacon-chain/operations/attestations/kv/block_test.go b/beacon-chain/operations/attestations/kv/block_test.go index c1a26181e9..fcf17d350d 100644 --- a/beacon-chain/operations/attestations/kv/block_test.go +++ b/beacon-chain/operations/attestations/kv/block_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -18,7 +17,7 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveBlockAttestation(att)) @@ -44,7 +43,7 @@ func TestKV_BlockAttestation_CanDelete(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveBlockAttestation(att)) @@ -54,6 +53,6 @@ func TestKV_BlockAttestation_CanDelete(t *testing.T) { require.NoError(t, cache.DeleteBlockAttestation(att3)) returned := cache.BlockAttestations() - wanted := []interfaces.Attestation{att2} + wanted := []ethpb.Att{att2} assert.DeepEqual(t, wanted, returned) } diff --git a/beacon-chain/operations/attestations/kv/forkchoice.go b/beacon-chain/operations/attestations/kv/forkchoice.go index 202b6ef899..3e79e8d23e 100644 --- a/beacon-chain/operations/attestations/kv/forkchoice.go +++ b/beacon-chain/operations/attestations/kv/forkchoice.go @@ -2,11 +2,11 @@ package kv import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) // SaveForkchoiceAttestation saves an forkchoice attestation in cache. -func (c *AttCaches) SaveForkchoiceAttestation(att interfaces.Attestation) error { +func (c *AttCaches) SaveForkchoiceAttestation(att ethpb.Att) error { if att == nil { return nil } @@ -15,16 +15,15 @@ func (c *AttCaches) SaveForkchoiceAttestation(att interfaces.Attestation) error return errors.Wrap(err, "could not tree hash attestation") } - att = interfaces.CopyAttestation(att) c.forkchoiceAttLock.Lock() defer c.forkchoiceAttLock.Unlock() - c.forkchoiceAtt[r] = att + c.forkchoiceAtt[r] = att.Copy() return nil } // SaveForkchoiceAttestations saves a list of forkchoice attestations in cache. -func (c *AttCaches) SaveForkchoiceAttestations(atts []interfaces.Attestation) error { +func (c *AttCaches) SaveForkchoiceAttestations(atts []ethpb.Att) error { for _, att := range atts { if err := c.SaveForkchoiceAttestation(att); err != nil { return err @@ -35,20 +34,20 @@ func (c *AttCaches) SaveForkchoiceAttestations(atts []interfaces.Attestation) er } // ForkchoiceAttestations returns the forkchoice attestations in cache. -func (c *AttCaches) ForkchoiceAttestations() []interfaces.Attestation { +func (c *AttCaches) ForkchoiceAttestations() []ethpb.Att { c.forkchoiceAttLock.RLock() defer c.forkchoiceAttLock.RUnlock() - atts := make([]interfaces.Attestation, 0, len(c.forkchoiceAtt)) + atts := make([]ethpb.Att, 0, len(c.forkchoiceAtt)) for _, att := range c.forkchoiceAtt { - atts = append(atts, interfaces.CopyAttestation(att) /* Copied */) + atts = append(atts, att.Copy()) } return atts } // DeleteForkchoiceAttestation deletes a forkchoice attestation in cache. -func (c *AttCaches) DeleteForkchoiceAttestation(att interfaces.Attestation) error { +func (c *AttCaches) DeleteForkchoiceAttestation(att ethpb.Att) error { if att == nil { return nil } diff --git a/beacon-chain/operations/attestations/kv/forkchoice_test.go b/beacon-chain/operations/attestations/kv/forkchoice_test.go index 005c53f79b..7f6b4d4b2c 100644 --- a/beacon-chain/operations/attestations/kv/forkchoice_test.go +++ b/beacon-chain/operations/attestations/kv/forkchoice_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -18,7 +17,7 @@ func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveForkchoiceAttestation(att)) @@ -39,7 +38,7 @@ func TestKV_Forkchoice_CanDelete(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveForkchoiceAttestation(att)) @@ -49,7 +48,7 @@ func TestKV_Forkchoice_CanDelete(t *testing.T) { require.NoError(t, cache.DeleteForkchoiceAttestation(att3)) returned := cache.ForkchoiceAttestations() - wanted := []interfaces.Attestation{att2} + wanted := []ethpb.Att{att2} assert.DeepEqual(t, wanted, returned) } diff --git a/beacon-chain/operations/attestations/kv/kv.go b/beacon-chain/operations/attestations/kv/kv.go index f6bd3bcd70..d0d1dc9ef8 100644 --- a/beacon-chain/operations/attestations/kv/kv.go +++ b/beacon-chain/operations/attestations/kv/kv.go @@ -9,8 +9,8 @@ import ( "github.com/patrickmn/go-cache" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/hash" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) var hashFn = hash.Proto @@ -20,13 +20,13 @@ var hashFn = hash.Proto // such are unaggregated, aggregated or attestations within a block. type AttCaches struct { aggregatedAttLock sync.RWMutex - aggregatedAtt map[[32]byte][]interfaces.Attestation + aggregatedAtt map[[32]byte][]ethpb.Att unAggregateAttLock sync.RWMutex - unAggregatedAtt map[[32]byte]interfaces.Attestation + unAggregatedAtt map[[32]byte]ethpb.Att forkchoiceAttLock sync.RWMutex - forkchoiceAtt map[[32]byte]interfaces.Attestation + forkchoiceAtt map[[32]byte]ethpb.Att blockAttLock sync.RWMutex - blockAtt map[[32]byte][]interfaces.Attestation + blockAtt map[[32]byte][]ethpb.Att seenAtt *cache.Cache } @@ -36,10 +36,10 @@ func NewAttCaches() *AttCaches { secsInEpoch := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) c := cache.New(secsInEpoch*time.Second, 2*secsInEpoch*time.Second) pool := &AttCaches{ - unAggregatedAtt: make(map[[32]byte]interfaces.Attestation), - aggregatedAtt: make(map[[32]byte][]interfaces.Attestation), - forkchoiceAtt: make(map[[32]byte]interfaces.Attestation), - blockAtt: make(map[[32]byte][]interfaces.Attestation), + unAggregatedAtt: make(map[[32]byte]ethpb.Att), + aggregatedAtt: make(map[[32]byte][]ethpb.Att), + forkchoiceAtt: make(map[[32]byte]ethpb.Att), + blockAtt: make(map[[32]byte][]ethpb.Att), seenAtt: c, } diff --git a/beacon-chain/operations/attestations/kv/seen_bits.go b/beacon-chain/operations/attestations/kv/seen_bits.go index bca1678d7a..03c5659104 100644 --- a/beacon-chain/operations/attestations/kv/seen_bits.go +++ b/beacon-chain/operations/attestations/kv/seen_bits.go @@ -6,10 +6,10 @@ import ( "github.com/patrickmn/go-cache" "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) -func (c *AttCaches) insertSeenBit(att interfaces.Attestation) error { +func (c *AttCaches) insertSeenBit(att ethpb.Att) error { r, err := hashFn(att.GetData()) if err != nil { return err @@ -41,7 +41,7 @@ func (c *AttCaches) insertSeenBit(att interfaces.Attestation) error { return nil } -func (c *AttCaches) hasSeenBit(att interfaces.Attestation) (bool, error) { +func (c *AttCaches) hasSeenBit(att ethpb.Att) (bool, error) { r, err := hashFn(att.GetData()) if err != nil { return false, err diff --git a/beacon-chain/operations/attestations/kv/unaggregated.go b/beacon-chain/operations/attestations/kv/unaggregated.go index e16e36cbc7..63064773f1 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated.go +++ b/beacon-chain/operations/attestations/kv/unaggregated.go @@ -5,13 +5,13 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "go.opencensus.io/trace" ) // SaveUnaggregatedAttestation saves an unaggregated attestation in cache. -func (c *AttCaches) SaveUnaggregatedAttestation(att interfaces.Attestation) error { +func (c *AttCaches) SaveUnaggregatedAttestation(att ethpb.Att) error { if att == nil { return nil } @@ -31,16 +31,15 @@ func (c *AttCaches) SaveUnaggregatedAttestation(att interfaces.Attestation) erro if err != nil { return errors.Wrap(err, "could not tree hash attestation") } - att = interfaces.CopyAttestation(att) // Copied. c.unAggregateAttLock.Lock() defer c.unAggregateAttLock.Unlock() - c.unAggregatedAtt[r] = att + c.unAggregatedAtt[r] = att.Copy() return nil } // SaveUnaggregatedAttestations saves a list of unaggregated attestations in cache. -func (c *AttCaches) SaveUnaggregatedAttestations(atts []interfaces.Attestation) error { +func (c *AttCaches) SaveUnaggregatedAttestations(atts []ethpb.Att) error { for _, att := range atts { if err := c.SaveUnaggregatedAttestation(att); err != nil { return err @@ -51,18 +50,18 @@ func (c *AttCaches) SaveUnaggregatedAttestations(atts []interfaces.Attestation) } // UnaggregatedAttestations returns all the unaggregated attestations in cache. -func (c *AttCaches) UnaggregatedAttestations() ([]interfaces.Attestation, error) { +func (c *AttCaches) UnaggregatedAttestations() ([]ethpb.Att, error) { c.unAggregateAttLock.RLock() defer c.unAggregateAttLock.RUnlock() unAggregatedAtts := c.unAggregatedAtt - atts := make([]interfaces.Attestation, 0, len(unAggregatedAtts)) + atts := make([]ethpb.Att, 0, len(unAggregatedAtts)) for _, att := range unAggregatedAtts { seen, err := c.hasSeenBit(att) if err != nil { return nil, err } if !seen { - atts = append(atts, interfaces.CopyAttestation(att) /* Copied */) + atts = append(atts, att.Copy()) } } return atts, nil @@ -70,11 +69,11 @@ func (c *AttCaches) UnaggregatedAttestations() ([]interfaces.Attestation, error) // UnaggregatedAttestationsBySlotIndex returns the unaggregated attestations in cache, // filtered by committee index and slot. -func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation { +func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []ethpb.Att { _, span := trace.StartSpan(ctx, "operations.attestations.kv.UnaggregatedAttestationsBySlotIndex") defer span.End() - atts := make([]interfaces.Attestation, 0) + atts := make([]ethpb.Att, 0) c.unAggregateAttLock.RLock() defer c.unAggregateAttLock.RUnlock() @@ -90,7 +89,7 @@ func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slo } // DeleteUnaggregatedAttestation deletes the unaggregated attestations in cache. -func (c *AttCaches) DeleteUnaggregatedAttestation(att interfaces.Attestation) error { +func (c *AttCaches) DeleteUnaggregatedAttestation(att ethpb.Att) error { if att == nil { return nil } diff --git a/beacon-chain/operations/attestations/kv/unaggregated_test.go b/beacon-chain/operations/attestations/kv/unaggregated_test.go index 115199d1b1..9131f58507 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated_test.go +++ b/beacon-chain/operations/attestations/kv/unaggregated_test.go @@ -10,7 +10,6 @@ import ( fssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/go-bitfield" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -20,7 +19,7 @@ import ( func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { tests := []struct { name string - att interfaces.Attestation + att ethpb.Att count int wantErrString string }{ @@ -86,13 +85,13 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { tests := []struct { name string - atts []interfaces.Attestation + atts []ethpb.Att count int wantErrString string }{ { name: "unaggregated only", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), @@ -101,7 +100,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { }, { name: "has aggregated", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}, util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), @@ -146,14 +145,14 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) { att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}}) att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}}) att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}}) - atts := []interfaces.Attestation{att1, att2, att3} + atts := []ethpb.Att{att1, att2, att3} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) for _, att := range atts { assert.NoError(t, cache.DeleteUnaggregatedAttestation(att)) } returned, err := cache.UnaggregatedAttestations() require.NoError(t, err) - assert.DeepEqual(t, []interfaces.Attestation{}, returned) + assert.DeepEqual(t, []ethpb.Att{}, returned) }) } @@ -169,7 +168,7 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("none seen", func(t *testing.T) { cache := NewAttCaches() - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), @@ -186,7 +185,7 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("some seen", func(t *testing.T) { cache := NewAttCaches() - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), @@ -206,12 +205,12 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { return bytes.Compare(returned[i].GetAggregationBits(), returned[j].GetAggregationBits()) < 0 }) require.NoError(t, err) - assert.DeepEqual(t, []interfaces.Attestation{atts[0], atts[2]}, returned) + assert.DeepEqual(t, []ethpb.Att{atts[0], atts[2]}, returned) }) t.Run("all seen", func(t *testing.T) { cache := NewAttCaches() - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), util.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), @@ -230,7 +229,7 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { assert.Equal(t, 0, cache.UnaggregatedAttestationCount()) returned, err := cache.UnaggregatedAttestations() require.NoError(t, err) - assert.DeepEqual(t, []interfaces.Attestation{}, returned) + assert.DeepEqual(t, []ethpb.Att{}, returned) }) } @@ -247,9 +246,9 @@ func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) { } ctx := context.Background() returned := cache.UnaggregatedAttestationsBySlotIndex(ctx, 1, 1) - assert.DeepEqual(t, []interfaces.Attestation{att1}, returned) + assert.DeepEqual(t, []ethpb.Att{att1}, returned) returned = cache.UnaggregatedAttestationsBySlotIndex(ctx, 1, 2) - assert.DeepEqual(t, []interfaces.Attestation{att2}, returned) + assert.DeepEqual(t, []ethpb.Att{att2}, returned) returned = cache.UnaggregatedAttestationsBySlotIndex(ctx, 2, 1) - assert.DeepEqual(t, []interfaces.Attestation{att3}, returned) + assert.DeepEqual(t, []ethpb.Att{att3}, returned) } diff --git a/beacon-chain/operations/attestations/pool.go b/beacon-chain/operations/attestations/pool.go index d6d4570790..e3bcf8a585 100644 --- a/beacon-chain/operations/attestations/pool.go +++ b/beacon-chain/operations/attestations/pool.go @@ -4,8 +4,8 @@ import ( "context" "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations/kv" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) // Pool defines the necessary methods for Prysm attestations pool to serve @@ -15,30 +15,30 @@ import ( type Pool interface { // For Aggregated attestations AggregateUnaggregatedAttestations(ctx context.Context) error - SaveAggregatedAttestation(att interfaces.Attestation) error - SaveAggregatedAttestations(atts []interfaces.Attestation) error - AggregatedAttestations() []interfaces.Attestation - AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation - DeleteAggregatedAttestation(att interfaces.Attestation) error - HasAggregatedAttestation(att interfaces.Attestation) (bool, error) + SaveAggregatedAttestation(att ethpb.Att) error + SaveAggregatedAttestations(atts []ethpb.Att) error + AggregatedAttestations() []ethpb.Att + AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []ethpb.Att + DeleteAggregatedAttestation(att ethpb.Att) error + HasAggregatedAttestation(att ethpb.Att) (bool, error) AggregatedAttestationCount() int // For unaggregated attestations. - SaveUnaggregatedAttestation(att interfaces.Attestation) error - SaveUnaggregatedAttestations(atts []interfaces.Attestation) error - UnaggregatedAttestations() ([]interfaces.Attestation, error) - UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation - DeleteUnaggregatedAttestation(att interfaces.Attestation) error + SaveUnaggregatedAttestation(att ethpb.Att) error + SaveUnaggregatedAttestations(atts []ethpb.Att) error + UnaggregatedAttestations() ([]ethpb.Att, error) + UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []ethpb.Att + DeleteUnaggregatedAttestation(att ethpb.Att) error DeleteSeenUnaggregatedAttestations() (int, error) UnaggregatedAttestationCount() int // For attestations that were included in the block. - SaveBlockAttestation(att interfaces.Attestation) error - BlockAttestations() []interfaces.Attestation - DeleteBlockAttestation(att interfaces.Attestation) error + SaveBlockAttestation(att ethpb.Att) error + BlockAttestations() []ethpb.Att + DeleteBlockAttestation(att ethpb.Att) error // For attestations to be passed to fork choice. - SaveForkchoiceAttestation(att interfaces.Attestation) error - SaveForkchoiceAttestations(atts []interfaces.Attestation) error - ForkchoiceAttestations() []interfaces.Attestation - DeleteForkchoiceAttestation(att interfaces.Attestation) error + SaveForkchoiceAttestation(att ethpb.Att) error + SaveForkchoiceAttestations(atts []ethpb.Att) error + ForkchoiceAttestations() []ethpb.Att + DeleteForkchoiceAttestation(att ethpb.Att) error ForkchoiceAttestationCount() int } diff --git a/beacon-chain/operations/attestations/prepare_forkchoice.go b/beacon-chain/operations/attestations/prepare_forkchoice.go index bb0840d629..057c8ca9ae 100644 --- a/beacon-chain/operations/attestations/prepare_forkchoice.go +++ b/beacon-chain/operations/attestations/prepare_forkchoice.go @@ -9,8 +9,8 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/config/features" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/hash" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations" "github.com/prysmaticlabs/prysm/v5/time/slots" "go.opencensus.io/trace" @@ -67,7 +67,7 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error { atts := append(s.cfg.Pool.AggregatedAttestations(), s.cfg.Pool.BlockAttestations()...) atts = append(atts, s.cfg.Pool.ForkchoiceAttestations()...) - attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(atts)) + attsByDataRoot := make(map[[32]byte][]ethpb.Att, len(atts)) // Consolidate attestations by aggregating them by similar data root. for _, att := range atts { @@ -103,10 +103,10 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error { // This aggregates a list of attestations using the aggregation algorithm defined in AggregateAttestations // and saves the attestations for fork choice. -func (s *Service) aggregateAndSaveForkChoiceAtts(atts []interfaces.Attestation) error { - clonedAtts := make([]interfaces.Attestation, len(atts)) +func (s *Service) aggregateAndSaveForkChoiceAtts(atts []ethpb.Att) error { + clonedAtts := make([]ethpb.Att, len(atts)) for i, a := range atts { - clonedAtts[i] = interfaces.CopyAttestation(a) + clonedAtts[i] = a.Copy() } aggregatedAtts, err := attaggregation.Aggregate(clonedAtts) if err != nil { @@ -118,7 +118,7 @@ func (s *Service) aggregateAndSaveForkChoiceAtts(atts []interfaces.Attestation) // This checks if the attestation has previously been aggregated for fork choice // return true if yes, false if no. -func (s *Service) seen(att interfaces.Attestation) (bool, error) { +func (s *Service) seen(att ethpb.Att) (bool, error) { attRoot, err := hash.Proto(att.GetData()) if err != nil { return false, err diff --git a/beacon-chain/operations/attestations/prepare_forkchoice_test.go b/beacon-chain/operations/attestations/prepare_forkchoice_test.go index 11578b7729..f5958aa8bc 100644 --- a/beacon-chain/operations/attestations/prepare_forkchoice_test.go +++ b/beacon-chain/operations/attestations/prepare_forkchoice_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations" @@ -26,7 +25,7 @@ func TestBatchAttestations_Multiple(t *testing.T) { sig := priv.Sign([]byte("dummy_test_data")) var mockRoot [32]byte - unaggregatedAtts := []interfaces.Attestation{ + unaggregatedAtts := []ethpb.Att{ ðpb.Attestation{Data: ðpb.AttestationData{ Slot: 2, BeaconBlockRoot: mockRoot[:], @@ -43,7 +42,7 @@ func TestBatchAttestations_Multiple(t *testing.T) { Source: ðpb.Checkpoint{Root: mockRoot[:]}, Target: ðpb.Checkpoint{Root: mockRoot[:]}}, AggregationBits: bitfield.Bitlist{0b100010}, Signature: sig.Marshal()}, } - aggregatedAtts := []interfaces.Attestation{ + aggregatedAtts := []ethpb.Att{ ðpb.Attestation{Data: ðpb.AttestationData{ Slot: 2, BeaconBlockRoot: mockRoot[:], @@ -94,12 +93,12 @@ func TestBatchAttestations_Multiple(t *testing.T) { } require.NoError(t, s.batchForkChoiceAtts(context.Background())) - wanted, err := attaggregation.Aggregate([]interfaces.Attestation{aggregatedAtts[0], blockAtts[0]}) + wanted, err := attaggregation.Aggregate([]ethpb.Att{aggregatedAtts[0], blockAtts[0]}) require.NoError(t, err) - aggregated, err := attaggregation.Aggregate([]interfaces.Attestation{aggregatedAtts[1], blockAtts[1]}) + aggregated, err := attaggregation.Aggregate([]ethpb.Att{aggregatedAtts[1], blockAtts[1]}) require.NoError(t, err) wanted = append(wanted, aggregated...) - aggregated, err = attaggregation.Aggregate([]interfaces.Attestation{aggregatedAtts[2], blockAtts[2]}) + aggregated, err = attaggregation.Aggregate([]ethpb.Att{aggregatedAtts[2], blockAtts[2]}) require.NoError(t, err) wanted = append(wanted, aggregated...) @@ -130,15 +129,15 @@ func TestBatchAttestations_Single(t *testing.T) { Target: ðpb.Checkpoint{Root: mockRoot[:]}, } - unaggregatedAtts := []interfaces.Attestation{ + unaggregatedAtts := []ethpb.Att{ ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b101000}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b100100}, Signature: sig.Marshal()}, } - aggregatedAtts := []interfaces.Attestation{ + aggregatedAtts := []ethpb.Att{ ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b101100}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b110010}, Signature: sig.Marshal()}, } - blockAtts := []interfaces.Attestation{ + blockAtts := []ethpb.Att{ ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b110010}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b100010}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b110010}, Signature: sig.Marshal()}, // Duplicated @@ -175,7 +174,7 @@ func TestAggregateAndSaveForkChoiceAtts_Single(t *testing.T) { Target: ðpb.Checkpoint{Root: mockRoot[:]}, } - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b101}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b110}, Signature: sig.Marshal()}} require.NoError(t, s.aggregateAndSaveForkChoiceAtts(atts)) @@ -205,18 +204,18 @@ func TestAggregateAndSaveForkChoiceAtts_Multiple(t *testing.T) { require.Equal(t, true, ok, "Entity is not of type *ethpb.AttestationData") d2.Slot = 2 - atts1 := []interfaces.Attestation{ + atts1 := []ethpb.Att{ ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b101}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b110}, Signature: sig.Marshal()}, } require.NoError(t, s.aggregateAndSaveForkChoiceAtts(atts1)) - atts2 := []interfaces.Attestation{ + atts2 := []ethpb.Att{ ðpb.Attestation{Data: d1, AggregationBits: bitfield.Bitlist{0b10110}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d1, AggregationBits: bitfield.Bitlist{0b11100}, Signature: sig.Marshal()}, ðpb.Attestation{Data: d1, AggregationBits: bitfield.Bitlist{0b11000}, Signature: sig.Marshal()}, } require.NoError(t, s.aggregateAndSaveForkChoiceAtts(atts2)) - att3 := []interfaces.Attestation{ + att3 := []ethpb.Att{ ðpb.Attestation{Data: d2, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig.Marshal()}, } require.NoError(t, s.aggregateAndSaveForkChoiceAtts(att3)) diff --git a/beacon-chain/operations/attestations/prune_expired_test.go b/beacon-chain/operations/attestations/prune_expired_test.go index 99397b3c13..0755eadf3a 100644 --- a/beacon-chain/operations/attestations/prune_expired_test.go +++ b/beacon-chain/operations/attestations/prune_expired_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/async" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -32,13 +31,13 @@ func TestPruneExpired_Ticker(t *testing.T) { ad2 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, fieldparams.BLSSignatureLength)}, ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, fieldparams.BLSSignatureLength)}, } require.NoError(t, s.cfg.Pool.SaveUnaggregatedAttestations(atts)) require.Equal(t, 2, s.cfg.Pool.UnaggregatedAttestationCount(), "Unexpected number of attestations") - atts = []interfaces.Attestation{ + atts = []ethpb.Att{ ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, fieldparams.BLSSignatureLength)}, ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1101, 0b1}, Signature: make([]byte, fieldparams.BLSSignatureLength)}, } @@ -97,7 +96,7 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) { att2 := ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1111}} att3 := ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1101}} att4 := ðpb.Attestation{Data: ad2, AggregationBits: bitfield.Bitlist{0b1110}} - atts := []interfaces.Attestation{att1, att2, att3, att4} + atts := []ethpb.Att{att1, att2, att3, att4} require.NoError(t, s.cfg.Pool.SaveAggregatedAttestations(atts)) for _, att := range atts { require.NoError(t, s.cfg.Pool.SaveBlockAttestation(att)) diff --git a/beacon-chain/operations/slashings/BUILD.bazel b/beacon-chain/operations/slashings/BUILD.bazel index 3d158ccce8..e8d40e8473 100644 --- a/beacon-chain/operations/slashings/BUILD.bazel +++ b/beacon-chain/operations/slashings/BUILD.bazel @@ -21,7 +21,6 @@ go_library( "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//container/slice:go_default_library", "//proto/prysm/v1alpha1:go_default_library", @@ -48,7 +47,6 @@ go_test( "//beacon-chain/state:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/operations/slashings/mock/BUILD.bazel b/beacon-chain/operations/slashings/mock/BUILD.bazel index d501e4c7ac..27ad017335 100644 --- a/beacon-chain/operations/slashings/mock/BUILD.bazel +++ b/beacon-chain/operations/slashings/mock/BUILD.bazel @@ -8,7 +8,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/state:go_default_library", - "//consensus-types/interfaces:go_default_library", "//proto/prysm/v1alpha1:go_default_library", ], ) diff --git a/beacon-chain/operations/slashings/mock/mock.go b/beacon-chain/operations/slashings/mock/mock.go index 1498b979b8..b30747a0a4 100644 --- a/beacon-chain/operations/slashings/mock/mock.go +++ b/beacon-chain/operations/slashings/mock/mock.go @@ -4,18 +4,17 @@ import ( "context" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) // PoolMock is a fake implementation of PoolManager. type PoolMock struct { - PendingAttSlashings []interfaces.AttesterSlashing + PendingAttSlashings []ethpb.AttSlashing PendingPropSlashings []*ethpb.ProposerSlashing } // PendingAttesterSlashings -- -func (m *PoolMock) PendingAttesterSlashings(_ context.Context, _ state.ReadOnlyBeaconState, _ bool) []interfaces.AttesterSlashing { +func (m *PoolMock) PendingAttesterSlashings(_ context.Context, _ state.ReadOnlyBeaconState, _ bool) []ethpb.AttSlashing { return m.PendingAttSlashings } @@ -25,7 +24,7 @@ func (m *PoolMock) PendingProposerSlashings(_ context.Context, _ state.ReadOnlyB } // InsertAttesterSlashing -- -func (m *PoolMock) InsertAttesterSlashing(_ context.Context, _ state.ReadOnlyBeaconState, slashing interfaces.AttesterSlashing) error { +func (m *PoolMock) InsertAttesterSlashing(_ context.Context, _ state.ReadOnlyBeaconState, slashing ethpb.AttSlashing) error { m.PendingAttSlashings = append(m.PendingAttSlashings, slashing) return nil } @@ -37,7 +36,7 @@ func (m *PoolMock) InsertProposerSlashing(_ context.Context, _ state.ReadOnlyBea } // MarkIncludedAttesterSlashing -- -func (*PoolMock) MarkIncludedAttesterSlashing(_ interfaces.AttesterSlashing) { +func (*PoolMock) MarkIncludedAttesterSlashing(_ ethpb.AttSlashing) { panic("implement me") } diff --git a/beacon-chain/operations/slashings/service.go b/beacon-chain/operations/slashings/service.go index 2439d9004f..ef7370975e 100644 --- a/beacon-chain/operations/slashings/service.go +++ b/beacon-chain/operations/slashings/service.go @@ -11,7 +11,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -31,7 +30,7 @@ func NewPool() *Pool { // PendingAttesterSlashings returns attester slashings that are able to be included into a block. // This method will return the amount of pending attester slashings for a block transition unless parameter `noLimit` is true // to indicate the request is for noLimit pending items. -func (p *Pool) PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []interfaces.AttesterSlashing { +func (p *Pool) PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []ethpb.AttSlashing { p.lock.Lock() defer p.lock.Unlock() _, span := trace.StartSpan(ctx, "operations.PendingAttesterSlashing") @@ -47,7 +46,7 @@ func (p *Pool) PendingAttesterSlashings(ctx context.Context, state state.ReadOnl if noLimit { maxSlashings = uint64(len(p.pendingAttesterSlashing)) } - pending := make([]interfaces.AttesterSlashing, 0, maxSlashings) + pending := make([]ethpb.AttSlashing, 0, maxSlashings) for i := 0; i < len(p.pendingAttesterSlashing); i++ { if uint64(len(pending)) >= maxSlashings { break @@ -65,8 +64,8 @@ func (p *Pool) PendingAttesterSlashings(ctx context.Context, state state.ReadOnl } attSlashing := slashing.attesterSlashing slashedVal := slice.IntersectionUint64( - attSlashing.GetFirstAttestation().GetAttestingIndices(), - attSlashing.GetSecondAttestation().GetAttestingIndices(), + attSlashing.FirstAttestation().GetAttestingIndices(), + attSlashing.SecondAttestation().GetAttestingIndices(), ) for _, idx := range slashedVal { included[primitives.ValidatorIndex(idx)] = true @@ -122,7 +121,7 @@ func (p *Pool) PendingProposerSlashings(ctx context.Context, state state.ReadOnl func (p *Pool) InsertAttesterSlashing( ctx context.Context, state state.ReadOnlyBeaconState, - slashing interfaces.AttesterSlashing, + slashing ethpb.AttSlashing, ) error { p.lock.Lock() defer p.lock.Unlock() @@ -133,7 +132,7 @@ func (p *Pool) InsertAttesterSlashing( return errors.Wrap(err, "could not verify attester slashing") } - slashedVal := slice.IntersectionUint64(slashing.GetFirstAttestation().GetAttestingIndices(), slashing.GetSecondAttestation().GetAttestingIndices()) + slashedVal := slice.IntersectionUint64(slashing.FirstAttestation().GetAttestingIndices(), slashing.SecondAttestation().GetAttestingIndices()) cantSlash := make([]uint64, 0, len(slashedVal)) slashingReason := "" for _, val := range slashedVal { @@ -233,10 +232,10 @@ func (p *Pool) InsertProposerSlashing( // MarkIncludedAttesterSlashing is used when an attester slashing has been included in a beacon block. // Every block seen by this node that contains proposer slashings should call this method to include // the proposer slashings. -func (p *Pool) MarkIncludedAttesterSlashing(as interfaces.AttesterSlashing) { +func (p *Pool) MarkIncludedAttesterSlashing(as ethpb.AttSlashing) { p.lock.Lock() defer p.lock.Unlock() - slashedVal := slice.IntersectionUint64(as.GetFirstAttestation().GetAttestingIndices(), as.GetSecondAttestation().GetAttestingIndices()) + slashedVal := slice.IntersectionUint64(as.FirstAttestation().GetAttestingIndices(), as.SecondAttestation().GetAttestingIndices()) for _, val := range slashedVal { i := sort.Search(len(p.pendingAttesterSlashing), func(i int) bool { return uint64(p.pendingAttesterSlashing[i].validatorToSlash) >= val diff --git a/beacon-chain/operations/slashings/service_attester_test.go b/beacon-chain/operations/slashings/service_attester_test.go index a032d52d27..50f4ab63d6 100644 --- a/beacon-chain/operations/slashings/service_attester_test.go +++ b/beacon-chain/operations/slashings/service_attester_test.go @@ -6,7 +6,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -456,7 +455,7 @@ func TestPool_PendingAttesterSlashings(t *testing.T) { params.SetupTestConfigCleanup(t) beaconState, privKeys := util.DeterministicGenesisState(t, 64) pendingSlashings := make([]*PendingAttesterSlashing, 20) - slashings := make([]interfaces.AttesterSlashing, 20) + slashings := make([]ethpb.AttSlashing, 20) for i := 0; i < len(pendingSlashings); i++ { sl, err := util.GenerateAttesterSlashingForValidator(beaconState, privKeys[i], primitives.ValidatorIndex(i)) require.NoError(t, err) @@ -469,14 +468,14 @@ func TestPool_PendingAttesterSlashings(t *testing.T) { tests := []struct { name string fields fields - want []interfaces.AttesterSlashing + want []ethpb.AttSlashing }{ { name: "Empty list", fields: fields{ pending: []*PendingAttesterSlashing{}, }, - want: []interfaces.AttesterSlashing{}, + want: []ethpb.AttSlashing{}, }, { name: "All pending", @@ -531,7 +530,7 @@ func TestPool_PendingAttesterSlashings_Slashed(t *testing.T) { require.NoError(t, beaconState.UpdateValidatorAtIndex(5, val)) pendingSlashings := make([]*PendingAttesterSlashing, 20) pendingSlashings2 := make([]*PendingAttesterSlashing, 20) - slashings := make([]interfaces.AttesterSlashing, 20) + slashings := make([]ethpb.AttSlashing, 20) for i := 0; i < len(pendingSlashings); i++ { sl, err := util.GenerateAttesterSlashingForValidator(beaconState, privKeys[i], primitives.ValidatorIndex(i)) require.NoError(t, err) @@ -549,7 +548,7 @@ func TestPool_PendingAttesterSlashings_Slashed(t *testing.T) { tests := []struct { name string fields fields - want []interfaces.AttesterSlashing + want []ethpb.AttSlashing }{ { name: "One item", @@ -589,7 +588,7 @@ func TestPool_PendingAttesterSlashings_NoDuplicates(t *testing.T) { params.OverrideBeaconConfig(conf) beaconState, privKeys := util.DeterministicGenesisState(t, 64) pendingSlashings := make([]*PendingAttesterSlashing, 3) - slashings := make([]interfaces.AttesterSlashing, 3) + slashings := make([]ethpb.AttSlashing, 3) for i := 0; i < 2; i++ { sl, err := util.GenerateAttesterSlashingForValidator(beaconState, privKeys[i], primitives.ValidatorIndex(i)) require.NoError(t, err) diff --git a/beacon-chain/operations/slashings/types.go b/beacon-chain/operations/slashings/types.go index 6bc6785f97..36e4bc17c6 100644 --- a/beacon-chain/operations/slashings/types.go +++ b/beacon-chain/operations/slashings/types.go @@ -5,7 +5,6 @@ import ( "sync" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) @@ -15,7 +14,7 @@ type PoolInserter interface { InsertAttesterSlashing( ctx context.Context, state state.ReadOnlyBeaconState, - slashing interfaces.AttesterSlashing, + slashing ethpb.AttSlashing, ) error InsertProposerSlashing( ctx context.Context, @@ -28,9 +27,9 @@ type PoolInserter interface { // This pool is used by proposers to insert data into new blocks. type PoolManager interface { PoolInserter - PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []interfaces.AttesterSlashing + PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []ethpb.AttSlashing PendingProposerSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []*ethpb.ProposerSlashing - MarkIncludedAttesterSlashing(as interfaces.AttesterSlashing) + MarkIncludedAttesterSlashing(as ethpb.AttSlashing) MarkIncludedProposerSlashing(ps *ethpb.ProposerSlashing) } @@ -45,6 +44,6 @@ type Pool struct { // PendingAttesterSlashing represents an attester slashing in the operation pool. // Allows for easy binary searching of included validator indexes. type PendingAttesterSlashing struct { - attesterSlashing interfaces.AttesterSlashing + attesterSlashing ethpb.AttSlashing validatorToSlash primitives.ValidatorIndex } diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 0ef51faed3..ddbbf7b5b1 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -57,7 +57,6 @@ go_library( "//cmd/beacon-chain/flags:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/wrapper:go_default_library", "//container/leaky-bucket:go_default_library", diff --git a/beacon-chain/p2p/broadcaster.go b/beacon-chain/p2p/broadcaster.go index 43a0270ee2..6d8d632575 100644 --- a/beacon-chain/p2p/broadcaster.go +++ b/beacon-chain/p2p/broadcaster.go @@ -12,7 +12,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/hash" "github.com/prysmaticlabs/prysm/v5/monitoring/tracing" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -57,7 +56,7 @@ func (s *Service) Broadcast(ctx context.Context, msg proto.Message) error { // BroadcastAttestation broadcasts an attestation to the p2p network, the message is assumed to be // broadcasted to the current fork. -func (s *Service) BroadcastAttestation(ctx context.Context, subnet uint64, att interfaces.Attestation) error { +func (s *Service) BroadcastAttestation(ctx context.Context, subnet uint64, att ethpb.Att) error { if att == nil { return errors.New("attempted to broadcast nil attestation") } @@ -97,7 +96,7 @@ func (s *Service) BroadcastSyncCommitteeMessage(ctx context.Context, subnet uint return nil } -func (s *Service) internalBroadcastAttestation(ctx context.Context, subnet uint64, att interfaces.Attestation, forkDigest [4]byte) { +func (s *Service) internalBroadcastAttestation(ctx context.Context, subnet uint64, att ethpb.Att, forkDigest [4]byte) { _, span := trace.StartSpan(ctx, "p2p.internalBroadcastAttestation") defer span.End() ctx = trace.NewContext(context.Background(), span) // clear parent context / deadline. diff --git a/beacon-chain/p2p/interfaces.go b/beacon-chain/p2p/interfaces.go index 112eadcb2b..a41d1768ab 100644 --- a/beacon-chain/p2p/interfaces.go +++ b/beacon-chain/p2p/interfaces.go @@ -12,7 +12,6 @@ import ( "github.com/multiformats/go-multiaddr" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata" "google.golang.org/protobuf/proto" @@ -34,7 +33,7 @@ type P2P interface { // Broadcaster broadcasts messages to peers over the p2p pubsub protocol. type Broadcaster interface { Broadcast(context.Context, proto.Message) error - BroadcastAttestation(ctx context.Context, subnet uint64, att interfaces.Attestation) error + BroadcastAttestation(ctx context.Context, subnet uint64, att ethpb.Att) error BroadcastSyncCommitteeMessage(ctx context.Context, subnet uint64, sMsg *ethpb.SyncCommitteeMessage) error BroadcastBlob(ctx context.Context, subnet uint64, blob *ethpb.BlobSidecar) error } diff --git a/beacon-chain/p2p/testing/BUILD.bazel b/beacon-chain/p2p/testing/BUILD.bazel index c4dea6b2b4..e6c2e8fe90 100644 --- a/beacon-chain/p2p/testing/BUILD.bazel +++ b/beacon-chain/p2p/testing/BUILD.bazel @@ -20,7 +20,6 @@ go_library( "//beacon-chain/p2p/encoder:go_default_library", "//beacon-chain/p2p/peers:go_default_library", "//beacon-chain/p2p/peers/scorers:go_default_library", - "//consensus-types/interfaces:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/metadata:go_default_library", "@com_github_ethereum_go_ethereum//crypto:go_default_library", diff --git a/beacon-chain/p2p/testing/fuzz_p2p.go b/beacon-chain/p2p/testing/fuzz_p2p.go index ce70a1c62e..13ba2c1a23 100644 --- a/beacon-chain/p2p/testing/fuzz_p2p.go +++ b/beacon-chain/p2p/testing/fuzz_p2p.go @@ -12,7 +12,6 @@ import ( "github.com/multiformats/go-multiaddr" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata" "google.golang.org/protobuf/proto" @@ -135,7 +134,7 @@ func (_ *FakeP2P) Broadcast(_ context.Context, _ proto.Message) error { } // BroadcastAttestation -- fake. -func (_ *FakeP2P) BroadcastAttestation(_ context.Context, _ uint64, _ interfaces.Attestation) error { +func (_ *FakeP2P) BroadcastAttestation(_ context.Context, _ uint64, _ ethpb.Att) error { return nil } diff --git a/beacon-chain/p2p/testing/mock_broadcaster.go b/beacon-chain/p2p/testing/mock_broadcaster.go index 336fda939b..6a740b3b85 100644 --- a/beacon-chain/p2p/testing/mock_broadcaster.go +++ b/beacon-chain/p2p/testing/mock_broadcaster.go @@ -5,7 +5,6 @@ import ( "sync" "sync/atomic" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "google.golang.org/protobuf/proto" ) @@ -14,7 +13,7 @@ import ( type MockBroadcaster struct { BroadcastCalled atomic.Bool BroadcastMessages []proto.Message - BroadcastAttestations []interfaces.Attestation + BroadcastAttestations []ethpb.Att msgLock sync.Mutex attLock sync.Mutex } @@ -29,7 +28,7 @@ func (m *MockBroadcaster) Broadcast(_ context.Context, msg proto.Message) error } // BroadcastAttestation records a broadcast occurred. -func (m *MockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, a interfaces.Attestation) error { +func (m *MockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, a ethpb.Att) error { m.BroadcastCalled.Store(true) m.attLock.Lock() defer m.attLock.Unlock() diff --git a/beacon-chain/p2p/testing/p2p.go b/beacon-chain/p2p/testing/p2p.go index 5c471ac3dd..19a6c2c9aa 100644 --- a/beacon-chain/p2p/testing/p2p.go +++ b/beacon-chain/p2p/testing/p2p.go @@ -25,7 +25,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers/scorers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata" "github.com/sirupsen/logrus" @@ -167,7 +166,7 @@ func (p *TestP2P) Broadcast(_ context.Context, _ proto.Message) error { } // BroadcastAttestation broadcasts an attestation. -func (p *TestP2P) BroadcastAttestation(_ context.Context, _ uint64, _ interfaces.Attestation) error { +func (p *TestP2P) BroadcastAttestation(_ context.Context, _ uint64, _ ethpb.Att) error { p.BroadcastCalled.Store(true) return nil } diff --git a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go index 5386320c25..d2ccfbfde2 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go +++ b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go @@ -29,7 +29,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core" state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/crypto/bls/common" @@ -116,8 +115,8 @@ func TestListAttestations(t *testing.T) { s := &Server{ AttestationsPool: attestations.NewPool(), } - require.NoError(t, s.AttestationsPool.SaveAggregatedAttestations([]interfaces.Attestation{att1, att2})) - require.NoError(t, s.AttestationsPool.SaveUnaggregatedAttestations([]interfaces.Attestation{att3, att4})) + require.NoError(t, s.AttestationsPool.SaveAggregatedAttestations([]ethpbv1alpha1.Att{att1, att2})) + require.NoError(t, s.AttestationsPool.SaveUnaggregatedAttestations([]ethpbv1alpha1.Att{att3, att4})) t.Run("empty request", func(t *testing.T) { url := "http://example.com" @@ -1061,7 +1060,7 @@ func TestGetAttesterSlashings(t *testing.T) { s := &Server{ ChainInfoFetcher: &blockchainmock.ChainService{State: bs}, - SlashingsPool: &slashingsmock.PoolMock{PendingAttSlashings: []interfaces.AttesterSlashing{slashing1, slashing2}}, + SlashingsPool: &slashingsmock.PoolMock{PendingAttSlashings: []ethpbv1alpha1.AttSlashing{slashing1, slashing2}}, } request := httptest.NewRequest(http.MethodGet, "http://example.com/beacon/pool/attester_slashings", nil) diff --git a/beacon-chain/rpc/eth/rewards/handlers_test.go b/beacon-chain/rpc/eth/rewards/handlers_test.go index 1acfa44b50..d950203485 100644 --- a/beacon-chain/rpc/eth/rewards/handlers_test.go +++ b/beacon-chain/rpc/eth/rewards/handlers_test.go @@ -104,7 +104,7 @@ func BlockRewardTestSetup(t *testing.T, forkName string) (state.BeaconState, int sbb.SetSlot(2) // we have to set the proposer index to the value that will be randomly chosen (fortunately it's deterministic) sbb.SetProposerIndex(12) - require.NoError(t, sbb.SetAttestations([]interfaces.Attestation{ + require.NoError(t, sbb.SetAttestations([]eth.Att{ ð.Attestation{ AggregationBits: bitfield.Bitlist{0b00000111}, Data: util.HydrateAttestationData(ð.AttestationData{}), @@ -125,7 +125,7 @@ func BlockRewardTestSetup(t *testing.T, forkName string) (state.BeaconState, int require.NoError(t, err) sigRoot2, err := signing.ComputeSigningRoot(attData2, domain) require.NoError(t, err) - require.NoError(t, sbb.SetAttesterSlashings([]interfaces.AttesterSlashing{ + require.NoError(t, sbb.SetAttesterSlashings([]eth.AttSlashing{ ð.AttesterSlashing{ Attestation_1: ð.IndexedAttestation{ AttestingIndices: []uint64{0}, diff --git a/beacon-chain/rpc/eth/validator/BUILD.bazel b/beacon-chain/rpc/eth/validator/BUILD.bazel index 4533938fe2..5ab2597a0c 100644 --- a/beacon-chain/rpc/eth/validator/BUILD.bazel +++ b/beacon-chain/rpc/eth/validator/BUILD.bazel @@ -33,7 +33,6 @@ go_library( "//config/params:go_default_library", "//consensus-types:go_default_library", "//consensus-types/blocks:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/validator:go_default_library", "//encoding/bytesutil:go_default_library", @@ -80,7 +79,6 @@ go_test( "//beacon-chain/sync/initial-sync/testing:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index 6bd914c365..8359ac5656 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -25,7 +25,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" validator2 "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -53,7 +52,7 @@ func (s *Server) GetAggregateAttestation(w http.ResponseWriter, r *http.Request) return } - var match interfaces.Attestation + var match ethpbalpha.Att var err error match, err = matchingAtt(s.AttestationsPool.AggregatedAttestations(), primitives.Slot(slot), attDataRoot) @@ -99,7 +98,7 @@ func (s *Server) GetAggregateAttestation(w http.ResponseWriter, r *http.Request) httputil.WriteJson(w, response) } -func matchingAtt(atts []interfaces.Attestation, slot primitives.Slot, attDataRoot []byte) (interfaces.Attestation, error) { +func matchingAtt(atts []ethpbalpha.Att, slot primitives.Slot, attDataRoot []byte) (ethpbalpha.Att, error) { for _, att := range atts { if att.GetData().Slot == slot { root, err := att.GetData().HashTreeRoot() diff --git a/beacon-chain/rpc/eth/validator/handlers_test.go b/beacon-chain/rpc/eth/validator/handlers_test.go index 6ef0a4ce3d..166d2f4042 100644 --- a/beacon-chain/rpc/eth/validator/handlers_test.go +++ b/beacon-chain/rpc/eth/validator/handlers_test.go @@ -33,7 +33,6 @@ import ( mockSync "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/initial-sync/testing" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -144,9 +143,9 @@ func TestGetAggregateAttestation(t *testing.T) { } pool := attestations.NewPool() - err := pool.SaveAggregatedAttestations([]interfaces.Attestation{attSlot1, attslot21, attslot22}) + err := pool.SaveAggregatedAttestations([]ethpbalpha.Att{attSlot1, attslot21, attslot22}) assert.NoError(t, err) - err = pool.SaveUnaggregatedAttestations([]interfaces.Attestation{attslot31, attslot32}) + err = pool.SaveUnaggregatedAttestations([]ethpbalpha.Att{attslot31, attslot32}) assert.NoError(t, err) s := &Server{ @@ -315,7 +314,7 @@ func TestGetAggregateAttestation_SameSlotAndRoot_ReturnMostAggregationBits(t *te Signature: sig, } pool := attestations.NewPool() - err := pool.SaveAggregatedAttestations([]interfaces.Attestation{att1, att2}) + err := pool.SaveAggregatedAttestations([]ethpbalpha.Att{att1, att2}) assert.NoError(t, err) s := &Server{ AttestationsPool: pool, diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go index fc8dc7b2c4..556cb57cd2 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go @@ -21,7 +21,7 @@ import ( // sortableAttestations implements the Sort interface to sort attestations // by slot as the canonical sorting attribute. -type sortableAttestations []interfaces.Attestation +type sortableAttestations []ethpb.Att // Len is the number of elements in the collection. func (s sortableAttestations) Len() int { return len(s) } @@ -34,8 +34,8 @@ func (s sortableAttestations) Less(i, j int) bool { return s[i].GetData().Slot < s[j].GetData().Slot } -func mapAttestationsByTargetRoot(atts []interfaces.Attestation) map[[32]byte][]interfaces.Attestation { - attsMap := make(map[[32]byte][]interfaces.Attestation, len(atts)) +func mapAttestationsByTargetRoot(atts []ethpb.Att) map[[32]byte][]ethpb.Att { + attsMap := make(map[[32]byte][]ethpb.Att, len(atts)) if len(atts) == 0 { return attsMap } @@ -74,7 +74,7 @@ func (bs *Server) ListAttestations( default: return nil, status.Error(codes.InvalidArgument, "Must specify a filter criteria for fetching attestations") } - atts := make([]interfaces.Attestation, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) + atts := make([]ethpb.Att, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) for _, blk := range blocks { atts = append(atts, blk.Block().Body().Attestations()...) } @@ -136,7 +136,7 @@ func (bs *Server) ListIndexedAttestations( return nil, status.Error(codes.InvalidArgument, "Must specify a filter criteria for fetching attestations") } - attsArray := make([]interfaces.Attestation, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) + attsArray := make([]ethpb.Att, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) for _, b := range blocks { attsArray = append(attsArray, b.Block().Body().Attestations()...) } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index bcc63c7c47..ae0a8685a1 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -263,7 +263,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) { ctx := context.Background() count := params.BeaconConfig().SlotsPerEpoch * 4 - atts := make([]interfaces.Attestation, 0, count) + atts := make([]ethpb.Att, 0, count) for i := primitives.Slot(0); i < params.BeaconConfig().SlotsPerEpoch; i++ { for s := primitives.CommitteeIndex(0); s < 4; s++ { blockExample := util.NewBeaconBlock() @@ -278,7 +278,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) { }), } util.SaveBlock(t, ctx, db, blockExample) - as := make([]interfaces.Attestation, len(blockExample.Block.Body.Attestations)) + as := make([]ethpb.Att, len(blockExample.Block.Body.Attestations)) for i, a := range blockExample.Block.Body.Attestations { as[i] = a } @@ -464,7 +464,7 @@ func TestServer_ListAttestations_Pagination_DefaultPageSize(t *testing.T) { func TestServer_mapAttestationToTargetRoot(t *testing.T) { count := primitives.Slot(100) - atts := make([]interfaces.Attestation, count) + atts := make([]ethpb.Att, count) targetRoot1 := bytesutil.ToBytes32([]byte("root1")) targetRoot2 := bytesutil.ToBytes32([]byte("root2")) @@ -707,7 +707,7 @@ func TestServer_AttestationPool_Pagination_OutOfRange(t *testing.T) { AttestationsPool: attestations.NewPool(), } - atts := []interfaces.Attestation{ + atts := []ethpb.Att{ ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, @@ -756,7 +756,7 @@ func TestServer_AttestationPool_Pagination_DefaultPageSize(t *testing.T) { AttestationsPool: attestations.NewPool(), } - atts := make([]interfaces.Attestation, params.BeaconConfig().DefaultPageSize+1) + atts := make([]ethpb.Att, params.BeaconConfig().DefaultPageSize+1) for i := 0; i < len(atts); i++ { att := util.NewAttestation() att.Data.Slot = primitives.Slot(i) @@ -778,7 +778,7 @@ func TestServer_AttestationPool_Pagination_CustomPageSize(t *testing.T) { } numAtts := 100 - atts := make([]interfaces.Attestation, numAtts) + atts := make([]ethpb.Att, numAtts) for i := 0; i < len(atts); i++ { att := util.NewAttestation() att.Data.Slot = primitives.Slot(i) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go index b1cc8100ed..59f2ad7bd7 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go @@ -18,7 +18,6 @@ import ( mockSync "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/initial-sync/testing" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -337,7 +336,7 @@ func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) { pubKey := v.PublicKey req := ðpb.AggregateSelectionRequest{CommitteeIndex: 1, SlotSignature: sig.Marshal(), PublicKey: pubKey} - err = aggregatorServer.AttPool.SaveAggregatedAttestations([]interfaces.Attestation{ + err = aggregatorServer.AttPool.SaveAggregatedAttestations([]ethpb.Att{ att0, att1, att2, @@ -388,7 +387,7 @@ func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t * pubKey := v.PublicKey req := ðpb.AggregateSelectionRequest{CommitteeIndex: 1, SlotSignature: sig.Marshal(), PublicKey: pubKey} - err = aggregatorServer.AttPool.SaveAggregatedAttestations([]interfaces.Attestation{ + err = aggregatorServer.AttPool.SaveAggregatedAttestations([]ethpb.Att{ att0, att1, }) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go index 03509789c1..1a523edb9a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go @@ -203,7 +203,7 @@ func (vs *Server) BuildBlockParallel(ctx context.Context, sBlk interfaces.Signed deposits, atts, err := vs.packDepositsAndAttestations(ctx, head, eth1Data) // TODO: split attestations and deposits if err != nil { sBlk.SetDeposits([]*ethpb.Deposit{}) - if err := sBlk.SetAttestations([]interfaces.Attestation{}); err != nil { + if err := sBlk.SetAttestations([]ethpb.Att{}); err != nil { log.WithError(err).Error("Could not set attestations on block") } log.WithError(err).Error("Could not pack deposits and attestations") diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations.go index 392113bc39..6e3cebb4b7 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations.go @@ -10,16 +10,16 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation" attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations" "go.opencensus.io/trace" ) -type proposerAtts []interfaces.Attestation +type proposerAtts []ethpb.Att -func (vs *Server) packAttestations(ctx context.Context, latestState state.BeaconState) ([]interfaces.Attestation, error) { +func (vs *Server) packAttestations(ctx context.Context, latestState state.BeaconState) ([]ethpb.Att, error) { ctx, span := trace.StartSpan(ctx, "ProposerServer.packAttestations") defer span.End() @@ -46,7 +46,7 @@ func (vs *Server) packAttestations(ctx context.Context, latestState state.Beacon return nil, err } - attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(atts)) + attsByDataRoot := make(map[[32]byte][]ethpb.Att, len(atts)) for _, att := range atts { attDataRoot, err := att.GetData().HashTreeRoot() if err != nil { @@ -55,7 +55,7 @@ func (vs *Server) packAttestations(ctx context.Context, latestState state.Beacon attsByDataRoot[attDataRoot] = append(attsByDataRoot[attDataRoot], att) } - attsForInclusion := proposerAtts(make([]interfaces.Attestation, 0)) + attsForInclusion := proposerAtts(make([]ethpb.Att, 0)) for _, as := range attsByDataRoot { as, err := attaggregation.Aggregate(as) if err != nil { @@ -79,8 +79,8 @@ func (vs *Server) packAttestations(ctx context.Context, latestState state.Beacon // The first group passes the all the required checks for attestation to be considered for proposing. // And attestations from the second group should be deleted. func (a proposerAtts) filter(ctx context.Context, st state.BeaconState) (proposerAtts, proposerAtts) { - validAtts := make([]interfaces.Attestation, 0, len(a)) - invalidAtts := make([]interfaces.Attestation, 0, len(a)) + validAtts := make([]ethpb.Att, 0, len(a)) + invalidAtts := make([]ethpb.Att, 0, len(a)) for _, att := range a { if err := blocks.VerifyAttestationNoVerifySignature(ctx, st, att); err == nil { @@ -182,7 +182,7 @@ func (a proposerAtts) dedup() (proposerAtts, error) { if len(a) < 2 { return a, nil } - attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(a)) + attsByDataRoot := make(map[[32]byte][]ethpb.Att, len(a)) for _, att := range a { attDataRoot, err := att.GetData().HashTreeRoot() if err != nil { @@ -191,7 +191,7 @@ func (a proposerAtts) dedup() (proposerAtts, error) { attsByDataRoot[attDataRoot] = append(attsByDataRoot[attDataRoot], att) } - uniqAtts := make([]interfaces.Attestation, 0, len(a)) + uniqAtts := make([]ethpb.Att, 0, len(a)) for _, atts := range attsByDataRoot { for i := 0; i < len(atts); i++ { a := atts[i] @@ -224,7 +224,7 @@ func (a proposerAtts) dedup() (proposerAtts, error) { } // This filters the input attestations to return a list of valid attestations to be packaged inside a beacon block. -func (vs *Server) validateAndDeleteAttsInPool(ctx context.Context, st state.BeaconState, atts []interfaces.Attestation) ([]interfaces.Attestation, error) { +func (vs *Server) validateAndDeleteAttsInPool(ctx context.Context, st state.BeaconState, atts []ethpb.Att) ([]ethpb.Att, error) { ctx, span := trace.StartSpan(ctx, "ProposerServer.validateAndDeleteAttsInPool") defer span.End() @@ -237,7 +237,7 @@ func (vs *Server) validateAndDeleteAttsInPool(ctx context.Context, st state.Beac // The input attestations are processed and seen by the node, this deletes them from pool // so proposers don't include them in a block for the future. -func (vs *Server) deleteAttsInPool(ctx context.Context, atts []interfaces.Attestation) error { +func (vs *Server) deleteAttsInPool(ctx context.Context, atts []ethpb.Att) error { ctx, span := trace.StartSpan(ctx, "ProposerServer.deleteAttsInPool") defer span.End() diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go index e1c9480a6d..f3705c671b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -15,7 +14,7 @@ import ( ) func TestProposer_ProposerAtts_sortByProfitability(t *testing.T) { - atts := proposerAtts([]interfaces.Attestation{ + atts := proposerAtts([]ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}}), @@ -23,7 +22,7 @@ func TestProposer_ProposerAtts_sortByProfitability(t *testing.T) { util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}}), }) - want := proposerAtts([]interfaces.Attestation{ + want := proposerAtts([]ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}}), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go index be110d9e30..d2a6ecfb4b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/container/trie" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/sirupsen/logrus" @@ -19,10 +18,10 @@ import ( "google.golang.org/grpc/status" ) -func (vs *Server) packDepositsAndAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []interfaces.Attestation, error) { +func (vs *Server) packDepositsAndAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []ethpb.Att, error) { eg, egctx := errgroup.WithContext(ctx) var deposits []*ethpb.Deposit - var atts []interfaces.Attestation + var atts []ethpb.Att eg.Go(func() error { // Pack ETH1 deposits which have not been included in the beacon chain. diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings.go index 2658140ac7..f8f8494a6a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings.go @@ -6,11 +6,10 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks" v "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) -func (vs *Server) getSlashings(ctx context.Context, head state.BeaconState) ([]*ethpb.ProposerSlashing, []interfaces.AttesterSlashing) { +func (vs *Server) getSlashings(ctx context.Context, head state.BeaconState) ([]*ethpb.ProposerSlashing, []ethpb.AttSlashing) { proposerSlashings := vs.SlashingsPool.PendingProposerSlashings(ctx, head, false /*noLimit*/) validProposerSlashings := make([]*ethpb.ProposerSlashing, 0, len(proposerSlashings)) for _, slashing := range proposerSlashings { @@ -22,7 +21,7 @@ func (vs *Server) getSlashings(ctx context.Context, head state.BeaconState) ([]* validProposerSlashings = append(validProposerSlashings, slashing) } attSlashings := vs.SlashingsPool.PendingAttesterSlashings(ctx, head, false /*noLimit*/) - validAttSlashings := make([]interfaces.AttesterSlashing, 0, len(attSlashings)) + validAttSlashings := make([]ethpb.AttSlashing, 0, len(attSlashings)) for _, slashing := range attSlashings { _, err := blocks.ProcessAttesterSlashing(ctx, head, slashing, v.SlashValidator) if err != nil { diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings_test.go index 3411a8b730..5bc23f1e9f 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_slashings_test.go @@ -6,7 +6,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/slashings" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -29,7 +28,7 @@ func TestServer_getSlashings(t *testing.T) { require.NoError(t, err) } - attSlashings := make([]interfaces.AttesterSlashing, params.BeaconConfig().MaxAttesterSlashings) + attSlashings := make([]ethpb.AttSlashing, params.BeaconConfig().MaxAttesterSlashings) for i := uint64(0); i < params.BeaconConfig().MaxAttesterSlashings; i++ { attesterSlashing, err := util.GenerateAttesterSlashingForValidator( beaconState, diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index e6c665c999..6ed6bd95cc 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -38,7 +38,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/trie" "github.com/prysmaticlabs/prysm/v5/crypto/bls" @@ -2550,22 +2549,22 @@ func TestProposer_FilterAttestation(t *testing.T) { tests := []struct { name string wantedErr string - inputAtts func() []interfaces.Attestation - expectedAtts func(inputAtts []interfaces.Attestation) []interfaces.Attestation + inputAtts func() []ethpb.Att + expectedAtts func(inputAtts []ethpb.Att) []ethpb.Att }{ { name: "nil attestations", - inputAtts: func() []interfaces.Attestation { + inputAtts: func() []ethpb.Att { return nil }, - expectedAtts: func(inputAtts []interfaces.Attestation) []interfaces.Attestation { - return []interfaces.Attestation{} + expectedAtts: func(inputAtts []ethpb.Att) []ethpb.Att { + return []ethpb.Att{} }, }, { name: "invalid attestations", - inputAtts: func() []interfaces.Attestation { - atts := make([]interfaces.Attestation, 10) + inputAtts: func() []ethpb.Att { + atts := make([]ethpb.Att, 10) for i := 0; i < len(atts); i++ { atts[i] = util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ @@ -2575,14 +2574,14 @@ func TestProposer_FilterAttestation(t *testing.T) { } return atts }, - expectedAtts: func(inputAtts []interfaces.Attestation) []interfaces.Attestation { - return []interfaces.Attestation{} + expectedAtts: func(inputAtts []ethpb.Att) []ethpb.Att { + return []ethpb.Att{} }, }, { name: "filter aggregates ok", - inputAtts: func() []interfaces.Attestation { - atts := make([]interfaces.Attestation, 10) + inputAtts: func() []ethpb.Att { + atts := make([]ethpb.Att, 10) for i := 0; i < len(atts); i++ { atts[i] = util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ @@ -2612,8 +2611,8 @@ func TestProposer_FilterAttestation(t *testing.T) { } return atts }, - expectedAtts: func(inputAtts []interfaces.Attestation) []interfaces.Attestation { - return []interfaces.Attestation{inputAtts[0], inputAtts[1]} + expectedAtts: func(inputAtts []ethpb.Att) []ethpb.Att { + return []ethpb.Att{inputAtts[0], inputAtts[1]} }, }, } @@ -2743,10 +2742,10 @@ func TestProposer_DeleteAttsInPool_Aggregated(t *testing.T) { priv, err := bls.RandKey() require.NoError(t, err) sig := priv.Sign([]byte("foo")).Marshal() - aggregatedAtts := []interfaces.Attestation{ + aggregatedAtts := []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10101}, Signature: sig}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11010}, Signature: sig})} - unaggregatedAtts := []interfaces.Attestation{ + unaggregatedAtts := []ethpb.Att{ util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10010}, Signature: sig}), util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10100}, Signature: sig})} diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_utils_bench_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_utils_bench_test.go index 5fa5071de2..c88b97a645 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_utils_bench_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_utils_bench_test.go @@ -6,7 +6,6 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" aggtesting "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/testing" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -45,7 +44,7 @@ func BenchmarkProposerAtts_sortByProfitability(b *testing.B) { }, } - runner := func(atts []interfaces.Attestation) { + runner := func(atts []ethpb.Att) { attsCopy := make(proposerAtts, len(atts)) for i, att := range atts { attsCopy[i] = ethpb.CopyAttestation(att.(*ethpb.Attestation)) diff --git a/beacon-chain/slasher/BUILD.bazel b/beacon-chain/slasher/BUILD.bazel index 60965a8cee..00bf4aaaea 100644 --- a/beacon-chain/slasher/BUILD.bazel +++ b/beacon-chain/slasher/BUILD.bazel @@ -36,7 +36,6 @@ go_library( "//beacon-chain/sync:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//container/slice:go_default_library", "//encoding/bytesutil:go_default_library", @@ -79,7 +78,6 @@ go_test( "//beacon-chain/sync/initial-sync/testing:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//crypto/bls/common:go_default_library", diff --git a/beacon-chain/slasher/chunks.go b/beacon-chain/slasher/chunks.go index dbb0803523..01b5943c66 100644 --- a/beacon-chain/slasher/chunks.go +++ b/beacon-chain/slasher/chunks.go @@ -9,7 +9,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/db" slashertypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/slasher/types" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/sirupsen/logrus" @@ -27,7 +26,7 @@ type Chunker interface { slasherDB db.SlasherDatabase, validatorIdx primitives.ValidatorIndex, attestation *slashertypes.IndexedAttestationWrapper, - ) (interfaces.AttesterSlashing, error) + ) (ethpb.AttSlashing, error) Update( chunkIndex uint64, currentEpoch primitives.Epoch, @@ -186,7 +185,7 @@ func (m *MinSpanChunksSlice) CheckSlashable( slasherDB db.SlasherDatabase, validatorIdx primitives.ValidatorIndex, incomingAttWrapper *slashertypes.IndexedAttestationWrapper, -) (interfaces.AttesterSlashing, error) { +) (ethpb.AttSlashing, error) { sourceEpoch := incomingAttWrapper.IndexedAttestation.GetData().Source.Epoch targetEpoch := incomingAttWrapper.IndexedAttestation.GetData().Target.Epoch @@ -282,7 +281,7 @@ func (m *MaxSpanChunksSlice) CheckSlashable( slasherDB db.SlasherDatabase, validatorIdx primitives.ValidatorIndex, incomingAttWrapper *slashertypes.IndexedAttestationWrapper, -) (interfaces.AttesterSlashing, error) { +) (ethpb.AttSlashing, error) { sourceEpoch := incomingAttWrapper.IndexedAttestation.GetData().Source.Epoch targetEpoch := incomingAttWrapper.IndexedAttestation.GetData().Target.Epoch diff --git a/beacon-chain/slasher/detect_attestations.go b/beacon-chain/slasher/detect_attestations.go index e3ed6abf39..0817e12ce6 100644 --- a/beacon-chain/slasher/detect_attestations.go +++ b/beacon-chain/slasher/detect_attestations.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" slashertypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/slasher/types" fieldparams "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/prysm/v1alpha1" "go.opencensus.io/trace" @@ -19,8 +18,8 @@ import ( // found attester slashings to the caller. func (s *Service) checkSlashableAttestations( ctx context.Context, currentEpoch primitives.Epoch, atts []*slashertypes.IndexedAttestationWrapper, -) (map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, error) { - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{} +) (map[[fieldparams.RootLength]byte]ethpb.AttSlashing, error) { + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{} // Double votes doubleVoteSlashings, err := s.checkDoubleVotes(ctx, atts) @@ -57,13 +56,13 @@ func (s *Service) checkSurroundVotes( ctx context.Context, attWrappers []*slashertypes.IndexedAttestationWrapper, currentEpoch primitives.Epoch, -) (map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, error) { +) (map[[fieldparams.RootLength]byte]ethpb.AttSlashing, error) { // With 256 validators and 16 epochs per chunk, there is 4096 `uint16` elements per chunk. // 4096 `uint16` elements = 8192 bytes = 8KB // 25_600 chunks * 8KB = 200MB const maxChunkBeforeFlush = 25_600 - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{} + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{} // Group attestation wrappers by validator chunk index. attWrappersByValidatorChunkIndex := s.groupByValidatorChunkIndex(attWrappers) @@ -154,7 +153,7 @@ func (s *Service) checkSurroundVotes( // Check for double votes in our database given a list of incoming attestations. func (s *Service) checkDoubleVotes( ctx context.Context, incomingAttWrappers []*slashertypes.IndexedAttestationWrapper, -) (map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, error) { +) (map[[fieldparams.RootLength]byte]ethpb.AttSlashing, error) { ctx, span := trace.StartSpan(ctx, "Slasher.checkDoubleVotesOnDisk") defer span.End() @@ -163,7 +162,7 @@ func (s *Service) checkDoubleVotes( epoch primitives.Epoch } - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{} + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{} // Check each incoming attestation for double votes against other incoming attestations. existingAttWrappers := make(map[attestationInfo]*slashertypes.IndexedAttestationWrapper) @@ -462,13 +461,13 @@ func (s *Service) updateSpans( kind slashertypes.ChunkKind, validatorChunkIndex uint64, currentEpoch primitives.Epoch, -) (map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, error) { +) (map[[fieldparams.RootLength]byte]ethpb.AttSlashing, error) { ctx, span := trace.StartSpan(ctx, "Slasher.updateSpans") defer span.End() // Apply the attestations to the related chunks and find any // slashings along the way. - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{} + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{} for _, attWrappers := range attWrapperByChunkIdx { for _, attWrapper := range attWrappers { @@ -527,7 +526,7 @@ func (s *Service) applyAttestationForValidator( validatorChunkIndex uint64, validatorIndex primitives.ValidatorIndex, currentEpoch primitives.Epoch, -) (interfaces.AttesterSlashing, error) { +) (ethpb.AttSlashing, error) { ctx, span := trace.StartSpan(ctx, "Slasher.applyAttestationForValidator") defer span.End() diff --git a/beacon-chain/slasher/helpers.go b/beacon-chain/slasher/helpers.go index 411282a6e4..6c6be1990c 100644 --- a/beacon-chain/slasher/helpers.go +++ b/beacon-chain/slasher/helpers.go @@ -10,7 +10,6 @@ import ( slashertypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/slasher/types" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -130,14 +129,14 @@ func validateBlockHeaderIntegrity(header *ethpb.SignedBeaconBlockHeader) bool { return true } -func logAttesterSlashing(slashing interfaces.AttesterSlashing) { - indices := slice.IntersectionUint64(slashing.GetFirstAttestation().GetAttestingIndices(), slashing.GetSecondAttestation().GetAttestingIndices()) +func logAttesterSlashing(slashing ethpb.AttSlashing) { + indices := slice.IntersectionUint64(slashing.FirstAttestation().GetAttestingIndices(), slashing.SecondAttestation().GetAttestingIndices()) log.WithFields(logrus.Fields{ "validatorIndex": indices, - "prevSourceEpoch": slashing.GetFirstAttestation().GetData().Source.Epoch, - "prevTargetEpoch": slashing.GetFirstAttestation().GetData().Target.Epoch, - "sourceEpoch": slashing.GetSecondAttestation().GetData().Source.Epoch, - "targetEpoch": slashing.GetSecondAttestation().GetData().Target.Epoch, + "prevSourceEpoch": slashing.FirstAttestation().GetData().Source.Epoch, + "prevTargetEpoch": slashing.FirstAttestation().GetData().Target.Epoch, + "sourceEpoch": slashing.SecondAttestation().GetData().Source.Epoch, + "targetEpoch": slashing.SecondAttestation().GetData().Target.Epoch, }).Info("Attester slashing detected") } diff --git a/beacon-chain/slasher/process_slashings.go b/beacon-chain/slasher/process_slashings.go index c98f5c0d1b..770324847d 100644 --- a/beacon-chain/slasher/process_slashings.go +++ b/beacon-chain/slasher/process_slashings.go @@ -6,7 +6,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) @@ -14,9 +13,9 @@ import ( // Verifies attester slashings, logs them, and submits them to the slashing operations pool // in the beacon node if they pass validation. func (s *Service) processAttesterSlashings( - ctx context.Context, slashings map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, -) (map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing, error) { - processedSlashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{} + ctx context.Context, slashings map[[fieldparams.RootLength]byte]ethpb.AttSlashing, +) (map[[fieldparams.RootLength]byte]ethpb.AttSlashing, error) { + processedSlashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{} // If no slashings, return early. if len(slashings) == 0 { @@ -31,8 +30,8 @@ func (s *Service) processAttesterSlashings( for root, slashing := range slashings { // Verify the signature of the first attestation. - if err := s.verifyAttSignature(ctx, slashing.GetFirstAttestation()); err != nil { - log.WithError(err).WithField("a", slashing.GetFirstAttestation()).Warn( + if err := s.verifyAttSignature(ctx, slashing.FirstAttestation()); err != nil { + log.WithError(err).WithField("a", slashing.FirstAttestation()).Warn( "Invalid signature for attestation in detected slashing offense", ) @@ -40,8 +39,8 @@ func (s *Service) processAttesterSlashings( } // Verify the signature of the second attestation. - if err := s.verifyAttSignature(ctx, slashing.GetSecondAttestation()); err != nil { - log.WithError(err).WithField("b", slashing.GetSecondAttestation()).Warn( + if err := s.verifyAttSignature(ctx, slashing.SecondAttestation()); err != nil { + log.WithError(err).WithField("b", slashing.SecondAttestation()).Warn( "Invalid signature for attestation in detected slashing offense", ) diff --git a/beacon-chain/slasher/process_slashings_test.go b/beacon-chain/slasher/process_slashings_test.go index 9076449729..293b1dd4a0 100644 --- a/beacon-chain/slasher/process_slashings_test.go +++ b/beacon-chain/slasher/process_slashings_test.go @@ -12,7 +12,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -85,7 +84,7 @@ func TestService_processAttesterSlashings(t *testing.T) { root, err := slashing.HashTreeRoot() require.NoError(tt, err, "failed to hash tree root") - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{ + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{ root: slashing, } @@ -109,7 +108,7 @@ func TestService_processAttesterSlashings(t *testing.T) { root, err := slashing.HashTreeRoot() require.NoError(tt, err, "failed to hash tree root") - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{ + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{ root: slashing, } @@ -133,7 +132,7 @@ func TestService_processAttesterSlashings(t *testing.T) { root, err := slashing.HashTreeRoot() require.NoError(tt, err, "failed to hash tree root") - slashings := map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing{ + slashings := map[[fieldparams.RootLength]byte]ethpb.AttSlashing{ root: slashing, } diff --git a/beacon-chain/slasher/receive.go b/beacon-chain/slasher/receive.go index 66b82de0fb..81c9cdf818 100644 --- a/beacon-chain/slasher/receive.go +++ b/beacon-chain/slasher/receive.go @@ -7,7 +7,6 @@ import ( "github.com/pkg/errors" slashertypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/slasher/types" fieldparams "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/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" @@ -109,7 +108,7 @@ func (s *Service) processAttestations( ctx context.Context, attestations []*slashertypes.IndexedAttestationWrapper, currentSlot primitives.Slot, -) map[[fieldparams.RootLength]byte]interfaces.AttesterSlashing { +) map[[fieldparams.RootLength]byte]ethpb.AttSlashing { // Get the current epoch from the current slot. currentEpoch := slots.ToEpoch(currentSlot) diff --git a/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go b/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go index eecc49fb99..cad7c41b1c 100644 --- a/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go +++ b/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations" lruwrpr "github.com/prysmaticlabs/prysm/v5/cache/lru" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" @@ -35,7 +34,7 @@ func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing. Signature: make([]byte, fieldparams.BLSSignatureLength), } require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a)) - assert.DeepSSZEqual(t, []interfaces.Attestation{a.Message.Aggregate}, r.cfg.attPool.AggregatedAttestations(), "Did not save aggregated attestation") + assert.DeepSSZEqual(t, []ethpb.Att{a.Message.Aggregate}, r.cfg.attPool.AggregatedAttestations(), "Did not save aggregated attestation") } func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testing.T) { @@ -60,5 +59,5 @@ func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testin atts, err := r.cfg.attPool.UnaggregatedAttestations() require.NoError(t, err) - assert.DeepEqual(t, []interfaces.Attestation{a.Message.Aggregate}, atts, "Did not save unaggregated attestation") + assert.DeepEqual(t, []ethpb.Att{a.Message.Aggregate}, atts, "Did not save unaggregated attestation") } diff --git a/beacon-chain/sync/subscriber_handlers.go b/beacon-chain/sync/subscriber_handlers.go index dd49d259ab..0d75624875 100644 --- a/beacon-chain/sync/subscriber_handlers.go +++ b/beacon-chain/sync/subscriber_handlers.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "google.golang.org/protobuf/proto" ) @@ -26,13 +25,13 @@ func (s *Service) voluntaryExitSubscriber(_ context.Context, msg proto.Message) } func (s *Service) attesterSlashingSubscriber(ctx context.Context, msg proto.Message) error { - aSlashing, ok := msg.(interfaces.AttesterSlashing) + aSlashing, ok := msg.(ethpb.AttSlashing) if !ok { return fmt.Errorf("wrong type, expected: *ethpb.AttesterSlashing got: %T", msg) } // Do some nil checks to prevent easy DoS'ing of this handler. - aSlashing1IsNil := aSlashing == nil || aSlashing.GetFirstAttestation() == nil || aSlashing.GetFirstAttestation().GetAttestingIndices() == nil - aSlashing2IsNil := aSlashing == nil || aSlashing.GetSecondAttestation() == nil || aSlashing.GetSecondAttestation().GetAttestingIndices() == nil + aSlashing1IsNil := aSlashing == nil || aSlashing.FirstAttestation() == nil || aSlashing.FirstAttestation().GetAttestingIndices() == nil + aSlashing2IsNil := aSlashing == nil || aSlashing.SecondAttestation() == nil || aSlashing.SecondAttestation().GetAttestingIndices() == nil if !aSlashing1IsNil && !aSlashing2IsNil { headState, err := s.cfg.chain.HeadState(ctx) if err != nil { @@ -41,7 +40,7 @@ func (s *Service) attesterSlashingSubscriber(ctx context.Context, msg proto.Mess if err := s.cfg.slashingPool.InsertAttesterSlashing(ctx, headState, aSlashing); err != nil { return errors.Wrap(err, "could not insert attester slashing into pool") } - s.setAttesterSlashingIndicesSeen(aSlashing.GetFirstAttestation().GetAttestingIndices(), aSlashing.GetSecondAttestation().GetAttestingIndices()) + s.setAttesterSlashingIndicesSeen(aSlashing.FirstAttestation().GetAttestingIndices(), aSlashing.SecondAttestation().GetAttestingIndices()) } return nil } diff --git a/beacon-chain/sync/validate_aggregate_proof.go b/beacon-chain/sync/validate_aggregate_proof.go index 38f591952f..893c3670b5 100644 --- a/beacon-chain/sync/validate_aggregate_proof.go +++ b/beacon-chain/sync/validate_aggregate_proof.go @@ -15,7 +15,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -177,7 +176,7 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed *ethpb.Signe tracing.AnnotateError(span, wrappedErr) return pubsub.ValidationIgnore, wrappedErr } - attSigSet, err := blocks.AttestationSignatureBatch(ctx, bs, []interfaces.Attestation{signed.Message.Aggregate}) + attSigSet, err := blocks.AttestationSignatureBatch(ctx, bs, []ethpb.Att{signed.Message.Aggregate}) if err != nil { wrappedErr := errors.Wrapf(err, "Could not verify aggregator signature %d", signed.Message.AggregatorIndex) tracing.AnnotateError(span, wrappedErr) @@ -226,7 +225,7 @@ func (s *Service) setAggregatorIndexEpochSeen(epoch primitives.Epoch, aggregator // - [REJECT] The aggregate attestation has participants -- that is, len(get_attesting_indices(state, aggregate.data, aggregate.aggregation_bits)) >= 1. // - [REJECT] The aggregator's validator index is within the committee -- // i.e. `aggregate_and_proof.aggregator_index in get_beacon_committee(state, aggregate.data.slot, aggregate.data.index)`. -func (s *Service) validateIndexInCommittee(ctx context.Context, bs state.ReadOnlyBeaconState, a interfaces.Attestation, validatorIndex primitives.ValidatorIndex) (pubsub.ValidationResult, error) { +func (s *Service) validateIndexInCommittee(ctx context.Context, bs state.ReadOnlyBeaconState, a ethpb.Att, validatorIndex primitives.ValidatorIndex) (pubsub.ValidationResult, error) { ctx, span := trace.StartSpan(ctx, "sync.validateIndexInCommittee") defer span.End() diff --git a/beacon-chain/sync/validate_attester_slashing.go b/beacon-chain/sync/validate_attester_slashing.go index a30499d19c..d854a94c0e 100644 --- a/beacon-chain/sync/validate_attester_slashing.go +++ b/beacon-chain/sync/validate_attester_slashing.go @@ -10,10 +10,10 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" "github.com/prysmaticlabs/prysm/v5/monitoring/tracing" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" "go.opencensus.io/trace" ) @@ -40,7 +40,7 @@ func (s *Service) validateAttesterSlashing(ctx context.Context, pid peer.ID, msg tracing.AnnotateError(span, err) return pubsub.ValidationReject, err } - slashing, ok := m.(interfaces.AttesterSlashing) + slashing, ok := m.(ethpb.AttSlashing) if !ok { return pubsub.ValidationReject, errWrongMessage } diff --git a/beacon-chain/sync/validate_beacon_attestation.go b/beacon-chain/sync/validate_beacon_attestation.go index 83a5d37170..c37abab219 100644 --- a/beacon-chain/sync/validate_beacon_attestation.go +++ b/beacon-chain/sync/validate_beacon_attestation.go @@ -17,7 +17,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/features" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/monitoring/tracing" @@ -172,7 +171,7 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p } // This validates beacon unaggregated attestation has correct topic string. -func (s *Service) validateUnaggregatedAttTopic(ctx context.Context, a interfaces.Attestation, bs state.ReadOnlyBeaconState, t string) (pubsub.ValidationResult, error) { +func (s *Service) validateUnaggregatedAttTopic(ctx context.Context, a eth.Att, bs state.ReadOnlyBeaconState, t string) (pubsub.ValidationResult, error) { ctx, span := trace.StartSpan(ctx, "sync.validateUnaggregatedAttTopic") defer span.End() @@ -194,7 +193,7 @@ func (s *Service) validateUnaggregatedAttTopic(ctx context.Context, a interfaces return pubsub.ValidationAccept, nil } -func (s *Service) validateCommitteeIndex(ctx context.Context, a interfaces.Attestation, bs state.ReadOnlyBeaconState) (uint64, pubsub.ValidationResult, error) { +func (s *Service) validateCommitteeIndex(ctx context.Context, a eth.Att, bs state.ReadOnlyBeaconState) (uint64, pubsub.ValidationResult, error) { valCount, err := helpers.ActiveValidatorCount(ctx, bs, slots.ToEpoch(a.GetData().Slot)) if err != nil { return 0, pubsub.ValidationIgnore, err @@ -208,7 +207,7 @@ func (s *Service) validateCommitteeIndex(ctx context.Context, a interfaces.Attes // This validates beacon unaggregated attestation using the given state, the validation consists of bitfield length and count consistency // and signature verification. -func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a interfaces.Attestation, bs state.ReadOnlyBeaconState) (pubsub.ValidationResult, error) { +func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a eth.Att, bs state.ReadOnlyBeaconState) (pubsub.ValidationResult, error) { ctx, span := trace.StartSpan(ctx, "sync.validateUnaggregatedAttWithState") defer span.End() @@ -224,7 +223,7 @@ func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a interf return pubsub.ValidationReject, errors.New("attestation bitfield is invalid") } - set, err := blocks.AttestationSignatureBatch(ctx, bs, []interfaces.Attestation{a}) + set, err := blocks.AttestationSignatureBatch(ctx, bs, []eth.Att{a}) if err != nil { tracing.AnnotateError(span, err) attBadSignatureBatchCount.Inc() @@ -233,7 +232,7 @@ func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a interf return s.validateWithBatchVerifier(ctx, "attestation", set) } -func (s *Service) validateBitLength(ctx context.Context, a interfaces.Attestation, bs state.ReadOnlyBeaconState) ([]primitives.ValidatorIndex, pubsub.ValidationResult, error) { +func (s *Service) validateBitLength(ctx context.Context, a eth.Att, bs state.ReadOnlyBeaconState) ([]primitives.ValidatorIndex, pubsub.ValidationResult, error) { committee, err := helpers.BeaconCommitteeFromState(ctx, bs, a.GetData().Slot, a.GetData().CommitteeIndex) if err != nil { return nil, pubsub.ValidationIgnore, err diff --git a/consensus-types/blocks/getters.go b/consensus-types/blocks/getters.go index 1c42187bd7..aae831b685 100644 --- a/consensus-types/blocks/getters.go +++ b/consensus-types/blocks/getters.go @@ -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 } diff --git a/consensus-types/blocks/getters_test.go b/consensus-types/blocks/getters_test.go index 6dac557099..318bd65203 100644 --- a/consensus-types/blocks/getters_test.go +++ b/consensus-types/blocks/getters_test.go @@ -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()) diff --git a/consensus-types/blocks/setters.go b/consensus-types/blocks/setters.go index caa1638211..3650903404 100644 --- a/consensus-types/blocks/setters.go +++ b/consensus-types/blocks/setters.go @@ -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 { diff --git a/consensus-types/interfaces/BUILD.bazel b/consensus-types/interfaces/BUILD.bazel index 3a20551c7d..0ae8ae86cb 100644 --- a/consensus-types/interfaces/BUILD.bazel +++ b/consensus-types/interfaces/BUILD.bazel @@ -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", ], ) diff --git a/consensus-types/interfaces/beacon_block.go b/consensus-types/interfaces/beacon_block.go index a852c683e0..68ce6f661c 100644 --- a/consensus-types/interfaces/beacon_block.go +++ b/consensus-types/interfaces/beacon_block.go @@ -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 -} diff --git a/consensus-types/mock/BUILD.bazel b/consensus-types/mock/BUILD.bazel index b37f4f30d5..08384eb05f 100644 --- a/consensus-types/mock/BUILD.bazel +++ b/consensus-types/mock/BUILD.bazel @@ -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", diff --git a/consensus-types/mock/block.go b/consensus-types/mock/block.go index e13e09be20..e172fd6df8 100644 --- a/consensus-types/mock/block.go +++ b/consensus-types/mock/block.go @@ -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 { diff --git a/proto/prysm/v1alpha1/attestation.go b/proto/prysm/v1alpha1/attestation.go index 2af00e0872..ee5cfb98ef 100644 --- a/proto/prysm/v1alpha1/attestation.go +++ b/proto/prysm/v1alpha1/attestation.go @@ -3,12 +3,26 @@ package eth import ( ssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/go-bitfield" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/runtime/version" "google.golang.org/protobuf/proto" ) -// TODO: it would be nicer to declare this inside consensus-types, but this will result in a circular dependency -// (because the interface method returns another interface, the implementation also returns an interface) +// Att defines common functionality for all attestation types. +type Att interface { + proto.Message + ssz.Marshaler + ssz.Unmarshaler + ssz.HashRoot + Version() int + Copy() Att + GetAggregationBits() bitfield.Bitlist + GetData() *AttestationData + CommitteeBitsVal() bitfield.Bitfield + GetSignature() []byte +} + +// IndexedAtt defines common functionality for all indexed attestation types. type IndexedAtt interface { proto.Message ssz.Marshaler @@ -20,62 +34,166 @@ type IndexedAtt interface { GetSignature() []byte } +// SignedAggregateAttAndProof defines common functionality for all signed aggregate attestation types. +type SignedAggregateAttAndProof interface { + proto.Message + ssz.Marshaler + ssz.Unmarshaler + ssz.HashRoot + Version() int + AggregateAttestationAndProof() AggregateAttAndProof + GetSignature() []byte +} + +// AggregateAttAndProof defines common functionality for all aggregate attestation types. +type AggregateAttAndProof interface { + proto.Message + ssz.Marshaler + ssz.Unmarshaler + ssz.HashRoot + Version() int + GetAggregatorIndex() primitives.ValidatorIndex + AggregateVal() Att + GetSelectionProof() []byte +} + +// AttSlashing defines common functionality for all attestation slashing types. +type AttSlashing interface { + proto.Message + ssz.Marshaler + ssz.Unmarshaler + ssz.HashRoot + Version() int + FirstAttestation() IndexedAtt + SecondAttestation() IndexedAtt +} + +// Version -- func (a *Attestation) Version() int { return version.Phase0 } -func (a *Attestation) GetCommitteeBitsVal() bitfield.Bitfield { +// Copy -- +func (a *Attestation) Copy() Att { + return CopyAttestation(a) +} + +// CommitteeBitsVal -- +func (a *Attestation) CommitteeBitsVal() bitfield.Bitfield { return nil } +// Version -- func (a *PendingAttestation) Version() int { return version.Phase0 } -func (a *PendingAttestation) GetCommitteeBitsVal() bitfield.Bitfield { +// Copy -- +func (a *PendingAttestation) Copy() Att { + return CopyPendingAttestation(a) +} + +// CommitteeBitsVal -- +func (a *PendingAttestation) CommitteeBitsVal() bitfield.Bitfield { return nil } +// GetSignature -- func (a *PendingAttestation) GetSignature() []byte { return nil } +// Version -- func (a *AttestationElectra) Version() int { return version.Electra } -func (a *AttestationElectra) GetCommitteeBitsVal() bitfield.Bitfield { +// Copy -- +func (a *AttestationElectra) Copy() Att { + return CopyAttestationElectra(a) +} + +// CommitteeBitsVal -- +func (a *AttestationElectra) CommitteeBitsVal() bitfield.Bitfield { return a.CommitteeBits } +// Version -- func (a *IndexedAttestation) Version() int { return version.Phase0 } +// Version -- func (a *IndexedAttestationElectra) Version() int { return version.Electra } +// Version -- func (a *AttesterSlashing) Version() int { return version.Phase0 } -func (a *AttesterSlashing) GetFirstAttestation() IndexedAtt { +// FirstAttestation -- +func (a *AttesterSlashing) FirstAttestation() IndexedAtt { return a.Attestation_1 } -func (a *AttesterSlashing) GetSecondAttestation() IndexedAtt { +// SecondAttestation -- +func (a *AttesterSlashing) SecondAttestation() IndexedAtt { return a.Attestation_2 } +// Version -- func (a *AttesterSlashingElectra) Version() int { return version.Electra } -func (a *AttesterSlashingElectra) GetFirstAttestation() IndexedAtt { +// FirstAttestation -- +func (a *AttesterSlashingElectra) FirstAttestation() IndexedAtt { return a.Attestation_1 } -func (a *AttesterSlashingElectra) GetSecondAttestation() IndexedAtt { +// SecondAttestation -- +func (a *AttesterSlashingElectra) SecondAttestation() IndexedAtt { return a.Attestation_2 } + +// Version -- +func (a *AggregateAttestationAndProof) Version() int { + return version.Phase0 +} + +// AggregateVal -- +func (a *AggregateAttestationAndProof) AggregateVal() Att { + return a.Aggregate +} + +// Version -- +func (a *AggregateAttestationAndProofElectra) Version() int { + return version.Electra +} + +// AggregateVal -- +func (a *AggregateAttestationAndProofElectra) AggregateVal() Att { + return a.Aggregate +} + +// Version -- +func (a *SignedAggregateAttestationAndProof) Version() int { + return version.Phase0 +} + +// AggregateAttestationAndProof -- +func (a *SignedAggregateAttestationAndProof) AggregateAttestationAndProof() AggregateAttAndProof { + return a.Message +} + +// Version -- +func (a *SignedAggregateAttestationAndProofElectra) Version() int { + return version.Electra +} + +// AggregateAttestationAndProof -- +func (a *SignedAggregateAttestationAndProofElectra) AggregateAttestationAndProof() AggregateAttAndProof { + return a.Message +} diff --git a/proto/prysm/v1alpha1/attestation/BUILD.bazel b/proto/prysm/v1alpha1/attestation/BUILD.bazel index 7277285cc7..ebe984e2c6 100644 --- a/proto/prysm/v1alpha1/attestation/BUILD.bazel +++ b/proto/prysm/v1alpha1/attestation/BUILD.bazel @@ -8,7 +8,6 @@ go_library( deps = [ "//beacon-chain/core/signing:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", @@ -26,7 +25,6 @@ go_test( ":go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", diff --git a/proto/prysm/v1alpha1/attestation/aggregation/attestations/BUILD.bazel b/proto/prysm/v1alpha1/attestation/aggregation/attestations/BUILD.bazel index 53fe85d025..1a537f2da0 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/attestations/BUILD.bazel +++ b/proto/prysm/v1alpha1/attestation/aggregation/attestations/BUILD.bazel @@ -9,7 +9,6 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations", visibility = ["//visibility:public"], deps = [ - "//consensus-types/interfaces:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/attestation/aggregation:go_default_library", @@ -28,7 +27,6 @@ go_test( embed = [":go_default_library"], deps = [ "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//crypto/bls:go_default_library", "//encoding/ssz/equality:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go b/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go index c7dc7542b0..8828687d81 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go +++ b/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go @@ -2,7 +2,6 @@ package attestations import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation" @@ -10,7 +9,7 @@ import ( ) // attList represents list of attestations, defined for easier en masse operations (filtering, sorting). -type attList []interfaces.Attestation +type attList []ethpb.Att // BLS aggregate signature aliases for testing / benchmark substitution. These methods are // significantly more expensive than the inner logic of AggregateAttestations so they must be @@ -33,13 +32,13 @@ var ErrInvalidAttestationCount = errors.New("invalid number of attestations") // clonedAtts[i] = stateTrie.CopyAttestation(a) // } // aggregatedAtts, err := attaggregation.Aggregate(clonedAtts) -func Aggregate(atts []interfaces.Attestation) ([]interfaces.Attestation, error) { +func Aggregate(atts []ethpb.Att) ([]ethpb.Att, error) { return MaxCoverAttestationAggregation(atts) } // AggregateDisjointOneBitAtts aggregates unaggregated attestations with the // exact same attestation data. -func AggregateDisjointOneBitAtts(atts []interfaces.Attestation) (interfaces.Attestation, error) { +func AggregateDisjointOneBitAtts(atts []ethpb.Att) (ethpb.Att, error) { if len(atts) == 0 { return nil, nil } diff --git a/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover.go b/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover.go index a59b835ff2..d399c7af67 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover.go +++ b/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover.go @@ -5,7 +5,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation" @@ -15,7 +14,7 @@ import ( // Aggregation occurs in many rounds, up until no more aggregation is possible (all attestations // are overlapping). // See https://hackmd.io/@farazdagi/in-place-attagg for design and rationale. -func MaxCoverAttestationAggregation(atts []interfaces.Attestation) ([]interfaces.Attestation, error) { +func MaxCoverAttestationAggregation(atts []ethpb.Att) ([]ethpb.Att, error) { if len(atts) < 2 { return atts, nil } @@ -150,7 +149,7 @@ func padSelectedKeys(keys []int, pad int) []int { // aggregateAttestations combines signatures of selected attestations into a single aggregate attestation, and // pushes that aggregated attestation into the position of the first of selected attestations. -func aggregateAttestations(atts []interfaces.Attestation, keys []int, coverage *bitfield.Bitlist64) (targetIdx int, err error) { +func aggregateAttestations(atts []ethpb.Att, keys []int, coverage *bitfield.Bitlist64) (targetIdx int, err error) { if len(keys) < 2 || atts == nil || len(atts) < 2 { return targetIdx, errors.Wrap(ErrInvalidAttestationCount, "cannot aggregate") } @@ -184,7 +183,7 @@ func aggregateAttestations(atts []interfaces.Attestation, keys []int, coverage * // rearrangeProcessedAttestations pushes processed attestations to the end of the slice, returning // the number of items re-arranged (so that caller can cut the slice, and allow processed items to be // garbage collected). -func rearrangeProcessedAttestations(atts []interfaces.Attestation, candidates []*bitfield.Bitlist64, processedKeys []int) { +func rearrangeProcessedAttestations(atts []ethpb.Att, candidates []*bitfield.Bitlist64, processedKeys []int) { if atts == nil || candidates == nil || processedKeys == nil { return } @@ -216,7 +215,7 @@ func (al attList) merge(al1 attList) attList { // selectUsingKeys returns only items with specified keys. func (al attList) selectUsingKeys(keys []int) attList { - filtered := make([]interfaces.Attestation, len(keys)) + filtered := make([]ethpb.Att, len(keys)) for i, key := range keys { filtered[i] = al[key] } diff --git a/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover_test.go b/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover_test.go index 638c85ded6..e99af315ad 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover_test.go +++ b/proto/prysm/v1alpha1/attestation/aggregation/attestations/maxcover_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation" @@ -145,35 +144,35 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) { func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { tests := []struct { name string - atts []interfaces.Attestation + atts []ethpb.Att keys []int - wantAtts []interfaces.Attestation + wantAtts []ethpb.Att }{ { name: "nil attestations", }, { name: "single attestation no processed keys", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{}, }, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{}, }, }, { name: "single attestation processed", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{}, }, keys: []int{0}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ nil, }, }, { name: "multiple processed, last attestation marked", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -181,7 +180,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x04}}, }, keys: []int{1, 4}, // Only attestation at index 1, should be moved, att at 4 is already at the end. - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -190,7 +189,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { }, { name: "all processed", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -198,13 +197,13 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x04}}, }, keys: []int{0, 1, 2, 3, 4}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ nil, nil, nil, nil, nil, }, }, { name: "operate on slice, single attestation marked", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -214,7 +213,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { nil, nil, nil, }, keys: []int{2}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x04}}, @@ -224,7 +223,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { }, { name: "operate on slice, non-last attestation marked", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -235,7 +234,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { nil, nil, nil, }, keys: []int{2, 3}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x05}}, @@ -245,7 +244,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { }, { name: "operate on slice, last attestation marked", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -255,7 +254,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { nil, nil, nil, }, keys: []int{2, 4}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}}, @@ -264,7 +263,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { }, { name: "many items, many selected, keys unsorted", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}, @@ -274,7 +273,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) { ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x06}}, }, keys: []int{4, 1, 2, 5, 6}, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}}, nil, nil, nil, nil, nil, @@ -303,8 +302,8 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { sign := bls.NewAggregateSignature().Marshal() tests := []struct { name string - atts []interfaces.Attestation - wantAtts []interfaces.Attestation + atts []ethpb.Att + wantAtts []ethpb.Att keys []int coverage *bitfield.Bitlist64 wantTargetIdx int @@ -318,7 +317,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "single attestation", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{}, }, wantTargetIdx: 0, @@ -332,7 +331,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "two attestations, none selected", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, }, @@ -342,7 +341,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "two attestations, one selected", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x00}}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, }, @@ -352,11 +351,11 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "two attestations, both selected, empty coverage", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00000001, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00000110, 0b1}, Signature: sign}, }, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00000111, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00000110, 0b1}, Signature: sign}, }, @@ -366,11 +365,11 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "two attestations, both selected", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000001, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000010, 0b1}, Signature: sign}, }, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000011, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000010, 0b1}, Signature: sign}, }, @@ -386,7 +385,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { }, { name: "many attestations, several selected", - atts: []interfaces.Attestation{ + atts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000001, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000010, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000100, 0b1}, Signature: sign}, @@ -394,7 +393,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00010000, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00100000, 0b1}, Signature: sign}, }, - wantAtts: []interfaces.Attestation{ + wantAtts: []ethpb.Att{ ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000001, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00010110, 0b1}, Signature: sign}, ðpb.Attestation{AggregationBits: bitfield.Bitlist{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0b00000100, 0b1}, Signature: sign}, @@ -423,7 +422,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) { assert.NoError(t, err) } assert.Equal(t, tt.wantTargetIdx, gotTargetIdx) - extractBitlists := func(atts []interfaces.Attestation) []bitfield.Bitlist { + extractBitlists := func(atts []ethpb.Att) []bitfield.Bitlist { bl := make([]bitfield.Bitlist, len(atts)) for i, att := range atts { bl[i] = att.GetAggregationBits() diff --git a/proto/prysm/v1alpha1/attestation/aggregation/testing/BUILD.bazel b/proto/prysm/v1alpha1/attestation/aggregation/testing/BUILD.bazel index c1e4ddcb0b..220bbe96bf 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/testing/BUILD.bazel +++ b/proto/prysm/v1alpha1/attestation/aggregation/testing/BUILD.bazel @@ -7,7 +7,6 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/testing", visibility = ["//visibility:public"], deps = [ - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/proto/prysm/v1alpha1/attestation/aggregation/testing/bitlistutils.go b/proto/prysm/v1alpha1/attestation/aggregation/testing/bitlistutils.go index c8510b5186..370f6f7166 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/testing/bitlistutils.go +++ b/proto/prysm/v1alpha1/attestation/aggregation/testing/bitlistutils.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -78,8 +77,8 @@ func Bitlists64WithMultipleBitSet(t testing.TB, n, length, count uint64) []*bitf } // MakeAttestationsFromBitlists creates list of attestations from list of bitlist. -func MakeAttestationsFromBitlists(bl []bitfield.Bitlist) []interfaces.Attestation { - atts := make([]interfaces.Attestation, len(bl)) +func MakeAttestationsFromBitlists(bl []bitfield.Bitlist) []ethpb.Att { + atts := make([]ethpb.Att, len(bl)) for i, b := range bl { atts[i] = ðpb.Attestation{ AggregationBits: b, diff --git a/proto/prysm/v1alpha1/attestation/attestation_utils.go b/proto/prysm/v1alpha1/attestation/attestation_utils.go index 432d496efb..1af3060e5e 100644 --- a/proto/prysm/v1alpha1/attestation/attestation_utils.go +++ b/proto/prysm/v1alpha1/attestation/attestation_utils.go @@ -13,7 +13,6 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -40,7 +39,7 @@ import ( // data=attestation.data, // signature=attestation.signature, // ) -func ConvertToIndexed(ctx context.Context, attestation interfaces.Attestation, committees ...[]primitives.ValidatorIndex) (ethpb.IndexedAtt, error) { +func ConvertToIndexed(ctx context.Context, attestation ethpb.Att, committees ...[]primitives.ValidatorIndex) (ethpb.IndexedAtt, error) { attIndices, err := AttestingIndices(attestation, committees...) if err != nil { return nil, err @@ -79,7 +78,7 @@ func ConvertToIndexed(ctx context.Context, attestation interfaces.Attestation, c // committee_offset += len(committee) // // return output -func AttestingIndices(att interfaces.Attestation, committees ...[]primitives.ValidatorIndex) ([]uint64, error) { +func AttestingIndices(att ethpb.Att, committees ...[]primitives.ValidatorIndex) ([]uint64, error) { if len(committees) == 0 { return []uint64{}, nil } diff --git a/proto/prysm/v1alpha1/attestation/attestation_utils_test.go b/proto/prysm/v1alpha1/attestation/attestation_utils_test.go index d24a331909..62d797f3ad 100644 --- a/proto/prysm/v1alpha1/attestation/attestation_utils_test.go +++ b/proto/prysm/v1alpha1/attestation/attestation_utils_test.go @@ -7,7 +7,6 @@ import ( "github.com/prysmaticlabs/go-bitfield" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation" @@ -17,7 +16,7 @@ import ( func TestAttestingIndices(t *testing.T) { type args struct { - att interfaces.Attestation + att eth.Att committees [][]primitives.ValidatorIndex } tests := []struct { diff --git a/proto/prysm/v1alpha1/validator-client/keymanager.proto b/proto/prysm/v1alpha1/validator-client/keymanager.proto index 455cff32a2..9c6888ea87 100644 --- a/proto/prysm/v1alpha1/validator-client/keymanager.proto +++ b/proto/prysm/v1alpha1/validator-client/keymanager.proto @@ -1,7 +1,6 @@ syntax = "proto3"; package ethereum.validator.accounts.v2; -import "google/protobuf/wrappers.proto"; import "proto/eth/ext/options.proto"; import "proto/prysm/v1alpha1/attestation.proto"; import "proto/prysm/v1alpha1/beacon_block.proto"; diff --git a/testing/slasher/simulator/BUILD.bazel b/testing/slasher/simulator/BUILD.bazel index 6f90421487..d8dccd2d37 100644 --- a/testing/slasher/simulator/BUILD.bazel +++ b/testing/slasher/simulator/BUILD.bazel @@ -26,7 +26,6 @@ go_library( "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/sync:go_default_library", "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//crypto/bls:go_default_library", "//crypto/rand:go_default_library", diff --git a/testing/slasher/simulator/simulator.go b/testing/slasher/simulator/simulator.go index d8825701e2..b4d51c5846 100644 --- a/testing/slasher/simulator/simulator.go +++ b/testing/slasher/simulator/simulator.go @@ -15,7 +15,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" @@ -238,7 +237,7 @@ func (s *Simulator) verifySlashingsWereDetected(ctx context.Context) { ctx, nil, true, /* no limit */ ) detectedProposerSlashings := make(map[[32]byte]*ethpb.ProposerSlashing) - detectedAttesterSlashings := make(map[[32]byte]interfaces.AttesterSlashing) + detectedAttesterSlashings := make(map[[32]byte]ethpb.AttSlashing) for _, slashing := range poolProposerSlashings { slashingRoot, err := slashing.HashTreeRoot() if err != nil { diff --git a/testing/spectest/shared/common/forkchoice/builder.go b/testing/spectest/shared/common/forkchoice/builder.go index d354df5af0..81421dc887 100644 --- a/testing/spectest/shared/common/forkchoice/builder.go +++ b/testing/spectest/shared/common/forkchoice/builder.go @@ -126,7 +126,7 @@ func (bb *Builder) Attestation(t testing.TB, a *ethpb.Attestation) { // AttesterSlashing receives an attester slashing and feeds it to forkchoice. func (bb *Builder) AttesterSlashing(s *ethpb.AttesterSlashing) { - slashings := []interfaces.AttesterSlashing{s} + slashings := []ethpb.AttSlashing{s} bb.service.InsertSlashingsToForkChoiceStore(context.TODO(), slashings) }