Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code inspect - clean ups #8445

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions beacon-chain/rpc/validator/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions shared/hashutil/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions slasher/beaconclient/receivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/comparesame/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/cryptorand/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/errcheck/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/featureconfig/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/maligned/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/nop/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/properpermissions/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/shadowpredecl/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/slicedirect/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions validator/accounts/accounts_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions validator/accounts/accounts_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions validator/accounts/accounts_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -58,7 +58,7 @@ func ExitAccountsCli(cliCtx *cli.Context, r io.Reader) error {
cfg := performExitCfg{
*validatorClient,
*nodeClient,
keymanager,
kManager,
rawPubKeys,
trimmedPubKeys,
}
Expand Down
4 changes: 2 additions & 2 deletions validator/client/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion validator/client/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down