Massive code cleanup (#10913)

* Massive code cleanup

* fix test issues

* remove GetGenesis mock expectations

* unused receiver

* rename unused params

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka
2022-06-27 15:34:38 +02:00
committed by GitHub
parent 9216be7d43
commit 7f56ac6355
158 changed files with 1020 additions and 1177 deletions

View File

@@ -34,7 +34,7 @@ var Analyzer = &analysis.Analyzer{
const over = 100
func run(pass *analysis.Pass) (interface{}, error) {
inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
inspectResult, 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) {
nodeFilter := []ast.Node{
(*ast.FuncDecl)(nil),
}
inspect.Preorder(nodeFilter, func(n ast.Node) {
inspectResult.Preorder(nodeFilter, func(n ast.Node) {
fnDecl, ok := n.(*ast.FuncDecl)
if !ok {
return

View File

@@ -66,7 +66,7 @@ func (m mode) ErrorFound() error {
}
func run(pass *analysis.Pass) (interface{}, error) {
inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
inspectResult, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, errors.New("analyzer is not type *inspector.Inspector")
}
@@ -86,7 +86,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
rLockTrack: &lockTracker{},
lockTrack: &lockTracker{},
}
inspect.Preorder(nodeFilter, func(node ast.Node) {
inspectResult.Preorder(nodeFilter, func(node ast.Node) {
if keepTrackOf.rLockTrack.funcLitEnd.IsValid() && node.Pos() <= keepTrackOf.rLockTrack.funcLitEnd &&
keepTrackOf.lockTrack.funcLitEnd.IsValid() && node.Pos() <= keepTrackOf.lockTrack.funcLitEnd {
return
@@ -113,7 +113,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
keepTrackOf.lockTrack.retEnd = token.NoPos
keepTrackOf.lockTrack.incFRU()
}
keepTrackOf = stmtSelector(node, pass, keepTrackOf, inspect)
keepTrackOf = stmtSelector(node, pass, keepTrackOf, inspectResult)
})
return nil, nil
}
@@ -418,7 +418,7 @@ func (s *selIdentList) changeRoot(r *ast.Ident, t types.Object) {
}
func (s selIdentList) String() (str string) {
var temp *selIdentNode = s.start
var temp = s.start
str = fmt.Sprintf("length: %v\n[\n", s.length)
for i := 0; temp != nil; i++ {
if i == s.currentIndex {

View File

@@ -39,7 +39,7 @@ type node struct {
func main() {
flag.Parse()
db, err := db.NewDB(context.Background(), *datadir, &kv.Config{})
database, err := db.NewDB(context.Background(), *datadir, &kv.Config{})
if err != nil {
panic(err)
}
@@ -51,7 +51,7 @@ func main() {
startSlot := types.Slot(*startSlot)
endSlot := types.Slot(*endSlot)
filter := filters.NewFilter().SetStartSlot(startSlot).SetEndSlot(endSlot)
blks, roots, err := db.Blocks(context.Background(), filter)
blks, roots, err := database.Blocks(context.Background(), filter)
if err != nil {
panic(err)
}
@@ -63,7 +63,7 @@ func main() {
r := roots[i]
m[r] = &node{score: make(map[uint64]bool)}
state, err := db.State(context.Background(), r)
state, err := database.State(context.Background(), r)
if err != nil {
panic(err)
}
@@ -71,11 +71,11 @@ func main() {
// If the state is not available, roll back
for state == nil {
slot--
_, rts, err := db.BlockRootsBySlot(context.Background(), slot)
_, rts, err := database.BlockRootsBySlot(context.Background(), slot)
if err != nil {
panic(err)
}
state, err = db.State(context.Background(), rts[0])
state, err = database.State(context.Background(), rts[0])
if err != nil {
panic(err)
}

View File

@@ -156,11 +156,11 @@ func createListener(ipAddr string, port int, cfg discover.Config) *discover.UDPv
log.Fatal(err)
}
network, err := discover.ListenV5(conn, localNode, cfg)
net, err := discover.ListenV5(conn, localNode, cfg)
if err != nil {
log.Fatal(err)
}
return network
return net
}
func (h *handler) httpHandler(w http.ResponseWriter, _ *http.Request) {

View File

@@ -116,11 +116,10 @@ func main() {
}
func printBucketStats(dbNameWithPath string) {
ctx := context.Background()
groupSize := uint64(128)
doneC := make(chan bool)
statsC := make(chan *bucketStat, groupSize)
go readBucketStat(ctx, dbNameWithPath, statsC)
go readBucketStat(dbNameWithPath, statsC)
go printBucketStat(statsC, doneC)
<-doneC
}
@@ -163,7 +162,7 @@ func printBucketContents(dbNameWithPath string, rowLimit uint64, bucketName stri
<-doneC
}
func readBucketStat(ctx context.Context, dbNameWithPath string, statsC chan<- *bucketStat) {
func readBucketStat(dbNameWithPath string, statsC chan<- *bucketStat) {
// open the raw database file. If the file is busy, then exit.
db, openErr := bolt.Open(dbNameWithPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
if openErr != nil {

View File

@@ -223,14 +223,14 @@ func encrypt(cliCtx *cli.Context) error {
// Reads the keystore file at the provided path and attempts
// to decrypt it with the specified passwords.
func readAndDecryptKeystore(fullPath, password string) error {
file, err := os.ReadFile(fullPath) // #nosec G304
f, err := os.ReadFile(fullPath) // #nosec G304
if err != nil {
return errors.Wrapf(err, "could not read file at path: %s", fullPath)
}
decryptor := keystorev4.New()
keystoreFile := &keymanager.Keystore{}
if err := json.Unmarshal(file, keystoreFile); err != nil {
if err := json.Unmarshal(f, keystoreFile); err != nil {
return errors.Wrap(err, "could not JSON unmarshal keystore file")
}
// We extract the validator signing private key from the keystore