Skip to content

Commit

Permalink
Merge pull request #69 from ethpandaops/chore/lint
Browse files Browse the repository at this point in the history
chore(lint): update golangci-lint and rules
  • Loading branch information
Savid authored Feb 20, 2023
2 parents 83cae46 + 9acdf25 commit 0877157
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.50.1
version: v1.51.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
25 changes: 20 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,48 @@ linters-settings:
linters:
disable-all: true
enable:
- asasalint
- bidichk
- bodyclose
- deadcode
- containedctx
- decorder
- depguard
- dogsled
- durationcheck
- errcheck
- errname
- exportloopref
- goconst
- gocritic
- gocyclo
- gofmt
- goheader
- goimports
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- nakedret
- nilerr
- nilerr
- nilnil
- nlreturn
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- thelper
- tparallel
- typecheck
- unconvert
- varcheck
- unused
- whitespace
- wsl

Expand Down
4 changes: 2 additions & 2 deletions docs/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ P2P configuration to get node records to discover from the [Xatu server coordina
| p2p.config.discV5 | bool | `true` | enable Node Discovery Protocol v5 *Note: both Node Discovery Protocol v4 and v5 can be enabled at the same time* |
| p2p.config.restart | string | `2m` | Time between initiating discovery scans and fetching new node record, will generate a fresh private key each time |
| p2p.config.networkIDs | array<string> | | List of network ids to filter node records by (decimal format, eg. '1' for mainnet) |
| p2p.config.forkIDHashes | array<string> | | List of [Fork ID hash](https://eips.ethereum.org/EIPS/eip-2124) to filter node records by (hex string) |
| p2p.config.forkIdHashes | array<string> | | List of [Fork ID hash](https://eips.ethereum.org/EIPS/eip-2124) to filter node records by (hex string) |

### P2P `static` configuration

Expand Down Expand Up @@ -111,7 +111,7 @@ p2p:
discV5: true
restart: 2m
networkIDs: [1]
forkIDHashes: [0xf0afd0e3]
forkIdHashes: [0xf0afd0e3]
```
## Running locally
Expand Down
10 changes: 5 additions & 5 deletions docs/mimicry.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Output configuration to send mimicry events to a [Xatu server](./server.md).
| outputs[].config.exportTimeout | string | `30s` | The maximum duration for exporting events. If the timeout is reached, the export will be cancelled |
| outputs[].config.maxExportBatchSize | int | `512` | MaxExportBatchSize is the maximum number of events to process in a single batch. If there are more than one batch worth of events then it processes multiple batches of events one batch after the other without any delay |
| outputs[].config.networkIDs | array<string> | | List of network ids to connect to (decimal format, eg. '1' for mainnet) |
| outputs[].config.forkIDHashes | array<string> | | List of [Fork ID hash](https://eips.ethereum.org/EIPS/eip-2124) to connect to (hex string) |
| outputs[].config.forkIdHashes | array<string> | | List of [Fork ID hash](https://eips.ethereum.org/EIPS/eip-2124) to connect to (hex string) |
| outputs[].config.maxPeers | int | `100` | Max number of peers to attempt to connect to simultaneously |

### Output `http` configuration
Expand All @@ -124,7 +124,7 @@ coordinator:
config:
address: localhost:8080
networkIDs: [1]
forkIDHashes: [0xf0afd0e3]
forkIdHashes: [0xf0afd0e3]
maxPeers: 100

outputs:
Expand Down Expand Up @@ -159,7 +159,7 @@ coordinator:
config:
address: localhost:8080
networkIDs: [1]
forkIDHashes: [0xf0afd0e3]
forkIdHashes: [0xf0afd0e3]

outputs:
- name: xatu-output
Expand All @@ -178,7 +178,7 @@ coordinator:
config:
address: localhost:8080
networkIDs: [1]
forkIDHashes: [0xf0afd0e3]
forkIdHashes: [0xf0afd0e3]

outputs:
- name: http-basic-auth
Expand Down Expand Up @@ -207,7 +207,7 @@ coordinator:
config:
address: localhost:8080
networkIDs: [1]
forkIDHashes: [0xf0afd0e3]
forkIdHashes: [0xf0afd0e3]

outputs:
- name: log
Expand Down
2 changes: 1 addition & 1 deletion example_discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ p2p:
# discV5: true
# restart: 2m
# networkIDs: [1]
# forkIDHashes: [0xf0afd0e3]
# forkIdHashes: [0xf0afd0e3]
2 changes: 1 addition & 1 deletion example_mimicry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ coordinator:
# headers:
# authorization: Someb64Value
# networkIDs: [1]
# forkIDHashes: [0xf0afd0e3]
# forkIdHashes: [0xf0afd0e3]
# maxPeers: 100

outputs:
Expand Down
2 changes: 2 additions & 0 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (d *Discovery) startCrons(ctx context.Context) error {
nodeRecords, err := d.coordinator.ListStaleNodeRecords(ctx)
if err != nil {
d.log.WithError(err).Error("Failed to list stale node records")

return
}
d.log.WithField("records", len(nodeRecords)).Info("Adding stale node records to status")
Expand All @@ -177,6 +178,7 @@ func (d *Discovery) startCrons(ctx context.Context) error {

func (d *Discovery) handleExecutionStatus(ctx context.Context, status *xatu.ExecutionNodeStatus) error {
d.metrics.AddNodeRecordStatus(1, fmt.Sprintf("%d", status.GetNetworkId()), fmt.Sprintf("0x%x", status.GetForkId().GetHash()))

return d.coordinator.HandleExecutionNodeRecordStatus(ctx, status)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/discovery/p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type Peer struct {
hello *mimicry.Hello

handlerFunc func(ctx context.Context, status *xatu.ExecutionNodeStatus)

response chan error
}

func NewPeer(ctx context.Context, log logrus.FieldLogger, nodeRecord string, handlerFunc func(ctx context.Context, status *xatu.ExecutionNodeStatus)) (*Peer, error) {
Expand All @@ -43,6 +41,7 @@ func (p *Peer) Start(ctx context.Context) (<-chan error, error) {

p.client.OnHello(ctx, func(ctx context.Context, hello *mimicry.Hello) error {
p.hello = hello

return nil
})

Expand Down
1 change: 1 addition & 0 deletions pkg/discovery/p2p/raw_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type RawMessage struct {

func (r *RawMessage) UnmarshalYAML(unmarshal func(interface{}) error) error {
r.unmarshal = unmarshal

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/discovery/p2p/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (s *Status) AddExecutionNodeRecords(ctx context.Context, nodeRecords []stri
retry.Attempts(5),
retry.DelayType(func(n uint, err error, config *retry.Config) time.Duration {
s.log.WithError(err).Debug("peer failed")

return 5 * time.Second
}),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/discovery/p2p/xatu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Config struct {
DiscV5 bool `yaml:"discV5" default:"true"`
Restart time.Duration `yaml:"restart" default:"2m"`
NetworkIDs []uint64 `yaml:"networkIDs"`
ForkIDHashes []string `yaml:"forkIDHashes"`
ForkIDHashes []string `yaml:"forkIdHashes"`
}

func (c *Config) Validate() error {
Expand Down
5 changes: 5 additions & 0 deletions pkg/discovery/p2p/xatu/xatu.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,31 @@ func (c *Coordinator) startCrons(ctx context.Context) error {

if err != nil {
c.log.WithError(err).Error("Failed to get a discovery node record")

return
}

if err = c.discV4.UpdateBootNodes([]string{res.NodeRecord}); err != nil {
c.log.WithError(err).Error("Failed to update discV4 boot nodes")

return
}

if errS := c.discV4.Start(ctx); errS != nil {
c.log.WithError(errS).Error("Failed to start discV4")

return
}

if err = c.discV5.UpdateBootNodes([]string{res.NodeRecord}); err != nil {
c.log.WithError(err).Error("Failed to update discV5 boot nodes")

return
}

if err := c.discV5.Start(ctx); err != nil {
c.log.WithError(err).Error("Failed to start discV5")

return
}
}); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/mimicry/coordinator/raw_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type RawMessage struct {

func (r *RawMessage) UnmarshalYAML(unmarshal func(interface{}) error) error {
r.unmarshal = unmarshal

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/mimicry/coordinator/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *Static) Start(ctx context.Context) error {
retry.Attempts(0),
retry.DelayType(func(n uint, err error, config *retry.Config) time.Duration {
s.log.WithError(err).Debug("peer failed")

return s.config.RetryInterval
}),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mimicry/coordinator/xatu/coordinator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type Config struct {
Address string `yaml:"address"`
Headers map[string]string `yaml:"headers"`
TLS bool `yaml:"tls" default:"false"`
NetworkIDs []uint64 `yaml:"networkIDs"`
ForkIDHashes []string `yaml:"forkIDHashes"`
NetworkIDs []uint64 `yaml:"networkIds"`
ForkIDHashes []string `yaml:"forkIdHashes"`
MaxPeers uint32 `yaml:"maxPeers" default:"100"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/mimicry/coordinator/xatu/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (p *Peer) Start(ctx context.Context) error {

func (p *Peer) Stop() error {
p.stopped = true

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/mimicry/coordinator/xatu/xatu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const Type = "xatu"

type Xatu struct {
handlers *handler.Peer
name string
log logrus.FieldLogger

cache *cache.SharedCache
Expand Down Expand Up @@ -106,11 +105,13 @@ func (x *Xatu) startCrons(ctx context.Context) error {
res, err := x.coordinator.CoordinateExecutionNodeRecords(ctx, records)
if err != nil {
x.log.WithError(err).Error("failed to coordinate execution node records")

return
}

if res == nil {
x.log.Error("failed to coordinate execution node records: nil response")

return
}

Expand All @@ -122,6 +123,7 @@ func (x *Xatu) startCrons(ctx context.Context) error {
if record == i {
found = true
peer.RetryDelay(retryDelay)

break
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/mimicry/p2p/execution/event_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package execution

import (
"context"
"errors"
"fmt"
"strconv"
"time"
Expand Down Expand Up @@ -31,7 +32,7 @@ func (p *Peer) handleTransaction(ctx context.Context, eventTime time.Time, event
"transaction_hash": event.Hash().String(),
}).Debug("Duplicate transaction event received")
// TODO(savid): add metrics
return nil, nil
return nil, errors.New("duplicate transaction event received")
}

meta, err := p.createNewClientMeta(ctx)
Expand Down Expand Up @@ -78,6 +79,7 @@ func (p *Peer) getTransactionData(ctx context.Context, event *types.Transaction,
from, err := p.signer.Sender(event)
if err != nil {
p.log.WithError(err).Error("failed to get sender")

return nil, err
}

Expand Down Expand Up @@ -138,6 +140,7 @@ func (p *Peer) ExportTransactions(ctx context.Context, items []*TransactionHashI
txs, err := p.client.GetPooledTransactions(ctx, hashes)
if err != nil {
p.log.WithError(err).Error("Failed to get pooled transactions")

return
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/mimicry/p2p/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func New(ctx context.Context, log logrus.FieldLogger, nodeRecord string, handler

func (p *Peer) createNewClientMeta(ctx context.Context) (*xatu.ClientMeta, error) {
if p.handlers.CreateNewClientMeta == nil {
return nil, nil
return nil, errors.New("no CreateNewClientMeta handler")
}

meta, err := p.handlers.CreateNewClientMeta(ctx)
Expand Down Expand Up @@ -244,6 +244,7 @@ func (p *Peer) Start(ctx context.Context) (<-chan error, error) {
}
}
}

return nil
})

Expand All @@ -267,6 +268,7 @@ func (p *Peer) Start(ctx context.Context) (<-chan error, error) {
err = p.client.Start(ctx)
if err != nil {
p.log.WithError(err).Debug("failed to dial client")

return nil, err
}

Expand Down
1 change: 1 addition & 0 deletions pkg/output/raw_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type RawMessage struct {

func (r *RawMessage) UnmarshalYAML(unmarshal func(interface{}) error) error {
r.unmarshal = unmarshal

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/processor/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (t *testBatchExporter[T]) ExportItems(ctx context.Context, items []*T) erro
select {
case <-ctx.Done():
t.err = ctx.Err()

return ctx.Err()
default:
}
Expand All @@ -64,6 +65,7 @@ func (t *testBatchExporter[T]) ExportItems(ctx context.Context, items []*T) erro

func (t *testBatchExporter[T]) Shutdown(context.Context) error {
t.shutdownCount++

return nil
}

Expand Down Expand Up @@ -379,6 +381,7 @@ type indefiniteExporter[T TestItem] struct{}
func (indefiniteExporter[T]) Shutdown(context.Context) error { return nil }
func (indefiniteExporter[T]) ExportItems(ctx context.Context, _ []*T) error {
<-ctx.Done()

return ctx.Err()
}

Expand Down
Loading

0 comments on commit 0877157

Please sign in to comment.