Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jul 30, 2024
1 parent ee5692d commit cd12344
Show file tree
Hide file tree
Showing 39 changed files with 444 additions and 116 deletions.
88 changes: 46 additions & 42 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,14 +109,44 @@ linters-settings:
lll:
line-length: 132

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" ]

tagliatelle:
case:
# use-field-name: true
rules:
json: camel
json: snake
yaml: snake

linters:
Expand All @@ -125,55 +156,28 @@ linters:
# Disable specific linter
# https://golangci-lint.run/usage/linters/#disabled-by-default
disable:
- contextcheck
- cyclop
- deadcode
- decorder
- depguard
- dupl
- dupword
- errchkjson
- errorlint
- execinquery
- exhaustive
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- godot
- goerr113
- gofumpt
- goheader
- golint
- err113
- gomnd
- ifshort
- interfacer
- ireturn
- lll
- maintidx
- maligned
- mnd
- musttag
- nestif
- nilnil
- nlreturn
- nolintlint
- nosnakecase
- perfsprint
- promlinter
- rowserrcheck
- scopelint
- sqlclosecheck
- structcheck
- thelper
- unparam
- varcheck
- tagliatelle
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl
1 change: 1 addition & 0 deletions api/eventsfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ func (e *EventsFilter) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
2 changes: 2 additions & 0 deletions api/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (i *Issuance) UnmarshalJSON(input []byte) error {
if err := json.Unmarshal(input, &data); err != nil {
return errors.Wrap(err, "invalid JSON")
}

return i.unpack(&data)
}

Expand Down Expand Up @@ -93,5 +94,6 @@ func (i *Issuance) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
3 changes: 3 additions & 0 deletions api/syncstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *SyncState) UnmarshalJSON(input []byte) error {
if err := json.Unmarshal(input, &data); err != nil {
return errors.Wrap(err, "invalid JSON")
}

return s.unpack(&data)
}

Expand All @@ -67,6 +68,7 @@ func (s *SyncState) UnmarshalJSON(input []byte) error {
s.HighestBlock = 0
s.StartingBlock = 0
s.Syncing = false

return nil
}

Expand Down Expand Up @@ -100,5 +102,6 @@ func (s *SyncState) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
2 changes: 2 additions & 0 deletions api/transactionresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (t *TransactionResult) MarshalJSON() ([]byte, error) {
for k, v := range t.StateDiff {
stateDiff[util.MarshalAddress(k[:])] = v
}

return json.Marshal(&transactionResultJSON{
Output: fmt.Sprintf("%#x", t.Output),
StateDiff: stateDiff,
Expand Down Expand Up @@ -93,5 +94,6 @@ func (t *TransactionResult) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
21 changes: 10 additions & 11 deletions api/transactionstatechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,17 @@ func (t *TransactionStateChange) unpack(data *transactionStateChangeJSON) error
}
}

if data.Alteration != nil {
if data.Alteration.From != "" {
t.From, err = util.StrToBigInt("from", data.Alteration.From)
if err != nil {
return err
}
if data.Alteration != nil && data.Alteration.From != "" {
t.From, err = util.StrToBigInt("from", data.Alteration.From)
if err != nil {
return err
}
}

if data.Alteration.To != "" {
t.To, err = util.StrToBigInt("to", data.Alteration.To)
if err != nil {
return err
}
if data.Alteration != nil && data.Alteration.To != "" {
t.To, err = util.StrToBigInt("to", data.Alteration.To)
if err != nil {
return err
}
}

Expand All @@ -113,5 +111,6 @@ func (t *TransactionStateChange) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
1 change: 1 addition & 0 deletions api/transactionstatediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ func (t *TransactionStateDiff) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
1 change: 1 addition & 0 deletions api/transactionstoragechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ func (t *TransactionStorageChange) String() string {
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
2 changes: 2 additions & 0 deletions jsonrpc/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ func (s *Service) Balance(ctx context.Context, address types.Address, blockID st
if err != nil {
return nil, errors.Wrap(err, "unhandled block ID")
}

return s.balanceAtHeight(ctx, address, height)
}

//nolint:unparam
func (s *Service) balanceAtHash(ctx context.Context,
address types.Address,
hash string,
Expand Down
4 changes: 3 additions & 1 deletion jsonrpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var blockIdentifiers = map[string]struct{}{
"finalized": {},
}

// Block returns the block given an ID
// Block returns the block given an ID.
func (s *Service) Block(ctx context.Context, blockID string) (*spec.Block, error) {
if blockID == "" ||
blockID == "latest" {
Expand All @@ -48,6 +48,7 @@ func (s *Service) Block(ctx context.Context, blockID string) (*spec.Block, error
if err != nil {
return nil, errors.Wrap(err, "unhandled block ID")
}

return s.blockAtHeight(ctx, height)
}

Expand Down Expand Up @@ -75,5 +76,6 @@ func (s *Service) blockAtHeight(ctx context.Context, height int64) (*spec.Block,
if height == -1 {
return s.blockAtIdentifier(ctx, "latest")
}

return s.blockAtIdentifier(ctx, util.MarshalInt64(height))
}
1 change: 1 addition & 0 deletions jsonrpc/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ func (s *Service) blockIDToHeight(ctx context.Context, blockID string) (int64, e
return -1, errors.Wrap(err, "unhandled block ID")
}
}

return height, nil
}
1 change: 1 addition & 0 deletions jsonrpc/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (s *Service) Issuance(ctx context.Context, blockID string) (*api.Issuance,
if err != nil {
return nil, err
}

return s.issuanceAtHeight(ctx, height)
}

Expand Down
11 changes: 9 additions & 2 deletions jsonrpc/newpendingtransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (s *Service) NewPendingTransactions(ctx context.Context, ch chan *spec.Tran
}

// Set up the subscription.
if err := conn.WriteMessage(websocket.TextMessage, []byte(`{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}`)); err != nil {
if err := conn.WriteMessage(websocket.TextMessage,
[]byte(`{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}`),
); err != nil {
return nil, errors.Wrap(err, "failed to request subscription")
}

Expand Down Expand Up @@ -71,36 +73,41 @@ func (s *Service) receiveNewPendingTransactionMsg(ctx context.Context, conn *web
}
if err != nil {
log.Error().Err(err).Msg("Failed to read received message")

continue
}
log.Info().Str("msg", string(msg)).Msg("Received message")
res := newPendingTransactionsEvent{}
if err := json.Unmarshal(msg, &res); err != nil {
log.Error().Err(err).Msg("Failed to unmarshal message")

continue
}

tx, err := s.Transaction(ctx, res.Params.Result)
if err != nil {
log.Error().Err(err).Str("tx_hash", fmt.Sprintf("%#x", res.Params.Result)).Msg("Failed to obtain transaction")

continue
}
ch <- tx
}
}

func (s *Service) closeSocketOnCtxDone(ctx context.Context, conn *websocket.Conn) {
func (*Service) closeSocketOnCtxDone(ctx context.Context, conn *websocket.Conn) {
<-ctx.Done()
log.Trace().Msg("Context done; closing websocket connection")

// Close the connection.
err := conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
if err != nil {
log.Error().Err(err).Msg("Failed to send websocket close message")

return
}
if err := conn.Close(); err != nil {
log.Error().Err(err).Msg("Failed to close websocket")

return
}

Expand Down
11 changes: 8 additions & 3 deletions jsonrpc/replayblocktransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ func (s *Service) ReplayBlockTransactions(ctx context.Context, blockID string) (
if err != nil {
return nil, errors.Wrap(err, "unhandled block ID")
}
return s.replayBlockTransactions(ctx, height)

return s.replayBlockTransactionsAtHeight(ctx, height)
}

func (s *Service) replayBlockTransactions(_ context.Context, height int64) ([]*api.TransactionResult, error) {
func (s *Service) replayBlockTransactionsAtHeight(_ context.Context, height int64) ([]*api.TransactionResult, error) {
var transactionResults []*api.TransactionResult

log.Trace().Int64("height", height).Msg("Replaying block transactions")
Expand All @@ -47,7 +48,11 @@ func (s *Service) replayBlockTransactions(_ context.Context, height int64) ([]*a
// Block 0 is a special case, with no transactions.
transactionResults = make([]*api.TransactionResult, 0)
default:
err = s.client.CallFor(&transactionResults, "trace_replayBlockTransactions", util.MarshalUint32(uint32(height)), []string{"stateDiff"})
err = s.client.CallFor(&transactionResults,
"trace_replayBlockTransactions",
util.MarshalUint32(uint32(height)),
[]string{"stateDiff"},
)
}
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit cd12344

Please sign in to comment.