From d77616f705aa71d94aa6ae6085d9e5c90ba11ed8 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 11 Aug 2021 13:12:22 -0700 Subject: [PATCH] Fixes Issues Found by Goland IDE Code Inspect (#9368) * Ran code inspect * Update shared/testutil/altair.go Co-authored-by: Raul Jordan Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/core/altair/attestation_test.go | 6 +- beacon-chain/core/altair/sync_committee.go | 2 +- beacon-chain/db/kv/blocks.go | 52 ++++----- beacon-chain/db/kv/state_test.go | 2 +- beacon-chain/rpc/eth/v1/beacon/blocks_test.go | 37 ++++--- beacon-chain/rpc/eth/v1/beacon/pool.go | 4 +- .../rpc/eth/v1/beacon/validator_test.go | 4 +- beacon-chain/rpc/eth/v1/events/events_test.go | 18 ++-- beacon-chain/rpc/eth/v1/node/node.go | 14 +-- .../rpc/prysm/v1alpha1/beacon/attestations.go | 10 +- proto/migration/enums.go | 8 +- proto/migration/v1alpha1_to_v1.go | 100 +++++++++--------- proto/migration/v1alpha1_to_v1_test.go | 52 ++++----- proto/prysm/v1alpha1/wrapper/beacon_block.go | 2 +- .../v1alpha1/wrapper/beacon_block_test.go | 2 +- shared/bls/blst/public_key_test.go | 2 +- shared/clientstats/scrapers_test.go | 2 +- shared/testutil/altair.go | 22 ++-- validator/graffiti/parse_graffiti.go | 2 +- 19 files changed, 170 insertions(+), 171 deletions(-) diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index 4e0d23b6a9..14a06c8086 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -269,8 +269,8 @@ func TestMatchingStatus(t *testing.T) { for _, test := range tests { src, tgt, head, err := altair.MatchingStatus(test.inputState, test.inputData, test.inputCheckpt) require.NoError(t, err) - require.Equal(t, test.matchedSource, bool(src)) - require.Equal(t, test.matchedTarget, bool(tgt)) - require.Equal(t, test.matchedHead, bool(head)) + require.Equal(t, test.matchedSource, src) + require.Equal(t, test.matchedTarget, tgt) + require.Equal(t, test.matchedHead, head) } } diff --git a/beacon-chain/core/altair/sync_committee.go b/beacon-chain/core/altair/sync_committee.go index 5bf5c8dd1e..0a391b518e 100644 --- a/beacon-chain/core/altair/sync_committee.go +++ b/beacon-chain/core/altair/sync_committee.go @@ -182,7 +182,7 @@ func IsSyncCommitteeAggregator(sig []byte) (bool, error) { return bytesutil.FromBytes8(hashedSig[:8])%modulo == 0, nil } -// Validate Sync Message to ensure that the provided slot is valid. +// ValidateSyncMessageTime validates sync message to ensure that the provided slot is valid. func ValidateSyncMessageTime(slot types.Slot, genesisTime time.Time, clockDisparity time.Duration) error { if err := helpers.ValidateSlotClock(slot, uint64(genesisTime.Unix())); err != nil { return err diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index ab7ee9afa3..d75e96b8e2 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -26,21 +26,21 @@ var errInvalidSlotRange = errors.New("invalid end slot and start slot provided") func (s *Store) Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) { ctx, span := trace.StartSpan(ctx, "BeaconDB.Block") defer span.End() - // Return block from cache if it exists. + // Return blk from cache if it exists. if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok { return v.(block.SignedBeaconBlock), nil } - var block *ethpb.SignedBeaconBlock + var blk *ethpb.SignedBeaconBlock err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) enc := bkt.Get(blockRoot[:]) if enc == nil { return nil } - block = ðpb.SignedBeaconBlock{} - return decode(ctx, enc, block) + blk = ðpb.SignedBeaconBlock{} + return decode(ctx, enc, blk) }) - return wrapper.WrappedPhase0SignedBeaconBlock(block), err + return wrapper.WrappedPhase0SignedBeaconBlock(blk), err } // HeadBlock returns the latest canonical block in the Ethereum Beacon Chain. @@ -81,11 +81,11 @@ func (s *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]block.Sig for i := 0; i < len(keys); i++ { encoded := bkt.Get(keys[i]) - block := ðpb.SignedBeaconBlock{} - if err := decode(ctx, encoded, block); err != nil { + blk := ðpb.SignedBeaconBlock{} + if err := decode(ctx, encoded, blk); err != nil { return err } - blocks = append(blocks, wrapper.WrappedPhase0SignedBeaconBlock(block)) + blocks = append(blocks, wrapper.WrappedPhase0SignedBeaconBlock(blk)) blockRoots = append(blockRoots, bytesutil.ToBytes32(keys[i])) } return nil @@ -153,11 +153,11 @@ func (s *Store) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []bloc for i := 0; i < len(keys); i++ { encoded := bkt.Get(keys[i]) - block := ðpb.SignedBeaconBlock{} - if err := decode(ctx, encoded, block); err != nil { + blk := ðpb.SignedBeaconBlock{} + if err := decode(ctx, encoded, blk); err != nil { return err } - blocks = append(blocks, wrapper.WrappedPhase0SignedBeaconBlock(block)) + blocks = append(blocks, wrapper.WrappedPhase0SignedBeaconBlock(blk)) } return nil }) @@ -196,11 +196,11 @@ func (s *Store) deleteBlock(ctx context.Context, blockRoot [32]byte) error { if enc == nil { return nil } - block := ðpb.SignedBeaconBlock{} - if err := decode(ctx, enc, block); err != nil { + blk := ðpb.SignedBeaconBlock{} + if err := decode(ctx, enc, blk); err != nil { return err } - indicesByBucket := createBlockIndicesFromBlock(ctx, wrapper.WrappedPhase0BeaconBlock(block.Block)) + indicesByBucket := createBlockIndicesFromBlock(ctx, wrapper.WrappedPhase0BeaconBlock(blk.Block)) if err := deleteValueForIndices(ctx, indicesByBucket, blockRoot[:], tx); err != nil { return errors.Wrap(err, "could not delete root for DB indices") } @@ -221,11 +221,11 @@ func (s *Store) deleteBlocks(ctx context.Context, blockRoots [][32]byte) error { if enc == nil { return nil } - block := ðpb.SignedBeaconBlock{} - if err := decode(ctx, enc, block); err != nil { + blk := ðpb.SignedBeaconBlock{} + if err := decode(ctx, enc, blk); err != nil { return err } - indicesByBucket := createBlockIndicesFromBlock(ctx, wrapper.WrappedPhase0BeaconBlock(block.Block)) + indicesByBucket := createBlockIndicesFromBlock(ctx, wrapper.WrappedPhase0BeaconBlock(blk.Block)) if err := deleteValueForIndices(ctx, indicesByBucket, blockRoot[:], tx); err != nil { return errors.Wrap(err, "could not delete root for DB indices") } @@ -260,8 +260,8 @@ func (s *Store) SaveBlocks(ctx context.Context, blocks []block.SignedBeaconBlock return s.db.Update(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) - for _, block := range blocks { - blockRoot, err := block.Block().HashTreeRoot() + for _, blk := range blocks { + blockRoot, err := blk.Block().HashTreeRoot() if err != nil { return err } @@ -269,15 +269,15 @@ func (s *Store) SaveBlocks(ctx context.Context, blocks []block.SignedBeaconBlock if existingBlock := bkt.Get(blockRoot[:]); existingBlock != nil { continue } - enc, err := encode(ctx, block.Proto()) + enc, err := encode(ctx, blk.Proto()) if err != nil { return err } - indicesByBucket := createBlockIndicesFromBlock(ctx, block.Block()) + indicesByBucket := createBlockIndicesFromBlock(ctx, blk.Block()) if err := updateValueForIndices(ctx, indicesByBucket, blockRoot[:], tx); err != nil { return errors.Wrap(err, "could not update DB indices") } - s.blockCache.Set(string(blockRoot[:]), block, int64(len(enc))) + s.blockCache.Set(string(blockRoot[:]), blk, int64(len(enc))) if err := bkt.Put(blockRoot[:], enc); err != nil { return err @@ -307,7 +307,7 @@ func (s *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error func (s *Store) GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, error) { ctx, span := trace.StartSpan(ctx, "BeaconDB.GenesisBlock") defer span.End() - var block *ethpb.SignedBeaconBlock + var blk *ethpb.SignedBeaconBlock err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) root := bkt.Get(genesisBlockRootKey) @@ -315,10 +315,10 @@ func (s *Store) GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, erro if enc == nil { return nil } - block = ðpb.SignedBeaconBlock{} - return decode(ctx, enc, block) + blk = ðpb.SignedBeaconBlock{} + return decode(ctx, enc, blk) }) - return wrapper.WrappedPhase0SignedBeaconBlock(block), err + return wrapper.WrappedPhase0SignedBeaconBlock(blk), err } // SaveGenesisBlockRoot to the db. diff --git a/beacon-chain/db/kv/state_test.go b/beacon-chain/db/kv/state_test.go index 871b5ac813..3c27021e91 100644 --- a/beacon-chain/db/kv/state_test.go +++ b/beacon-chain/db/kv/state_test.go @@ -596,7 +596,7 @@ func validators(limit int) []*ethpb.Validator { val := ðpb.Validator{ PublicKey: pubKey, WithdrawalCredentials: bytesutil.ToBytes(rand.Uint64(), 32), - EffectiveBalance: uint64(rand.Uint64()), + EffectiveBalance: rand.Uint64(), Slashed: i%2 != 0, ActivationEligibilityEpoch: types.Epoch(rand.Uint64()), ActivationEpoch: types.Epoch(rand.Uint64()), diff --git a/beacon-chain/rpc/eth/v1/beacon/blocks_test.go b/beacon-chain/rpc/eth/v1/beacon/blocks_test.go index 8553d2c4c0..0da06c70ad 100644 --- a/beacon-chain/rpc/eth/v1/beacon/blocks_test.go +++ b/beacon-chain/rpc/eth/v1/beacon/blocks_test.go @@ -12,8 +12,7 @@ import ( mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" "github.com/prysmaticlabs/prysm/proto/migration" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - statepb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/shared/bytesutil" @@ -23,7 +22,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil/require" ) -func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*ethpb_alpha.SignedBeaconBlock, []*ethpb_alpha.BeaconBlockContainer) { +func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*eth.SignedBeaconBlock, []*eth.BeaconBlockContainer) { parentRoot := [32]byte{1, 2, 3} genBlk := testutil.NewBeaconBlock() genBlk.Block.ParentRoot = parentRoot[:] @@ -34,7 +33,7 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) ( count := types.Slot(100) blks := make([]block.SignedBeaconBlock, count) - blkContainers := make([]*ethpb_alpha.BeaconBlockContainer, count) + blkContainers := make([]*eth.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { b := testutil.NewBeaconBlock() b.Block.Slot = i @@ -45,15 +44,15 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) ( att2 := testutil.NewAttestation() att2.Data.Slot = i att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) - b.Block.Body.Attestations = []*ethpb_alpha.Attestation{att1, att2} + b.Block.Body.Attestations = []*eth.Attestation{att1, att2} root, err := b.Block.HashTreeRoot() require.NoError(t, err) blks[i] = wrapper.WrappedPhase0SignedBeaconBlock(b) - blkContainers[i] = ðpb_alpha.BeaconBlockContainer{Block: b, BlockRoot: root[:]} + blkContainers[i] = ð.BeaconBlockContainer{Block: b, BlockRoot: root[:]} } require.NoError(t, beaconDB.SaveBlocks(ctx, blks)) headRoot := bytesutil.ToBytes32(blkContainers[len(blks)-1].BlockRoot) - summary := &statepb.StateSummary{ + summary := ð.StateSummary{ Root: headRoot[:], Slot: blkContainers[len(blks)-1].Block.Block.Slot, } @@ -86,14 +85,14 @@ func TestServer_GetBlockHeader(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } tests := []struct { name string blockID []byte - want *ethpb_alpha.SignedBeaconBlock + want *eth.SignedBeaconBlock wantErr bool }{ { @@ -171,7 +170,7 @@ func TestServer_ListBlockHeaders(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } @@ -196,13 +195,13 @@ func TestServer_ListBlockHeaders(t *testing.T) { name string slot types.Slot parentRoot []byte - want []*ethpb_alpha.SignedBeaconBlock + want []*eth.SignedBeaconBlock wantErr bool }{ { name: "slot", slot: types.Slot(30), - want: []*ethpb_alpha.SignedBeaconBlock{ + want: []*eth.SignedBeaconBlock{ blkContainers[30].Block, b2, b3, @@ -211,7 +210,7 @@ func TestServer_ListBlockHeaders(t *testing.T) { { name: "parent root", parentRoot: b2.Block.ParentRoot, - want: []*ethpb_alpha.SignedBeaconBlock{ + want: []*eth.SignedBeaconBlock{ blkContainers[1].Block, b2, b4, @@ -301,7 +300,7 @@ func TestServer_GetBlock(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } @@ -312,7 +311,7 @@ func TestServer_GetBlock(t *testing.T) { tests := []struct { name string blockID []byte - want *ethpb_alpha.SignedBeaconBlock + want *eth.SignedBeaconBlock wantErr bool }{ { @@ -410,7 +409,7 @@ func TestServer_GetBlockSSZ(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } @@ -447,7 +446,7 @@ func TestServer_GetBlockRoot(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } @@ -538,7 +537,7 @@ func TestServer_ListBlockAttestations(t *testing.T) { DB: beaconDB, Block: wrapper.WrappedPhase0SignedBeaconBlock(headBlock.Block), Root: headBlock.BlockRoot, - FinalizedCheckPoint: ðpb_alpha.Checkpoint{Root: blkContainers[64].BlockRoot}, + FinalizedCheckPoint: ð.Checkpoint{Root: blkContainers[64].BlockRoot}, }, } @@ -549,7 +548,7 @@ func TestServer_ListBlockAttestations(t *testing.T) { tests := []struct { name string blockID []byte - want *ethpb_alpha.SignedBeaconBlock + want *eth.SignedBeaconBlock wantErr bool }{ { diff --git a/beacon-chain/rpc/eth/v1/beacon/pool.go b/beacon-chain/rpc/eth/v1/beacon/pool.go index a3592f69e0..5c41d01b76 100644 --- a/beacon-chain/rpc/eth/v1/beacon/pool.go +++ b/beacon-chain/rpc/eth/v1/beacon/pool.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" "github.com/prysmaticlabs/prysm/proto/migration" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/copyutil" "github.com/prysmaticlabs/prysm/shared/featureconfig" @@ -73,7 +73,7 @@ func (bs *Server) SubmitAttestations(ctx context.Context, req *ethpb.SubmitAttes ctx, span := trace.StartSpan(ctx, "beaconv1.SubmitAttestation") defer span.End() - var validAttestations []*ethpb_alpha.Attestation + var validAttestations []*eth.Attestation var attFailures []*singleAttestationVerificationFailure for i, sourceAtt := range req.Data { att := migration.V1AttToV1Alpha1(sourceAtt) diff --git a/beacon-chain/rpc/eth/v1/beacon/validator_test.go b/beacon-chain/rpc/eth/v1/beacon/validator_test.go index 6d060eb6fb..33b3774fb7 100644 --- a/beacon-chain/rpc/eth/v1/beacon/validator_test.go +++ b/beacon-chain/rpc/eth/v1/beacon/validator_test.go @@ -16,7 +16,7 @@ import ( v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" "github.com/prysmaticlabs/prysm/proto/migration" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/params" sharedtestutil "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" @@ -210,7 +210,7 @@ func TestListValidators_Status(t *testing.T) { state, _ = sharedtestutil.DeterministicGenesisState(t, 8192) farFutureEpoch := params.BeaconConfig().FarFutureEpoch - validators := []*ethpb_alpha.Validator{ + validators := []*eth.Validator{ // Pending initialized. { ActivationEpoch: farFutureEpoch, diff --git a/beacon-chain/rpc/eth/v1/events/events_test.go b/beacon-chain/rpc/eth/v1/events/events_test.go index 30d32e0923..e09270f07f 100644 --- a/beacon-chain/rpc/eth/v1/events/events_test.go +++ b/beacon-chain/rpc/eth/v1/events/events_test.go @@ -13,7 +13,7 @@ import ( statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" "github.com/prysmaticlabs/prysm/proto/migration" - ethpb_v1alpha1 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/mock" @@ -48,8 +48,8 @@ func TestStreamEvents_BlockEvents(t *testing.T) { srv, ctrl, mockStream := setupServer(ctx, t) defer ctrl.Finish() - wantedBlock := testutil.HydrateSignedBeaconBlock(ðpb_v1alpha1.SignedBeaconBlock{ - Block: ðpb_v1alpha1.BeaconBlock{ + wantedBlock := testutil.HydrateSignedBeaconBlock(ð.SignedBeaconBlock{ + Block: ð.BeaconBlock{ Slot: 8, }, }) @@ -88,8 +88,8 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { srv, ctrl, mockStream := setupServer(ctx, t) defer ctrl.Finish() - wantedAttV1alpha1 := testutil.HydrateAttestation(ðpb_v1alpha1.Attestation{ - Data: ðpb_v1alpha1.AttestationData{ + wantedAttV1alpha1 := testutil.HydrateAttestation(ð.Attestation{ + Data: ð.AttestationData{ Slot: 8, }, }) @@ -122,8 +122,8 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { srv, ctrl, mockStream := setupServer(ctx, t) defer ctrl.Finish() - wantedAttV1alpha1 := ðpb_v1alpha1.AggregateAttestationAndProof{ - Aggregate: testutil.HydrateAttestation(ðpb_v1alpha1.Attestation{}), + wantedAttV1alpha1 := ð.AggregateAttestationAndProof{ + Aggregate: testutil.HydrateAttestation(ð.Attestation{}), } wantedAtt := migration.V1Alpha1AggregateAttAndProofToV1(wantedAttV1alpha1) genericResponse, err := anypb.New(wantedAtt) @@ -154,8 +154,8 @@ func TestStreamEvents_OperationsEvents(t *testing.T) { srv, ctrl, mockStream := setupServer(ctx, t) defer ctrl.Finish() - wantedExitV1alpha1 := ðpb_v1alpha1.SignedVoluntaryExit{ - Exit: ðpb_v1alpha1.VoluntaryExit{ + wantedExitV1alpha1 := ð.SignedVoluntaryExit{ + Exit: ð.VoluntaryExit{ Epoch: 1, ValidatorIndex: 1, }, diff --git a/beacon-chain/rpc/eth/v1/node/node.go b/beacon-chain/rpc/eth/v1/node/node.go index d97a9906e2..b705ad472a 100644 --- a/beacon-chain/rpc/eth/v1/node/node.go +++ b/beacon-chain/rpc/eth/v1/node/node.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" "github.com/prysmaticlabs/prysm/proto/migration" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/grpcutils" "github.com/prysmaticlabs/prysm/shared/version" "go.opencensus.io/trace" @@ -112,12 +112,12 @@ func (ns *Server) GetPeer(ctx context.Context, req *ethpb.PeerRequest) (*ethpb.P if err != nil { return nil, status.Errorf(codes.Internal, "Could not obtain direction: %v", err) } - if ethpb_alpha.PeerDirection(direction) == ethpb_alpha.PeerDirection_UNKNOWN { + if eth.PeerDirection(direction) == eth.PeerDirection_UNKNOWN { return nil, status.Error(codes.NotFound, "Peer not found") } - v1ConnState := migration.V1Alpha1ConnectionStateToV1(ethpb_alpha.ConnectionState(state)) - v1PeerDirection, err := migration.V1Alpha1PeerDirectionToV1(ethpb_alpha.PeerDirection(direction)) + v1ConnState := migration.V1Alpha1ConnectionStateToV1(eth.ConnectionState(state)) + v1PeerDirection, err := migration.V1Alpha1PeerDirectionToV1(eth.PeerDirection(direction)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not handle peer direction: %v", err) } @@ -349,11 +349,11 @@ func peerInfo(peerStatus *peers.Status, id peer.ID) (*ethpb.Peer, error) { if err != nil { return nil, errors.Wrap(err, "could not obtain direction") } - if ethpb_alpha.PeerDirection(direction) == ethpb_alpha.PeerDirection_UNKNOWN { + if eth.PeerDirection(direction) == eth.PeerDirection_UNKNOWN { return nil, nil } - v1ConnState := migration.V1Alpha1ConnectionStateToV1(ethpb_alpha.ConnectionState(connectionState)) - v1PeerDirection, err := migration.V1Alpha1PeerDirectionToV1(ethpb_alpha.PeerDirection(direction)) + v1ConnState := migration.V1Alpha1ConnectionStateToV1(eth.ConnectionState(connectionState)) + v1PeerDirection, err := migration.V1Alpha1PeerDirectionToV1(eth.PeerDirection(direction)) if err != nil { return nil, errors.Wrapf(err, "could not handle peer direction") } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go index 7305ab654a..64acdd0d2a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go @@ -80,8 +80,8 @@ func (bs *Server) ListAttestations( return nil, status.Error(codes.InvalidArgument, "Must specify a filter criteria for fetching attestations") } atts := make([]*ethpb.Attestation, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) - for _, block := range blocks { - atts = append(atts, block.Block().Body().Attestations()...) + for _, blk := range blocks { + atts = append(atts, blk.Block().Body().Attestations()...) } // We sort attestations according to the Sortable interface. sort.Sort(sortableAttestations(atts)) @@ -135,8 +135,8 @@ func (bs *Server) ListIndexedAttestations( } attsArray := make([]*ethpb.Attestation, 0, params.BeaconConfig().MaxAttestations*uint64(len(blocks))) - for _, block := range blocks { - attsArray = append(attsArray, block.Block().Body().Attestations()...) + for _, b := range blocks { + attsArray = append(attsArray, b.Block().Body().Attestations()...) } // We sort attestations according to the Sortable interface. sort.Sort(sortableAttestations(attsArray)) @@ -151,7 +151,7 @@ func (bs *Server) ListIndexedAttestations( NextPageToken: strconv.Itoa(0), }, nil } - // We use the retrieved committees for the block root to convert all attestations + // We use the retrieved committees for the b root to convert all attestations // into indexed form effectively. mappedAttestations := mapAttestationsByTargetRoot(attsArray) indexedAtts := make([]*ethpb.IndexedAttestation, 0, numAttestations) diff --git a/proto/migration/enums.go b/proto/migration/enums.go index a022157f74..5509cee450 100644 --- a/proto/migration/enums.go +++ b/proto/migration/enums.go @@ -3,18 +3,18 @@ package migration import ( "github.com/pkg/errors" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) -func V1Alpha1ConnectionStateToV1(connState ethpb_alpha.ConnectionState) ethpb.ConnectionState { +func V1Alpha1ConnectionStateToV1(connState eth.ConnectionState) ethpb.ConnectionState { alphaString := connState.String() v1Value := ethpb.ConnectionState_value[alphaString] return ethpb.ConnectionState(v1Value) } -func V1Alpha1PeerDirectionToV1(peerDirection ethpb_alpha.PeerDirection) (ethpb.PeerDirection, error) { +func V1Alpha1PeerDirectionToV1(peerDirection eth.PeerDirection) (ethpb.PeerDirection, error) { alphaString := peerDirection.String() - if alphaString == ethpb_alpha.PeerDirection_UNKNOWN.String() { + if alphaString == eth.PeerDirection_UNKNOWN.String() { return 0, errors.New("peer direction unknown") } v1Value := ethpb.PeerDirection_value[alphaString] diff --git a/proto/migration/v1alpha1_to_v1.go b/proto/migration/v1alpha1_to_v1.go index bf58778084..a17cc47ee4 100644 --- a/proto/migration/v1alpha1_to_v1.go +++ b/proto/migration/v1alpha1_to_v1.go @@ -3,7 +3,7 @@ package migration import ( "github.com/pkg/errors" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "google.golang.org/protobuf/proto" ) @@ -27,7 +27,7 @@ func BlockIfaceToV1BlockHeader(block block.SignedBeaconBlock) (*ethpb.SignedBeac } // V1Alpha1BlockToV1BlockHeader converts a v1alpha1 SignedBeaconBlock proto to a v1 SignedBeaconBlockHeader proto. -func V1Alpha1BlockToV1BlockHeader(block *ethpb_alpha.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) { +func V1Alpha1BlockToV1BlockHeader(block *eth.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) { bodyRoot, err := block.Block.Body.HashTreeRoot() if err != nil { return nil, errors.Wrap(err, "failed to get body root of block") @@ -45,7 +45,7 @@ func V1Alpha1BlockToV1BlockHeader(block *ethpb_alpha.SignedBeaconBlock) (*ethpb. } // V1Alpha1ToV1SignedBlock converts a v1alpha1 SignedBeaconBlock proto to a v1 proto. -func V1Alpha1ToV1SignedBlock(alphaBlk *ethpb_alpha.SignedBeaconBlock) (*ethpb.SignedBeaconBlock, error) { +func V1Alpha1ToV1SignedBlock(alphaBlk *eth.SignedBeaconBlock) (*ethpb.SignedBeaconBlock, error) { marshaledBlk, err := proto.Marshal(alphaBlk) if err != nil { return nil, errors.Wrap(err, "could not marshal block") @@ -58,12 +58,12 @@ func V1Alpha1ToV1SignedBlock(alphaBlk *ethpb_alpha.SignedBeaconBlock) (*ethpb.Si } // V1ToV1Alpha1SignedBlock converts a v1 SignedBeaconBlock proto to a v1alpha1 proto. -func V1ToV1Alpha1SignedBlock(alphaBlk *ethpb.SignedBeaconBlock) (*ethpb_alpha.SignedBeaconBlock, error) { +func V1ToV1Alpha1SignedBlock(alphaBlk *ethpb.SignedBeaconBlock) (*eth.SignedBeaconBlock, error) { marshaledBlk, err := proto.Marshal(alphaBlk) if err != nil { return nil, errors.Wrap(err, "could not marshal block") } - v1alpha1Block := ðpb_alpha.SignedBeaconBlock{} + v1alpha1Block := ð.SignedBeaconBlock{} if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil { return nil, errors.Wrap(err, "could not unmarshal block") } @@ -71,7 +71,7 @@ func V1ToV1Alpha1SignedBlock(alphaBlk *ethpb.SignedBeaconBlock) (*ethpb_alpha.Si } // V1Alpha1ToV1Block converts a v1alpha1 BeaconBlock proto to a v1 proto. -func V1Alpha1ToV1Block(alphaBlk *ethpb_alpha.BeaconBlock) (*ethpb.BeaconBlock, error) { +func V1Alpha1ToV1Block(alphaBlk *eth.BeaconBlock) (*ethpb.BeaconBlock, error) { marshaledBlk, err := proto.Marshal(alphaBlk) if err != nil { return nil, errors.Wrap(err, "could not marshal block") @@ -84,7 +84,7 @@ func V1Alpha1ToV1Block(alphaBlk *ethpb_alpha.BeaconBlock) (*ethpb.BeaconBlock, e } // V1Alpha1AggregateAttAndProofToV1 converts a v1alpha1 aggregate attestation and proof to v1. -func V1Alpha1AggregateAttAndProofToV1(v1alpha1Att *ethpb_alpha.AggregateAttestationAndProof) *ethpb.AggregateAttestationAndProof { +func V1Alpha1AggregateAttAndProofToV1(v1alpha1Att *eth.AggregateAttestationAndProof) *ethpb.AggregateAttestationAndProof { if v1alpha1Att == nil { return ðpb.AggregateAttestationAndProof{} } @@ -96,12 +96,12 @@ func V1Alpha1AggregateAttAndProofToV1(v1alpha1Att *ethpb_alpha.AggregateAttestat } // V1SignedAggregateAttAndProofToV1Alpha1 converts a v1 signed aggregate attestation and proof to v1alpha1. -func V1SignedAggregateAttAndProofToV1Alpha1(v1Att *ethpb.SignedAggregateAttestationAndProof) *ethpb_alpha.SignedAggregateAttestationAndProof { +func V1SignedAggregateAttAndProofToV1Alpha1(v1Att *ethpb.SignedAggregateAttestationAndProof) *eth.SignedAggregateAttestationAndProof { if v1Att == nil { - return ðpb_alpha.SignedAggregateAttestationAndProof{} + return ð.SignedAggregateAttestationAndProof{} } - return ðpb_alpha.SignedAggregateAttestationAndProof{ - Message: ðpb_alpha.AggregateAttestationAndProof{ + return ð.SignedAggregateAttestationAndProof{ + Message: ð.AggregateAttestationAndProof{ AggregatorIndex: v1Att.Message.AggregatorIndex, Aggregate: V1AttestationToV1Alpha1(v1Att.Message.Aggregate), SelectionProof: v1Att.Message.SelectionProof, @@ -111,7 +111,7 @@ func V1SignedAggregateAttAndProofToV1Alpha1(v1Att *ethpb.SignedAggregateAttestat } // V1Alpha1IndexedAttToV1 converts a v1alpha1 indexed attestation to v1. -func V1Alpha1IndexedAttToV1(v1alpha1Att *ethpb_alpha.IndexedAttestation) *ethpb.IndexedAttestation { +func V1Alpha1IndexedAttToV1(v1alpha1Att *eth.IndexedAttestation) *ethpb.IndexedAttestation { if v1alpha1Att == nil { return ðpb.IndexedAttestation{} } @@ -123,7 +123,7 @@ func V1Alpha1IndexedAttToV1(v1alpha1Att *ethpb_alpha.IndexedAttestation) *ethpb. } // V1Alpha1AttestationToV1 converts a v1alpha1 attestation to v1. -func V1Alpha1AttestationToV1(v1alpha1Att *ethpb_alpha.Attestation) *ethpb.Attestation { +func V1Alpha1AttestationToV1(v1alpha1Att *eth.Attestation) *ethpb.Attestation { if v1alpha1Att == nil { return ðpb.Attestation{} } @@ -135,11 +135,11 @@ func V1Alpha1AttestationToV1(v1alpha1Att *ethpb_alpha.Attestation) *ethpb.Attest } // V1AttestationToV1Alpha1 converts a v1 attestation to v1alpha1. -func V1AttestationToV1Alpha1(v1Att *ethpb.Attestation) *ethpb_alpha.Attestation { +func V1AttestationToV1Alpha1(v1Att *ethpb.Attestation) *eth.Attestation { if v1Att == nil { - return ðpb_alpha.Attestation{} + return ð.Attestation{} } - return ðpb_alpha.Attestation{ + return ð.Attestation{ AggregationBits: v1Att.AggregationBits, Data: V1AttDataToV1Alpha1(v1Att.Data), Signature: v1Att.Signature, @@ -147,7 +147,7 @@ func V1AttestationToV1Alpha1(v1Att *ethpb.Attestation) *ethpb_alpha.Attestation } // V1Alpha1AttDataToV1 converts a v1alpha1 attestation data to v1. -func V1Alpha1AttDataToV1(v1alpha1AttData *ethpb_alpha.AttestationData) *ethpb.AttestationData { +func V1Alpha1AttDataToV1(v1alpha1AttData *eth.AttestationData) *ethpb.AttestationData { if v1alpha1AttData == nil || v1alpha1AttData.Source == nil || v1alpha1AttData.Target == nil { return ðpb.AttestationData{} } @@ -167,7 +167,7 @@ func V1Alpha1AttDataToV1(v1alpha1AttData *ethpb_alpha.AttestationData) *ethpb.At } // V1Alpha1AttSlashingToV1 converts a v1alpha1 attester slashing to v1. -func V1Alpha1AttSlashingToV1(v1alpha1Slashing *ethpb_alpha.AttesterSlashing) *ethpb.AttesterSlashing { +func V1Alpha1AttSlashingToV1(v1alpha1Slashing *eth.AttesterSlashing) *ethpb.AttesterSlashing { if v1alpha1Slashing == nil { return ðpb.AttesterSlashing{} } @@ -178,7 +178,7 @@ func V1Alpha1AttSlashingToV1(v1alpha1Slashing *ethpb_alpha.AttesterSlashing) *et } // V1Alpha1SignedHeaderToV1 converts a v1alpha1 signed beacon block header to v1. -func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *ethpb_alpha.SignedBeaconBlockHeader) *ethpb.SignedBeaconBlockHeader { +func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *eth.SignedBeaconBlockHeader) *ethpb.SignedBeaconBlockHeader { if v1alpha1Hdr == nil || v1alpha1Hdr.Header == nil { return ðpb.SignedBeaconBlockHeader{} } @@ -195,12 +195,12 @@ func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *ethpb_alpha.SignedBeaconBlockHeader) } // V1SignedHeaderToV1Alpha1 converts a v1 signed beacon block header to v1alpha1. -func V1SignedHeaderToV1Alpha1(v1Header *ethpb.SignedBeaconBlockHeader) *ethpb_alpha.SignedBeaconBlockHeader { +func V1SignedHeaderToV1Alpha1(v1Header *ethpb.SignedBeaconBlockHeader) *eth.SignedBeaconBlockHeader { if v1Header == nil || v1Header.Message == nil { - return ðpb_alpha.SignedBeaconBlockHeader{} + return ð.SignedBeaconBlockHeader{} } - return ðpb_alpha.SignedBeaconBlockHeader{ - Header: ðpb_alpha.BeaconBlockHeader{ + return ð.SignedBeaconBlockHeader{ + Header: ð.BeaconBlockHeader{ Slot: v1Header.Message.Slot, ProposerIndex: v1Header.Message.ProposerIndex, ParentRoot: v1Header.Message.ParentRoot, @@ -212,7 +212,7 @@ func V1SignedHeaderToV1Alpha1(v1Header *ethpb.SignedBeaconBlockHeader) *ethpb_al } // V1Alpha1ProposerSlashingToV1 converts a v1alpha1 proposer slashing to v1. -func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *ethpb_alpha.ProposerSlashing) *ethpb.ProposerSlashing { +func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *eth.ProposerSlashing) *ethpb.ProposerSlashing { if v1alpha1Slashing == nil { return ðpb.ProposerSlashing{} } @@ -223,7 +223,7 @@ func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *ethpb_alpha.ProposerSlashing } // V1Alpha1ExitToV1 converts a v1alpha1 SignedVoluntaryExit to v1. -func V1Alpha1ExitToV1(v1alpha1Exit *ethpb_alpha.SignedVoluntaryExit) *ethpb.SignedVoluntaryExit { +func V1Alpha1ExitToV1(v1alpha1Exit *eth.SignedVoluntaryExit) *ethpb.SignedVoluntaryExit { if v1alpha1Exit == nil || v1alpha1Exit.Exit == nil { return ðpb.SignedVoluntaryExit{} } @@ -237,12 +237,12 @@ func V1Alpha1ExitToV1(v1alpha1Exit *ethpb_alpha.SignedVoluntaryExit) *ethpb.Sign } // V1ExitToV1Alpha1 converts a v1 SignedVoluntaryExit to v1alpha1. -func V1ExitToV1Alpha1(v1Exit *ethpb.SignedVoluntaryExit) *ethpb_alpha.SignedVoluntaryExit { +func V1ExitToV1Alpha1(v1Exit *ethpb.SignedVoluntaryExit) *eth.SignedVoluntaryExit { if v1Exit == nil || v1Exit.Message == nil { - return ðpb_alpha.SignedVoluntaryExit{} + return ð.SignedVoluntaryExit{} } - return ðpb_alpha.SignedVoluntaryExit{ - Exit: ðpb_alpha.VoluntaryExit{ + return ð.SignedVoluntaryExit{ + Exit: ð.VoluntaryExit{ Epoch: v1Exit.Message.Epoch, ValidatorIndex: v1Exit.Message.ValidatorIndex, }, @@ -251,11 +251,11 @@ func V1ExitToV1Alpha1(v1Exit *ethpb.SignedVoluntaryExit) *ethpb_alpha.SignedVolu } // V1AttToV1Alpha1 converts a v1 attestation to v1alpha1. -func V1AttToV1Alpha1(v1Att *ethpb.Attestation) *ethpb_alpha.Attestation { +func V1AttToV1Alpha1(v1Att *ethpb.Attestation) *eth.Attestation { if v1Att == nil { - return ðpb_alpha.Attestation{} + return ð.Attestation{} } - return ðpb_alpha.Attestation{ + return ð.Attestation{ AggregationBits: v1Att.AggregationBits, Data: V1AttDataToV1Alpha1(v1Att.Data), Signature: v1Att.Signature, @@ -263,11 +263,11 @@ func V1AttToV1Alpha1(v1Att *ethpb.Attestation) *ethpb_alpha.Attestation { } // V1IndexedAttToV1Alpha1 converts a v1 indexed attestation to v1alpha1. -func V1IndexedAttToV1Alpha1(v1Att *ethpb.IndexedAttestation) *ethpb_alpha.IndexedAttestation { +func V1IndexedAttToV1Alpha1(v1Att *ethpb.IndexedAttestation) *eth.IndexedAttestation { if v1Att == nil { - return ðpb_alpha.IndexedAttestation{} + return ð.IndexedAttestation{} } - return ðpb_alpha.IndexedAttestation{ + return ð.IndexedAttestation{ AttestingIndices: v1Att.AttestingIndices, Data: V1AttDataToV1Alpha1(v1Att.Data), Signature: v1Att.Signature, @@ -275,19 +275,19 @@ func V1IndexedAttToV1Alpha1(v1Att *ethpb.IndexedAttestation) *ethpb_alpha.Indexe } // V1AttDataToV1Alpha1 converts a v1 attestation data to v1alpha1. -func V1AttDataToV1Alpha1(v1AttData *ethpb.AttestationData) *ethpb_alpha.AttestationData { +func V1AttDataToV1Alpha1(v1AttData *ethpb.AttestationData) *eth.AttestationData { if v1AttData == nil || v1AttData.Source == nil || v1AttData.Target == nil { - return ðpb_alpha.AttestationData{} + return ð.AttestationData{} } - return ðpb_alpha.AttestationData{ + return ð.AttestationData{ Slot: v1AttData.Slot, CommitteeIndex: v1AttData.Index, BeaconBlockRoot: v1AttData.BeaconBlockRoot, - Source: ðpb_alpha.Checkpoint{ + Source: ð.Checkpoint{ Root: v1AttData.Source.Root, Epoch: v1AttData.Source.Epoch, }, - Target: ðpb_alpha.Checkpoint{ + Target: ð.Checkpoint{ Root: v1AttData.Target.Root, Epoch: v1AttData.Target.Epoch, }, @@ -295,29 +295,29 @@ func V1AttDataToV1Alpha1(v1AttData *ethpb.AttestationData) *ethpb_alpha.Attestat } // V1AttSlashingToV1Alpha1 converts a v1 attester slashing to v1alpha1. -func V1AttSlashingToV1Alpha1(v1Slashing *ethpb.AttesterSlashing) *ethpb_alpha.AttesterSlashing { +func V1AttSlashingToV1Alpha1(v1Slashing *ethpb.AttesterSlashing) *eth.AttesterSlashing { if v1Slashing == nil { - return ðpb_alpha.AttesterSlashing{} + return ð.AttesterSlashing{} } - return ðpb_alpha.AttesterSlashing{ + return ð.AttesterSlashing{ Attestation_1: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_1), Attestation_2: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_2), } } // V1ProposerSlashingToV1Alpha1 converts a v1 proposer slashing to v1alpha1. -func V1ProposerSlashingToV1Alpha1(v1Slashing *ethpb.ProposerSlashing) *ethpb_alpha.ProposerSlashing { +func V1ProposerSlashingToV1Alpha1(v1Slashing *ethpb.ProposerSlashing) *eth.ProposerSlashing { if v1Slashing == nil { - return ðpb_alpha.ProposerSlashing{} + return ð.ProposerSlashing{} } - return ðpb_alpha.ProposerSlashing{ + return ð.ProposerSlashing{ Header_1: V1SignedHeaderToV1Alpha1(v1Slashing.SignedHeader_1), Header_2: V1SignedHeaderToV1Alpha1(v1Slashing.SignedHeader_2), } } // V1Alpha1ValidatorToV1 converts a v1alpha1 validator to v1. -func V1Alpha1ValidatorToV1(v1Alpha1Validator *ethpb_alpha.Validator) *ethpb.Validator { +func V1Alpha1ValidatorToV1(v1Alpha1Validator *eth.Validator) *ethpb.Validator { if v1Alpha1Validator == nil { return ðpb.Validator{} } @@ -334,11 +334,11 @@ func V1Alpha1ValidatorToV1(v1Alpha1Validator *ethpb_alpha.Validator) *ethpb.Vali } // V1ValidatorToV1Alpha1 converts a v1 validator to v1alpha1. -func V1ValidatorToV1Alpha1(v1Validator *ethpb.Validator) *ethpb_alpha.Validator { +func V1ValidatorToV1Alpha1(v1Validator *ethpb.Validator) *eth.Validator { if v1Validator == nil { - return ðpb_alpha.Validator{} + return ð.Validator{} } - return ðpb_alpha.Validator{ + return ð.Validator{ PublicKey: v1Validator.Pubkey, WithdrawalCredentials: v1Validator.WithdrawalCredentials, EffectiveBalance: v1Validator.EffectiveBalance, diff --git a/proto/migration/v1alpha1_to_v1_test.go b/proto/migration/v1alpha1_to_v1_test.go index fa02dd1789..8b92c1ee63 100644 --- a/proto/migration/v1alpha1_to_v1_test.go +++ b/proto/migration/v1alpha1_to_v1_test.go @@ -6,7 +6,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1" - ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -36,7 +36,7 @@ var ( ) func Test_BlockIfaceToV1BlockHeader(t *testing.T) { - alphaBlock := testutil.HydrateSignedBeaconBlock(ðpb_alpha.SignedBeaconBlock{}) + alphaBlock := testutil.HydrateSignedBeaconBlock(ð.SignedBeaconBlock{}) alphaBlock.Block.Slot = slot alphaBlock.Block.ProposerIndex = validatorIndex alphaBlock.Block.ParentRoot = parentRoot @@ -57,12 +57,12 @@ func Test_BlockIfaceToV1BlockHeader(t *testing.T) { func Test_V1Alpha1AggregateAttAndProofToV1(t *testing.T) { proof := [32]byte{1} - att := testutil.HydrateAttestation(ðpb_alpha.Attestation{ - Data: ðpb_alpha.AttestationData{ + att := testutil.HydrateAttestation(ð.Attestation{ + Data: ð.AttestationData{ Slot: 5, }, }) - alpha := ðpb_alpha.AggregateAttestationAndProof{ + alpha := ð.AggregateAttestationAndProof{ AggregatorIndex: 1, Aggregate: att, SelectionProof: proof[:], @@ -74,7 +74,7 @@ func Test_V1Alpha1AggregateAttAndProofToV1(t *testing.T) { } func Test_V1Alpha1BlockToV1BlockHeader(t *testing.T) { - alphaBlock := testutil.HydrateSignedBeaconBlock(ðpb_alpha.SignedBeaconBlock{}) + alphaBlock := testutil.HydrateSignedBeaconBlock(ð.SignedBeaconBlock{}) alphaBlock.Block.Slot = slot alphaBlock.Block.ProposerIndex = validatorIndex alphaBlock.Block.ParentRoot = parentRoot @@ -94,13 +94,13 @@ func Test_V1Alpha1BlockToV1BlockHeader(t *testing.T) { } func Test_V1Alpha1ToV1SignedBlock(t *testing.T) { - alphaBlock := testutil.HydrateSignedBeaconBlock(ðpb_alpha.SignedBeaconBlock{}) + alphaBlock := testutil.HydrateSignedBeaconBlock(ð.SignedBeaconBlock{}) alphaBlock.Block.Slot = slot alphaBlock.Block.ProposerIndex = validatorIndex alphaBlock.Block.ParentRoot = parentRoot alphaBlock.Block.StateRoot = stateRoot alphaBlock.Block.Body.RandaoReveal = randaoReveal - alphaBlock.Block.Body.Eth1Data = ðpb_alpha.Eth1Data{ + alphaBlock.Block.Body.Eth1Data = ð.Eth1Data{ DepositRoot: depositRoot, DepositCount: depositCount, BlockHash: blockHash, @@ -140,13 +140,13 @@ func Test_V1ToV1Alpha1SignedBlock(t *testing.T) { } func Test_V1ToV1Alpha1Block(t *testing.T) { - alphaBlock := testutil.HydrateBeaconBlock(ðpb_alpha.BeaconBlock{}) + alphaBlock := testutil.HydrateBeaconBlock(ð.BeaconBlock{}) alphaBlock.Slot = slot alphaBlock.ProposerIndex = validatorIndex alphaBlock.ParentRoot = parentRoot alphaBlock.StateRoot = stateRoot alphaBlock.Body.RandaoReveal = randaoReveal - alphaBlock.Body.Eth1Data = ðpb_alpha.Eth1Data{ + alphaBlock.Body.Eth1Data = ð.Eth1Data{ DepositRoot: depositRoot, DepositCount: depositCount, BlockHash: blockHash, @@ -162,24 +162,24 @@ func Test_V1ToV1Alpha1Block(t *testing.T) { } func Test_V1Alpha1AttSlashingToV1(t *testing.T) { - alphaAttestation := ðpb_alpha.IndexedAttestation{ + alphaAttestation := ð.IndexedAttestation{ AttestingIndices: attestingIndices, - Data: ðpb_alpha.AttestationData{ + Data: ð.AttestationData{ Slot: slot, CommitteeIndex: committeeIndex, BeaconBlockRoot: beaconBlockRoot, - Source: ðpb_alpha.Checkpoint{ + Source: ð.Checkpoint{ Epoch: epoch, Root: sourceRoot, }, - Target: ðpb_alpha.Checkpoint{ + Target: ð.Checkpoint{ Epoch: epoch, Root: targetRoot, }, }, Signature: signature, } - alphaSlashing := ðpb_alpha.AttesterSlashing{ + alphaSlashing := ð.AttesterSlashing{ Attestation_1: alphaAttestation, Attestation_2: alphaAttestation, } @@ -193,14 +193,14 @@ func Test_V1Alpha1AttSlashingToV1(t *testing.T) { } func Test_V1Alpha1ProposerSlashingToV1(t *testing.T) { - alphaHeader := testutil.HydrateSignedBeaconHeader(ðpb_alpha.SignedBeaconBlockHeader{}) + alphaHeader := testutil.HydrateSignedBeaconHeader(ð.SignedBeaconBlockHeader{}) alphaHeader.Header.Slot = slot alphaHeader.Header.ProposerIndex = validatorIndex alphaHeader.Header.ParentRoot = parentRoot alphaHeader.Header.StateRoot = stateRoot alphaHeader.Header.BodyRoot = bodyRoot alphaHeader.Signature = signature - alphaSlashing := ðpb_alpha.ProposerSlashing{ + alphaSlashing := ð.ProposerSlashing{ Header_1: alphaHeader, Header_2: alphaHeader, } @@ -214,8 +214,8 @@ func Test_V1Alpha1ProposerSlashingToV1(t *testing.T) { } func Test_V1Alpha1ExitToV1(t *testing.T) { - alphaExit := ðpb_alpha.SignedVoluntaryExit{ - Exit: ðpb_alpha.VoluntaryExit{ + alphaExit := ð.SignedVoluntaryExit{ + Exit: ð.VoluntaryExit{ Epoch: epoch, ValidatorIndex: validatorIndex, }, @@ -303,17 +303,17 @@ func Test_V1ProposerSlashingToV1Alpha1(t *testing.T) { } func Test_V1Alpha1AttToV1(t *testing.T) { - alphaAtt := ðpb_alpha.Attestation{ + alphaAtt := ð.Attestation{ AggregationBits: aggregationBits, - Data: ðpb_alpha.AttestationData{ + Data: ð.AttestationData{ Slot: slot, CommitteeIndex: committeeIndex, BeaconBlockRoot: beaconBlockRoot, - Source: ðpb_alpha.Checkpoint{ + Source: ð.Checkpoint{ Epoch: epoch, Root: sourceRoot, }, - Target: ðpb_alpha.Checkpoint{ + Target: ð.Checkpoint{ Epoch: epoch, Root: targetRoot, }, @@ -357,13 +357,13 @@ func Test_V1AttToV1Alpha1(t *testing.T) { } func Test_BlockInterfaceToV1Block(t *testing.T) { - v1Alpha1Block := testutil.HydrateSignedBeaconBlock(ðpb_alpha.SignedBeaconBlock{}) + v1Alpha1Block := testutil.HydrateSignedBeaconBlock(ð.SignedBeaconBlock{}) v1Alpha1Block.Block.Slot = slot v1Alpha1Block.Block.ProposerIndex = validatorIndex v1Alpha1Block.Block.ParentRoot = parentRoot v1Alpha1Block.Block.StateRoot = stateRoot v1Alpha1Block.Block.Body.RandaoReveal = randaoReveal - v1Alpha1Block.Block.Body.Eth1Data = ðpb_alpha.Eth1Data{ + v1Alpha1Block.Block.Body.Eth1Data = ð.Eth1Data{ DepositRoot: depositRoot, DepositCount: depositCount, BlockHash: blockHash, @@ -380,7 +380,7 @@ func Test_BlockInterfaceToV1Block(t *testing.T) { } func Test_V1Alpha1ValidatorToV1(t *testing.T) { - v1Alpha1Validator := ðpb_alpha.Validator{ + v1Alpha1Validator := ð.Validator{ PublicKey: []byte("pubkey"), WithdrawalCredentials: []byte("withdraw"), EffectiveBalance: 99, diff --git a/proto/prysm/v1alpha1/wrapper/beacon_block.go b/proto/prysm/v1alpha1/wrapper/beacon_block.go index 88548cd1a7..1c0d6288c0 100644 --- a/proto/prysm/v1alpha1/wrapper/beacon_block.go +++ b/proto/prysm/v1alpha1/wrapper/beacon_block.go @@ -85,7 +85,7 @@ func (w Phase0SignedBeaconBlock) PbPhase0Block() (*eth.SignedBeaconBlock, error) return w.b, nil } -// AltairBlock returns the underlying protobuf object. +// PbAltairBlock returns the underlying protobuf object. func (w Phase0SignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair, error) { return nil, errors.New("unsupported altair block") } diff --git a/proto/prysm/v1alpha1/wrapper/beacon_block_test.go b/proto/prysm/v1alpha1/wrapper/beacon_block_test.go index c560bc4e1c..4519901afa 100644 --- a/proto/prysm/v1alpha1/wrapper/beacon_block_test.go +++ b/proto/prysm/v1alpha1/wrapper/beacon_block_test.go @@ -83,7 +83,7 @@ func TestAltairSignedBeaconBlock_MarshalSSZTo(t *testing.T) { wsb, err := wrapper.WrappedAltairSignedBeaconBlock(testutil.HydrateSignedBeaconBlockAltair(ðpb.SignedBeaconBlockAltair{})) assert.NoError(t, err) - b := []byte{} + var b []byte b, err = wsb.MarshalSSZTo(b) assert.NoError(t, err) assert.NotEqual(t, 0, len(b)) diff --git a/shared/bls/blst/public_key_test.go b/shared/bls/blst/public_key_test.go index e086e5b0fd..8194434f1a 100644 --- a/shared/bls/blst/public_key_test.go +++ b/shared/bls/blst/public_key_test.go @@ -78,7 +78,7 @@ func TestPublicKey_Copy(t *testing.T) { } func TestPublicKeysEmpty(t *testing.T) { - pubs := [][]byte{} + var pubs [][]byte _, err := blst.AggregatePublicKeys(pubs) require.ErrorContains(t, "nil or empty public keys", err) } diff --git a/shared/clientstats/scrapers_test.go b/shared/clientstats/scrapers_test.go index 5850183e78..1aa5bf9fcb 100644 --- a/shared/clientstats/scrapers_test.go +++ b/shared/clientstats/scrapers_test.go @@ -62,7 +62,7 @@ func TestBeaconNodeScraper(t *testing.T) { // helper function to wrap up all the scrape logic so tests can focus on data cases and assertions func scrapeBeaconNodeStats(body string) (*BeaconNodeStats, error) { if !strings.HasSuffix(body, "\n") { - return nil, fmt.Errorf("Bad test fixture -- make sure there is a trailing newline unless you want to waste time debugging tests") + return nil, fmt.Errorf("bad test fixture -- make sure there is a trailing newline unless you want to waste time debugging tests") } bnScraper := beaconNodeScraper{} bnScraper.tripper = &mockRT{body: body} diff --git a/shared/testutil/altair.go b/shared/testutil/altair.go index 4780afa3b4..4e1d516d8f 100644 --- a/shared/testutil/altair.go +++ b/shared/testutil/altair.go @@ -42,23 +42,23 @@ func DeterministicGenesisStateAltair(t testing.TB, numValidators uint64) (state. // GenesisBeaconState returns the genesis beacon state. func GenesisBeaconState(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data) (state.BeaconStateAltair, error) { - state, err := emptyGenesisState() + st, err := emptyGenesisState() if err != nil { return nil, err } // Process initial deposits. - state, err = helpers.UpdateGenesisEth1Data(state, deposits, eth1Data) + st, err = helpers.UpdateGenesisEth1Data(st, deposits, eth1Data) if err != nil { return nil, err } - state, err = processPreGenesisDeposits(ctx, state, deposits) + st, err = processPreGenesisDeposits(ctx, st, deposits) if err != nil { return nil, errors.Wrap(err, "could not process validator deposits") } - return buildGenesisBeaconState(genesisTime, state, state.Eth1Data()) + return buildGenesisBeaconState(genesisTime, st, st.Eth1Data()) } // processPreGenesisDeposits processes a deposit for the beacon state Altair before chain start. @@ -127,7 +127,7 @@ func buildGenesisBeaconState(genesisTime uint64, preState state.BeaconStateAltai if err != nil { return nil, err } - state := ðpb.BeaconStateAltair{ + st := ðpb.BeaconStateAltair{ // Misc fields. Slot: 0, GenesisTime: genesisTime, @@ -191,7 +191,7 @@ func buildGenesisBeaconState(genesisTime uint64, preState state.BeaconStateAltai return nil, errors.Wrap(err, "could not hash tree root empty block body") } - state.LatestBlockHeader = ðpb.BeaconBlockHeader{ + st.LatestBlockHeader = ðpb.BeaconBlockHeader{ ParentRoot: zeroHash, StateRoot: zeroHash, BodyRoot: bodyRoot[:], @@ -201,20 +201,20 @@ func buildGenesisBeaconState(genesisTime uint64, preState state.BeaconStateAltai for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSize; i++ { pubKeys = append(pubKeys, bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength)) } - state.CurrentSyncCommittee = ðpb.SyncCommittee{ + st.CurrentSyncCommittee = ðpb.SyncCommittee{ Pubkeys: pubKeys, AggregatePubkey: bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength), } - state.NextSyncCommittee = ðpb.SyncCommittee{ + st.NextSyncCommittee = ðpb.SyncCommittee{ Pubkeys: bytesutil.Copy2dBytes(pubKeys), AggregatePubkey: bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength), } - return stateAltair.InitializeFromProto(state) + return stateAltair.InitializeFromProto(st) } func emptyGenesisState() (state.BeaconStateAltair, error) { - state := ðpb.BeaconStateAltair{ + st := ðpb.BeaconStateAltair{ // Misc fields. Slot: 0, Fork: ðpb.Fork{ @@ -237,7 +237,7 @@ func emptyGenesisState() (state.BeaconStateAltair, error) { Eth1DataVotes: []*ethpb.Eth1Data{}, Eth1DepositIndex: 0, } - return stateAltair.InitializeFromProto(state) + return stateAltair.InitializeFromProto(st) } // NewBeaconBlockAltair creates a beacon block with minimum marshalable fields. diff --git a/validator/graffiti/parse_graffiti.go b/validator/graffiti/parse_graffiti.go index c419e22dda..a20d38013a 100644 --- a/validator/graffiti/parse_graffiti.go +++ b/validator/graffiti/parse_graffiti.go @@ -40,7 +40,7 @@ func ParseGraffitiFile(f string) (*Graffiti, error) { } for i, o := range g.Specific { - g.Specific[types.ValidatorIndex(i)] = ParseHexGraffiti(o) + g.Specific[i] = ParseHexGraffiti(o) } for i, v := range g.Ordered {