Skip to content

Commit 1723e9c

Browse files
committed
update golangci-lint & make linter happy
1 parent c5bdce5 commit 1723e9c

File tree

60 files changed

+359
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+359
-267
lines changed

.golangci.yml

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
1-
linters-settings:
2-
errcheck:
3-
check-type-assertions: true
4-
goconst:
5-
min-len: 2
6-
min-occurrences: 3
7-
gocritic:
8-
enabled-tags:
9-
- diagnostic
10-
- experimental
11-
- opinionated
12-
- performance
13-
- style
14-
govet:
15-
enable:
16-
- shadow
17-
nolintlint:
18-
require-explanation: true
19-
require-specific: true
20-
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
214
linters:
22-
disable-all: true
5+
default: none
236
enable:
247
- bodyclose
258
- dogsled
269
- dupl
2710
- errcheck
28-
- exportloopref
2911
- exhaustive
3012
- goconst
3113
- gocritic
32-
- gofmt
33-
- goimports
3414
- gocyclo
3515
- gosec
36-
- gosimple
3716
- govet
3817
- ineffassign
3918
- misspell
40-
- nolintlint
4119
- nakedret
20+
- nolintlint
4221
- prealloc
4322
- revive
4423
- staticcheck
45-
- stylecheck
4624
- thelper
4725
- tparallel
48-
- typecheck
4926
- unconvert
5027
- unparam
5128
- unused
5229
- whitespace
5330
- wsl
54-
55-
run:
56-
issues-exit-code: 1
31+
settings:
32+
errcheck:
33+
check-type-assertions: true
34+
goconst:
35+
min-len: 2
36+
min-occurrences: 3
37+
gocritic:
38+
enabled-tags:
39+
- diagnostic
40+
- experimental
41+
- opinionated
42+
- performance
43+
- style
44+
govet:
45+
enable:
46+
- shadow
47+
nolintlint:
48+
require-explanation: true
49+
require-specific: true
50+
exclusions:
51+
generated: lax
52+
presets:
53+
- comments
54+
- common-false-positives
55+
- legacy
56+
- std-error-handling
57+
paths:
58+
- third_party$
59+
- builtin$
60+
- examples$
61+
formatters:
62+
enable:
63+
- gofmt
64+
- goimports
65+
exclusions:
66+
generated: lax
67+
paths:
68+
- third_party$
69+
- builtin$
70+
- examples$

cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ var rootCmd = &cobra.Command{
3030
config.Coordinator.MaxConcurrentTests = maxConcurrentTests
3131
}
3232

33-
if logFormat == "json" {
33+
switch logFormat {
34+
case "json":
3435
logr.SetFormatter(&logrus.JSONFormatter{})
3536
logr.Info("Log format set to json")
36-
} else if logFormat == "text" {
37+
case "text":
3738
logr.SetFormatter(&logrus.TextFormatter{})
3839
logr.Info("Log format set to text")
40+
default:
41+
logr.Fatalf("Invalid log format: %s", logFormat)
3942
}
4043
if verbose {
4144
logr.SetLevel(logrus.DebugLevel)

pkg/coordinator/clients/clients.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ func (pool *ClientPool) AddClient(config *ClientConfig) error {
111111
func (pool *ClientPool) processConsensusBlockNotification(poolClient *PoolClient) {
112112
defer func() {
113113
if err := recover(); err != nil {
114-
pool.logger.WithError(err.(error)).Errorf("uncaught panic in processConsensusBlockNotification subroutine: %v, stack: %v", err, string(debug.Stack()))
114+
var err2 error
115+
if errval, errok := err.(error); errok {
116+
err2 = errval
117+
}
118+
119+
pool.logger.WithError(err2).Errorf("uncaught panic in processConsensusBlockNotification subroutine: %v, stack: %v", err, string(debug.Stack()))
115120
}
116121
}()
117122

pkg/coordinator/clients/consensus/blockcache.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
type BlockCache struct {
22-
followDistance uint64
22+
followDistance uint32
2323

2424
specMutex sync.RWMutex
2525
specs *ChainSpec
@@ -50,7 +50,7 @@ type BlockCache struct {
5050
wallclockSlotDispatcher Dispatcher[*ethwallclock.Slot]
5151
}
5252

53-
func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistance uint64) (*BlockCache, error) {
53+
func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistance uint32) (*BlockCache, error) {
5454
if followDistance == 0 {
5555
return nil, fmt.Errorf("cannot initialize block cache without follow distance")
5656
}
@@ -64,7 +64,12 @@ func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistanc
6464
go func() {
6565
defer func() {
6666
if err := recover(); err != nil {
67-
logger.WithError(err.(error)).Errorf("uncaught panic in BlockCache.runCacheCleanup subroutine: %v, stack: %v", err, string(debug.Stack()))
67+
var err2 error
68+
if errval, errok := err.(error); errok {
69+
err2 = errval
70+
}
71+
72+
logger.WithError(err2).Errorf("uncaught panic in BlockCache.runCacheCleanup subroutine: %v, stack: %v", err, string(debug.Stack()))
6873
}
6974
}()
7075
cache.runCacheCleanup(ctx)
@@ -94,8 +99,14 @@ func (cache *BlockCache) notifyBlockReady(block *Block) {
9499
}
95100

96101
func (cache *BlockCache) SetMinFollowDistance(followDistance uint64) {
97-
if followDistance > cache.followDistance {
98-
cache.followDistance = followDistance
102+
if followDistance > 10000 {
103+
followDistance = 10000
104+
}
105+
106+
followDistance32 := uint32(followDistance) //nolint:gosec // no overflow possible
107+
108+
if followDistance32 > cache.followDistance {
109+
cache.followDistance = followDistance32
99110
}
100111
}
101112

@@ -248,7 +259,7 @@ func (cache *BlockCache) AddBlock(root phase0.Root, slot phase0.Slot) (*Block, b
248259
return cache.blockRootMap[root], false
249260
}
250261

251-
if int64(slot) < cache.maxSlotIdx-int64(cache.followDistance) {
262+
if cutOffSlot := cache.maxSlotIdx - int64(cache.followDistance); cutOffSlot > 0 && slot < phase0.Slot(cutOffSlot) {
252263
return nil, false
253264
}
254265

@@ -267,8 +278,8 @@ func (cache *BlockCache) AddBlock(root phase0.Root, slot phase0.Slot) (*Block, b
267278
cache.blockSlotMap[slot] = append(cache.blockSlotMap[slot], cacheBlock)
268279
}
269280

270-
if int64(slot) > cache.maxSlotIdx {
271-
cache.maxSlotIdx = int64(slot)
281+
if cache.maxSlotIdx < 0 || slot > phase0.Slot(cache.maxSlotIdx) {
282+
cache.maxSlotIdx = int64(slot) //nolint:gosec // no overflow possible
272283
}
273284

274285
return cacheBlock, true

pkg/coordinator/clients/consensus/clientlogic.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
func (client *Client) runClientLoop() {
1717
defer func() {
1818
if err := recover(); err != nil {
19-
client.logger.WithError(err.(error)).Errorf("uncaught panic in PoolClient.runPoolClientLoop subroutine: %v, stack: %v", err, string(debug.Stack()))
19+
var err2 error
20+
if errval, errok := err.(error); errok {
21+
err2 = errval
22+
}
23+
24+
client.logger.WithError(err2).Errorf("uncaught panic in PoolClient.runPoolClientLoop subroutine: %v, stack: %v", err, string(debug.Stack()))
2025
}
2126
}()
2227

@@ -154,15 +159,19 @@ func (client *Client) runClientLogic() error {
154159

155160
switch evt.Event {
156161
case rpc.StreamBlockEvent:
157-
err := client.processBlockEvent(evt.Data.(*v1.BlockEvent))
158-
if err != nil {
159-
client.logger.Warnf("failed processing block event: %v", err)
162+
if blockEvent, ok := evt.Data.(*v1.BlockEvent); ok {
163+
err := client.processBlockEvent(blockEvent)
164+
if err != nil {
165+
client.logger.Warnf("failed processing block event: %v", err)
166+
}
160167
}
161168

162169
case rpc.StreamFinalizedEvent:
163-
err := client.processFinalizedEvent(evt.Data.(*v1.FinalizedCheckpointEvent))
164-
if err != nil {
165-
client.logger.Warnf("failed processing finalized event: %v", err)
170+
if finalizedEvent, ok := evt.Data.(*v1.FinalizedCheckpointEvent); ok {
171+
err := client.processFinalizedEvent(finalizedEvent)
172+
if err != nil {
173+
client.logger.Warnf("failed processing finalized event: %v", err)
174+
}
166175
}
167176
}
168177

pkg/coordinator/clients/consensus/forks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (pool *Pool) GetHeadForks(forkDistance int64) []*HeadFork {
8989
_, headDistance = pool.blockCache.GetBlockDistance(cHeadRoot, fork.Root)
9090
}
9191

92-
if headDistance <= uint64(forkDistance) {
92+
if forkDistance < 0 || headDistance <= uint64(forkDistance) {
9393
fork.ReadyClients = append(fork.ReadyClients, client)
9494
}
9595
}

pkg/coordinator/clients/consensus/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var (
1818
)
1919

2020
type PoolConfig struct {
21-
FollowDistance uint64 `yaml:"followDistance" envconfig:"CONSENSUS_POOL_FOLLOW_DISTANCE"`
22-
ForkDistance uint64 `yaml:"forkDistance" envconfig:"CONSENSUS_POOL_FORK_DISTANCE"`
21+
FollowDistance uint32 `yaml:"followDistance" envconfig:"CONSENSUS_POOL_FOLLOW_DISTANCE"`
22+
ForkDistance uint32 `yaml:"forkDistance" envconfig:"CONSENSUS_POOL_FORK_DISTANCE"`
2323
SchedulerMode string `yaml:"schedulerMode" envconfig:"CONSENSUS_POOL_SCHEDULER_MODE"`
2424
}
2525

pkg/coordinator/clients/execution/blockcache.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
type BlockCache struct {
20-
followDistance uint64
20+
followDistance uint32
2121
specMutex sync.RWMutex
2222
specs *rpc.ChainSpec
2323
cacheMutex sync.RWMutex
@@ -27,7 +27,7 @@ type BlockCache struct {
2727
blockDispatcher Dispatcher[*Block]
2828
}
2929

30-
func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistance uint64) (*BlockCache, error) {
30+
func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistance uint32) (*BlockCache, error) {
3131
if followDistance == 0 {
3232
return nil, fmt.Errorf("cannot initialize block cache without follow distance")
3333
}
@@ -41,7 +41,12 @@ func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistanc
4141
go func() {
4242
defer func() {
4343
if err := recover(); err != nil {
44-
logger.WithError(err.(error)).Errorf("uncaught panic in BlockCache.runCacheCleanup subroutine: %v, stack: %v", err, string(debug.Stack()))
44+
var err2 error
45+
if errval, errok := err.(error); errok {
46+
err2 = errval
47+
}
48+
49+
logger.WithError(err2).Errorf("uncaught panic in BlockCache.runCacheCleanup subroutine: %v, stack: %v", err, string(debug.Stack()))
4550
}
4651
}()
4752
cache.runCacheCleanup(ctx)
@@ -63,8 +68,14 @@ func (cache *BlockCache) notifyBlockReady(block *Block) {
6368
}
6469

6570
func (cache *BlockCache) SetMinFollowDistance(followDistance uint64) {
66-
if followDistance > cache.followDistance {
67-
cache.followDistance = followDistance
71+
if followDistance > 10000 {
72+
followDistance = 10000
73+
}
74+
75+
followDistance32 := uint32(followDistance) //nolint:gosec // no overflow possible
76+
77+
if followDistance32 > cache.followDistance {
78+
cache.followDistance = followDistance32
6879
}
6980
}
7081

@@ -117,7 +128,7 @@ func (cache *BlockCache) AddBlock(hash common.Hash, number uint64) (*Block, bool
117128
return cache.hashMap[hash], false
118129
}
119130

120-
if int64(number) < cache.maxSlotIdx-int64(cache.followDistance) {
131+
if cutOffSlot := cache.maxSlotIdx - int64(cache.followDistance); cutOffSlot > 0 && number < uint64(cutOffSlot) {
121132
return nil, false
122133
}
123134

@@ -135,8 +146,8 @@ func (cache *BlockCache) AddBlock(hash common.Hash, number uint64) (*Block, bool
135146
cache.numberMap[number] = append(cache.numberMap[number], cacheBlock)
136147
}
137148

138-
if int64(number) > cache.maxSlotIdx {
139-
cache.maxSlotIdx = int64(number)
149+
if cache.maxSlotIdx < 0 || number > uint64(cache.maxSlotIdx) {
150+
cache.maxSlotIdx = int64(number) //nolint:gosec // no overflow possible
140151
}
141152

142153
return cacheBlock, true

pkg/coordinator/clients/execution/clientlogic.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import (
1414
func (client *Client) runClientLoop() {
1515
defer func() {
1616
if err := recover(); err != nil {
17-
client.logger.WithError(err.(error)).Errorf("uncaught panic in executionClient.runClientLoop subroutine: %v, stack: %v", err, string(debug.Stack()))
17+
var err2 error
18+
if errval, errok := err.(error); errok {
19+
err2 = errval
20+
}
21+
22+
client.logger.WithError(err2).Errorf("uncaught panic in executionClient.runClientLoop subroutine: %v, stack: %v", err, string(debug.Stack()))
1823
}
1924
}()
2025

pkg/coordinator/clients/execution/forks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (pool *Pool) GetHeadForks(forkDistance int64) []*HeadFork {
8989
_, headDistance = pool.blockCache.GetBlockDistance(cHeadRoot, fork.Hash)
9090
}
9191

92-
if headDistance <= uint64(forkDistance) {
92+
if forkDistance < 0 || headDistance <= uint64(forkDistance) {
9393
fork.ReadyClients = append(fork.ReadyClients, client)
9494
}
9595
}

0 commit comments

Comments
 (0)