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

chore: bump eigenda dep to v8 and add linting #92

Merged
merged 13 commits into from
Aug 20, 2024
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
20 changes: 0 additions & 20 deletions .github/workflows/gosec.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: lint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
golangci:
name: Linter
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.21' # The Go version to download (if necessary) and use.
- run: go version

- name: Checkout EigenDA
uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: --timeout 3m --verbose

go-sec:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v3
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
224 changes: 224 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
run:
# Analysis timeout, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
linters-settings:
cyclop:
# The maximal code complexity to report.
# Default: 10
max-complexity: 30
# The maximal average package complexity.
# If it's higher than 0.0 (float) the check is enabled
# Default: 0.0
package-average: 20.0

errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
# Default: false
check-type-assertions: true

exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
check:
- switch
- map

exhaustruct:
# List of regular expressions to exclude struct packages and names from check.
# Default: []
exclude:
# std libs
- "^os/exec.Cmd$"
# public libs
- "^github.com/stretchr/testify/mock.Mock$"

funlen:
# Assert a maximum number of lines for a function.
# Default: 60
lines: 150
# Assert a maximum number of statements in a function.
# Default: 40
statements: 60

gocognit:
# Minimal code complexity to report.
# Default: 30
min-complexity: 35

gocritic:
# Settings passed to gocritic.
# The settings key is the name of a supported gocritic checker.
# The list of supported checkers can be find in https://go-critic.github.io/overview.
settings:
captLocal:
# Whether to restrict checker to params only.
# Default: true
paramsOnly: false
underef:
# Whether to skip (*x).method() calls where x is a pointer receiver.
# Default: true
skipRecvDeref: false

# gomnd:
# # List of function regex patterns to exclude from analysis.
# # Default: []
# ignored-functions:
# -
gomodguard:
blocked:
# List of blocked modules.
# Default: []
modules:
-
govet:
# Enable all analyzers.
# Default: false
enable-all: true
# Disable analyzers by name.
# Run `go tool vet help` to see all analyzers.
# Default: []
disable:
- fieldalignment # too strict
# Settings per analyzer.
settings:
shadow:
# Whether to be strict about shadowing; can be noisy.
# Default: false
strict: true

nakedret:
# Make an issue if func has more lines of code than this setting, and it has naked returns.
# Default: 30
max-func-lines: 0

nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [ funlen, gocognit, lll, whitespace ]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true

tenv:
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
# Default: false
all: true


linters:
disable-all: true
enable:
## enabled by default
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
- unused # checks for unused constants, variables, functions and types
## disabled by default
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
# - gochecknoinits # checks that no init functions are present in Go code
- gocognit # computes and checks the cognitive complexity of functions
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
- gocyclo # computes and checks the cyclomatic complexity of functions
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
# - gomnd # detects magic numbers
- gofmt
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- misspell # Ensures real english is used within strings
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- reassign # checks that package variables are not reassigned
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- stylecheck # is a replacement for golint
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- testableexamples # checks if examples are testable (have an expected output)
- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
- whitespace # detects leading and trailing whitespace

## May want to enable
#- - gochecknoglobals # checks that no global variables exist
#- - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
#- - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
#- - godot # checks if comments end in a period
#- decorder # checks declaration order and count of types, constants, variables and functions
#- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
#- gci # controls golang package import order and makes it always deterministic
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
#- godox # detects FIXME, TODO and other comment keywords
#- goheader # checks is file header matches to pattern
#- interfacebloat # checks the number of methods inside an interface
#- ireturn # accept interfaces, return concrete types
#- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
#- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
#- wrapcheck # checks that errors returned from external packages are wrapped

issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 50

exclude-rules:
- source: "(noinspection|TODO)"
linters: [ godot ]
- source: "// noinspection"
linters:
- gocritic
- unparam

- path: "_test\\.go"
linters:
- gocognit
- govet
- testpackage
- bodyclose
- dupl
- funlen
- goconst
- gosec
- noctx
- wrapcheck
- lll
- whitespace

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ lint:

@golangci-lint run

install-lint:
@echo "Installing golangci-lint..."
@sh -c $(GET_LINT_CMD)

gosec:
@echo "Running security scan with gosec..."
gosec ./...
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Compiles](https://github.com/Layr-Labs/eigenda-proxy/actions/workflows/build.yml/badge.svg)
![Unit Tests](https://github.com/Layr-Labs/eigenda-proxy/actions/workflows/unit-tests.yml/badge.svg)
![Linter](https://github.com/Layr-Labs/eigenda-proxy/actions/workflows/gosec.yml/badge.svg)
![Linter](https://github.com/Layr-Labs/eigenda-proxy/actions/workflows/lint.yml/badge.svg)
![Integration Tests](https://github.com/Layr-Labs/eigenda-proxy/actions/workflows/holesky-test.yml/badge.svg)

# EigenDA Sidecar Proxy
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func New(cfg *Config) ProxyClient {
// when integration testing
func (c *client) Health() error {
url := c.cfg.URL + "/health"
req, err := http.NewRequest(http.MethodGet, url, nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
return err
}
Expand All @@ -48,6 +48,7 @@ func (c *client) Health() error {
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("received bad status code: %d", resp.StatusCode)
Expand All @@ -62,7 +63,7 @@ func (c *client) GetData(ctx context.Context, comm []byte) ([]byte, error) {

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("failed to construct http request: %e", err)
return nil, fmt.Errorf("failed to construct http request: %w", err)
}

req.Header.Set("Content-Type", "application/octet-stream")
Expand All @@ -83,7 +84,6 @@ func (c *client) GetData(ctx context.Context, comm []byte) ([]byte, error) {
}

return b, nil

}

// SetData writes raw byte data to DA and returns the respective certificate
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ func StartProxySvr(cliCtx *cli.Context) error {

log.Info("Initializing EigenDA proxy server...")

daRouter, err := server.LoadStoreRouter(cfg, ctx, log)
daRouter, err := server.LoadStoreRouter(ctx, cfg, log)
if err != nil {
return fmt.Errorf("failed to create store: %w", err)
}
server := server.NewServer(cliCtx.String(server.ListenAddrFlagName), cliCtx.Int(server.PortFlagName), daRouter, log, m)

if err := server.Start(); err != nil {
return fmt.Errorf("failed to start the DA server")
} else {
log.Info("Started EigenDA proxy server")
}

log.Info("Started EigenDA proxy server")

defer func() {
if err := server.Stop(); err != nil {
log.Error("failed to stop DA server", "err", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ func main() {
if err != nil {
log.Crit("Application failed", "message", err)
}

}
2 changes: 0 additions & 2 deletions commitments/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func StringToDecodedCommitment(key string, c CommitmentMode) ([]byte, error) {
}

func EncodeCommitment(b []byte, c CommitmentMode) ([]byte, error) {

switch c {
case OptimismGeneric:
return Keccak256Commitment(b).Encode(), nil
Expand All @@ -70,7 +69,6 @@ func EncodeCommitment(b []byte, c CommitmentMode) ([]byte, error) {

case SimpleCommitmentMode:
return NewV0CertCommitment(b).Encode(), nil

}

return nil, fmt.Errorf("unknown commitment mode")
Expand Down
Loading
Loading