From 386b69f473bb6d3bd0186a77adbb179f1c5ed8c1 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Fri, 23 Apr 2021 15:06:05 +0300 Subject: [PATCH] Fix comments (#8802) * fix incorrect exported name in comments * add comments to exported methods --- beacon-chain/core/epoch/epoch_processing.go | 7 ++++- .../core/helpers/weak_subjectivity.go | 2 +- beacon-chain/db/kafka/passthrough.go | 2 +- beacon-chain/operations/attestations/mock.go | 26 +++++++++++++++++++ beacon-chain/rpc/beacon/attestations.go | 7 ++++- beacon-chain/rpc/beacon/validators_stream.go | 7 ++++- beacon-chain/rpc/beaconv1/pool.go | 2 +- beacon-chain/rpc/debugv1/server.go | 2 +- .../rpc/testutil/mock_state_fetcher.go | 1 + beacon-chain/state/stateutil/eth1_root.go | 2 +- .../stateutil/pending_attestation_root.go | 2 +- .../state/stateutil/validator_map_handler.go | 2 +- beacon-chain/sync/utils.go | 3 +++ cmd/beacon-chain/flags/base.go | 2 ++ endtoend/components/boot_node.go | 2 +- endtoend/components/validator.go | 2 +- endtoend/helpers/helpers.go | 2 ++ fuzz/common.go | 1 + proto/migration/migration.go | 2 +- shared/backuputil/http_backup_handler.go | 1 + shared/event/feed.go | 2 ++ shared/event/subscription.go | 6 +++++ shared/fileutil/fileutil.go | 1 + shared/httputils/endpoint.go | 2 ++ shared/logutil/logutil.go | 2 +- shared/service_registry.go | 2 +- .../effective_balance_updates.go | 1 + .../epoch_processing/eth1_data_reset.go | 1 + .../historical_roots_update.go | 1 + .../justification_and_finalization.go | 1 + .../participation_record_updates.go | 1 + .../epoch_processing/randao_mixes_reset.go | 1 + .../phase0/epoch_processing/registry.go | 1 + .../epoch_processing/rewards_and_penalties.go | 1 + .../phase0/epoch_processing/slashings.go | 1 + .../epoch_processing/slashings_reset.go | 1 + .../shared/phase0/operations/attestation.go | 1 + .../phase0/operations/attester_slashing.go | 1 + .../shared/phase0/operations/block_header.go | 1 + spectest/shared/phase0/operations/deposit.go | 1 + .../phase0/operations/proposer_slashing.go | 1 + .../phase0/operations/voluntary_exit.go | 1 + .../phase0/rewards/rewards_penalties.go | 2 ++ .../shared/phase0/sanity/block_processing.go | 1 + .../shared/phase0/sanity/slot_processing.go | 1 + .../phase0/shuffling/core/shuffle/shuffle.go | 1 + .../shared/phase0/ssz_static/ssz_static.go | 2 ++ .../comparesame/testdata/compare_len.go | 6 +++++ .../cryptorand/testdata/custom_import.go | 4 ++- .../analyzers/cryptorand/testdata/rand_new.go | 2 ++ tools/analyzers/ineffassign/ineffassign.go | 10 +++++-- .../ineffassign/testdata/ctx_assignment.go | 1 + tools/analyzers/maligned/maligned.go | 6 +++++ tools/analyzers/nop/testdata/no_op.go | 2 ++ .../testdata/custom_imports.go | 1 + .../testdata/regular_imports.go | 1 + .../shadowpredecl/testdata/shadow.go | 9 ++++++- tools/analyzers/slicedirect/testdata/slice.go | 6 +++++ tools/cluster-pk-manager/server/db.go | 7 +++-- tools/cluster-pk-manager/server/server.go | 1 + tools/forkchecker/forkchecker.go | 1 + validator/accounts/accounts.go | 2 +- validator/accounts/accounts_import.go | 4 +++ validator/accounts/doc.go | 2 +- validator/client/log.go | 2 ++ .../multiple_endpoints_grpc_resolver.go | 4 +++ validator/client/testutil/mock_validator.go | 2 +- validator/db/kv/db.go | 1 + validator/graffiti/parse_graffiti.go | 1 + validator/keymanager/constants.go | 1 + validator/keymanager/derived/mnemonic.go | 1 + validator/keymanager/remote/keymanager.go | 1 + .../keymanager/remote/mock_keymanager.go | 5 ++++ validator/rpc/beacon.go | 2 +- .../format/format.go | 2 +- .../standard-protection-format/helpers.go | 2 +- validator/testing/constants.go | 1 + 77 files changed, 178 insertions(+), 27 deletions(-) diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index a7d49ffcbc..876d5afb4f 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -28,8 +28,13 @@ type sortableIndices struct { validators []*ethpb.Validator } -func (s sortableIndices) Len() int { return len(s.indices) } +// Len is the number of elements in the collection. +func (s sortableIndices) Len() int { return len(s.indices) } + +// Swap swaps the elements with indexes i and j. func (s sortableIndices) Swap(i, j int) { s.indices[i], s.indices[j] = s.indices[j], s.indices[i] } + +// Less reports whether the element with index i must sort before the element with index j. func (s sortableIndices) Less(i, j int) bool { if s.validators[s.indices[i]].ActivationEligibilityEpoch == s.validators[s.indices[j]].ActivationEligibilityEpoch { return s.indices[i] < s.indices[j] diff --git a/beacon-chain/core/helpers/weak_subjectivity.go b/beacon-chain/core/helpers/weak_subjectivity.go index 490be1cc2f..2c25268520 100644 --- a/beacon-chain/core/helpers/weak_subjectivity.go +++ b/beacon-chain/core/helpers/weak_subjectivity.go @@ -108,7 +108,7 @@ func ComputeWeakSubjectivityPeriod(st iface.ReadOnlyBeaconState) (types.Epoch, e // // Reference implementation: // https://github.com/ethereum/eth2.0-specs/blob/master/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint - +// // def is_within_weak_subjectivity_period(store: Store, ws_state: BeaconState, ws_checkpoint: Checkpoint) -> bool: // # Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint // assert ws_state.latest_block_header.state_root == ws_checkpoint.root diff --git a/beacon-chain/db/kafka/passthrough.go b/beacon-chain/db/kafka/passthrough.go index 2ee531d67d..50b185b973 100644 --- a/beacon-chain/db/kafka/passthrough.go +++ b/beacon-chain/db/kafka/passthrough.go @@ -268,7 +268,7 @@ func (e Exporter) CleanUpDirtyStates(ctx context.Context, slotsPerArchivedPoint return e.db.RunMigrations(ctx) } -// LoadGenesisFromFile -- passthrough +// LoadGenesis -- passthrough func (e Exporter) LoadGenesis(ctx context.Context, r io.Reader) error { return e.db.LoadGenesis(ctx, r) } diff --git a/beacon-chain/operations/attestations/mock.go b/beacon-chain/operations/attestations/mock.go index 1a5aa6c6be..e74abc2874 100644 --- a/beacon-chain/operations/attestations/mock.go +++ b/beacon-chain/operations/attestations/mock.go @@ -7,107 +7,133 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" ) +// PoolMock -- type PoolMock struct { AggregatedAtts []*ethpb.Attestation } +// AggregateUnaggregatedAttestations -- func (*PoolMock) AggregateUnaggregatedAttestations(_ context.Context) error { panic("implement me") } +// AggregateUnaggregatedAttestationsBySlotIndex -- func (*PoolMock) AggregateUnaggregatedAttestationsBySlotIndex(_ context.Context, _ types.Slot, _ types.CommitteeIndex) error { panic("implement me") } +// SaveAggregatedAttestation -- func (*PoolMock) SaveAggregatedAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// SaveAggregatedAttestations -- func (m *PoolMock) SaveAggregatedAttestations(atts []*ethpb.Attestation) error { m.AggregatedAtts = append(m.AggregatedAtts, atts...) return nil } +// AggregatedAttestations -- func (m *PoolMock) AggregatedAttestations() []*ethpb.Attestation { return m.AggregatedAtts } +// AggregatedAttestationsBySlotIndex -- func (*PoolMock) AggregatedAttestationsBySlotIndex(_ context.Context, _ types.Slot, _ types.CommitteeIndex) []*ethpb.Attestation { panic("implement me") } +// DeleteAggregatedAttestation -- func (*PoolMock) DeleteAggregatedAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// HasAggregatedAttestation -- func (*PoolMock) HasAggregatedAttestation(_ *ethpb.Attestation) (bool, error) { panic("implement me") } +// AggregatedAttestationCount -- func (*PoolMock) AggregatedAttestationCount() int { panic("implement me") } +// SaveUnaggregatedAttestation -- func (*PoolMock) SaveUnaggregatedAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// SaveUnaggregatedAttestations -- func (*PoolMock) SaveUnaggregatedAttestations(_ []*ethpb.Attestation) error { panic("implement me") } +// UnaggregatedAttestations -- func (*PoolMock) UnaggregatedAttestations() ([]*ethpb.Attestation, error) { panic("implement me") } +// UnaggregatedAttestationsBySlotIndex -- func (*PoolMock) UnaggregatedAttestationsBySlotIndex(_ context.Context, _ types.Slot, _ types.CommitteeIndex) []*ethpb.Attestation { panic("implement me") } +// DeleteUnaggregatedAttestation -- func (*PoolMock) DeleteUnaggregatedAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// DeleteSeenUnaggregatedAttestations -- func (*PoolMock) DeleteSeenUnaggregatedAttestations() (int, error) { panic("implement me") } +// UnaggregatedAttestationCount -- func (*PoolMock) UnaggregatedAttestationCount() int { panic("implement me") } +// SaveBlockAttestation -- func (*PoolMock) SaveBlockAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// SaveBlockAttestations -- func (*PoolMock) SaveBlockAttestations(_ []*ethpb.Attestation) error { panic("implement me") } +// BlockAttestations -- func (*PoolMock) BlockAttestations() []*ethpb.Attestation { panic("implement me") } +// DeleteBlockAttestation -- func (*PoolMock) DeleteBlockAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// SaveForkchoiceAttestation -- func (*PoolMock) SaveForkchoiceAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// SaveForkchoiceAttestations -- func (*PoolMock) SaveForkchoiceAttestations(_ []*ethpb.Attestation) error { panic("implement me") } +// ForkchoiceAttestations -- func (*PoolMock) ForkchoiceAttestations() []*ethpb.Attestation { panic("implement me") } +// DeleteForkchoiceAttestation -- func (*PoolMock) DeleteForkchoiceAttestation(_ *ethpb.Attestation) error { panic("implement me") } +// ForkchoiceAttestationCount -- func (*PoolMock) ForkchoiceAttestationCount() int { panic("implement me") } diff --git a/beacon-chain/rpc/beacon/attestations.go b/beacon-chain/rpc/beacon/attestations.go index de02bac414..cda00b3edf 100644 --- a/beacon-chain/rpc/beacon/attestations.go +++ b/beacon-chain/rpc/beacon/attestations.go @@ -27,8 +27,13 @@ import ( // by slot as the canonical sorting attribute. type sortableAttestations []*ethpb.Attestation -func (s sortableAttestations) Len() int { return len(s) } +// Len is the number of elements in the collection. +func (s sortableAttestations) Len() int { return len(s) } + +// Swap swaps the elements with indexes i and j. func (s sortableAttestations) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +// Less reports whether the element with index i must sort before the element with index j. func (s sortableAttestations) Less(i, j int) bool { return s[i].Data.Slot < s[j].Data.Slot } diff --git a/beacon-chain/rpc/beacon/validators_stream.go b/beacon-chain/rpc/beacon/validators_stream.go index 9d9ad9b224..bfac01f4e2 100644 --- a/beacon-chain/rpc/beacon/validators_stream.go +++ b/beacon-chain/rpc/beacon/validators_stream.go @@ -470,8 +470,13 @@ type indicesSorter struct { indices []types.ValidatorIndex } -func (s indicesSorter) Len() int { return len(s.indices) } +// Len is the number of elements in the collection. +func (s indicesSorter) Len() int { return len(s.indices) } + +// Swap swaps the elements with indexes i and j. func (s indicesSorter) Swap(i, j int) { s.indices[i], s.indices[j] = s.indices[j], s.indices[i] } + +// Less reports whether the element with index i must sort before the element with index j. func (s indicesSorter) Less(i, j int) bool { return s.indices[i] < s.indices[j] } diff --git a/beacon-chain/rpc/beaconv1/pool.go b/beacon-chain/rpc/beaconv1/pool.go index 3325b37481..cd3005a5ff 100644 --- a/beacon-chain/rpc/beaconv1/pool.go +++ b/beacon-chain/rpc/beaconv1/pool.go @@ -21,7 +21,7 @@ func (bs *Server) ListPoolAttestations(ctx context.Context, req *ethpb.Attestati return nil, errors.New("unimplemented") } -// SubmitAttestation submits Attestation object to node. If attestation passes all validation +// SubmitAttestations submits Attestation object to node. If attestation passes all validation // constraints, node MUST publish attestation on appropriate subnet. func (bs *Server) SubmitAttestations(ctx context.Context, req *ethpb.SubmitAttestationsRequest) (*ptypes.Empty, error) { ctx, span := trace.StartSpan(ctx, "beaconv1.SubmitAttestation") diff --git a/beacon-chain/rpc/debugv1/server.go b/beacon-chain/rpc/debugv1/server.go index 5048a2cec9..18d0b8317a 100644 --- a/beacon-chain/rpc/debugv1/server.go +++ b/beacon-chain/rpc/debugv1/server.go @@ -1,4 +1,4 @@ -// Package beaconv1 defines a gRPC beacon service implementation, +// Package debugv1 defines a gRPC beacon service implementation, // following the official API standards https://ethereum.github.io/eth2.0-APIs/#/. // This package includes the beacon and config endpoints. package debugv1 diff --git a/beacon-chain/rpc/testutil/mock_state_fetcher.go b/beacon-chain/rpc/testutil/mock_state_fetcher.go index c2867c3320..58b36639a9 100644 --- a/beacon-chain/rpc/testutil/mock_state_fetcher.go +++ b/beacon-chain/rpc/testutil/mock_state_fetcher.go @@ -11,6 +11,7 @@ type MockFetcher struct { BeaconState iface.BeaconState } +// State -- func (m *MockFetcher) State(context.Context, []byte) (iface.BeaconState, error) { return m.BeaconState, nil } diff --git a/beacon-chain/state/stateutil/eth1_root.go b/beacon-chain/state/stateutil/eth1_root.go index 1346e42a8a..0780fb4f2b 100644 --- a/beacon-chain/state/stateutil/eth1_root.go +++ b/beacon-chain/state/stateutil/eth1_root.go @@ -62,7 +62,7 @@ func Eth1DataRootWithHasher(hasher htrutils.HashFn, eth1Data *ethpb.Eth1Data) ([ return root, nil } -// Eth1DataEncKey returns the encoded key in bytes of input `eth1Data`s, +// Eth1DatasEncKey returns the encoded key in bytes of input `eth1Data`s, // the returned key bytes can be used for caching purposes. func Eth1DatasEncKey(eth1Datas []*ethpb.Eth1Data) ([32]byte, error) { hasher := hashutil.CustomSHA256Hasher() diff --git a/beacon-chain/state/stateutil/pending_attestation_root.go b/beacon-chain/state/stateutil/pending_attestation_root.go index adb526802e..a2248ccbf5 100644 --- a/beacon-chain/state/stateutil/pending_attestation_root.go +++ b/beacon-chain/state/stateutil/pending_attestation_root.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" ) -// PendingAttestationRoot describes a method from which the hash tree root +// PendingAttRootWithHasher describes a method from which the hash tree root // of a pending attestation is returned. func PendingAttRootWithHasher(hasher htrutils.HashFn, att *pb.PendingAttestation) ([32]byte, error) { var fieldRoots [][32]byte diff --git a/beacon-chain/state/stateutil/validator_map_handler.go b/beacon-chain/state/stateutil/validator_map_handler.go index 6ba55c8334..539ba12e48 100644 --- a/beacon-chain/state/stateutil/validator_map_handler.go +++ b/beacon-chain/state/stateutil/validator_map_handler.go @@ -21,7 +21,7 @@ func NewValMapHandler(vals []*ethpb.Validator) *ValidatorMapHandler { } } -// Copy the whole map and returns a map handler with the copied map. +// AddRef copies the whole map and returns a map handler with the copied map. func (v *ValidatorMapHandler) AddRef() { v.mapRef.AddRef() } diff --git a/beacon-chain/sync/utils.go b/beacon-chain/sync/utils.go index 337a497b10..5c7b3aba67 100644 --- a/beacon-chain/sync/utils.go +++ b/beacon-chain/sync/utils.go @@ -15,15 +15,18 @@ type sortedObj struct { roots [][32]byte } +// Less reports whether the element with index i must sort before the element with index j. func (s sortedObj) Less(i, j int) bool { return s.blks[i].Block.Slot < s.blks[j].Block.Slot } +// Swap swaps the elements with indexes i and j. func (s sortedObj) Swap(i, j int) { s.blks[i], s.blks[j] = s.blks[j], s.blks[i] s.roots[i], s.roots[j] = s.roots[j], s.roots[i] } +// Len is the number of elements in the collection. func (s sortedObj) Len() int { return len(s.blks) } diff --git a/cmd/beacon-chain/flags/base.go b/cmd/beacon-chain/flags/base.go index fc10cb4f9e..beb0304b2a 100644 --- a/cmd/beacon-chain/flags/base.go +++ b/cmd/beacon-chain/flags/base.go @@ -14,6 +14,7 @@ var ( Usage: "A mainchain web3 provider string http endpoint. Can contain auth header as well in the format --http-web3provider=\"https://goerli.infura.io/v3/xxxx,Basic xxx\" for project secret (base64 encoded) and --http-web3provider=\"https://goerli.infura.io/v3/xxxx,Bearer xxx\" for jwt use", Value: "", } + // FallbackWeb3ProviderFlag provides a fallback endpoint to an ETH 1.0 RPC. FallbackWeb3ProviderFlag = &cli.StringSliceFlag{ Name: "fallback-web3provider", Usage: "A mainchain web3 provider string http endpoint. This is our fallback web3 provider, this flag may be used multiple times.", @@ -135,6 +136,7 @@ var ( Name: "enable-debug-rpc-endpoints", Usage: "Enables the debug rpc service, containing utility endpoints such as /eth/v1alpha1/beacon/state.", } + // SubscribeToAllSubnets defines a flag to specify whether to subscribe to all possible attestation subnets or not. SubscribeToAllSubnets = &cli.BoolFlag{ Name: "subscribe-all-subnets", Usage: "Subscribe to all possible attestation subnets.", diff --git a/endtoend/components/boot_node.go b/endtoend/components/boot_node.go index 7129c6b6dc..9b7da4bf0e 100644 --- a/endtoend/components/boot_node.go +++ b/endtoend/components/boot_node.go @@ -35,7 +35,7 @@ func (node *BootNode) ENR() string { return node.enr } -// StartBootnode starts a bootnode blocks up until ctx is cancelled. +// Start starts a bootnode blocks up until ctx is cancelled. func (node *BootNode) Start(ctx context.Context) error { binaryPath, found := bazel.FindBinary("tools/bootnode", "bootnode") if !found { diff --git a/endtoend/components/validator.go b/endtoend/components/validator.go index b1c9a66c55..3611ddf391 100644 --- a/endtoend/components/validator.go +++ b/endtoend/components/validator.go @@ -95,7 +95,7 @@ func NewValidatorNode(config *e2etypes.E2EConfig, validatorNum, index, offset in } } -// StartNewValidatorNode starts a validator client. +// Start starts a validator client. func (v *ValidatorNode) Start(ctx context.Context) error { binaryPath, found := bazel.FindBinary("cmd/validator", "validator") if !found { diff --git a/endtoend/helpers/helpers.go b/endtoend/helpers/helpers.go index 14028ba4f9..7b6a636619 100644 --- a/endtoend/helpers/helpers.go +++ b/endtoend/helpers/helpers.go @@ -35,6 +35,7 @@ const ( maxFileBufferSize = 1024 * 1024 ) +// Graffiti is a list of sample graffiti strings. var Graffiti = []string{"Sushi", "Ramen", "Takoyaki"} // DeleteAndCreateFile checks if the file path given exists, if it does, it deletes it and creates a new file. @@ -91,6 +92,7 @@ func WaitForTextInFile(file *os.File, text string) error { } } +// GraffitiYamlFile outputs graffiti YAML file into a testing directory. func GraffitiYamlFile(testDir string) (string, error) { b := []byte(`default: "Rice" random: diff --git a/fuzz/common.go b/fuzz/common.go index ba66f998c0..1f2b02e2c2 100644 --- a/fuzz/common.go +++ b/fuzz/common.go @@ -6,6 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" ) +// EnvBls defines an environment variable name to check whether BLS is enabled or not. const EnvBls = "BLS_ENABLED" func init() { diff --git a/proto/migration/migration.go b/proto/migration/migration.go index 108c742823..697a74b701 100644 --- a/proto/migration/migration.go +++ b/proto/migration/migration.go @@ -25,7 +25,7 @@ func V1Alpha1BlockToV1BlockHeader(block *ethpb_alpha.SignedBeaconBlock) (*ethpb. }, nil } -// V1Alpha1BlockToV1Block converts a v1alpha1 SignedBeaconBlock proto to a v1 proto. +// V1Alpha1ToV1Block converts a v1alpha1 SignedBeaconBlock proto to a v1 proto. func V1Alpha1ToV1Block(alphaBlk *ethpb_alpha.SignedBeaconBlock) (*ethpb.SignedBeaconBlock, error) { marshaledBlk, err := alphaBlk.Marshal() if err != nil { diff --git a/shared/backuputil/http_backup_handler.go b/shared/backuputil/http_backup_handler.go index 316ac3151b..141d6fe8f3 100644 --- a/shared/backuputil/http_backup_handler.go +++ b/shared/backuputil/http_backup_handler.go @@ -8,6 +8,7 @@ import ( "github.com/sirupsen/logrus" ) +// BackupExporter defines a backup exporter methods. type BackupExporter interface { Backup(ctx context.Context, outputPath string) error } diff --git a/shared/event/feed.go b/shared/event/feed.go index 8e3643f0b0..6eebbd7248 100644 --- a/shared/event/feed.go +++ b/shared/event/feed.go @@ -196,6 +196,7 @@ type feedSub struct { err chan error } +// Unsubscribe remove feed subscription. func (sub *feedSub) Unsubscribe() { sub.errOnce.Do(func() { sub.feed.remove(sub) @@ -203,6 +204,7 @@ func (sub *feedSub) Unsubscribe() { }) } +// Err returns error channel. func (sub *feedSub) Err() <-chan error { return sub.err } diff --git a/shared/event/subscription.go b/shared/event/subscription.go index 61a0e6889f..52355fc35b 100644 --- a/shared/event/subscription.go +++ b/shared/event/subscription.go @@ -74,6 +74,7 @@ type funcSub struct { unsubscribed bool } +// Unsubscribe unsubscribes from subscription. func (s *funcSub) Unsubscribe() { s.mu.Lock() if s.unsubscribed { @@ -87,6 +88,7 @@ func (s *funcSub) Unsubscribe() { <-s.err } +// Err exposes error channel. func (s *funcSub) Err() <-chan error { return s.err } @@ -122,6 +124,7 @@ type resubscribeSub struct { waitTime, backoffMax time.Duration } +// Unsubscribe unsubscribes from subscription. func (s *resubscribeSub) Unsubscribe() { s.unsubOnce.Do(func() { s.unsub <- struct{}{} @@ -129,6 +132,7 @@ func (s *resubscribeSub) Unsubscribe() { }) } +// Err exposes error channel. func (s *resubscribeSub) Err() <-chan error { return s.err } @@ -267,6 +271,7 @@ func (sc *SubscriptionScope) Count() int { return len(sc.subs) } +// Unsubscribe unsubscribes from subscription. func (s *scopeSub) Unsubscribe() { s.s.Unsubscribe() s.sc.mu.Lock() @@ -274,6 +279,7 @@ func (s *scopeSub) Unsubscribe() { delete(s.sc.subs, s) } +// Err exposes error channel. func (s *scopeSub) Err() <-chan error { return s.s.Err() } diff --git a/shared/fileutil/fileutil.go b/shared/fileutil/fileutil.go index ca51c684d7..66aa81e207 100644 --- a/shared/fileutil/fileutil.go +++ b/shared/fileutil/fileutil.go @@ -136,6 +136,7 @@ func FileExists(filename string) bool { // Define non-fatal error to stop the recursive directory walk var stopWalk = errors.New("stop walking") +// RecursiveFileFind searches for file in a directory and its subdirectories. func RecursiveFileFind(filename, dir string) (bool, string, error) { var found bool var fpath string diff --git a/shared/httputils/endpoint.go b/shared/httputils/endpoint.go index 55e24f75fc..aa5fd350c8 100644 --- a/shared/httputils/endpoint.go +++ b/shared/httputils/endpoint.go @@ -19,10 +19,12 @@ type AuthorizationData struct { Value string } +// Equals compares two endpoints for equality. func (e Endpoint) Equals(other Endpoint) bool { return e.Url == other.Url && e.Auth.Equals(other.Auth) } +// Equals compares two authorization data objects for equality. func (d AuthorizationData) Equals(other AuthorizationData) bool { return d.Method == other.Method && d.Value == other.Value } diff --git a/shared/logutil/logutil.go b/shared/logutil/logutil.go index ef1ca19bb6..3396fc0b5a 100644 --- a/shared/logutil/logutil.go +++ b/shared/logutil/logutil.go @@ -31,7 +31,7 @@ func ConfigurePersistentLogging(logFileName string) error { return nil } -// Masks the url credentials before logging for security purpose +// MaskCredentialsLogging masks the url credentials before logging for security purpose // [scheme:][//[userinfo@]host][/]path[?query][#fragment] --> [scheme:][//[***]host][/***][#***] // if the format is not matched nothing is done, string is returned as is. func MaskCredentialsLogging(currUrl string) string { diff --git a/shared/service_registry.go b/shared/service_registry.go index 30d6a332ba..66ddf8f916 100644 --- a/shared/service_registry.go +++ b/shared/service_registry.go @@ -19,7 +19,7 @@ type Service interface { // Stop terminates all goroutines belonging to the service, // blocking until they are all terminated. Stop() error - // Returns error if the service is not considered healthy. + // Status returns error if the service is not considered healthy. Status() error } diff --git a/spectest/shared/phase0/epoch_processing/effective_balance_updates.go b/spectest/shared/phase0/epoch_processing/effective_balance_updates.go index 0c8214b3a4..cf17e8d240 100644 --- a/spectest/shared/phase0/epoch_processing/effective_balance_updates.go +++ b/spectest/shared/phase0/epoch_processing/effective_balance_updates.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunEffectiveBalanceUpdatesTests executes "epoch_processing/effective_balance_updates" tests. func RunEffectiveBalanceUpdatesTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/eth1_data_reset.go b/spectest/shared/phase0/epoch_processing/eth1_data_reset.go index c9cfcf62c3..9cc4a18692 100644 --- a/spectest/shared/phase0/epoch_processing/eth1_data_reset.go +++ b/spectest/shared/phase0/epoch_processing/eth1_data_reset.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunEth1DataResetTests executes "epoch_processing/eth1_data_reset" tests. func RunEth1DataResetTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/historical_roots_update.go b/spectest/shared/phase0/epoch_processing/historical_roots_update.go index cbcf2c3c47..be2b894735 100644 --- a/spectest/shared/phase0/epoch_processing/historical_roots_update.go +++ b/spectest/shared/phase0/epoch_processing/historical_roots_update.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunHistoricalRootsUpdateTests executes "epoch_processing/historical_roots_update" tests. func RunHistoricalRootsUpdateTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/justification_and_finalization.go b/spectest/shared/phase0/epoch_processing/justification_and_finalization.go index f03bab1e40..ba6d926b67 100644 --- a/spectest/shared/phase0/epoch_processing/justification_and_finalization.go +++ b/spectest/shared/phase0/epoch_processing/justification_and_finalization.go @@ -11,6 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunJustificationAndFinalizationTests executes "epoch_processing/justification_and_finalization" tests. func RunJustificationAndFinalizationTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/participation_record_updates.go b/spectest/shared/phase0/epoch_processing/participation_record_updates.go index 32df977ca8..4500133010 100644 --- a/spectest/shared/phase0/epoch_processing/participation_record_updates.go +++ b/spectest/shared/phase0/epoch_processing/participation_record_updates.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunParticipationRecordUpdatesTests executes "epoch_processing/participation_record_updates" tests. func RunParticipationRecordUpdatesTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/randao_mixes_reset.go b/spectest/shared/phase0/epoch_processing/randao_mixes_reset.go index 7c7d69b61d..aa8bfa63fa 100644 --- a/spectest/shared/phase0/epoch_processing/randao_mixes_reset.go +++ b/spectest/shared/phase0/epoch_processing/randao_mixes_reset.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunRandaoMixesResetTests executes "epoch_processing/randao_mixes_reset" tests. func RunRandaoMixesResetTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/registry.go b/spectest/shared/phase0/epoch_processing/registry.go index 32d004b4a7..e77b784e58 100644 --- a/spectest/shared/phase0/epoch_processing/registry.go +++ b/spectest/shared/phase0/epoch_processing/registry.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunRegistryUpdatesTests executes "epoch_processing/registry_updates" tests. func RunRegistryUpdatesTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/rewards_and_penalties.go b/spectest/shared/phase0/epoch_processing/rewards_and_penalties.go index 71790c3402..41d6c558b5 100644 --- a/spectest/shared/phase0/epoch_processing/rewards_and_penalties.go +++ b/spectest/shared/phase0/epoch_processing/rewards_and_penalties.go @@ -12,6 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunRewardsAndPenaltiesTests executes "epoch_processing/rewards_and_penalties" tests. func RunRewardsAndPenaltiesTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/slashings.go b/spectest/shared/phase0/epoch_processing/slashings.go index 6e55cca89f..4f990468f0 100644 --- a/spectest/shared/phase0/epoch_processing/slashings.go +++ b/spectest/shared/phase0/epoch_processing/slashings.go @@ -12,6 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunSlashingsTests executes "epoch_processing/slashings" tests. func RunSlashingsTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/epoch_processing/slashings_reset.go b/spectest/shared/phase0/epoch_processing/slashings_reset.go index f7e0eee000..0365b9186b 100644 --- a/spectest/shared/phase0/epoch_processing/slashings_reset.go +++ b/spectest/shared/phase0/epoch_processing/slashings_reset.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunSlashingsResetTests executes "epoch_processing/slashings_reset" tests. func RunSlashingsResetTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/operations/attestation.go b/spectest/shared/phase0/operations/attestation.go index 447d339308..511d224e33 100644 --- a/spectest/shared/phase0/operations/attestation.go +++ b/spectest/shared/phase0/operations/attestation.go @@ -12,6 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunAttestationTest executes "operations/attestation" tests. func RunAttestationTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/attestation/pyspec_tests") diff --git a/spectest/shared/phase0/operations/attester_slashing.go b/spectest/shared/phase0/operations/attester_slashing.go index c5b138508b..c13f76f8ee 100644 --- a/spectest/shared/phase0/operations/attester_slashing.go +++ b/spectest/shared/phase0/operations/attester_slashing.go @@ -15,6 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunAttesterSlashingTest executes "operations/attester_slashing" tests. func RunAttesterSlashingTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/attester_slashing/pyspec_tests") diff --git a/spectest/shared/phase0/operations/block_header.go b/spectest/shared/phase0/operations/block_header.go index 2cdad1c9c0..95f878e9a1 100644 --- a/spectest/shared/phase0/operations/block_header.go +++ b/spectest/shared/phase0/operations/block_header.go @@ -19,6 +19,7 @@ import ( "gopkg.in/d4l3k/messagediff.v1" ) +// RunBlockHeaderTest executes "operations/block_header" tests. func RunBlockHeaderTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/block_header/pyspec_tests") diff --git a/spectest/shared/phase0/operations/deposit.go b/spectest/shared/phase0/operations/deposit.go index 625cc1015f..0f822716bb 100644 --- a/spectest/shared/phase0/operations/deposit.go +++ b/spectest/shared/phase0/operations/deposit.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunDepositTest executes "operations/deposit" tests. func RunDepositTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/deposit/pyspec_tests") diff --git a/spectest/shared/phase0/operations/proposer_slashing.go b/spectest/shared/phase0/operations/proposer_slashing.go index a1ad019458..e1a8fdcb19 100644 --- a/spectest/shared/phase0/operations/proposer_slashing.go +++ b/spectest/shared/phase0/operations/proposer_slashing.go @@ -15,6 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunProposerSlashingTest executes "operations/proposer_slashing" tests. func RunProposerSlashingTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/proposer_slashing/pyspec_tests") diff --git a/spectest/shared/phase0/operations/voluntary_exit.go b/spectest/shared/phase0/operations/voluntary_exit.go index 707498725d..8a16396532 100644 --- a/spectest/shared/phase0/operations/voluntary_exit.go +++ b/spectest/shared/phase0/operations/voluntary_exit.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunVoluntaryExitTest executes "operations/voluntary_exit" tests. func RunVoluntaryExitTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/voluntary_exit/pyspec_tests") diff --git a/spectest/shared/phase0/rewards/rewards_penalties.go b/spectest/shared/phase0/rewards/rewards_penalties.go index 5189f41321..de3f613dd0 100644 --- a/spectest/shared/phase0/rewards/rewards_penalties.go +++ b/spectest/shared/phase0/rewards/rewards_penalties.go @@ -17,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// Delta contains list of rewards and penalties. type Delta struct { Rewards []uint64 `json:"rewards"` Penalties []uint64 `json:"penalties"` @@ -42,6 +43,7 @@ var deltaFiles = []string{ "inclusion_delay_deltas.ssz_snappy", } +// RunPrecomputeRewardsAndPenaltiesTests executes "rewards/{basic, leak, random}" tests. func RunPrecomputeRewardsAndPenaltiesTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) testPaths := []string{"rewards/basic/pyspec_tests", "rewards/leak/pyspec_tests", "rewards/random/pyspec_tests"} diff --git a/spectest/shared/phase0/sanity/block_processing.go b/spectest/shared/phase0/sanity/block_processing.go index 4f077868f9..c2c16a05f8 100644 --- a/spectest/shared/phase0/sanity/block_processing.go +++ b/spectest/shared/phase0/sanity/block_processing.go @@ -27,6 +27,7 @@ func init() { state.SkipSlotCache.Disable() } +// RunBlockProcessingTest executes "sanity/blocks" tests. func RunBlockProcessingTest(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/sanity/slot_processing.go b/spectest/shared/phase0/sanity/slot_processing.go index ca939b4ea9..4f7d2301ba 100644 --- a/spectest/shared/phase0/sanity/slot_processing.go +++ b/spectest/shared/phase0/sanity/slot_processing.go @@ -20,6 +20,7 @@ func init() { state.SkipSlotCache.Disable() } +// RunSlotProcessingTests executes "sanity/slots" tests. func RunSlotProcessingTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/shuffling/core/shuffle/shuffle.go b/spectest/shared/phase0/shuffling/core/shuffle/shuffle.go index 1d9fe8b613..7b672e0497 100644 --- a/spectest/shared/phase0/shuffling/core/shuffle/shuffle.go +++ b/spectest/shared/phase0/shuffling/core/shuffle/shuffle.go @@ -16,6 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/spectest/utils" ) +// RunShuffleTests executes "shuffling/core/shuffle" tests. func RunShuffleTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) diff --git a/spectest/shared/phase0/ssz_static/ssz_static.go b/spectest/shared/phase0/ssz_static/ssz_static.go index 2ed237e64d..4e734487b6 100644 --- a/spectest/shared/phase0/ssz_static/ssz_static.go +++ b/spectest/shared/phase0/ssz_static/ssz_static.go @@ -23,6 +23,7 @@ type SSZRoots struct { SigningRoot string `json:"signing_root"` } +// RunSSZStaticTests executes "ssz_static" tests. func RunSSZStaticTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) @@ -89,6 +90,7 @@ func RunSSZStaticTests(t *testing.T, config string) { } } +// UnmarshalledSSZ unmarshalls serialized input. func UnmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (interface{}, error) { var obj interface{} switch folderName { diff --git a/tools/analyzers/comparesame/testdata/compare_len.go b/tools/analyzers/comparesame/testdata/compare_len.go index 49cae86b15..8c4b688d96 100644 --- a/tools/analyzers/comparesame/testdata/compare_len.go +++ b/tools/analyzers/comparesame/testdata/compare_len.go @@ -1,35 +1,41 @@ package testdata +// Equal -- func Equal() { x := []string{"a"} if len(x) == len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true." } } +// NotEqual -- func NotEqual() { x := []string{"a"} if len(x) != len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true." } } +// GreaterThanOrEqual -- func GreaterThanOrEqual() { x := []string{"a"} if len(x) >= len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true." } } +// LessThanOrEqual -- func LessThanOrEqual() { x := []string{"a"} if len(x) <= len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true." } } +// GreaterThan -- func GreaterThan() { x := []string{"a"} if len(x) > len(x) { // want "Boolean expression has identical expressions on both sides. The result is always false." } } +// LessThan -- func LessThan() { x := []string{"a"} if len(x) < len(x) { // want "Boolean expression has identical expressions on both sides. The result is always false." diff --git a/tools/analyzers/cryptorand/testdata/custom_import.go b/tools/analyzers/cryptorand/testdata/custom_import.go index 6c21801c59..6ecf393c99 100644 --- a/tools/analyzers/cryptorand/testdata/custom_import.go +++ b/tools/analyzers/cryptorand/testdata/custom_import.go @@ -6,6 +6,7 @@ import ( "time" ) +// UseRandNewCustomImport -- func UseRandNewCustomImport() { source := mathRand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" @@ -16,7 +17,8 @@ func UseRandNewCustomImport() { randGenerator = mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" } -func UseWithoutSeeCustomImportd() { +// UseWithoutSeeCustomImport -- +func UseWithoutSeeCustomImport() { assignedIndex := mathRand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" _ = assignedIndex foobar.Shuffle(10, func(i, j int) { // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" diff --git a/tools/analyzers/cryptorand/testdata/rand_new.go b/tools/analyzers/cryptorand/testdata/rand_new.go index d916a14b7b..566dd6ff42 100644 --- a/tools/analyzers/cryptorand/testdata/rand_new.go +++ b/tools/analyzers/cryptorand/testdata/rand_new.go @@ -6,6 +6,7 @@ import ( "time" ) +// UseRandNew -- func UseRandNew() { source := rand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" @@ -16,6 +17,7 @@ func UseRandNew() { randGenerator = rand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" } +// UseWithoutSeed -- func UseWithoutSeed() { assignedIndex := rand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand" _ = assignedIndex diff --git a/tools/analyzers/ineffassign/ineffassign.go b/tools/analyzers/ineffassign/ineffassign.go index 3dbfe2e099..53aea623cf 100644 --- a/tools/analyzers/ineffassign/ineffassign.go +++ b/tools/analyzers/ineffassign/ineffassign.go @@ -41,6 +41,7 @@ func (bld *builder) walk(n ast.Node) { } } +// Visit -- func (bld *builder) Visit(n ast.Node) ast.Visitor { switch n := n.(type) { case *ast.FuncDecl: @@ -545,6 +546,11 @@ func used(obj *ast.Object, b *block, seen map[*block]bool) bool { type idents []*ast.Ident -func (ids idents) Len() int { return len(ids) } +// Len -- +func (ids idents) Len() int { return len(ids) } + +// Less -- func (ids idents) Less(i, j int) bool { return ids[i].Pos() < ids[j].Pos() } -func (ids idents) Swap(i, j int) { ids[i], ids[j] = ids[j], ids[i] } + +// Swap -- +func (ids idents) Swap(i, j int) { ids[i], ids[j] = ids[j], ids[i] } diff --git a/tools/analyzers/ineffassign/testdata/ctx_assignment.go b/tools/analyzers/ineffassign/testdata/ctx_assignment.go index ae0d5c1e5c..c0cdf7fae8 100644 --- a/tools/analyzers/ineffassign/testdata/ctx_assignment.go +++ b/tools/analyzers/ineffassign/testdata/ctx_assignment.go @@ -13,6 +13,7 @@ func headState(ctx context.Context) { return } +// StartSpan -- func StartSpan(ctx context.Context, name string) (context.Context, int) { return ctx, 42 } diff --git a/tools/analyzers/maligned/maligned.go b/tools/analyzers/maligned/maligned.go index 95659f4968..d88016962f 100644 --- a/tools/analyzers/maligned/maligned.go +++ b/tools/analyzers/maligned/maligned.go @@ -78,13 +78,17 @@ type byAlignAndSize struct { sizeofs []int64 } +// Len -- func (s *byAlignAndSize) Len() int { return len(s.fields) } + +// Swap -- func (s *byAlignAndSize) Swap(i, j int) { s.fields[i], s.fields[j] = s.fields[j], s.fields[i] s.alignofs[i], s.alignofs[j] = s.alignofs[j], s.alignofs[i] s.sizeofs[i], s.sizeofs[j] = s.sizeofs[j], s.sizeofs[i] } +// Less -- func (s *byAlignAndSize) Less(i, j int) bool { // Place zero sized objects before non-zero sized objects. if s.sizeofs[i] == 0 && s.sizeofs[j] != 0 { @@ -114,6 +118,7 @@ type gcSizes struct { MaxAlign int64 } +// Alignof -- func (s *gcSizes) Alignof(T types.Type) int64 { // NOTE: On amd64, complex64 is 8 byte aligned, // even though float32 is only 4 byte aligned. @@ -164,6 +169,7 @@ var basicSizes = [...]byte{ types.Complex128: 16, } +// Sizeof -- func (s *gcSizes) Sizeof(T types.Type) int64 { switch t := T.Underlying().(type) { case *types.Basic: diff --git a/tools/analyzers/nop/testdata/no_op.go b/tools/analyzers/nop/testdata/no_op.go index 8f962665eb..9ec76734f8 100644 --- a/tools/analyzers/nop/testdata/no_op.go +++ b/tools/analyzers/nop/testdata/no_op.go @@ -3,11 +3,13 @@ package testdata type foo struct { } +// AddressOfDereferencedValue -- func AddressOfDereferencedValue() { x := &foo{} _ = &*x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended." } +// DereferencedAddressOfValue -- func DereferencedAddressOfValue() { x := foo{} _ = *&x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended." diff --git a/tools/analyzers/properpermissions/testdata/custom_imports.go b/tools/analyzers/properpermissions/testdata/custom_imports.go index 7d6145ed82..d0febfa762 100644 --- a/tools/analyzers/properpermissions/testdata/custom_imports.go +++ b/tools/analyzers/properpermissions/testdata/custom_imports.go @@ -9,6 +9,7 @@ import ( "path/filepath" ) +// UseAliasedPackages -- func UseAliasedPackages() { randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000)) p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath)) diff --git a/tools/analyzers/properpermissions/testdata/regular_imports.go b/tools/analyzers/properpermissions/testdata/regular_imports.go index 0e9cbb3f40..d56813b0f0 100644 --- a/tools/analyzers/properpermissions/testdata/regular_imports.go +++ b/tools/analyzers/properpermissions/testdata/regular_imports.go @@ -17,6 +17,7 @@ func tempDir() string { return d } +// UseOsMkdirAllAndWriteFile -- func UseOsMkdirAllAndWriteFile() { randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000)) p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath)) diff --git a/tools/analyzers/shadowpredecl/testdata/shadow.go b/tools/analyzers/shadowpredecl/testdata/shadow.go index 86302093dc..7cba7cb2c0 100644 --- a/tools/analyzers/shadowpredecl/testdata/shadow.go +++ b/tools/analyzers/shadowpredecl/testdata/shadow.go @@ -8,16 +8,19 @@ type int interface { // want "Type 'int' shadows a predeclared identifier with t } +// Struct -- func Struct() { type error struct { // want "Type 'error' shadows a predeclared identifier with the same name. Choose another name." int int // No diagnostic because the name is always referenced indirectly through a struct variable. } } +// TypeAlias -- func TypeAlias() { type error string // want "Type 'error' shadows a predeclared identifier with the same name. Choose another name." } +// UninitializedVarAndAssignments -- func UninitializedVarAndAssignments() { var error int // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name." error = 1 // No diagnostic because the original declaration already triggered one. @@ -25,24 +28,28 @@ func UninitializedVarAndAssignments() { } } +// InitializedVar -- func InitializedVar() { error := 0 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name." if error == 0 { } } +// FirstInVarList -- func FirstInVarList() { error, x := 0, 1 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name." if error == x { } } +// SecondInVarList -- func SecondInVarList() { x, error := 0, 1 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name." if error == x { } } +// Const -- func Const() { const error = 0 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name." } @@ -63,7 +70,7 @@ func error(len int) { // want "Function 'error' shadows a predeclared identifier type receiver struct { } -// Test receiver function. +// Receiver is a test receiver function. func (s *receiver) Receiver(len int) { } diff --git a/tools/analyzers/slicedirect/testdata/slice.go b/tools/analyzers/slicedirect/testdata/slice.go index 4819bce567..b9dbee91ee 100644 --- a/tools/analyzers/slicedirect/testdata/slice.go +++ b/tools/analyzers/slicedirect/testdata/slice.go @@ -1,5 +1,6 @@ package testdata +// NoIndexProvided -- func NoIndexProvided() { x := []byte{'f', 'o', 'o'} y := x[:] // want "Expression is already a slice." @@ -7,6 +8,7 @@ func NoIndexProvided() { } } +// StartindexprovidedNodiagnostic -- func StartindexprovidedNodiagnostic() { x := []byte{'f', 'o', 'o'} y := x[1:] @@ -14,6 +16,7 @@ func StartindexprovidedNodiagnostic() { } } +// EndindexprovidedNodiagnostic -- func EndindexprovidedNodiagnostic() { x := []byte{'f', 'o', 'o'} y := x[:2] @@ -21,6 +24,7 @@ func EndindexprovidedNodiagnostic() { } } +// BothindicesprovidedNodiagnostic -- func BothindicesprovidedNodiagnostic() { x := []byte{'f', 'o', 'o'} y := x[1:2] @@ -28,6 +32,7 @@ func BothindicesprovidedNodiagnostic() { } } +// StringSlice -- func StringSlice() { x := "foo" y := x[:] // want "Expression is already a slice." @@ -35,6 +40,7 @@ func StringSlice() { } } +// SliceFromFunction -- func SliceFromFunction() { x := slice()[:] // want "Expression is already a slice." if len(x) == 3 { diff --git a/tools/cluster-pk-manager/server/db.go b/tools/cluster-pk-manager/server/db.go index f00c977009..9fcf2aa68b 100644 --- a/tools/cluster-pk-manager/server/db.go +++ b/tools/cluster-pk-manager/server/db.go @@ -118,6 +118,7 @@ func (d *db) UnallocatedPKs(_ context.Context, numKeys uint64) (*pb.PrivateKeys, return pks, nil } +// DeleteUnallocatedKey removes provided private key. func (d *db) DeleteUnallocatedKey(_ context.Context, privateKey []byte) error { return d.db.Update(func(tx *bolt.Tx) error { if err := tx.Bucket(unassignedPkBucket).Delete(privateKey); err != nil { @@ -132,7 +133,7 @@ func (d *db) DeleteUnallocatedKey(_ context.Context, privateKey []byte) error { }) } -// PodPK returns an assigned private key to the given pod name, if one exists. +// PodPKs returns an assigned private key to the given pod name, if one exists. func (d *db) PodPKs(_ context.Context, podName string) (*pb.PrivateKeys, error) { pks := &pb.PrivateKeys{} if err := d.db.View(func(tx *bolt.Tx) error { @@ -173,7 +174,7 @@ func (d *db) AllocateNewPkToPod( }) } -// RemovePKAssignments from pod and put the private keys into the unassigned +// RemovePKAssignment from pod and put the private keys into the unassigned // bucket. func (d *db) RemovePKAssignment(_ context.Context, podName string) error { return d.db.Update(func(tx *bolt.Tx) error { @@ -245,6 +246,7 @@ func (d *db) AllocatedPodNames(_ context.Context) ([]string, error) { return podNames, nil } +// Allocations builds and returns key allocations. func (d *db) Allocations() (map[string][][]byte, error) { m := make(map[string][][]byte) if err := d.db.View(func(tx *bolt.Tx) error { @@ -274,6 +276,7 @@ func (d *db) Allocations() (map[string][][]byte, error) { return m, nil } +// KeyMap builds and returns key map. func (d *db) KeyMap() ([][]byte, map[[48]byte]keyMap, error) { m := make(map[[48]byte]keyMap) pubkeys := make([][]byte, 0) diff --git a/tools/cluster-pk-manager/server/server.go b/tools/cluster-pk-manager/server/server.go index 97aaf9197c..cc97d65896 100644 --- a/tools/cluster-pk-manager/server/server.go +++ b/tools/cluster-pk-manager/server/server.go @@ -87,6 +87,7 @@ func (s *server) makeDeposit(pubkey, withdrawalCredentials, signature []byte, de return tx, nil } +// Request processes private keys requests. func (s *server) Request(ctx context.Context, req *pb.PrivateKeyRequest) (*pb.PrivateKeyResponse, error) { s.clientLock.Lock() defer s.clientLock.Unlock() diff --git a/tools/forkchecker/forkchecker.go b/tools/forkchecker/forkchecker.go index 1be910b2f0..309f8ca2f1 100644 --- a/tools/forkchecker/forkchecker.go +++ b/tools/forkchecker/forkchecker.go @@ -32,6 +32,7 @@ func (e *endpoint) String() string { return "gRPC endpoints" } +// Set adds endpoint value to list. func (e *endpoint) Set(value string) error { *e = append(*e, value) return nil diff --git a/validator/accounts/accounts.go b/validator/accounts/accounts.go index 836ebef168..6dd680fd01 100644 --- a/validator/accounts/accounts.go +++ b/validator/accounts/accounts.go @@ -7,7 +7,7 @@ import ( var ( errKeymanagerNotSupported = "keymanager kind not supported: %s" - // MsgCouldNotInitializeKeymanager informs about failed keymanager initialization + // ErrCouldNotInitializeKeymanager informs about failed keymanager initialization ErrCouldNotInitializeKeymanager = "could not initialize keymanager" ) diff --git a/validator/accounts/accounts_import.go b/validator/accounts/accounts_import.go index f0ac79e397..bbbdd6b1e8 100644 --- a/validator/accounts/accounts_import.go +++ b/validator/accounts/accounts_import.go @@ -36,7 +36,10 @@ var derivationPathRegex = regexp.MustCompile(`m_12381_3600_(\d+)_(\d+)_(\d+)`) // in a directory and import them nicely in order of the derivation path. type byDerivationPath []string +// Len is the number of elements in the collection. func (fileNames byDerivationPath) Len() int { return len(fileNames) } + +// Less reports whether the element with index i must sort before the element with index j. func (fileNames byDerivationPath) Less(i, j int) bool { // We check if file name at index i has a derivation path // in the filename. If it does not, then it is not less than j, and @@ -63,6 +66,7 @@ func (fileNames byDerivationPath) Less(i, j int) bool { return a < b } +// Swap swaps the elements with indexes i and j. func (fileNames byDerivationPath) Swap(i, j int) { fileNames[i], fileNames[j] = fileNames[j], fileNames[i] } diff --git a/validator/accounts/doc.go b/validator/accounts/doc.go index 2eb80be895..b1bd44316b 100644 --- a/validator/accounts/doc.go +++ b/validator/accounts/doc.go @@ -1,4 +1,4 @@ -// Package v2 defines a new model for accounts management in Prysm, using best +// Package accounts defines a new model for accounts management in Prysm, using best // practices for user security, UX, and extensibility via different wallet types // including HD wallets, imported (non-HD) wallets, and remote-signing capable configurations. This model // is compliant with the EIP-2333, EIP-2334, and EIP-2335 standards for key management in eth2. diff --git a/validator/client/log.go b/validator/client/log.go index 7a34dfc6da..14efc1a81d 100644 --- a/validator/client/log.go +++ b/validator/client/log.go @@ -21,6 +21,7 @@ type attSubmitted struct { aggregatorIndices []types.ValidatorIndex } +// LogAttestationsSubmitted logs info about submitted attestations. func (v *validator) LogAttestationsSubmitted() { v.attLogsLock.Lock() defer v.attLogsLock.Unlock() @@ -42,6 +43,7 @@ func (v *validator) LogAttestationsSubmitted() { v.attLogs = make(map[[32]byte]*attSubmitted) } +// LogNextDutyTimeLeft logs the next duty info. func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error { if !v.logDutyCountDown { return nil diff --git a/validator/client/multiple_endpoints_grpc_resolver.go b/validator/client/multiple_endpoints_grpc_resolver.go index 46495ae6e2..ddcf432e4f 100644 --- a/validator/client/multiple_endpoints_grpc_resolver.go +++ b/validator/client/multiple_endpoints_grpc_resolver.go @@ -14,6 +14,7 @@ import ( // grpc.WithDefaultServiceConfig("{\"loadBalancingConfig\":[{\"round_robin\":{}}]}") type multipleEndpointsGrpcResolverBuilder struct{} +// Build creates and starts multiple endpoints resolver. func (*multipleEndpointsGrpcResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) { r := &multipleEndpointsGrpcResolver{ target: target, @@ -23,6 +24,7 @@ func (*multipleEndpointsGrpcResolverBuilder) Build(target resolver.Target, cc re return r, nil } +// Scheme returns default scheme. func (*multipleEndpointsGrpcResolverBuilder) Scheme() string { return resolver.GetDefaultScheme() } @@ -41,6 +43,8 @@ func (r *multipleEndpointsGrpcResolver) start() { r.cc.UpdateState(resolver.State{Addresses: addrs}) } +// ResolveNow -- func (*multipleEndpointsGrpcResolver) ResolveNow(_ resolver.ResolveNowOptions) {} +// Close -- func (*multipleEndpointsGrpcResolver) Close() {} diff --git a/validator/client/testutil/mock_validator.go b/validator/client/testutil/mock_validator.go index f03be22703..79e785b70f 100644 --- a/validator/client/testutil/mock_validator.go +++ b/validator/client/testutil/mock_validator.go @@ -172,7 +172,7 @@ func (fv *FakeValidator) SubmitAggregateAndProof(_ context.Context, _ types.Slot // LogAttestationsSubmitted for mocking. func (fv *FakeValidator) LogAttestationsSubmitted() {} -// LogNextDutyCountDown for mocking. +// LogNextDutyTimeLeft for mocking. func (fv *FakeValidator) LogNextDutyTimeLeft(slot types.Slot) error { return nil } diff --git a/validator/db/kv/db.go b/validator/db/kv/db.go index d6d8a05e71..3294e94ed0 100644 --- a/validator/db/kv/db.go +++ b/validator/db/kv/db.go @@ -50,6 +50,7 @@ var blockedBuckets = [][]byte{ attestationTargetEpochsBucket, } +// Config represents store's config object. type Config struct { PubKeys [][48]byte InitialMMapSize int diff --git a/validator/graffiti/parse_graffiti.go b/validator/graffiti/parse_graffiti.go index 5f5d703ea9..9e23dfebc2 100644 --- a/validator/graffiti/parse_graffiti.go +++ b/validator/graffiti/parse_graffiti.go @@ -8,6 +8,7 @@ import ( "gopkg.in/yaml.v2" ) +// Graffiti is a graffiti container. type Graffiti struct { Hash [32]byte Default string `yaml:"default,omitempty"` diff --git a/validator/keymanager/constants.go b/validator/keymanager/constants.go index dc0af7f438..a8f3a4ee6c 100644 --- a/validator/keymanager/constants.go +++ b/validator/keymanager/constants.go @@ -1,3 +1,4 @@ package keymanager +// KeysReloaded is a "key reloaded" message. const KeysReloaded = "Reloaded validator keys into keymanager" diff --git a/validator/keymanager/derived/mnemonic.go b/validator/keymanager/derived/mnemonic.go index ea8d5f4252..b8ed4aef2d 100644 --- a/validator/keymanager/derived/mnemonic.go +++ b/validator/keymanager/derived/mnemonic.go @@ -19,6 +19,7 @@ type EnglishMnemonicGenerator struct { skipMnemonicConfirm bool } +// GenerateAndConfirmMnemonic requires confirming the generated mnemonics. func GenerateAndConfirmMnemonic( skipMnemonicConfirm bool, ) (string, error) { diff --git a/validator/keymanager/remote/keymanager.go b/validator/keymanager/remote/keymanager.go index 8ac668f26a..c374363d3c 100644 --- a/validator/keymanager/remote/keymanager.go +++ b/validator/keymanager/remote/keymanager.go @@ -207,6 +207,7 @@ func (km *Keymanager) KeymanagerOpts() *KeymanagerOpts { return km.opts } +// ReloadPublicKeys reloads public keys. func (km *Keymanager) ReloadPublicKeys(ctx context.Context) ([][48]byte, error) { pubKeys, err := km.FetchValidatingPublicKeys(ctx) if err != nil { diff --git a/validator/keymanager/remote/mock_keymanager.go b/validator/keymanager/remote/mock_keymanager.go index 19911595f9..f59c7ad4b0 100644 --- a/validator/keymanager/remote/mock_keymanager.go +++ b/validator/keymanager/remote/mock_keymanager.go @@ -8,22 +8,27 @@ import ( "github.com/prysmaticlabs/prysm/shared/event" ) +// MockKeymanager -- type MockKeymanager struct { PublicKeys [][48]byte } +// FetchValidatingPublicKeys -- func (m *MockKeymanager) FetchValidatingPublicKeys(context.Context) ([][48]byte, error) { return m.PublicKeys, nil } +// Sign -- func (*MockKeymanager) Sign(context.Context, *validatorpb.SignRequest) (bls.Signature, error) { panic("implement me") } +// SubscribeAccountChanges -- func (*MockKeymanager) SubscribeAccountChanges(chan [][48]byte) event.Subscription { panic("implement me") } +// ReloadPublicKeys -- func (m *MockKeymanager) ReloadPublicKeys(context.Context) ([][48]byte, error) { return m.PublicKeys, nil } diff --git a/validator/rpc/beacon.go b/validator/rpc/beacon.go index 01cc29db5f..5e2065a7c7 100644 --- a/validator/rpc/beacon.go +++ b/validator/rpc/beacon.go @@ -99,7 +99,7 @@ func (s *Server) GetValidatorPerformance( return s.beaconChainClient.GetValidatorPerformance(ctx, req) } -// GetValidatorBalance is a wrapper around the /eth/v1alpha1 endpoint of the same name. +// GetValidatorBalances is a wrapper around the /eth/v1alpha1 endpoint of the same name. func (s *Server) GetValidatorBalances( ctx context.Context, req *ethpb.ListValidatorBalancesRequest, ) (*ethpb.ValidatorBalances, error) { diff --git a/validator/slashing-protection/local/standard-protection-format/format/format.go b/validator/slashing-protection/local/standard-protection-format/format/format.go index 31e5b14fb6..d8bdd97a3c 100644 --- a/validator/slashing-protection/local/standard-protection-format/format/format.go +++ b/validator/slashing-protection/local/standard-protection-format/format/format.go @@ -1,4 +1,4 @@ -// Package interchangeformat defines methods to parse, import, and export slashing protection data +// Package format defines methods to parse, import, and export slashing protection data // from a standard JSON file according to EIP-3076 https://eips.ethereum.org/EIPS/eip-3076. This format // is critical to allow safe interoperability between eth2 clients. package format diff --git a/validator/slashing-protection/local/standard-protection-format/helpers.go b/validator/slashing-protection/local/standard-protection-format/helpers.go index 3464b3937a..cee1b9b1fc 100644 --- a/validator/slashing-protection/local/standard-protection-format/helpers.go +++ b/validator/slashing-protection/local/standard-protection-format/helpers.go @@ -34,7 +34,7 @@ func Uint64FromString(str string) (uint64, error) { return strconv.ParseUint(str, 10, 64) } -// Uint64FromString converts a string into Epoch. +// EpochFromString converts a string into Epoch. func EpochFromString(str string) (types.Epoch, error) { e, err := strconv.ParseUint(str, 10, 64) if err != nil { diff --git a/validator/testing/constants.go b/validator/testing/constants.go index 262573914e..f5a757095e 100644 --- a/validator/testing/constants.go +++ b/validator/testing/constants.go @@ -1,3 +1,4 @@ package testing +// TestMnemonic -- const TestMnemonic = "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason"