diff --git a/beacon-chain/blockchain/metrics_test.go b/beacon-chain/blockchain/metrics_test.go index 5c3d42536e..f7e58ed8d3 100644 --- a/beacon-chain/blockchain/metrics_test.go +++ b/beacon-chain/blockchain/metrics_test.go @@ -35,7 +35,7 @@ func TestReportEpochMetrics_SlashedValidatorOutOfBound(t *testing.T) { require.NoError(t, err) v.Slashed = true require.NoError(t, h.UpdateValidatorAtIndex(0, v)) - require.NoError(t, h.AppendCurrentEpochAttestations(ð.PendingAttestation{InclusionDelay: 1, Data: util.NewAttestationUtil().HydrateAttestationData(ð.AttestationData{})})) + require.NoError(t, h.AppendCurrentEpochAttestations(ð.PendingAttestation{InclusionDelay: 1, Data: util.HydrateAttestationData(ð.AttestationData{})})) err = reportEpochMetrics(context.Background(), h, h) require.ErrorContains(t, "slot 0 out of bounds", err) } diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index b7d69e2fef..b137f5ed6b 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -70,7 +70,6 @@ func TestStore_OnAttestation_ErrorConditions_ProtoArray(t *testing.T) { require.NoError(t, err) require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, s, blkWithValidStateRoot)) - au := util.AttestationUtil{} tests := []struct { name string a *ethpb.Attestation @@ -78,17 +77,17 @@ func TestStore_OnAttestation_ErrorConditions_ProtoArray(t *testing.T) { }{ { name: "attestation's data slot not aligned with target vote", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), wantedErr: "slot 32 does not match target epoch 0", }, { name: "no pre state for attestations's target block", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), wantedErr: "could not get pre state for epoch 0", }, { name: "process attestation doesn't match current epoch", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, Root: BlkWithStateBadAttRoot[:]}}}), wantedErr: "target epoch 100 does not match current epoch", }, @@ -177,7 +176,6 @@ func TestStore_OnAttestation_ErrorConditions_DoublyLinkedTree(t *testing.T) { require.NoError(t, err) require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, s, blkWithValidStateRoot)) - au := util.AttestationUtil{} tests := []struct { name string a *ethpb.Attestation @@ -185,17 +183,17 @@ func TestStore_OnAttestation_ErrorConditions_DoublyLinkedTree(t *testing.T) { }{ { name: "attestation's data slot not aligned with target vote", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), wantedErr: "slot 32 does not match target epoch 0", }, { name: "no pre state for attestations's target block", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), wantedErr: "could not get pre state for epoch 0", }, { name: "process attestation doesn't match current epoch", - a: au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, + a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, Root: BlkWithStateBadAttRoot[:]}}}), wantedErr: "target epoch 100 does not match current epoch", }, @@ -251,7 +249,7 @@ func TestStore_OnAttestation_Ok_ProtoArray(t *testing.T) { genesisState, pks := util.DeterministicGenesisState(t, 64) service.SetGenesisTime(time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0)) require.NoError(t, service.saveGenesisData(ctx, genesisState)) - att, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) + att, err := util.GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(att[0].Data.Target.Root) copied := genesisState.Copy() @@ -281,7 +279,7 @@ func TestStore_OnAttestation_Ok_DoublyLinkedTree(t *testing.T) { genesisState, pks := util.DeterministicGenesisState(t, 64) service.SetGenesisTime(time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0)) require.NoError(t, service.saveGenesisData(ctx, genesisState)) - att, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) + att, err := util.GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(att[0].Data.Target.Root) copied := genesisState.Copy() @@ -424,7 +422,8 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) { opts := testServiceOptsWithDB(t) service, err := NewService(ctx, opts...) require.NoError(t, err) - d := util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}) + + d := util.HydrateAttestationData(ðpb.AttestationData{}) require.Equal(t, errBlockNotFoundInCacheOrDB, service.verifyBeaconBlock(ctx, d)) } diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 5dbe3ebb59..af22691758 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -1668,9 +1668,8 @@ func TestService_insertSlashingsToForkChoiceStore(t *testing.T) { service, err := NewService(ctx, opts...) require.NoError(t, err) - au := util.AttestationUtil{} beaconState, privKeys := util.DeterministicGenesisState(t, 100) - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -1685,7 +1684,7 @@ func TestService_insertSlashingsToForkChoiceStore(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) diff --git a/beacon-chain/blockchain/receive_attestation_test.go b/beacon-chain/blockchain/receive_attestation_test.go index 44ae3f12cd..dcdffe24f9 100644 --- a/beacon-chain/blockchain/receive_attestation_test.go +++ b/beacon-chain/blockchain/receive_attestation_test.go @@ -60,7 +60,7 @@ func TestVerifyLMDFFGConsistent_NotOK(t *testing.T) { require.NoError(t, err) wanted := "FFG and LMD votes are not consistent" - a := util.NewAttestationUtil().NewAttestation() + a := util.NewAttestation() a.Data.Target.Epoch = 1 a.Data.Target.Root = []byte{'a'} a.Data.BeaconBlockRoot = r33[:] @@ -85,7 +85,8 @@ func TestVerifyLMDFFGConsistent_OK(t *testing.T) { util.SaveBlock(t, ctx, service.cfg.BeaconDB, b33) r33, err := b33.Block.HashTreeRoot() require.NoError(t, err) - a := util.NewAttestationUtil().NewAttestation() + + a := util.NewAttestation() a.Data.Target.Epoch = 1 a.Data.Target.Root = r32[:] a.Data.BeaconBlockRoot = r33[:] @@ -105,7 +106,7 @@ func TestProcessAttestations_Ok(t *testing.T) { genesisState, pks := util.DeterministicGenesisState(t, 64) require.NoError(t, genesisState.SetGenesisTime(uint64(prysmTime.Now().Unix())-params.BeaconConfig().SecondsPerSlot)) require.NoError(t, service.saveGenesisData(ctx, genesisState)) - atts, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) + atts, err := util.GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(atts[0].Data.Target.Root) copied := genesisState.Copy() @@ -226,7 +227,7 @@ func TestService_ProcessAttestationsAndUpdateHead(t *testing.T) { require.NoError(t, service.cfg.BeaconDB.SaveBlock(ctx, wsb)) // Generate attestatios for this block in Slot 1 - atts, err := util.NewAttestationUtil().GenerateAttestations(copied, pks, 1, 1, false) + atts, err := util.GenerateAttestations(copied, pks, 1, 1, false) require.NoError(t, err) require.NoError(t, service.cfg.AttPool.SaveForkchoiceAttestations(atts)) // Verify the target is in forchoice diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index 2f6f809a2d..813497e965 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -27,7 +27,7 @@ import ( func TestProcessAttestations_InclusionDelayFailure(t *testing.T) { attestations := []*ethpb.Attestation{ - util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, Slot: 5, @@ -55,7 +55,7 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) { } func TestProcessAttestations_NeitherCurrentNorPrevEpoch(t *testing.T) { - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: []byte("hello-world")}, Target: ðpb.Checkpoint{Epoch: 0}}}) @@ -201,7 +201,7 @@ func TestProcessAttestations_OK(t *testing.T) { aggBits.SetBitAt(0, true) var mockRoot [32]byte copy(mockRoot[:], "hello-world") - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Root: mockRoot[:]}, Target: ðpb.Checkpoint{Root: mockRoot[:]}, diff --git a/beacon-chain/core/blocks/attestation_test.go b/beacon-chain/core/blocks/attestation_test.go index f20db63f37..b3aec2b767 100644 --- a/beacon-chain/core/blocks/attestation_test.go +++ b/beacon-chain/core/blocks/attestation_test.go @@ -25,7 +25,7 @@ import ( func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) { beaconState, privKeys := util.DeterministicGenesisState(t, 100) - data := util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{ + data := util.HydrateAttestationData(ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)}, Target: ðpb.Checkpoint{Epoch: 0, Root: bytesutil.PadTo([]byte("hello-world"), 32)}, }) @@ -85,7 +85,7 @@ func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) { func TestVerifyAttestationNoVerifySignature_IncorrectSlotTargetEpoch(t *testing.T) { beaconState, _ := util.DeterministicGenesisState(t, 1) - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}, @@ -218,7 +218,7 @@ func TestConvertToIndexed_OK(t *testing.T) { var sig [fieldparams.BLSSignatureLength]byte copy(sig[:], "signed") - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Signature: sig[:], }) for _, tt := range tests { @@ -261,12 +261,11 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) require.NoError(t, err) - au := util.AttestationUtil{} tests := []struct { attestation *ethpb.IndexedAttestation }{ {attestation: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 2, }, @@ -276,7 +275,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 1, }, @@ -285,7 +284,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 4, }, @@ -294,7 +293,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 7, }, @@ -412,8 +411,7 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) { comm1, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{ + att1 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -432,7 +430,7 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) { comm2, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1*params.BeaconConfig().SlotsPerEpoch+1 /*slot*/, 1 /*committeeIndex*/) require.NoError(t, err) - att2 := au.HydrateAttestation(ðpb.Attestation{ + att2 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), Data: ðpb.AttestationData{ Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1, @@ -472,8 +470,7 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing comm1, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{ + att1 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -492,7 +489,7 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing comm2, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 1 /*committeeIndex*/) require.NoError(t, err) - att2 := au.HydrateAttestation(ðpb.Attestation{ + att2 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), Data: ðpb.AttestationData{ Slot: 1, @@ -537,8 +534,7 @@ func TestRetrieveAttestationSignatureSet_AcrossFork(t *testing.T) { comm1, err := helpers.BeaconCommitteeFromState(ctx, st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{ + att1 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -557,7 +553,7 @@ func TestRetrieveAttestationSignatureSet_AcrossFork(t *testing.T) { comm2, err := helpers.BeaconCommitteeFromState(ctx, st, 1 /*slot*/, 1 /*committeeIndex*/) require.NoError(t, err) - att2 := au.HydrateAttestation(ðpb.Attestation{ + att2 := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), Data: ðpb.AttestationData{ Slot: 1, diff --git a/beacon-chain/core/blocks/attester_slashing_test.go b/beacon-chain/core/blocks/attester_slashing_test.go index 88ed35e822..46b8edcc31 100644 --- a/beacon-chain/core/blocks/attester_slashing_test.go +++ b/beacon-chain/core/blocks/attester_slashing_test.go @@ -19,12 +19,11 @@ import ( ) func TestSlashableAttestationData_CanSlash(t *testing.T) { - au := util.AttestationUtil{} - att1 := au.HydrateAttestationData(ðpb.AttestationData{ + att1 := util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}, }) - att2 := au.HydrateAttestationData(ðpb.AttestationData{ + att2 := util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'B'}, 32)}, }) @@ -36,10 +35,9 @@ func TestSlashableAttestationData_CanSlash(t *testing.T) { } func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) { - au := util.AttestationUtil{} slashings := []*ethpb.AttesterSlashing{{ - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{}), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{}), + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, Target: ðpb.Checkpoint{Epoch: 1}}, @@ -73,16 +71,15 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T) }) require.NoError(t, err) - au := util.AttestationUtil{} slashings := []*ethpb.AttesterSlashing{ { - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), }), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), }), }, @@ -105,8 +102,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - au := util.AttestationUtil{} - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -121,7 +117,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -175,8 +171,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - au := util.AttestationUtil{} - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -191,7 +186,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -245,8 +240,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - au := util.AttestationUtil{} - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -261,7 +255,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) diff --git a/beacon-chain/core/blocks/block_regression_test.go b/beacon-chain/core/blocks/block_regression_test.go index 1e0147cfff..d8e01bf6f3 100644 --- a/beacon-chain/core/blocks/block_regression_test.go +++ b/beacon-chain/core/blocks/block_regression_test.go @@ -39,9 +39,8 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) { expectedSlashedVal := 2800 root1 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '1'} - au := util.AttestationUtil{} att1 := ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]}}), + Data: util.HydrateAttestationData(ðpb.AttestationData{Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]}}), AttestingIndices: setA, Signature: make([]byte, 96), } @@ -59,7 +58,7 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) { root2 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '2'} att2 := ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{Root: root2[:]}, }), AttestingIndices: setB, diff --git a/beacon-chain/core/transition/transition_test.go b/beacon-chain/core/transition/transition_test.go index 259aba2749..54e4d05e0a 100644 --- a/beacon-chain/core/transition/transition_test.go +++ b/beacon-chain/core/transition/transition_test.go @@ -133,16 +133,15 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { }), }, } - au := util.AttestationUtil{} attesterSlashings := []*ethpb.AttesterSlashing{ { Attestation_1: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{}), + Data: util.HydrateAttestationData(ðpb.AttestationData{}), AttestingIndices: []uint64{0, 1}, Signature: make([]byte, 96), }, Attestation_2: ðpb.IndexedAttestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{}), + Data: util.HydrateAttestationData(ðpb.AttestationData{}), AttestingIndices: []uint64{0, 1}, Signature: make([]byte, 96), }, @@ -153,7 +152,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { blockRoots = append(blockRoots, []byte{byte(i)}) } require.NoError(t, beaconState.SetBlockRoots(blockRoots)) - blockAtt := au.HydrateAttestation(ðpb.Attestation{ + blockAtt := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("hello-world"), 32)}, }, @@ -256,8 +255,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, require.NoError(t, beaconState.SetValidators(validators)) mockRoot2 := [32]byte{'A'} - au := util.AttestationUtil{} - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]}, }, @@ -273,7 +271,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, att1.Signature = aggregateSig.Marshal() mockRoot3 := [32]byte{'B'} - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]}, Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, @@ -303,7 +301,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, aggBits := bitfield.NewBitlist(1) aggBits.SetBitAt(0, true) - blockAtt := au.HydrateAttestation(ðpb.Attestation{ + blockAtt := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: beaconState.Slot(), Target: ðpb.Checkpoint{Epoch: time.CurrentEpoch(beaconState)}, diff --git a/beacon-chain/monitor/process_block_test.go b/beacon-chain/monitor/process_block_test.go index fa7136b2d3..50c1ed38c5 100644 --- a/beacon-chain/monitor/process_block_test.go +++ b/beacon-chain/monitor/process_block_test.go @@ -18,7 +18,6 @@ import ( ) func TestProcessSlashings(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string block *ethpb.BeaconBlock @@ -78,13 +77,13 @@ func TestProcessSlashings(t *testing.T) { Body: ðpb.BeaconBlockBody{ AttesterSlashings: []*ethpb.AttesterSlashing{ { - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: []uint64{1, 3, 4}, }), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{1, 5, 6}, }), }, @@ -100,13 +99,13 @@ func TestProcessSlashings(t *testing.T) { Body: ðpb.BeaconBlockBody{ AttesterSlashings: []*ethpb.AttesterSlashing{ { - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: []uint64{1, 3, 4}, }), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3, 5, 6}, }), }, diff --git a/beacon-chain/operations/attestations/kv/aggregated_test.go b/beacon-chain/operations/attestations/kv/aggregated_test.go index 84b1958ed0..b23cbdd69d 100644 --- a/beacon-chain/operations/attestations/kv/aggregated_test.go +++ b/beacon-chain/operations/attestations/kv/aggregated_test.go @@ -23,15 +23,14 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { require.NoError(t, err) sig1 := priv.Sign([]byte{'a'}) sig2 := priv.Sign([]byte{'b'}) - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}) - att4 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}) - att5 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}) - att6 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}) - att7 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}) - att8 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}) + att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}) + att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1010}, Signature: sig1.Marshal()}) + att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}, Signature: sig1.Marshal()}) + att4 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig2.Marshal()}) + att5 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1001}, Signature: sig1.Marshal()}) + 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 := []*ethpb.Attestation{att1, att2, att3, att4, att5, att6, att7, att8} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) require.NoError(t, cache.AggregateUnaggregatedAttestations(context.Background())) @@ -43,7 +42,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { func TestKV_Aggregated_AggregateUnaggregatedAttestationsBySlotIndex(t *testing.T) { cache := NewAttCaches() genData := func(slot types.Slot, committeeIndex types.CommitteeIndex) *ethpb.AttestationData { - return util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{ + return util.HydrateAttestationData(ðpb.AttestationData{ Slot: slot, CommitteeIndex: committeeIndex, }) @@ -96,7 +95,6 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestationsBySlotIndex(t *testing.T } func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string att *ethpb.Attestation @@ -115,14 +113,14 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "not aggregated", - att: au.HydrateAttestation(ðpb.Attestation{ + att: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0b10100}}), wantErrString: "attestation is not aggregated", }, { name: "invalid hash", att: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ BeaconBlockRoot: []byte{0b0}, }), AggregationBits: bitfield.Bitlist{0b10111}, @@ -131,7 +129,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "already seen", - att: au.HydrateAttestation(ðpb.Attestation{ + att: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 100, }, @@ -141,7 +139,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "normal save", - att: au.HydrateAttestation(ðpb.Attestation{ + att: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -150,7 +148,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { count: 1, }, } - r, err := hashFn(au.HydrateAttestationData(ðpb.AttestationData{ + r, err := hashFn(util.HydrateAttestationData(ðpb.AttestationData{ Slot: 100, })) require.NoError(t, err) @@ -174,7 +172,6 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { } func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string atts []*ethpb.Attestation @@ -184,9 +181,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { { name: "no duplicates", atts: []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), }, count: 1, @@ -210,7 +207,6 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { } func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string atts []*ethpb.Attestation @@ -220,9 +216,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) { name: "the first attestation is bad", atts: []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), }, count: 1, @@ -247,11 +243,10 @@ func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) func TestKV_Aggregated_AggregatedAttestations(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -266,17 +261,16 @@ func TestKV_Aggregated_AggregatedAttestations(t *testing.T) { } func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { - au := util.AttestationUtil{} t.Run("nil attestation", func(t *testing.T) { cache := NewAttCaches() assert.ErrorContains(t, "attestation can't be nil", cache.DeleteAggregatedAttestation(nil)) - att := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: ðpb.AttestationData{Slot: 2}}) + att := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: ðpb.AttestationData{Slot: 2}}) assert.NoError(t, cache.DeleteAggregatedAttestation(att)) }) t.Run("non aggregated attestation", func(t *testing.T) { cache := NewAttCaches() - att := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2}}) + att := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2}}) err := cache.DeleteAggregatedAttestation(att) assert.ErrorContains(t, "attestation is not aggregated", err) }) @@ -298,16 +292,16 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { t.Run("nonexistent attestation", func(t *testing.T) { cache := NewAttCaches() - att := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}) + att := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}) assert.NoError(t, cache.DeleteAggregatedAttestation(att)) }) t.Run("non-filtered deletion", func(t *testing.T) { cache := NewAttCaches() - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11010}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11010}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11010}}) - att4 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b10101}}) + att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11010}}) + 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 := []*ethpb.Attestation{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) require.NoError(t, cache.DeleteAggregatedAttestation(att1)) @@ -320,10 +314,10 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { t.Run("filtered deletion", func(t *testing.T) { cache := NewAttCaches() - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b110101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110111}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110100}}) - att4 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110101}}) + att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b110101}}) + 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 := []*ethpb.Attestation{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) @@ -340,7 +334,6 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { } func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string existing []*ethpb.Attestation @@ -364,7 +357,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "empty cache aggregated", - input: au.HydrateAttestation(ðpb.Attestation{ + input: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -373,7 +366,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "empty cache unaggregated", - input: au.HydrateAttestation(ðpb.Attestation{ + input: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -383,13 +376,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with exact match", existing: []*ethpb.Attestation{{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, @@ -398,13 +391,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with subset aggregation", existing: []*ethpb.Attestation{{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1110}}, @@ -413,13 +406,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with superset aggregation", existing: []*ethpb.Attestation{{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1110}}, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, @@ -429,20 +422,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "multiple attestations with same data in cache with overlapping aggregation, input is subset", existing: []*ethpb.Attestation{ { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100000}}, @@ -452,20 +445,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "multiple attestations with same data in cache with overlapping aggregation and input is superset", existing: []*ethpb.Attestation{ { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111111}}, @@ -475,20 +468,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "multiple attestations with different data in cache", existing: []*ethpb.Attestation{ { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 3, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111111}}, @@ -498,14 +491,14 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "attestations with different bitlist lengths", existing: []*ethpb.Attestation{ { - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, }, input: ðpb.Attestation{ - Data: au.HydrateAttestationData(ðpb.AttestationData{ + Data: util.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111}, @@ -547,9 +540,8 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1111}}) + att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) + att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1111}}) atts := []*ethpb.Attestation{att1, att2} for _, att := range atts { diff --git a/beacon-chain/operations/attestations/kv/block_test.go b/beacon-chain/operations/attestations/kv/block_test.go index a3aed55be4..c197002963 100644 --- a/beacon-chain/operations/attestations/kv/block_test.go +++ b/beacon-chain/operations/attestations/kv/block_test.go @@ -14,17 +14,16 @@ import ( func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveBlockAttestation(att)) } // Diff bit length should not panic. - att4 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11011}}) + att4 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11011}}) if err := cache.SaveBlockAttestation(att4); err != bitfield.ErrBitlistDifferentLength { t.Errorf("Unexpected error: wanted %v, got %v", bitfield.ErrBitlistDifferentLength, err) } @@ -41,10 +40,9 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { func TestKV_BlockAttestation_CanDelete(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { diff --git a/beacon-chain/operations/attestations/kv/forkchoice_test.go b/beacon-chain/operations/attestations/kv/forkchoice_test.go index 7dd4426324..610ce34200 100644 --- a/beacon-chain/operations/attestations/kv/forkchoice_test.go +++ b/beacon-chain/operations/attestations/kv/forkchoice_test.go @@ -14,10 +14,9 @@ import ( func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -36,10 +35,9 @@ func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { func TestKV_Forkchoice_CanDelete(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -57,10 +55,9 @@ func TestKV_Forkchoice_CanDelete(t *testing.T) { func TestKV_Forkchoice_CanCount(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}) + 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 := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { diff --git a/beacon-chain/operations/attestations/kv/seen_bits_test.go b/beacon-chain/operations/attestations/kv/seen_bits_test.go index d9a5e11047..b81492e1a8 100644 --- a/beacon-chain/operations/attestations/kv/seen_bits_test.go +++ b/beacon-chain/operations/attestations/kv/seen_bits_test.go @@ -12,21 +12,20 @@ import ( func TestAttCaches_hasSeenBit(t *testing.T) { c := NewAttCaches() - au := util.AttestationUtil{} - seenA1 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) - seenA2 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11100000}}) + seenA1 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) + seenA2 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11100000}}) require.NoError(t, c.insertSeenBit(seenA1)) require.NoError(t, c.insertSeenBit(seenA2)) tests := []struct { att *ethpb.Attestation want bool }{ - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000000}}), want: true}, - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000001}}), want: true}, - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11100000}}), want: true}, - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}), want: true}, - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10001000}}), want: false}, - {att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11110111}}), want: false}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000000}}), want: true}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000001}}), want: true}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11100000}}), want: true}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}), want: true}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10001000}}), want: false}, + {att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11110111}}), want: false}, } for _, tt := range tests { got, err := c.hasSeenBit(tt.att) @@ -39,8 +38,7 @@ func TestAttCaches_hasSeenBit(t *testing.T) { func TestAttCaches_insertSeenBitDuplicates(t *testing.T) { c := NewAttCaches() - - att1 := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) + att1 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) r, err := hashFn(att1.Data) require.NoError(t, err) require.NoError(t, c.insertSeenBit(att1)) diff --git a/beacon-chain/operations/attestations/kv/unaggregated_test.go b/beacon-chain/operations/attestations/kv/unaggregated_test.go index e71414b731..a42f863417 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated_test.go +++ b/beacon-chain/operations/attestations/kv/unaggregated_test.go @@ -17,7 +17,6 @@ import ( ) func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string att *ethpb.Attestation @@ -44,12 +43,12 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { }, { name: "normal save", - att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}}), + att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}}), count: 1, }, { name: "already seen", - att: au.HydrateAttestation(ðpb.Attestation{ + att: util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 100, }, @@ -58,7 +57,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { count: 0, }, } - r, err := hashFn(au.HydrateAttestationData(ðpb.AttestationData{Slot: 100})) + r, err := hashFn(util.HydrateAttestationData(ðpb.AttestationData{Slot: 100})) require.NoError(t, err) for _, tt := range tests { @@ -84,7 +83,6 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { } func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { - au := util.AttestationUtil{} tests := []struct { name string atts []*ethpb.Attestation @@ -94,18 +92,18 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { { name: "unaggregated only", atts: []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), + 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}}), }, count: 3, }, { name: "has aggregated", atts: []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), {AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}, - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), }, wantErrString: "attestation is aggregated", count: 1, @@ -143,11 +141,10 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) { }) t.Run("successful deletion", func(t *testing.T) { - au := util.AttestationUtil{} cache := NewAttCaches() - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}}) + 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 := []*ethpb.Attestation{att1, att2, att3} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) for _, att := range atts { @@ -160,8 +157,7 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) { } func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { - au := util.AttestationUtil{} - d := au.HydrateAttestationData(ðpb.AttestationData{}) + d := util.HydrateAttestationData(ðpb.AttestationData{}) t.Run("no attestations", func(t *testing.T) { cache := NewAttCaches() @@ -173,9 +169,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("none seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -190,9 +186,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("some seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -215,9 +211,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("all seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1001}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1010}}), - au.HydrateAttestation(ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b1100}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -240,10 +236,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) { cache := NewAttCaches() - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}}) - att3 := au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}}) + att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}}) + att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}}) + att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}}) atts := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { diff --git a/beacon-chain/operations/attestations/prepare_forkchoice_test.go b/beacon-chain/operations/attestations/prepare_forkchoice_test.go index 575f3b3658..295538c50f 100644 --- a/beacon-chain/operations/attestations/prepare_forkchoice_test.go +++ b/beacon-chain/operations/attestations/prepare_forkchoice_test.go @@ -234,7 +234,7 @@ func TestSeenAttestations_PresentInCache(t *testing.T) { s, err := NewService(context.Background(), &Config{Pool: NewPool()}) require.NoError(t, err) - ad1 := util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}) + ad1 := util.HydrateAttestationData(ðpb.AttestationData{}) att1 := ðpb.Attestation{Data: ad1, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0x13} /* 0b00010011 */} got, err := s.seen(att1) require.NoError(t, err) @@ -252,9 +252,9 @@ func TestSeenAttestations_PresentInCache(t *testing.T) { } func TestService_seen(t *testing.T) { - au := util.AttestationUtil{} - ad1 := au.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) - ad2 := au.HydrateAttestationData(ðpb.AttestationData{Slot: 2}) + ad1 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) + + ad2 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 2}) // Attestation are checked in order of this list. tests := []struct { diff --git a/beacon-chain/operations/attestations/prune_expired_test.go b/beacon-chain/operations/attestations/prune_expired_test.go index 97f8e7e12c..70e511b692 100644 --- a/beacon-chain/operations/attestations/prune_expired_test.go +++ b/beacon-chain/operations/attestations/prune_expired_test.go @@ -26,9 +26,9 @@ func TestPruneExpired_Ticker(t *testing.T) { }) require.NoError(t, err) - au := util.AttestationUtil{} - ad1 := au.HydrateAttestationData(ðpb.AttestationData{}) - ad2 := au.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) + ad1 := util.HydrateAttestationData(ðpb.AttestationData{}) + + ad2 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) atts := []*ethpb.Attestation{ {Data: ad1, AggregationBits: bitfield.Bitlist{0b1000, 0b1}, Signature: make([]byte, fieldparams.BLSSignatureLength)}, @@ -85,9 +85,9 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) { s, err := NewService(context.Background(), &Config{Pool: NewPool()}) require.NoError(t, err) - au := util.AttestationUtil{} - ad1 := au.HydrateAttestationData(ðpb.AttestationData{}) - ad2 := au.HydrateAttestationData(ðpb.AttestationData{}) + ad1 := util.HydrateAttestationData(ðpb.AttestationData{}) + + ad2 := util.HydrateAttestationData(ðpb.AttestationData{}) att1 := ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1101}} att2 := ðpb.Attestation{Data: ad1, AggregationBits: bitfield.Bitlist{0b1111}} diff --git a/beacon-chain/p2p/broadcaster_test.go b/beacon-chain/p2p/broadcaster_test.go index 592943afb0..9a5c938d8e 100644 --- a/beacon-chain/p2p/broadcaster_test.go +++ b/beacon-chain/p2p/broadcaster_test.go @@ -162,7 +162,7 @@ func TestService_BroadcastAttestation(t *testing.T) { }), } - msg := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) + msg := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) subnet := uint64(5) topic := AttestationSubnetTopicFormat @@ -323,7 +323,7 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) { go p.listenForNewNodes() go p2.listenForNewNodes() - msg := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) + msg := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) topic := AttestationSubnetTopicFormat GossipTypeMapping[reflect.TypeOf(msg)] = topic digest, err := p.currentForkDigest() diff --git a/beacon-chain/rpc/eth/beacon/blocks_test.go b/beacon-chain/rpc/eth/beacon/blocks_test.go index e8ed53b51f..401ac3e405 100644 --- a/beacon-chain/rpc/eth/beacon/blocks_test.go +++ b/beacon-chain/rpc/eth/beacon/blocks_test.go @@ -43,11 +43,10 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) ( b := util.NewBeaconBlock() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - au := util.AttestationUtil{} - att1 := au.NewAttestation() + att1 := util.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := au.NewAttestation() + att2 := util.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} @@ -87,11 +86,10 @@ func fillDBTestBlocksAltair(ctx context.Context, t *testing.T, beaconDB db.Datab b := util.NewBeaconBlockAltair() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - au := util.AttestationUtil{} - att1 := au.NewAttestation() + att1 := util.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := au.NewAttestation() + att2 := util.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} @@ -130,11 +128,10 @@ func fillDBTestBlocksBellatrix(ctx context.Context, t *testing.T, beaconDB db.Da b := util.NewBeaconBlockBellatrix() b.Block.Slot = i b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) - au := util.AttestationUtil{} - att1 := au.NewAttestation() + att1 := util.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := au.NewAttestation() + att2 := util.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} diff --git a/beacon-chain/rpc/eth/events/events_test.go b/beacon-chain/rpc/eth/events/events_test.go index ca044a3f98..10d3b06838 100644 --- a/beacon-chain/rpc/eth/events/events_test.go +++ b/beacon-chain/rpc/eth/events/events_test.go @@ -92,7 +92,7 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { srv, ctrl, mockStream := setupServer(ctx, t) defer ctrl.Finish() - wantedAttV1alpha1 := util.NewAttestationUtil().HydrateAttestation(ð.Attestation{ + wantedAttV1alpha1 := util.HydrateAttestation(ð.Attestation{ Data: ð.AttestationData{ Slot: 8, }, @@ -127,7 +127,7 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { defer ctrl.Finish() wantedAttV1alpha1 := ð.AggregateAttestationAndProof{ - Aggregate: util.NewAttestationUtil().HydrateAttestation(ð.Attestation{}), + Aggregate: util.HydrateAttestation(ð.Attestation{}), } wantedAtt := migration.V1Alpha1AggregateAttAndProofToV1(wantedAttV1alpha1) genericResponse, err := anypb.New(wantedAtt) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index a314781a79..74138ed6a5 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -81,7 +81,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) { }, } - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(0), Data: ðpb.AttestationData{ Slot: 2, @@ -275,7 +275,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) { blockExample := util.NewBeaconBlock() blockExample.Block.Slot = i blockExample.Block.Body.Attestations = []*ethpb.Attestation{ - util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: s, Slot: i, @@ -754,7 +754,7 @@ func TestServer_AttestationPool_Pagination_DefaultPageSize(t *testing.T) { atts := make([]*ethpb.Attestation, params.BeaconConfig().DefaultPageSize+1) for i := 0; i < len(atts); i++ { - att := util.NewAttestationUtil().NewAttestation() + att := util.NewAttestation() att.Data.Slot = types.Slot(i) atts[i] = att } @@ -776,7 +776,7 @@ func TestServer_AttestationPool_Pagination_CustomPageSize(t *testing.T) { numAtts := 100 atts := make([]*ethpb.Attestation, numAtts) for i := 0; i < len(atts); i++ { - att := util.NewAttestationUtil().NewAttestation() + att := util.NewAttestation() att.Data.Slot = types.Slot(i) atts[i] = att } @@ -1031,11 +1031,10 @@ func TestServer_StreamAttestations_OnSlotTick(t *testing.T) { AttestationNotifier: chainService.OperationNotifier(), } - au := util.AttestationUtil{} atts := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}), } mockStream := mock.NewMockBeaconChain_StreamAttestationsServer(ctrl) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index a066e043b0..5d67a497fd 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -1525,7 +1525,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) { } atts := []*ethpb.PendingAttestation{{ - Data: util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}), + Data: util.HydrateAttestationData(ðpb.AttestationData{}), InclusionDelay: 1, AggregationBits: bitfield.NewBitlist(validatorCount / uint64(params.BeaconConfig().SlotsPerEpoch)), }} @@ -1607,7 +1607,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) { } atts := []*ethpb.PendingAttestation{{ - Data: util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}), + Data: util.HydrateAttestationData(ðpb.AttestationData{}), InclusionDelay: 1, AggregationBits: bitfield.NewBitlist(validatorCount / uint64(params.BeaconConfig().SlotsPerEpoch)), }} @@ -2292,10 +2292,9 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) { require.NoError(t, beaconState.SetValidators(stateWithValidators.Validators())) bf := bitfield.NewBitlist(validators / uint64(params.BeaconConfig().SlotsPerEpoch)) - au := util.AttestationUtil{} - att1 := au.NewAttestation() + att1 := util.NewAttestation() att1.AggregationBits = bf - att2 := au.NewAttestation() + att2 := util.NewAttestation() att2.AggregationBits = bf rt := [32]byte{'A'} att1.Data.Target.Root = rt[:] diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go index 909de82af9..4c9461ef5e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go @@ -217,7 +217,7 @@ func generateAtt(state state.ReadOnlyBeaconState, index uint64, privKeys []bls.S aggBits := bitfield.NewBitlist(4) aggBits.SetBitAt(index, true) aggBits.SetBitAt(index+1, true) - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{CommitteeIndex: 1}, AggregationBits: aggBits, }) @@ -254,7 +254,7 @@ func generateAtt(state state.ReadOnlyBeaconState, index uint64, privKeys []bls.S func generateUnaggregatedAtt(state state.ReadOnlyBeaconState, index uint64, privKeys []bls.SecretKey) (*ethpb.Attestation, error) { aggBits := bitfield.NewBitlist(4) aggBits.SetBitAt(index, true) - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: 1, }, diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go index 4047fed606..77ed0b5bbe 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go @@ -83,7 +83,7 @@ func TestProposeAttestation_IncorrectSignature(t *testing.T) { OperationNotifier: (&mock.ChainService{}).OperationNotifier(), } - req := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{}) + req := util.HydrateAttestation(ðpb.Attestation{}) wanted := "Incorrect attestation signature" _, err := attesterServer.ProposeAttestation(context.Background(), req) assert.ErrorContains(t, wanted, err) 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 92448bba90..a8e24608de 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go @@ -14,22 +14,21 @@ import ( ) func TestProposer_ProposerAtts_sortByProfitability(t *testing.T) { - au := util.AttestationUtil{} atts := proposerAtts([]*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}}), + 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}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}}), + 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([]*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11110000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 4}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11000000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}}), + 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}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b11100000}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11100000}}), + util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11000000}}), }) atts, err := atts.sortByProfitability() if err != nil { @@ -46,7 +45,7 @@ func TestProposer_ProposerAtts_sortByProfitabilityUsingMaxCover(t *testing.T) { getAtts := func(data []testData) proposerAtts { var atts proposerAtts for _, att := range data { - atts = append(atts, util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + atts = append(atts, util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{Slot: att.slot}, AggregationBits: att.bits})) } return atts @@ -190,11 +189,10 @@ func TestProposer_ProposerAtts_sortByProfitabilityUsingMaxCover(t *testing.T) { } func TestProposer_ProposerAtts_dedup(t *testing.T) { - au := util.AttestationUtil{} - data1 := au.HydrateAttestationData(ðpb.AttestationData{ + data1 := util.HydrateAttestationData(ðpb.AttestationData{ Slot: 4, }) - data2 := au.HydrateAttestationData(ðpb.AttestationData{ + data2 := util.HydrateAttestationData(ðpb.AttestationData{ Slot: 5, }) tests := []struct { diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index 14dae067a5..4821095e62 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -148,9 +148,8 @@ func TestProposer_GetBlock_AddsUnaggregatedAtts(t *testing.T) { // Generate a bunch of random attestations at slot. These would be considered double votes, but // we don't care for the purpose of this test. var atts []*ethpb.Attestation - au := util.AttestationUtil{} for i := uint64(0); len(atts) < int(params.BeaconConfig().MaxAttestations); i++ { - a, err := au.GenerateAttestations(beaconState, privKeys, 4, 1, true) + a, err := util.GenerateAttestations(beaconState, privKeys, 4, 1, true) require.NoError(t, err) atts = append(atts, a...) } @@ -161,7 +160,7 @@ func TestProposer_GetBlock_AddsUnaggregatedAtts(t *testing.T) { // Generate some more random attestations with a larger spread so that we can capture at least // one unaggregated attestation. - atts, err := au.GenerateAttestations(beaconState, privKeys, 300, 1, true) + atts, err := util.GenerateAttestations(beaconState, privKeys, 300, 1, true) require.NoError(t, err) found := false for _, a := range atts { @@ -1816,7 +1815,6 @@ func TestProposer_FilterAttestation(t *testing.T) { genesisRoot, err := genesis.Block.HashTreeRoot() require.NoError(t, err) - au := util.AttestationUtil{} tests := []struct { name string wantedErr string @@ -1837,7 +1835,7 @@ func TestProposer_FilterAttestation(t *testing.T) { inputAtts: func() []*ethpb.Attestation { atts := make([]*ethpb.Attestation, 10) for i := 0; i < len(atts); i++ { - atts[i] = au.HydrateAttestation(ðpb.Attestation{ + atts[i] = util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: types.CommitteeIndex(i), }, @@ -1854,7 +1852,7 @@ func TestProposer_FilterAttestation(t *testing.T) { inputAtts: func() []*ethpb.Attestation { atts := make([]*ethpb.Attestation, 10) for i := 0; i < len(atts); i++ { - atts[i] = au.HydrateAttestation(ðpb.Attestation{ + atts[i] = util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: types.CommitteeIndex(i), Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, @@ -2013,13 +2011,12 @@ func TestProposer_DeleteAttsInPool_Aggregated(t *testing.T) { priv, err := bls.RandKey() require.NoError(t, err) sig := priv.Sign([]byte("foo")).Marshal() - au := util.AttestationUtil{} aggregatedAtts := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10101}, Signature: sig}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b11010}, Signature: sig})} + 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 := []*ethpb.Attestation{ - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10010}, Signature: sig}), - au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b10100}, Signature: sig})} + 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})} require.NoError(t, s.AttPool.SaveAggregatedAttestations(aggregatedAtts)) require.NoError(t, s.AttPool.SaveUnaggregatedAttestations(unaggregatedAtts)) diff --git a/beacon-chain/slasher/process_slashings_test.go b/beacon-chain/slasher/process_slashings_test.go index 3add88b98b..26ec523e17 100644 --- a/beacon-chain/slasher/process_slashings_test.go +++ b/beacon-chain/slasher/process_slashings_test.go @@ -50,11 +50,10 @@ func TestService_processAttesterSlashings(t *testing.T) { }, } - au := util.AttestationUtil{} - firstAtt := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + firstAtt := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0}, }) - secondAtt := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + secondAtt := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0}, }) diff --git a/beacon-chain/sync/pending_attestations_queue_test.go b/beacon-chain/sync/pending_attestations_queue_test.go index 844d00cace..c1976df477 100644 --- a/beacon-chain/sync/pending_attestations_queue_test.go +++ b/beacon-chain/sync/pending_attestations_queue_test.go @@ -162,7 +162,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) { Aggregate: ðpb.Attestation{ Signature: priv.Sign([]byte("foo")).Marshal(), AggregationBits: bitfield.Bitlist{0x02}, - Data: util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}), + Data: util.HydrateAttestationData(ðpb.AttestationData{}), }, SelectionProof: make([]byte, fieldparams.BLSSignatureLength), } diff --git a/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go b/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go index 411c4265eb..2dfeb72d48 100644 --- a/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go +++ b/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go @@ -26,7 +26,7 @@ func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing. a := ðpb.SignedAggregateAttestationAndProof{ Message: ðpb.AggregateAttestationAndProof{ - Aggregate: util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + Aggregate: util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0x07}, }), AggregatorIndex: 100, @@ -48,7 +48,7 @@ func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testin a := ðpb.SignedAggregateAttestationAndProof{ Message: ðpb.AggregateAttestationAndProof{ - Aggregate: util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + Aggregate: util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0x03}, Signature: make([]byte, fieldparams.BLSSignatureLength), }), diff --git a/beacon-chain/sync/subscriber_beacon_blocks_test.go b/beacon-chain/sync/subscriber_beacon_blocks_test.go index 1e30c97923..98de24ede8 100644 --- a/beacon-chain/sync/subscriber_beacon_blocks_test.go +++ b/beacon-chain/sync/subscriber_beacon_blocks_test.go @@ -25,11 +25,10 @@ func TestDeleteAttsInPool(t *testing.T) { cfg: &config{attPool: attestations.NewPool()}, } - au := util.AttestationUtil{} - att1 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1101}}) - att2 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1110}}) - att3 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1011}}) - att4 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}}) + att1 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1101}}) + att2 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1110}}) + att3 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1011}}) + att4 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}}) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att1)) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att2)) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att3)) @@ -43,12 +42,11 @@ func TestDeleteAttsInPool(t *testing.T) { } func TestService_beaconBlockSubscriber(t *testing.T) { - au := util.AttestationUtil{} pooledAttestations := []*ethpb.Attestation{ // Aggregated. - au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00011111}}), + util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00011111}}), // Unaggregated. - au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00010001}}), + util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00010001}}), } type args struct { diff --git a/beacon-chain/sync/validate_aggregate_proof_test.go b/beacon-chain/sync/validate_aggregate_proof_test.go index 414d718dea..91d0fcceb3 100644 --- a/beacon-chain/sync/validate_aggregate_proof_test.go +++ b/beacon-chain/sync/validate_aggregate_proof_test.go @@ -87,7 +87,7 @@ func TestVerifySelection_NotAnAggregator(t *testing.T) { beaconState, privKeys := util.DeterministicGenesisState(t, validators) sig := privKeys[0].Sign([]byte{'A'}) - data := util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}) + data := util.HydrateAttestationData(ðpb.AttestationData{}) _, err := validateSelectionIndex(ctx, beaconState, data, 0, sig.Marshal()) wanted := "validator is not an aggregator for slot" @@ -98,7 +98,7 @@ func TestValidateAggregateAndProof_NoBlock(t *testing.T) { db := dbtest.SetupDB(t) p := p2ptest.NewTestP2P(t) - att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + att := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("hello-world"), 32)}, Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("hello-world"), 32)}, diff --git a/beacon-chain/sync/validate_attester_slashing_test.go b/beacon-chain/sync/validate_attester_slashing_test.go index ba7af9ccfd..bf870c1969 100644 --- a/beacon-chain/sync/validate_attester_slashing_test.go +++ b/beacon-chain/sync/validate_attester_slashing_test.go @@ -33,8 +33,7 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be } require.NoError(t, s.SetValidators(vals)) - au := util.AttestationUtil{} - att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -49,7 +48,7 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) hashTreeRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -133,13 +132,12 @@ func TestValidateAttesterSlashing_CanFilter(t *testing.T) { d, err := r.currentForkDigest() assert.NoError(t, err) topic = r.addDigestToTopic(topic, d) - au := util.AttestationUtil{} buf := new(bytes.Buffer) _, err = p.Encoding().EncodeGossip(buf, ðpb.AttesterSlashing{ - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3}, }), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3}, }), }) @@ -157,10 +155,10 @@ func TestValidateAttesterSlashing_CanFilter(t *testing.T) { buf = new(bytes.Buffer) _, err = p.Encoding().EncodeGossip(buf, ðpb.AttesterSlashing{ - Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{4, 3}, }), - Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3, 4}, }), }) diff --git a/proto/migration/v1alpha1_to_v1_test.go b/proto/migration/v1alpha1_to_v1_test.go index e0d525d3d3..cbfb73ad1b 100644 --- a/proto/migration/v1alpha1_to_v1_test.go +++ b/proto/migration/v1alpha1_to_v1_test.go @@ -72,7 +72,7 @@ func Test_BlockIfaceToV1BlockHeader(t *testing.T) { func Test_V1Alpha1AggregateAttAndProofToV1(t *testing.T) { proof := [32]byte{1} - att := util.NewAttestationUtil().HydrateAttestation(ðpbalpha.Attestation{ + att := util.HydrateAttestation(ðpbalpha.Attestation{ Data: ðpbalpha.AttestationData{ Slot: 5, }, @@ -428,7 +428,7 @@ func Test_V1SignedAggregateAttAndProofToV1Alpha1(t *testing.T) { v1Att := ðpbv1.SignedAggregateAttestationAndProof{ Message: ðpbv1.AggregateAttestationAndProof{ AggregatorIndex: 1, - Aggregate: util.NewAttestationUtil().HydrateV1Attestation(ðpbv1.Attestation{}), + Aggregate: util.HydrateV1Attestation(ðpbv1.Attestation{}), SelectionProof: selectionProof, }, Signature: signature, @@ -443,7 +443,7 @@ func Test_V1SignedAggregateAttAndProofToV1Alpha1(t *testing.T) { } func Test_V1AttestationToV1Alpha1(t *testing.T) { - v1Att := util.NewAttestationUtil().HydrateV1Attestation(ðpbv1.Attestation{}) + v1Att := util.HydrateV1Attestation(ðpbv1.Attestation{}) v1Alpha1Att := V1AttToV1Alpha1(v1Att) v1Root, err := v1Att.HashTreeRoot() diff --git a/testing/util/altair.go b/testing/util/altair.go index a25b917ad5..8a814e65f6 100644 --- a/testing/util/altair.go +++ b/testing/util/altair.go @@ -352,7 +352,7 @@ func GenerateFullBlockAltair( numToGen = conf.NumAttestations var atts []*ethpb.Attestation if numToGen > 0 { - atts, err = NewAttestationUtil().GenerateAttestations(bState, privs, numToGen, slot, false) + atts, err = GenerateAttestations(bState, privs, numToGen, slot, false) if err != nil { return nil, errors.Wrapf(err, "failed generating %d attestations:", numToGen) } diff --git a/testing/util/attestation.go b/testing/util/attestation.go index 971fdbf2dc..c34de8971d 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -25,16 +25,8 @@ import ( log "github.com/sirupsen/logrus" ) -// AttestationUtil is an empty struct used as the receiver for all attestation utility methods. -type AttestationUtil struct{} - -// NewAttestationUtil returns a set of attestation utilities. -func NewAttestationUtil() *AttestationUtil { - return &AttestationUtil{} -} - // NewAttestation creates an attestation block with minimum marshalable fields. -func (u *AttestationUtil) NewAttestation() *ethpb.Attestation { +func NewAttestation() *ethpb.Attestation { return ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0b1101}, Data: ðpb.AttestationData{ @@ -57,7 +49,7 @@ func (u *AttestationUtil) NewAttestation() *ethpb.Attestation { // for the same data with their aggregation bits split uniformly. // // If you request 4 attestations, but there are 8 committees, you will get 4 fully aggregated attestations. -func (u *AttestationUtil) GenerateAttestations( +func GenerateAttestations( bState state.BeaconState, privs []bls.SecretKey, numToGen uint64, slot types.Slot, randomRoot bool, ) ([]*ethpb.Attestation, error) { var attestations []*ethpb.Attestation @@ -213,7 +205,7 @@ func (u *AttestationUtil) GenerateAttestations( // HydrateAttestation hydrates an attestation object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func (u *AttestationUtil) HydrateAttestation(a *ethpb.Attestation) *ethpb.Attestation { +func HydrateAttestation(a *ethpb.Attestation) *ethpb.Attestation { if a.Signature == nil { a.Signature = make([]byte, 96) } @@ -223,13 +215,13 @@ func (u *AttestationUtil) HydrateAttestation(a *ethpb.Attestation) *ethpb.Attest if a.Data == nil { a.Data = ðpb.AttestationData{} } - a.Data = u.HydrateAttestationData(a.Data) + a.Data = HydrateAttestationData(a.Data) return a } // HydrateV1Attestation hydrates a v1 attestation object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func (u *AttestationUtil) HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { +func HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { if a.Signature == nil { a.Signature = make([]byte, 96) } @@ -239,13 +231,13 @@ func (u *AttestationUtil) HydrateV1Attestation(a *attv1.Attestation) *attv1.Atte if a.Data == nil { a.Data = &attv1.AttestationData{} } - a.Data = u.HydrateV1AttestationData(a.Data) + a.Data = HydrateV1AttestationData(a.Data) return a } // HydrateAttestationData hydrates an attestation data object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func (u *AttestationUtil) HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { +func HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { if d.BeaconBlockRoot == nil { d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } @@ -266,7 +258,7 @@ func (u *AttestationUtil) HydrateAttestationData(d *ethpb.AttestationData) *ethp // HydrateV1AttestationData hydrates a v1 attestation data object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func (u *AttestationUtil) HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { +func HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { if d.BeaconBlockRoot == nil { d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } @@ -287,13 +279,13 @@ func (u *AttestationUtil) HydrateV1AttestationData(d *attv1.AttestationData) *at // HydrateIndexedAttestation hydrates an indexed attestation with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func (u *AttestationUtil) HydrateIndexedAttestation(a *ethpb.IndexedAttestation) *ethpb.IndexedAttestation { +func HydrateIndexedAttestation(a *ethpb.IndexedAttestation) *ethpb.IndexedAttestation { if a.Signature == nil { a.Signature = make([]byte, 96) } if a.Data == nil { a.Data = ðpb.AttestationData{} } - a.Data = u.HydrateAttestationData(a.Data) + a.Data = HydrateAttestationData(a.Data) return a } diff --git a/testing/util/attestation_test.go b/testing/util/attestation_test.go index f2598d444f..4ac8874967 100644 --- a/testing/util/attestation_test.go +++ b/testing/util/attestation_test.go @@ -11,14 +11,14 @@ import ( ) func TestHydrateAttestation(t *testing.T) { - a := NewAttestationUtil().HydrateAttestation(ðpb.Attestation{}) + a := HydrateAttestation(ðpb.Attestation{}) _, err := a.HashTreeRoot() require.NoError(t, err) require.DeepEqual(t, a.Signature, make([]byte, fieldparams.BLSSignatureLength)) } func TestHydrateAttestationData(t *testing.T) { - d := NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}) + d := HydrateAttestationData(ðpb.AttestationData{}) _, err := d.HashTreeRoot() require.NoError(t, err) require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength)) @@ -27,14 +27,14 @@ func TestHydrateAttestationData(t *testing.T) { } func TestHydrateV1Attestation(t *testing.T) { - a := NewAttestationUtil().HydrateV1Attestation(&v1.Attestation{}) + a := HydrateV1Attestation(&v1.Attestation{}) _, err := a.HashTreeRoot() require.NoError(t, err) require.DeepEqual(t, a.Signature, make([]byte, fieldparams.BLSSignatureLength)) } func TestHydrateV1AttestationData(t *testing.T) { - d := NewAttestationUtil().HydrateV1AttestationData(&v1.AttestationData{}) + d := HydrateV1AttestationData(&v1.AttestationData{}) _, err := d.HashTreeRoot() require.NoError(t, err) require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength)) @@ -44,7 +44,7 @@ func TestHydrateV1AttestationData(t *testing.T) { func TestHydrateIndexedAttestation(t *testing.T) { a := ðpb.IndexedAttestation{} - a = NewAttestationUtil().HydrateIndexedAttestation(a) + a = HydrateIndexedAttestation(a) _, err := a.HashTreeRoot() require.NoError(t, err) _, err = a.Data.HashTreeRoot() @@ -53,6 +53,6 @@ func TestHydrateIndexedAttestation(t *testing.T) { func TestGenerateAttestations_EpochBoundary(t *testing.T) { gs, pk := DeterministicGenesisState(t, 32) - _, err := NewAttestationUtil().GenerateAttestations(gs, pk, 1, params.BeaconConfig().SlotsPerEpoch, false) + _, err := GenerateAttestations(gs, pk, 1, params.BeaconConfig().SlotsPerEpoch, false) require.NoError(t, err) } diff --git a/testing/util/block.go b/testing/util/block.go index 924b73278c..ffcf822aab 100644 --- a/testing/util/block.go +++ b/testing/util/block.go @@ -113,7 +113,7 @@ func GenerateFullBlock( numToGen = conf.NumAttestations var atts []*ethpb.Attestation if numToGen > 0 { - atts, err = NewAttestationUtil().GenerateAttestations(bState, privs, numToGen, slot, false) + atts, err = GenerateAttestations(bState, privs, numToGen, slot, false) if err != nil { return nil, errors.Wrapf(err, "failed generating %d attestations:", numToGen) } diff --git a/tools/benchmark-files-gen/main.go b/tools/benchmark-files-gen/main.go index ad2c1dd791..bc2e9db8f3 100644 --- a/tools/benchmark-files-gen/main.go +++ b/tools/benchmark-files-gen/main.go @@ -122,7 +122,7 @@ func generateMarshalledFullStateAndBlock() error { var atts []*ethpb.Attestation for i := slotOffset + 1; i < slotsPerEpoch+slotOffset; i++ { - attsForSlot, err := util.NewAttestationUtil().GenerateAttestations(beaconState, privs, attConfig.NumAttestations, i, false) + attsForSlot, err := util.GenerateAttestations(beaconState, privs, attConfig.NumAttestations, i, false) if err != nil { return err } diff --git a/validator/client/aggregate_test.go b/validator/client/aggregate_test.go index 62cf39b730..161a5e1c32 100644 --- a/validator/client/aggregate_test.go +++ b/validator/client/aggregate_test.go @@ -57,7 +57,7 @@ func TestSubmitAggregateAndProof_SignFails(t *testing.T) { ).Return(ðpb.AggregateSelectionResponse{ AggregateAndProof: ðpb.AggregateAttestationAndProof{ AggregatorIndex: 0, - Aggregate: util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + Aggregate: util.HydrateAttestation(ðpb.Attestation{ AggregationBits: make([]byte, 1), }), SelectionProof: make([]byte, 96), @@ -96,7 +96,7 @@ func TestSubmitAggregateAndProof_Ok(t *testing.T) { ).Return(ðpb.AggregateSelectionResponse{ AggregateAndProof: ðpb.AggregateAttestationAndProof{ AggregatorIndex: 0, - Aggregate: util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + Aggregate: util.HydrateAttestation(ðpb.Attestation{ AggregationBits: make([]byte, 1), }), SelectionProof: make([]byte, 96), @@ -159,7 +159,7 @@ func TestAggregateAndProofSignature_CanSignValidSignature(t *testing.T) { agg := ðpb.AggregateAttestationAndProof{ AggregatorIndex: 0, - Aggregate: util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ + Aggregate: util.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(1), }), SelectionProof: make([]byte, 96), diff --git a/validator/client/attest_test.go b/validator/client/attest_test.go index c29a45e4dd..a0939845a4 100644 --- a/validator/client/attest_test.go +++ b/validator/client/attest_test.go @@ -461,7 +461,7 @@ func TestSignAttestation(t *testing.T) { DomainData(gomock.Any(), gomock.Any()). Return(ðpb.DomainResponse{SignatureDomain: attesterDomain}, nil) ctx := context.Background() - att := util.NewAttestationUtil().NewAttestation() + att := util.NewAttestation() att.Data.Source.Epoch = 100 att.Data.Target.Epoch = 200 att.Data.Slot = 999