Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 22, 2024
1 parent 035b931 commit 814483f
Show file tree
Hide file tree
Showing 50 changed files with 426 additions and 237 deletions.
72 changes: 50 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
# This file is not a configuration example,
# it contains the exhaustive configuration with explanations of the options.

issues:
# Which files to exclude: they will be analyzed, but issues from them won't be reported.
# There is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not, please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
# Default: []
exclude-files:
- ".*_ssz\\.go$"

# Options for analysis running.
run:
# The default concurrency value is the number of available CPU.
Expand Down Expand Up @@ -39,15 +49,6 @@ run:
# Default: true
# skip-dirs-use-default: false

# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
# but there is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-files:
- ".*_ssz\\.go$"

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -68,7 +69,7 @@ run:
# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
go: '1.19'
# go: '1.20'


# output configuration options
Expand Down Expand Up @@ -108,6 +109,39 @@ linters-settings:
lll:
line-length: 132

nlreturn:
block-size: 3

revive:
ignore-generated-header: false
severity: error
confidence: 0.8
errorCode: 0
warningCode: 0
enable-all-rules: true
rules:
- name: add-constant
disabled: true
- name: cyclomatic
disabled: true
- name: cognitive-complexity
disabled: true
- name: confusing-results
- name: function-length
disabled: true
- name: line-length-limit
arguments: [132]
- name: max-public-structs
disabled: true
- name: package-comments
disabled: true
- name: struct-tag
arguments: ["json,allowempty"]
- name: unhandled-error
arguments:
- "fmt.Fprint"
- "fmt.Fprintf"

stylecheck:
checks: [ "all", "-ST1000" ]

Expand All @@ -118,10 +152,6 @@ linters-settings:
json: snake
yaml: snake

nlreturn:
# Allow two-line blocks without requiring a newline
block-size: 3

linters:
# Enable all available linters.
# Default: false
Expand All @@ -133,35 +163,33 @@ linters:
- deadcode
- depguard
- dupl
- execinquery
- exhaustive
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- goerr113
- err113
- golint
- gomnd
- ifshort
- inamedparam
- interfacer
- ireturn
- lll
- maintidx
- maligned
- mnd
- musttag
- nestif
- nilnil
- nlreturn
- nosnakecase
- perfsprint
- promlinter
- scopelint
- structcheck
- varcheck
- varnamelen
- wrapcheck
- wsl
- zerologlint
37 changes: 21 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
)

// ReleaseVersion is the release version for the code.
var ReleaseVersion = "0.2.10"
var ReleaseVersion = "0.2.11-dev"

func main() {
os.Exit(main2())
Expand All @@ -66,7 +66,7 @@ func main2() int {
return 1
}

majordomo, err := util.InitMajordomo(ctx)
majordomoSvc, err := util.InitMajordomo(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to initialise majordomo: %v\n", err)
return 1
Expand All @@ -83,7 +83,7 @@ func main2() int {
logModules()
log.Info().Str("version", ReleaseVersion).Msg("Starting comptrollerd")

if err := initTracing(ctx, majordomo); err != nil {
if err := initTracing(ctx, majordomoSvc); err != nil {
log.Error().Err(err).Msg("Failed to initialise tracing")
return 1
}
Expand All @@ -103,7 +103,7 @@ func main2() int {
setRelease(ctx, ReleaseVersion)
setReady(ctx, false)

if err := startServices(ctx, monitor, majordomo); err != nil {
if err := startServices(ctx, monitor, majordomoSvc); err != nil {
log.Error().Err(err).Msg("Failed to initialise services")
return 1
}
Expand All @@ -122,6 +122,7 @@ func main2() int {
}

log.Info().Msg("Stopping comptrollerd")

return 0
}

Expand Down Expand Up @@ -201,22 +202,25 @@ func startMonitor(ctx context.Context) (metrics.Service, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to start prometheus metrics service")
}
log.Info().Str("listen_address", viper.GetString("metrics.prometheus.listen-address")).Msg("Started prometheus metrics service")
log.Info().
Str("listen_address", viper.GetString("metrics.prometheus.listen-address")).
Msg("Started prometheus metrics service")
} else {
log.Debug().Msg("No metrics service supplied; monitor not starting")
monitor = &nullmetrics.Service{}
}

return monitor, nil
}

func startServices(ctx context.Context, monitor metrics.Service, majordomo majordomo.Service) error {
func startServices(ctx context.Context, monitor metrics.Service, majordomoSvc majordomo.Service) error {
log.Trace().Msg("Starting execution database")
execDB, err := util.InitExecDB(ctx, majordomo)
execDB, err := util.InitExecDB(ctx, majordomoSvc)
if err != nil {
return errors.Wrap(err, "failed to start execution database")
}

comptrollerDB, err := util.InitComptrollerDB(ctx, majordomo)
comptrollerDB, err := util.InitComptrollerDB(ctx, majordomoSvc)
if err != nil {
return errors.Wrap(err, "failed to start comptroller database")
}
Expand All @@ -225,7 +229,7 @@ func startServices(ctx context.Context, monitor metrics.Service, majordomo major
return errors.Wrap(err, "failed to upgrade comptroller database")
}

scheduler, err := standardscheduler.New(ctx,
schedulerSvc, err := standardscheduler.New(ctx,
standardscheduler.WithLogLevel(util.LogLevel("scheduler")),
standardscheduler.WithMonitor(monitor),
)
Expand All @@ -249,12 +253,12 @@ func startServices(ctx context.Context, monitor metrics.Service, majordomo major
}

log.Trace().Msg("Starting bids service")
if err := startBids(ctx, comptrollerDB, monitor, scheduler, chainTime, execDB); err != nil {
if err := startBids(ctx, comptrollerDB, monitor, schedulerSvc, chainTime, execDB); err != nil {
return errors.Wrap(err, "failed to start bids service")
}

log.Trace().Msg("Starting relays service")
if err := startRelays(ctx, comptrollerDB, monitor, scheduler); err != nil {
if err := startRelays(ctx, comptrollerDB, monitor, schedulerSvc); err != nil {
return errors.Wrap(err, "failed to start relays service")
}

Expand All @@ -281,7 +285,7 @@ func startRelays(
ctx context.Context,
comptrollerDB comptrollerdb.Service,
monitor metrics.Service,
scheduler scheduler.Service,
schedulerSvc scheduler.Service,
) error {
queuedProposerProviders := make([]relayclient.QueuedProposersProvider, 0)
for _, relayAddress := range viper.GetStringSlice("relays.addresses") {
Expand All @@ -295,7 +299,7 @@ func startRelays(
_, err := standardrelays.New(ctx,
standardrelays.WithLogLevel(util.LogLevel("relays")),
standardrelays.WithMonitor(monitor),
standardrelays.WithScheduler(scheduler),
standardrelays.WithScheduler(schedulerSvc),
standardrelays.WithQueuedProposersProviders(queuedProposerProviders),
standardrelays.WithValidatorRegistrationsProvider(comptrollerDB.(comptrollerdb.ValidatorRegistrationsProvider)),
standardrelays.WithValidatorRegistrationsSetter(comptrollerDB.(comptrollerdb.ValidatorRegistrationsSetter)),
Expand All @@ -312,7 +316,7 @@ func startBids(
ctx context.Context,
comptrollerDB comptrollerdb.Service,
monitor metrics.Service,
scheduler scheduler.Service,
schedulerSvc scheduler.Service,
chainTime chaintime.Service,
execDB execdb.Service,
) error {
Expand Down Expand Up @@ -357,7 +361,7 @@ func startBids(
if _, err := standardbids.New(ctx,
standardbids.WithLogLevel(util.LogLevel("bids")),
standardbids.WithMonitor(monitor),
standardbids.WithScheduler(scheduler),
standardbids.WithScheduler(schedulerSvc),
standardbids.WithChainTime(chainTime),
standardbids.WithDeliveredBidTraceProviders(deliveredBidTraceProviders),
standardbids.WithReceivedBidTracesProviders(receivedBidTracesProviders),
Expand All @@ -375,7 +379,8 @@ func startBids(

func runCommands(_ context.Context) {
if viper.GetBool("version") {
fmt.Printf("%s\n", ReleaseVersion)
fmt.Fprintf(os.Stdout, "%s\n", ReleaseVersion)
//nolint:revive
os.Exit(0)
}
}
2 changes: 2 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func registerMetrics(ctx context.Context, monitor metrics.Service) error {
case "null":
log.Debug().Msg("No metrics will be generated for this module")
}

return nil
}

Expand Down Expand Up @@ -87,6 +88,7 @@ func setRelease(_ context.Context, version string) {
releaseMetric.WithLabelValues(version).Set(1)
}

//nolint:revive
func setReady(_ context.Context, ready bool) {
if readyMetric == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion services/bids/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

// Service defines a service that obtains bid information from relays.
type Service interface{}
type Service any

// ReceivedHandler defines the interface for handlers triggered by received bids.
type ReceivedHandler interface {
Expand Down
Loading

0 comments on commit 814483f

Please sign in to comment.