From 068f758f497d9118d549c008950a1f6f68103667 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 12 Feb 2021 15:04:45 -0800 Subject: [PATCH] Code inspect - clean ups (#8445) --- beacon-chain/rpc/validator/assignments.go | 6 +++--- shared/hashutil/hash.go | 6 +++--- slasher/beaconclient/receivers.go | 4 ++-- tools/analyzers/comparesame/analyzer.go | 4 ++-- tools/analyzers/cryptorand/analyzer.go | 4 ++-- tools/analyzers/errcheck/analyzer.go | 4 ++-- tools/analyzers/featureconfig/analyzer.go | 4 ++-- tools/analyzers/maligned/analyzer.go | 4 ++-- tools/analyzers/nop/analyzer.go | 4 ++-- tools/analyzers/properpermissions/analyzer.go | 4 ++-- tools/analyzers/shadowpredecl/analyzer.go | 4 ++-- tools/analyzers/slicedirect/analyzer.go | 4 ++-- validator/accounts/accounts_backup.go | 4 ++-- validator/accounts/accounts_delete.go | 6 +++--- validator/accounts/accounts_exit.go | 4 ++-- validator/client/aggregate.go | 4 ++-- validator/client/propose.go | 2 +- 17 files changed, 36 insertions(+), 36 deletions(-) diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 5f9eb6dc8..f7b95a452 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -156,15 +156,15 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb. } idx, ok := s.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey)) if ok { - status := assignmentStatus(s, idx) + s := assignmentStatus(s, idx) assignment.ValidatorIndex = idx - assignment.Status = status + assignment.Status = s assignment.ProposerSlots = proposerIndexToSlots[idx] // The next epoch has no lookup for proposer indexes. nextAssignment.ValidatorIndex = idx - nextAssignment.Status = status + nextAssignment.Status = s ca, ok := committeeAssignments[idx] if ok { diff --git a/shared/hashutil/hash.go b/shared/hashutil/hash.go index 15b9301e9..e406823a9 100644 --- a/shared/hashutil/hash.go +++ b/shared/hashutil/hash.go @@ -59,7 +59,7 @@ func CustomSHA256Hasher() func([]byte) [32]byte { } else { hasher.Reset() } - var hash [32]byte + var h [32]byte return func(data []byte) [32]byte { // The hash interface never returns an error, for that reason @@ -68,10 +68,10 @@ func CustomSHA256Hasher() func([]byte) [32]byte { // #nosec G104 hasher.Write(data) - hasher.Sum(hash[:0]) + hasher.Sum(h[:0]) hasher.Reset() - return hash + return h } } diff --git a/slasher/beaconclient/receivers.go b/slasher/beaconclient/receivers.go index b2465c2f6..90d99e6c7 100644 --- a/slasher/beaconclient/receivers.go +++ b/slasher/beaconclient/receivers.go @@ -197,12 +197,12 @@ func (s *Service) restartBeaconConnection(ctx context.Context) error { log.Info("Beacon node is still down") continue } - status, err := s.nodeClient.GetSyncStatus(ctx, &ptypes.Empty{}) + s, err := s.nodeClient.GetSyncStatus(ctx, &ptypes.Empty{}) if err != nil { log.WithError(err).Error("Could not fetch sync status") continue } - if status == nil || status.Syncing { + if s == nil || s.Syncing { log.Info("Waiting for beacon node to be fully synced...") continue } diff --git a/tools/analyzers/comparesame/analyzer.go b/tools/analyzers/comparesame/analyzer.go index 8dc2f9eba..44e69be60 100644 --- a/tools/analyzers/comparesame/analyzer.go +++ b/tools/analyzers/comparesame/analyzer.go @@ -28,7 +28,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -37,7 +37,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.BinaryExpr)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { expr, ok := node.(*ast.BinaryExpr) if !ok { return diff --git a/tools/analyzers/cryptorand/analyzer.go b/tools/analyzers/cryptorand/analyzer.go index 495e68c54..9bd97250d 100644 --- a/tools/analyzers/cryptorand/analyzer.go +++ b/tools/analyzers/cryptorand/analyzer.go @@ -27,7 +27,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -42,7 +42,7 @@ func run(pass *analysis.Pass) (interface{}, error) { disallowedFns := []string{"NewSource", "New", "Seed", "Int63", "Uint32", "Uint64", "Int31", "Int", "Int63n", "Int31n", "Intn", "Float64", "Float32", "Perm", "Shuffle", "Read"} - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { switch stmt := node.(type) { case *ast.File: // Reset aliases (per file). diff --git a/tools/analyzers/errcheck/analyzer.go b/tools/analyzers/errcheck/analyzer.go index c95434c3c..2564f17f1 100644 --- a/tools/analyzers/errcheck/analyzer.go +++ b/tools/analyzers/errcheck/analyzer.go @@ -63,7 +63,7 @@ func init() { } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -76,7 +76,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.AssignStmt)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { switch stmt := node.(type) { case *ast.ExprStmt: if call, ok := stmt.X.(*ast.CallExpr); ok { diff --git a/tools/analyzers/featureconfig/analyzer.go b/tools/analyzers/featureconfig/analyzer.go index 02f37c765..d34c9672d 100644 --- a/tools/analyzers/featureconfig/analyzer.go +++ b/tools/analyzers/featureconfig/analyzer.go @@ -23,7 +23,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -36,7 +36,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.AssignStmt)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { if ce, ok := node.(*ast.CallExpr); ok && isPkgDot(ce.Fun, "featureconfig", "Init") { reportForbiddenUsage(pass, ce.Pos()) return diff --git a/tools/analyzers/maligned/analyzer.go b/tools/analyzers/maligned/analyzer.go index a50246615..1b4d4c9fb 100644 --- a/tools/analyzers/maligned/analyzer.go +++ b/tools/analyzers/maligned/analyzer.go @@ -23,7 +23,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -32,7 +32,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.StructType)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { if s, ok := node.(*ast.StructType); ok { if err := malign(node.Pos(), pass.TypesInfo.Types[s].Type.(*types.Struct)); err != nil { pass.Reportf(node.Pos(), err.Error()) diff --git a/tools/analyzers/nop/analyzer.go b/tools/analyzers/nop/analyzer.go index 2a09306a4..45d8baf92 100644 --- a/tools/analyzers/nop/analyzer.go +++ b/tools/analyzers/nop/analyzer.go @@ -26,7 +26,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -36,7 +36,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.UnaryExpr)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { switch expr := node.(type) { case *ast.StarExpr: unaryExpr, ok := expr.X.(*ast.UnaryExpr) diff --git a/tools/analyzers/properpermissions/analyzer.go b/tools/analyzers/properpermissions/analyzer.go index 534f6de00..1c9b3dd20 100644 --- a/tools/analyzers/properpermissions/analyzer.go +++ b/tools/analyzers/properpermissions/analyzer.go @@ -33,7 +33,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -46,7 +46,7 @@ func run(pass *analysis.Pass) (interface{}, error) { aliases := make(map[string]string) - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { switch stmt := node.(type) { case *ast.File: // Reset aliases (per file). diff --git a/tools/analyzers/shadowpredecl/analyzer.go b/tools/analyzers/shadowpredecl/analyzer.go index b39b9f105..19fdc47cf 100644 --- a/tools/analyzers/shadowpredecl/analyzer.go +++ b/tools/analyzers/shadowpredecl/analyzer.go @@ -32,7 +32,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -45,7 +45,7 @@ func run(pass *analysis.Pass) (interface{}, error) { (*ast.ValueSpec)(nil), } - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { switch declaration := node.(type) { case *ast.FuncDecl: if declaration.Recv != nil { diff --git a/tools/analyzers/slicedirect/analyzer.go b/tools/analyzers/slicedirect/analyzer.go index 2e81d67e8..6c4fd66a5 100644 --- a/tools/analyzers/slicedirect/analyzer.go +++ b/tools/analyzers/slicedirect/analyzer.go @@ -24,7 +24,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { return nil, errors.New("analyzer is not type *inspector.Inspector") } @@ -35,7 +35,7 @@ func run(pass *analysis.Pass) (interface{}, error) { typeInfo := types.Info{Types: make(map[ast.Expr]types.TypeAndValue)} - inspect.Preorder(nodeFilter, func(node ast.Node) { + inspection.Preorder(nodeFilter, func(node ast.Node) { sliceExpr, ok := node.(*ast.SliceExpr) if !ok { return diff --git a/validator/accounts/accounts_backup.go b/validator/accounts/accounts_backup.go index 037922ed8..9003bc637 100644 --- a/validator/accounts/accounts_backup.go +++ b/validator/accounts/accounts_backup.go @@ -142,14 +142,14 @@ func selectAccounts(selectionPrompt string, pubKeys [][48]byte) (filteredPubKeys results := make([]int, 0) au := aurora.NewAurora(true) for result != exit { - prompt := promptui.Select{ + p := promptui.Select{ Label: selectionPrompt, HideSelected: true, Items: append([]string{exit, allAccountsText}, pubKeyStrings...), Templates: templates, } - _, result, err = prompt.Run() + _, result, err = p.Run() if err != nil { return nil, err } diff --git a/validator/accounts/accounts_delete.go b/validator/accounts/accounts_delete.go index 1e6812929..a0d9455b0 100644 --- a/validator/accounts/accounts_delete.go +++ b/validator/accounts/accounts_delete.go @@ -27,11 +27,11 @@ func DeleteAccountCli(cliCtx *cli.Context) error { if err != nil { return errors.Wrap(err, "could not open wallet") } - keymanager, err := w.InitializeKeymanager(cliCtx.Context) + kManager, err := w.InitializeKeymanager(cliCtx.Context) if err != nil { return errors.Wrap(err, ErrCouldNotInitializeKeymanager) } - validatingPublicKeys, err := keymanager.FetchAllValidatingPublicKeys(cliCtx.Context) + validatingPublicKeys, err := kManager.FetchAllValidatingPublicKeys(cliCtx.Context) if err != nil { return err } @@ -87,7 +87,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error { } if err := DeleteAccount(cliCtx.Context, &Config{ Wallet: w, - Keymanager: keymanager, + Keymanager: kManager, DeletePublicKeys: rawPublicKeys, }); err != nil { return err diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index 6827f3087..4f552c2d5 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -36,7 +36,7 @@ const exitPassphrase = "Exit my validator" // ExitAccountsCli performs a voluntary exit on one or more accounts. func ExitAccountsCli(cliCtx *cli.Context, r io.Reader) error { - validatingPublicKeys, keymanager, err := prepareWallet(cliCtx) + validatingPublicKeys, kManager, err := prepareWallet(cliCtx) if err != nil { return err } @@ -58,7 +58,7 @@ func ExitAccountsCli(cliCtx *cli.Context, r io.Reader) error { cfg := performExitCfg{ *validatorClient, *nodeClient, - keymanager, + kManager, rawPubKeys, trimmedPubKeys, } diff --git a/validator/client/aggregate.go b/validator/client/aggregate.go index a17f7e690..e37d1f894 100644 --- a/validator/client/aggregate.go +++ b/validator/client/aggregate.go @@ -70,8 +70,8 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot uint64, pu SlotSignature: slotSig, }) if err != nil { - status, ok := status.FromError(err) - if ok && status.Code() == codes.NotFound { + s, ok := status.FromError(err) + if ok && s.Code() == codes.NotFound { log.WithField("slot", slot).WithError(err).Warn("No attestations to aggregate") } else { log.WithField("slot", slot).WithError(err).Error("Could not submit slot signature to beacon node") diff --git a/validator/client/propose.go b/validator/client/propose.go index 9fc27a273..97497b6b3 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -39,7 +39,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot uint64, pubKey [48]by log.Debug("Assigned to genesis slot, skipping proposal") return } - lock := mputil.NewMultilock(string(roleProposer), string(pubKey[:])) + lock := mputil.NewMultilock(string(rune(roleProposer)), string(pubKey[:])) lock.Lock() defer lock.Unlock() ctx, span := trace.StartSpan(ctx, "validator.ProposeBlock")