diff --git a/beacon-chain/blockchain/metrics_test.go b/beacon-chain/blockchain/metrics_test.go index f7e58ed8d3..5c3d42536e 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.HydrateAttestationData(ð.AttestationData{})})) + require.NoError(t, h.AppendCurrentEpochAttestations(ð.PendingAttestation{InclusionDelay: 1, Data: util.NewAttestationUtil().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 b137f5ed6b..b7d69e2fef 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -70,6 +70,7 @@ 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 @@ -77,17 +78,17 @@ func TestStore_OnAttestation_ErrorConditions_ProtoArray(t *testing.T) { }{ { name: "attestation's data slot not aligned with target vote", - a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), + a: au.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: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), + a: au.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: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, + a: au.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", }, @@ -176,6 +177,7 @@ 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 @@ -183,17 +185,17 @@ func TestStore_OnAttestation_ErrorConditions_DoublyLinkedTree(t *testing.T) { }{ { name: "attestation's data slot not aligned with target vote", - a: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Root: make([]byte, 32)}}}), + a: au.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: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}), + a: au.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: util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 100 * params.BeaconConfig().SlotsPerEpoch, Target: ðpb.Checkpoint{Epoch: 100, + a: au.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", }, @@ -249,7 +251,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.GenerateAttestations(genesisState, pks, 1, 0, false) + att, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(att[0].Data.Target.Root) copied := genesisState.Copy() @@ -279,7 +281,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.GenerateAttestations(genesisState, pks, 1, 0, false) + att, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(att[0].Data.Target.Root) copied := genesisState.Copy() @@ -422,8 +424,7 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) { opts := testServiceOptsWithDB(t) service, err := NewService(ctx, opts...) require.NoError(t, err) - - d := util.HydrateAttestationData(ðpb.AttestationData{}) + d := util.NewAttestationUtil().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 8de349a3ed..537269c1a4 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -1606,8 +1606,9 @@ 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 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -1622,7 +1623,7 @@ func TestService_insertSlashingsToForkChoiceStore(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.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 a7976906f8..8b9b80bbb0 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.NewAttestation() + a := util.NewAttestationUtil().NewAttestation() a.Data.Target.Epoch = 1 a.Data.Target.Root = []byte{'a'} a.Data.BeaconBlockRoot = r33[:] @@ -85,8 +85,7 @@ 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.NewAttestation() + a := util.NewAttestationUtil().NewAttestation() a.Data.Target.Epoch = 1 a.Data.Target.Root = r32[:] a.Data.BeaconBlockRoot = r33[:] @@ -106,7 +105,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.GenerateAttestations(genesisState, pks, 1, 0, false) + atts, err := util.NewAttestationUtil().GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) tRoot := bytesutil.ToBytes32(atts[0].Data.Target.Root) copied := genesisState.Copy() @@ -227,7 +226,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.GenerateAttestations(copied, pks, 1, 1, false) + atts, err := util.NewAttestationUtil().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 813497e965..2f6f809a2d 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.HydrateAttestation(ðpb.Attestation{ + util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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 b3aec2b767..f20db63f37 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.HydrateAttestationData(ðpb.AttestationData{ + data := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ Signature: sig[:], }) for _, tt := range tests { @@ -261,11 +261,12 @@ 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: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 2, }, @@ -275,7 +276,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 1, }, @@ -284,7 +285,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 4, }, @@ -293,7 +294,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { Signature: make([]byte, fieldparams.BLSSignatureLength), }}, {attestation: ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{ Epoch: 7, }, @@ -411,7 +412,8 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) { comm1, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - att1 := util.HydrateAttestation(ðpb.Attestation{ + au := util.AttestationUtil{} + att1 := au.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -430,7 +432,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 := util.HydrateAttestation(ðpb.Attestation{ + att2 := au.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), Data: ðpb.AttestationData{ Slot: 1*params.BeaconConfig().SlotsPerEpoch + 1, @@ -470,7 +472,8 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing comm1, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - att1 := util.HydrateAttestation(ðpb.Attestation{ + au := util.AttestationUtil{} + att1 := au.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -489,7 +492,7 @@ func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing comm2, err := helpers.BeaconCommitteeFromState(context.Background(), st, 1 /*slot*/, 1 /*committeeIndex*/) require.NoError(t, err) - att2 := util.HydrateAttestation(ðpb.Attestation{ + att2 := au.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm2))), Data: ðpb.AttestationData{ Slot: 1, @@ -534,7 +537,8 @@ func TestRetrieveAttestationSignatureSet_AcrossFork(t *testing.T) { comm1, err := helpers.BeaconCommitteeFromState(ctx, st, 1 /*slot*/, 0 /*committeeIndex*/) require.NoError(t, err) - att1 := util.HydrateAttestation(ðpb.Attestation{ + au := util.AttestationUtil{} + att1 := au.HydrateAttestation(ðpb.Attestation{ AggregationBits: bitfield.NewBitlist(uint64(len(comm1))), Data: ðpb.AttestationData{ Slot: 1, @@ -553,7 +557,7 @@ func TestRetrieveAttestationSignatureSet_AcrossFork(t *testing.T) { comm2, err := helpers.BeaconCommitteeFromState(ctx, st, 1 /*slot*/, 1 /*committeeIndex*/) require.NoError(t, err) - att2 := util.HydrateAttestation(ðpb.Attestation{ + att2 := au.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 46b8edcc31..88ed35e822 100644 --- a/beacon-chain/core/blocks/attester_slashing_test.go +++ b/beacon-chain/core/blocks/attester_slashing_test.go @@ -19,11 +19,12 @@ import ( ) func TestSlashableAttestationData_CanSlash(t *testing.T) { - att1 := util.HydrateAttestationData(ðpb.AttestationData{ + au := util.AttestationUtil{} + att1 := au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}, }) - att2 := util.HydrateAttestationData(ðpb.AttestationData{ + att2 := au.HydrateAttestationData(ðpb.AttestationData{ Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'B'}, 32)}, }) @@ -35,9 +36,10 @@ func TestSlashableAttestationData_CanSlash(t *testing.T) { } func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) { + au := util.AttestationUtil{} slashings := []*ethpb.AttesterSlashing{{ - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{}), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{}), + Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, Target: ðpb.Checkpoint{Epoch: 1}}, @@ -71,15 +73,16 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T) }) require.NoError(t, err) + au := util.AttestationUtil{} slashings := []*ethpb.AttesterSlashing{ { - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), }), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: make([]uint64, params.BeaconConfig().MaxValidatorsPerCommittee+1), }), }, @@ -102,7 +105,8 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -117,7 +121,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -171,7 +175,8 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -186,7 +191,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusAltair(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) signingRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -240,7 +245,8 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) { vv.WithdrawableEpoch = types.Epoch(params.BeaconConfig().SlotsPerEpoch) } - att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -255,7 +261,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatusBellatrix(t *testing.T) { aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.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 d8e01bf6f3..1e0147cfff 100644 --- a/beacon-chain/core/blocks/block_regression_test.go +++ b/beacon-chain/core/blocks/block_regression_test.go @@ -39,8 +39,9 @@ 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: util.HydrateAttestationData(ðpb.AttestationData{Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]}}), + Data: au.HydrateAttestationData(ðpb.AttestationData{Target: ðpb.Checkpoint{Epoch: 0, Root: root1[:]}}), AttestingIndices: setA, Signature: make([]byte, 96), } @@ -58,7 +59,7 @@ func TestProcessAttesterSlashings_RegressionSlashableIndices(t *testing.T) { root2 := [32]byte{'d', 'o', 'u', 'b', 'l', 'e', '2'} att2 := ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.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 54e4d05e0a..259aba2749 100644 --- a/beacon-chain/core/transition/transition_test.go +++ b/beacon-chain/core/transition/transition_test.go @@ -133,15 +133,16 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { }), }, } + au := util.AttestationUtil{} attesterSlashings := []*ethpb.AttesterSlashing{ { Attestation_1: ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{}), + Data: au.HydrateAttestationData(ðpb.AttestationData{}), AttestingIndices: []uint64{0, 1}, Signature: make([]byte, 96), }, Attestation_2: ðpb.IndexedAttestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{}), + Data: au.HydrateAttestationData(ðpb.AttestationData{}), AttestingIndices: []uint64{0, 1}, Signature: make([]byte, 96), }, @@ -152,7 +153,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) { blockRoots = append(blockRoots, []byte{byte(i)}) } require.NoError(t, beaconState.SetBlockRoots(blockRoots)) - blockAtt := util.HydrateAttestation(ðpb.Attestation{ + blockAtt := au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("hello-world"), 32)}, }, @@ -255,7 +256,8 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, require.NoError(t, beaconState.SetValidators(validators)) mockRoot2 := [32]byte{'A'} - att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot2[:]}, }, @@ -271,7 +273,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, att1.Signature = aggregateSig.Marshal() mockRoot3 := [32]byte{'B'} - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]}, Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, @@ -301,7 +303,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, aggBits := bitfield.NewBitlist(1) aggBits.SetBitAt(0, true) - blockAtt := util.HydrateAttestation(ðpb.Attestation{ + blockAtt := au.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 50c1ed38c5..fa7136b2d3 100644 --- a/beacon-chain/monitor/process_block_test.go +++ b/beacon-chain/monitor/process_block_test.go @@ -18,6 +18,7 @@ import ( ) func TestProcessSlashings(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string block *ethpb.BeaconBlock @@ -77,13 +78,13 @@ func TestProcessSlashings(t *testing.T) { Body: ðpb.BeaconBlockBody{ AttesterSlashings: []*ethpb.AttesterSlashing{ { - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: []uint64{1, 3, 4}, }), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{1, 5, 6}, }), }, @@ -99,13 +100,13 @@ func TestProcessSlashings(t *testing.T) { Body: ðpb.BeaconBlockBody{ AttesterSlashings: []*ethpb.AttesterSlashing{ { - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, AttestingIndices: []uint64{1, 3, 4}, }), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: au.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 b23cbdd69d..84b1958ed0 100644 --- a/beacon-chain/operations/attestations/kv/aggregated_test.go +++ b/beacon-chain/operations/attestations/kv/aggregated_test.go @@ -23,14 +23,15 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { require.NoError(t, err) sig1 := priv.Sign([]byte{'a'}) sig2 := priv.Sign([]byte{'b'}) - 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()}) + 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()}) atts := []*ethpb.Attestation{att1, att2, att3, att4, att5, att6, att7, att8} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) require.NoError(t, cache.AggregateUnaggregatedAttestations(context.Background())) @@ -42,7 +43,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.HydrateAttestationData(ðpb.AttestationData{ + return util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{ Slot: slot, CommitteeIndex: committeeIndex, }) @@ -95,6 +96,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestationsBySlotIndex(t *testing.T } func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string att *ethpb.Attestation @@ -113,14 +115,14 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "not aggregated", - att: util.HydrateAttestation(ðpb.Attestation{ + att: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0b10100}}), wantErrString: "attestation is not aggregated", }, { name: "invalid hash", att: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ BeaconBlockRoot: []byte{0b0}, }), AggregationBits: bitfield.Bitlist{0b10111}, @@ -129,7 +131,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "already seen", - att: util.HydrateAttestation(ðpb.Attestation{ + att: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 100, }, @@ -139,7 +141,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { }, { name: "normal save", - att: util.HydrateAttestation(ðpb.Attestation{ + att: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -148,7 +150,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { count: 1, }, } - r, err := hashFn(util.HydrateAttestationData(ðpb.AttestationData{ + r, err := hashFn(au.HydrateAttestationData(ðpb.AttestationData{ Slot: 100, })) require.NoError(t, err) @@ -172,6 +174,7 @@ func TestKV_Aggregated_SaveAggregatedAttestation(t *testing.T) { } func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string atts []*ethpb.Attestation @@ -181,9 +184,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) { { name: "no duplicates", atts: []*ethpb.Attestation{ - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), }, count: 1, @@ -207,6 +210,7 @@ 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 @@ -216,9 +220,9 @@ func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) { name: "the first attestation is bad", atts: []*ethpb.Attestation{ - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1100}}), - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}), }, count: 1, @@ -243,10 +247,11 @@ func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) func TestKV_Aggregated_AggregatedAttestations(t *testing.T) { cache := NewAttCaches() + au := util.AttestationUtil{} - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -261,16 +266,17 @@ 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 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}, Data: ðpb.AttestationData{Slot: 2}}) + att := au.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 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2}}) + att := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1001}, Data: ðpb.AttestationData{Slot: 2}}) err := cache.DeleteAggregatedAttestation(att) assert.ErrorContains(t, "attestation is not aggregated", err) }) @@ -292,16 +298,16 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { t.Run("nonexistent attestation", func(t *testing.T) { cache := NewAttCaches() - att := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}) + att := au.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 := 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) require.NoError(t, cache.DeleteAggregatedAttestation(att1)) @@ -314,10 +320,10 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { t.Run("filtered deletion", func(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3, att4} require.NoError(t, cache.SaveAggregatedAttestations(atts)) @@ -334,6 +340,7 @@ func TestKV_Aggregated_DeleteAggregatedAttestation(t *testing.T) { } func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string existing []*ethpb.Attestation @@ -357,7 +364,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "empty cache aggregated", - input: util.HydrateAttestation(ðpb.Attestation{ + input: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -366,7 +373,7 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { }, { name: "empty cache unaggregated", - input: util.HydrateAttestation(ðpb.Attestation{ + input: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 1, }, @@ -376,13 +383,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with exact match", existing: []*ethpb.Attestation{{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, @@ -391,13 +398,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with subset aggregation", existing: []*ethpb.Attestation{{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1110}}, @@ -406,13 +413,13 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { { name: "single attestation in cache with superset aggregation", existing: []*ethpb.Attestation{{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1110}}, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111}}, @@ -422,20 +429,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: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100000}}, @@ -445,20 +452,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: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111111}}, @@ -468,20 +475,20 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "multiple attestations with different data in cache", existing: []*ethpb.Attestation{ { - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, { - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 3, }), AggregationBits: bitfield.Bitlist{0b1100111}, }, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 1, }), AggregationBits: bitfield.Bitlist{0b1111111}}, @@ -491,14 +498,14 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { name: "attestations with different bitlist lengths", existing: []*ethpb.Attestation{ { - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111000}, }, }, input: ðpb.Attestation{ - Data: util.HydrateAttestationData(ðpb.AttestationData{ + Data: au.HydrateAttestationData(ðpb.AttestationData{ Slot: 2, }), AggregationBits: bitfield.Bitlist{0b1111}, @@ -540,8 +547,9 @@ func TestKV_Aggregated_HasAggregatedAttestation(t *testing.T) { func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) 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 c197002963..a3aed55be4 100644 --- a/beacon-chain/operations/attestations/kv/block_test.go +++ b/beacon-chain/operations/attestations/kv/block_test.go @@ -14,16 +14,17 @@ import ( func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { require.NoError(t, cache.SaveBlockAttestation(att)) } // Diff bit length should not panic. - att4 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b11011}}) + att4 := au.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) } @@ -40,9 +41,10 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) { func TestKV_BlockAttestation_CanDelete(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) 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 610ce34200..7dd4426324 100644 --- a/beacon-chain/operations/attestations/kv/forkchoice_test.go +++ b/beacon-chain/operations/attestations/kv/forkchoice_test.go @@ -14,9 +14,10 @@ import ( func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -35,9 +36,10 @@ func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) { func TestKV_Forkchoice_CanDelete(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3} for _, att := range atts { @@ -55,9 +57,10 @@ func TestKV_Forkchoice_CanDelete(t *testing.T) { func TestKV_Forkchoice_CanCount(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) 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 b81492e1a8..d9a5e11047 100644 --- a/beacon-chain/operations/attestations/kv/seen_bits_test.go +++ b/beacon-chain/operations/attestations/kv/seen_bits_test.go @@ -12,20 +12,21 @@ import ( func TestAttCaches_hasSeenBit(t *testing.T) { c := NewAttCaches() - seenA1 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) - seenA2 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b11100000}}) + au := util.AttestationUtil{} + seenA1 := au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) + seenA2 := au.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: 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}, + {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}, } for _, tt := range tests { got, err := c.hasSeenBit(tt.att) @@ -38,7 +39,8 @@ func TestAttCaches_hasSeenBit(t *testing.T) { func TestAttCaches_insertSeenBitDuplicates(t *testing.T) { c := NewAttCaches() - att1 := util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10000011}}) + + att1 := util.NewAttestationUtil().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 a42f863417..e71414b731 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated_test.go +++ b/beacon-chain/operations/attestations/kv/unaggregated_test.go @@ -17,6 +17,7 @@ import ( ) func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string att *ethpb.Attestation @@ -43,12 +44,12 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { }, { name: "normal save", - att: util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}}), + att: au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b0001}}), count: 1, }, { name: "already seen", - att: util.HydrateAttestation(ðpb.Attestation{ + att: au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: 100, }, @@ -57,7 +58,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { count: 0, }, } - r, err := hashFn(util.HydrateAttestationData(ðpb.AttestationData{Slot: 100})) + r, err := hashFn(au.HydrateAttestationData(ðpb.AttestationData{Slot: 100})) require.NoError(t, err) for _, tt := range tests { @@ -83,6 +84,7 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) { } func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { + au := util.AttestationUtil{} tests := []struct { name string atts []*ethpb.Attestation @@ -92,18 +94,18 @@ func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) { { name: "unaggregated only", atts: []*ethpb.Attestation{ - 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}}), + 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}}), }, count: 3, }, { name: "has aggregated", atts: []*ethpb.Attestation{ - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}}), {AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}, - util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), + au.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}}), }, wantErrString: "attestation is aggregated", count: 1, @@ -141,10 +143,11 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) { }) t.Run("successful deletion", func(t *testing.T) { + au := util.AttestationUtil{} cache := NewAttCaches() - 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}}) + 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}}) atts := []*ethpb.Attestation{att1, att2, att3} require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) for _, att := range atts { @@ -157,7 +160,8 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) { } func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { - d := util.HydrateAttestationData(ðpb.AttestationData{}) + au := util.AttestationUtil{} + d := au.HydrateAttestationData(ðpb.AttestationData{}) t.Run("no attestations", func(t *testing.T) { cache := NewAttCaches() @@ -169,9 +173,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("none seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - 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}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -186,9 +190,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("some seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - 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}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -211,9 +215,9 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { t.Run("all seen", func(t *testing.T) { cache := NewAttCaches() atts := []*ethpb.Attestation{ - 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}}), + 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}}), } require.NoError(t, cache.SaveUnaggregatedAttestations(atts)) assert.Equal(t, 3, cache.UnaggregatedAttestationCount()) @@ -236,9 +240,10 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) { func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) { cache := NewAttCaches() - 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}}) + 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}}) 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 295538c50f..575f3b3658 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.HydrateAttestationData(ðpb.AttestationData{}) + ad1 := util.NewAttestationUtil().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) { - ad1 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) - - ad2 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 2}) + au := util.AttestationUtil{} + ad1 := au.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) + ad2 := au.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 70e511b692..97f8e7e12c 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) - ad1 := util.HydrateAttestationData(ðpb.AttestationData{}) - - ad2 := util.HydrateAttestationData(ðpb.AttestationData{Slot: 1}) + au := util.AttestationUtil{} + ad1 := au.HydrateAttestationData(ðpb.AttestationData{}) + ad2 := au.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) - ad1 := util.HydrateAttestationData(ðpb.AttestationData{}) - - ad2 := util.HydrateAttestationData(ðpb.AttestationData{}) + au := util.AttestationUtil{} + ad1 := au.HydrateAttestationData(ðpb.AttestationData{}) + ad2 := au.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 9a5c938d8e..592943afb0 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.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) + msg := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.NewBitlist(7)}) + msg := util.NewAttestationUtil().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 6ae7d5879f..2627266c91 100644 --- a/beacon-chain/rpc/eth/beacon/blocks_test.go +++ b/beacon-chain/rpc/eth/beacon/blocks_test.go @@ -41,10 +41,11 @@ 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) - att1 := util.NewAttestation() + au := util.AttestationUtil{} + att1 := au.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() + att2 := au.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} @@ -84,10 +85,11 @@ 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) - att1 := util.NewAttestation() + au := util.AttestationUtil{} + att1 := au.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() + att2 := au.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpbalpha.Attestation{att1, att2} @@ -126,10 +128,11 @@ 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) - att1 := util.NewAttestation() + au := util.AttestationUtil{} + att1 := au.NewAttestation() att1.Data.Slot = i att1.Data.CommitteeIndex = types.CommitteeIndex(i) - att2 := util.NewAttestation() + att2 := au.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 10d3b06838..ca044a3f98 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.HydrateAttestation(ð.Attestation{ + wantedAttV1alpha1 := util.NewAttestationUtil().HydrateAttestation(ð.Attestation{ Data: ð.AttestationData{ Slot: 8, }, @@ -127,7 +127,7 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { defer ctrl.Finish() wantedAttV1alpha1 := ð.AggregateAttestationAndProof{ - Aggregate: util.HydrateAttestation(ð.Attestation{}), + Aggregate: util.NewAttestationUtil().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 74138ed6a5..a314781a79 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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + util.NewAttestationUtil().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.NewAttestation() + att := util.NewAttestationUtil().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.NewAttestation() + att := util.NewAttestationUtil().NewAttestation() att.Data.Slot = types.Slot(i) atts[i] = att } @@ -1031,10 +1031,11 @@ func TestServer_StreamAttestations_OnSlotTick(t *testing.T) { AttestationNotifier: chainService.OperationNotifier(), } + au := util.AttestationUtil{} atts := []*ethpb.Attestation{ - 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}}), + 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}}), } 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 5d67a497fd..a066e043b0 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.HydrateAttestationData(ðpb.AttestationData{}), + Data: util.NewAttestationUtil().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.HydrateAttestationData(ðpb.AttestationData{}), + Data: util.NewAttestationUtil().HydrateAttestationData(ðpb.AttestationData{}), InclusionDelay: 1, AggregationBits: bitfield.NewBitlist(validatorCount / uint64(params.BeaconConfig().SlotsPerEpoch)), }} @@ -2292,9 +2292,10 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) { require.NoError(t, beaconState.SetValidators(stateWithValidators.Validators())) bf := bitfield.NewBitlist(validators / uint64(params.BeaconConfig().SlotsPerEpoch)) - att1 := util.NewAttestation() + au := util.AttestationUtil{} + att1 := au.NewAttestation() att1.AggregationBits = bf - att2 := util.NewAttestation() + att2 := au.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 4c9461ef5e..909de82af9 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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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 77ed0b5bbe..4047fed606 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.HydrateAttestation(ðpb.Attestation{}) + req := util.NewAttestationUtil().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 a8e24608de..92448bba90 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_test.go @@ -14,21 +14,22 @@ import ( ) func TestProposer_ProposerAtts_sortByProfitability(t *testing.T) { + au := util.AttestationUtil{} atts := proposerAtts([]*ethpb.Attestation{ - 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}}), + 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}}), }) want := proposerAtts([]*ethpb.Attestation{ - 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}}), + 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}}), }) atts, err := atts.sortByProfitability() if err != nil { @@ -45,7 +46,7 @@ func TestProposer_ProposerAtts_sortByProfitabilityUsingMaxCover(t *testing.T) { getAtts := func(data []testData) proposerAtts { var atts proposerAtts for _, att := range data { - atts = append(atts, util.HydrateAttestation(ðpb.Attestation{ + atts = append(atts, util.NewAttestationUtil().HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{Slot: att.slot}, AggregationBits: att.bits})) } return atts @@ -189,10 +190,11 @@ func TestProposer_ProposerAtts_sortByProfitabilityUsingMaxCover(t *testing.T) { } func TestProposer_ProposerAtts_dedup(t *testing.T) { - data1 := util.HydrateAttestationData(ðpb.AttestationData{ + au := util.AttestationUtil{} + data1 := au.HydrateAttestationData(ðpb.AttestationData{ Slot: 4, }) - data2 := util.HydrateAttestationData(ðpb.AttestationData{ + data2 := au.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 4821095e62..14dae067a5 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -148,8 +148,9 @@ 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 := util.GenerateAttestations(beaconState, privKeys, 4, 1, true) + a, err := au.GenerateAttestations(beaconState, privKeys, 4, 1, true) require.NoError(t, err) atts = append(atts, a...) } @@ -160,7 +161,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 := util.GenerateAttestations(beaconState, privKeys, 300, 1, true) + atts, err := au.GenerateAttestations(beaconState, privKeys, 300, 1, true) require.NoError(t, err) found := false for _, a := range atts { @@ -1815,6 +1816,7 @@ func TestProposer_FilterAttestation(t *testing.T) { genesisRoot, err := genesis.Block.HashTreeRoot() require.NoError(t, err) + au := util.AttestationUtil{} tests := []struct { name string wantedErr string @@ -1835,7 +1837,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] = util.HydrateAttestation(ðpb.Attestation{ + atts[i] = au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: types.CommitteeIndex(i), }, @@ -1852,7 +1854,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] = util.HydrateAttestation(ðpb.Attestation{ + atts[i] = au.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ CommitteeIndex: types.CommitteeIndex(i), Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, @@ -2011,12 +2013,13 @@ 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{ - 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})} + 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})} unaggregatedAtts := []*ethpb.Attestation{ - 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})} + 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})} 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 26ec523e17..3add88b98b 100644 --- a/beacon-chain/slasher/process_slashings_test.go +++ b/beacon-chain/slasher/process_slashings_test.go @@ -50,10 +50,11 @@ func TestService_processAttesterSlashings(t *testing.T) { }, } - firstAtt := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + firstAtt := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0}, }) - secondAtt := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + secondAtt := au.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 c1976df477..844d00cace 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.HydrateAttestationData(ðpb.AttestationData{}), + Data: util.NewAttestationUtil().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 2dfeb72d48..411c4265eb 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.HydrateAttestation(ðpb.Attestation{ + Aggregate: util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + Aggregate: util.NewAttestationUtil().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 98de24ede8..1e30c97923 100644 --- a/beacon-chain/sync/subscriber_beacon_blocks_test.go +++ b/beacon-chain/sync/subscriber_beacon_blocks_test.go @@ -25,10 +25,11 @@ func TestDeleteAttsInPool(t *testing.T) { cfg: &config{attPool: attestations.NewPool()}, } - 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}}) + 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}}) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att1)) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att2)) require.NoError(t, r.cfg.attPool.SaveAggregatedAttestation(att3)) @@ -42,11 +43,12 @@ func TestDeleteAttsInPool(t *testing.T) { } func TestService_beaconBlockSubscriber(t *testing.T) { + au := util.AttestationUtil{} pooledAttestations := []*ethpb.Attestation{ // Aggregated. - util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00011111}}), + au.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00011111}}), // Unaggregated. - util.HydrateAttestation(ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b00010001}}), + au.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 91d0fcceb3..414d718dea 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.HydrateAttestationData(ðpb.AttestationData{}) + data := util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + att := util.NewAttestationUtil().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 bf870c1969..ba7af9ccfd 100644 --- a/beacon-chain/sync/validate_attester_slashing_test.go +++ b/beacon-chain/sync/validate_attester_slashing_test.go @@ -33,7 +33,8 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be } require.NoError(t, s.SetValidators(vals)) - att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + au := util.AttestationUtil{} + att1 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 1}, }, @@ -48,7 +49,7 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be aggregateSig := bls.AggregateSignatures([]bls.Signature{sig0, sig1}) att1.Signature = aggregateSig.Marshal() - att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + att2 := au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{0, 1}, }) hashTreeRoot, err = signing.ComputeSigningRoot(att2.Data, domain) @@ -132,12 +133,13 @@ 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: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3}, }), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{3}, }), }) @@ -155,10 +157,10 @@ func TestValidateAttesterSlashing_CanFilter(t *testing.T) { buf = new(bytes.Buffer) _, err = p.Encoding().EncodeGossip(buf, ðpb.AttesterSlashing{ - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_1: au.HydrateIndexedAttestation(ðpb.IndexedAttestation{ AttestingIndices: []uint64{4, 3}, }), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ + Attestation_2: au.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 cbfb73ad1b..e0d525d3d3 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.HydrateAttestation(ðpbalpha.Attestation{ + att := util.NewAttestationUtil().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.HydrateV1Attestation(ðpbv1.Attestation{}), + Aggregate: util.NewAttestationUtil().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.HydrateV1Attestation(ðpbv1.Attestation{}) + v1Att := util.NewAttestationUtil().HydrateV1Attestation(ðpbv1.Attestation{}) v1Alpha1Att := V1AttToV1Alpha1(v1Att) v1Root, err := v1Att.HashTreeRoot() diff --git a/testing/util/altair.go b/testing/util/altair.go index 8a814e65f6..a25b917ad5 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 = GenerateAttestations(bState, privs, numToGen, slot, false) + atts, err = NewAttestationUtil().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 c34de8971d..971fdbf2dc 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -25,8 +25,16 @@ 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 NewAttestation() *ethpb.Attestation { +func (u *AttestationUtil) NewAttestation() *ethpb.Attestation { return ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0b1101}, Data: ðpb.AttestationData{ @@ -49,7 +57,7 @@ func 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 GenerateAttestations( +func (u *AttestationUtil) GenerateAttestations( bState state.BeaconState, privs []bls.SecretKey, numToGen uint64, slot types.Slot, randomRoot bool, ) ([]*ethpb.Attestation, error) { var attestations []*ethpb.Attestation @@ -205,7 +213,7 @@ func GenerateAttestations( // HydrateAttestation hydrates an attestation object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateAttestation(a *ethpb.Attestation) *ethpb.Attestation { +func (u *AttestationUtil) HydrateAttestation(a *ethpb.Attestation) *ethpb.Attestation { if a.Signature == nil { a.Signature = make([]byte, 96) } @@ -215,13 +223,13 @@ func HydrateAttestation(a *ethpb.Attestation) *ethpb.Attestation { if a.Data == nil { a.Data = ðpb.AttestationData{} } - a.Data = HydrateAttestationData(a.Data) + a.Data = u.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 HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { +func (u *AttestationUtil) HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { if a.Signature == nil { a.Signature = make([]byte, 96) } @@ -231,13 +239,13 @@ func HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { if a.Data == nil { a.Data = &attv1.AttestationData{} } - a.Data = HydrateV1AttestationData(a.Data) + a.Data = u.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 HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { +func (u *AttestationUtil) HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { if d.BeaconBlockRoot == nil { d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } @@ -258,7 +266,7 @@ func HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { // HydrateV1AttestationData hydrates a v1 attestation data object with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { +func (u *AttestationUtil) HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { if d.BeaconBlockRoot == nil { d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } @@ -279,13 +287,13 @@ func HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { // HydrateIndexedAttestation hydrates an indexed attestation with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateIndexedAttestation(a *ethpb.IndexedAttestation) *ethpb.IndexedAttestation { +func (u *AttestationUtil) 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 = HydrateAttestationData(a.Data) + a.Data = u.HydrateAttestationData(a.Data) return a } diff --git a/testing/util/attestation_test.go b/testing/util/attestation_test.go index 4ac8874967..f2598d444f 100644 --- a/testing/util/attestation_test.go +++ b/testing/util/attestation_test.go @@ -11,14 +11,14 @@ import ( ) func TestHydrateAttestation(t *testing.T) { - a := HydrateAttestation(ðpb.Attestation{}) + a := NewAttestationUtil().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 := HydrateAttestationData(ðpb.AttestationData{}) + d := NewAttestationUtil().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 := HydrateV1Attestation(&v1.Attestation{}) + a := NewAttestationUtil().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 := HydrateV1AttestationData(&v1.AttestationData{}) + d := NewAttestationUtil().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 = HydrateIndexedAttestation(a) + a = NewAttestationUtil().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 := GenerateAttestations(gs, pk, 1, params.BeaconConfig().SlotsPerEpoch, false) + _, err := NewAttestationUtil().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 ffcf822aab..924b73278c 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 = GenerateAttestations(bState, privs, numToGen, slot, false) + atts, err = NewAttestationUtil().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 bc2e9db8f3..ad2c1dd791 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.GenerateAttestations(beaconState, privs, attConfig.NumAttestations, i, false) + attsForSlot, err := util.NewAttestationUtil().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 161a5e1c32..62cf39b730 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.HydrateAttestation(ðpb.Attestation{ + Aggregate: util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + Aggregate: util.NewAttestationUtil().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.HydrateAttestation(ðpb.Attestation{ + Aggregate: util.NewAttestationUtil().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 a0939845a4..c29a45e4dd 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.NewAttestation() + att := util.NewAttestationUtil().NewAttestation() att.Data.Source.Epoch = 100 att.Data.Target.Epoch = 200 att.Data.Slot = 999