Skip to content
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
37 changes: 18 additions & 19 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: node-crawler workflow


on:
push:
branches:
Expand All @@ -16,26 +15,26 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.5
- name: Download golangci-lint
run: wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
- name: Lint
run: ./bin/golangci-lint run --config .golangci.yml
- name: Vet
run: go vet ./...
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.24.2
- name: Download golangci-lint
run: wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
- name: Lint
run: ./bin/golangci-lint run --config .golangci.yml
- name: Vet
run: go vet ./...

test:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.5
- name: Test
run: go test -v ./...
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.24.2
- name: Test
run: go test -v ./...
66 changes: 32 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
# This file configures github.com/golangci/golangci-lint.

version: "2"
run:
timeout: 20m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

linters:
disable-all: true
default: none
enable:
- bidichk
- durationcheck
- goconst
- goimports
- gosimple
- govet
- ineffassign
- misspell
- unconvert
- typecheck
# this repo contains a few copied files from go-ethereum,
# and some of them have unused fields/functions
#- unused
- staticcheck
- bidichk
- durationcheck
- exportloopref
- unconvert
- whitespace

# - structcheck # lots of false positives
# - errcheck #lot of false positives
# - contextcheck
# - errchkjson # lots of false positives
# - errorlint # this check crashes
# - exhaustive # silly check
# - makezero # false positives
# - nilerr # several intentional

linters-settings:
gofmt:
simplify: true
goconst:
min-len: 3 # minimum length of string constant
min-occurrences: 6 # minimum number of occurrences
settings:
goconst:
min-len: 3
min-occurrences: 6
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
settings:
gofmt:
simplify: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Compile api
FROM golang:1.21-alpine AS builder
FROM golang:1.24.2-alpine AS builder
WORKDIR /app

COPY go.mod go.sum ./
Expand All @@ -8,7 +8,6 @@ RUN go mod download
COPY ./ ./
RUN go build ./cmd/crawler


# Copy compiled stuff and run it
FROM alpine

Expand Down
4 changes: 2 additions & 2 deletions cmd/crawler/crawlercmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
nodekeyFlag,
timeoutFlag,
workersFlag,
utils.GoerliFlag,
utils.HoodiFlag,
utils.NetworkIdFlag,
utils.SepoliaFlag,
},
Expand Down Expand Up @@ -118,7 +118,7 @@ func crawlNodes(ctx *cli.Context) error {
Timeout: ctx.Duration(timeoutFlag.Name),
Workers: ctx.Uint64(workersFlag.Name),
Sepolia: ctx.Bool(utils.SepoliaFlag.Name),
Goerli: ctx.Bool(utils.GoerliFlag.Name),
Hoodi: ctx.Bool(utils.HoodiFlag.Name),
NodeDB: nodeDB,
}

Expand Down
35 changes: 7 additions & 28 deletions cmd/crawler/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ var (
Name: "log.json",
Usage: "Format logs with JSON",
}
backtraceAtFlag = cli.StringFlag{
Name: "log.backtrace",
Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")",
Value: "",
}
debugFlag = cli.BoolFlag{
Name: "log.debug",
Usage: "Prepends log messages with call-site location (file and line number)",
}
pprofFlag = cli.BoolFlag{
Name: "pprof",
Usage: "Enable the pprof HTTP server",
Expand Down Expand Up @@ -77,10 +68,8 @@ var (

// Flags holds all command-line flags required for debugging.
var Flags = []cli.Flag{
&backtraceAtFlag,
&blockprofilerateFlag,
&cpuprofileFlag,
&debugFlag,
&logjsonFlag,
&memprofilerateFlag,
&pprofAddrFlag,
Expand All @@ -94,43 +83,33 @@ var Flags = []cli.Flag{
var glogger *log.GlogHandler

func init() {
glogger = log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
terminalOutput := io.Writer(os.Stderr)
glogger := log.NewGlogHandler(log.NewTerminalHandler(terminalOutput, false))
glogger.Verbosity(log.LvlInfo)
log.Root().SetHandler(glogger)
log.SetDefault(log.NewLogger(glogger))
}

// Setup initializes profiling and logging based on the CLI flags.
// It should be called as early as possible in the program.
func Setup(ctx *cli.Context) error {
var ostream log.Handler
output := io.Writer(os.Stderr)
if ctx.Bool(logjsonFlag.Name) {
ostream = log.StreamHandler(output, log.JSONFormat())
glogger = log.NewGlogHandler(log.JSONHandler(output))
} else {
usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb"
if usecolor {
output = colorable.NewColorableStderr()
}
ostream = log.StreamHandler(output, log.TerminalFormat(usecolor))
glogger = log.NewGlogHandler(log.NewTerminalHandler(output, usecolor))
}
glogger.SetHandler(ostream)

// logging
verbosity := ctx.Int(verbosityFlag.Name)
glogger.Verbosity(log.Lvl(verbosity))
glogger.Verbosity(log.FromLegacyLevel(verbosity))
vmodule := ctx.String(vmoduleFlag.Name)
glogger.Vmodule(vmodule)

debug := ctx.Bool(debugFlag.Name)
if ctx.IsSet(debugFlag.Name) {
debug = ctx.Bool(debugFlag.Name)
}
log.PrintOrigins(debug)

backtrace := ctx.String(backtraceAtFlag.Name)
glogger.BacktraceAt(backtrace)

log.Root().SetHandler(glogger)
log.SetDefault(log.NewLogger(glogger))

// profiling, tracing
runtime.MemProfileRate = memprofilerateFlag.Value
Expand Down
Loading