Skip to content

Commit e4dc50b

Browse files
committed
add stricterlinting
1 parent 805f927 commit e4dc50b

24 files changed

Lines changed: 141 additions & 69 deletions

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
go.sum
2929
- uses: golangci/golangci-lint-action@v9.2.0
3030
with:
31-
version: latest
32-
args: --timeout 10m
31+
version: v2.10.1
32+
args: --timeout 10m ./...
3333
github-token: ${{ secrets.github_token }}
3434
if: env.GIT_DIFF
3535

.golangci.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
11
version: "2"
22
run:
33
modules-download-mode: readonly
4+
timeout: 10m
5+
tests: true
46
build-tags:
57
- evm
68
- e2e
79
- docker
810
linters:
911
enable:
12+
- asciicheck
13+
- bidichk
14+
- bodyclose
15+
- containedctx
16+
- contextcheck
17+
- copyloopvar
18+
- durationcheck
19+
- errname
20+
- errcheck
1021
- errorlint
22+
- gocritic
23+
- govet
24+
- ineffassign
25+
- makezero
1126
- gosec
1227
- misspell
28+
- nilerr
29+
- noctx
30+
- nolintlint
31+
- prealloc
32+
- predeclared
33+
- reassign
1334
- revive
35+
- rowserrcheck
36+
- sqlclosecheck
37+
- staticcheck
38+
- testifylint
1439
- unconvert
40+
- unparam
41+
- unused
42+
- usestdlibvars
43+
- wastedassign
1544
settings:
45+
errcheck:
46+
check-type-assertions: true
47+
check-blank: true
48+
govet:
49+
enable-all: true
50+
disable:
51+
- fieldalignment
52+
- shadow
53+
gocritic:
54+
enabled-tags:
55+
- diagnostic
56+
- style
57+
- performance
58+
disabled-checks:
59+
- hugeParam
60+
- rangeValCopy
1661
gosec:
1762
excludes:
1863
- G115
@@ -21,7 +66,7 @@ linters:
2166
- name: package-comments
2267
disabled: true
2368
- name: duplicated-imports
24-
severity: warning
69+
severity: error
2570
- name: exported
2671
arguments:
2772
- disableStutteringCheck
@@ -36,6 +81,21 @@ linters:
3681
- third_party$
3782
- builtin$
3883
- examples$
84+
disable:
85+
- containedctx
86+
- errcheck
87+
- gocritic
88+
- nolintlint
89+
- prealloc
90+
- predeclared
91+
- testifylint
92+
- thelper
93+
- tparallel
94+
- unparam
95+
- wrapcheck
96+
issues:
97+
max-issues-per-linter: 0
98+
max-same-issues: 0
3999
formatters:
40100
enable:
41101
- gci

.just/lint.just

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[group('lint')]
33
lint: vet
44
@echo "--> Running golangci-lint"
5-
@golangci-lint run
5+
@golangci-lint run ./...
66
@echo "--> Running markdownlint"
77
@markdownlint --config .markdownlint.yaml '**/*.md'
88
@echo "--> Running hadolint"
@@ -18,7 +18,7 @@ lint: vet
1818
[group('lint')]
1919
lint-fix:
2020
@echo "--> Formatting go"
21-
@golangci-lint run --fix
21+
@golangci-lint run --fix ./...
2222
@echo "--> Formatting markdownlint"
2323
@markdownlint --config .markdownlint.yaml --ignore './changelog.md' '**/*.md' -f
2424

block/internal/da/async_block_retriever_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,6 @@ func TestBlockData_SerializationEmpty(t *testing.T) {
266266
}
267267

268268
assert.Equal(t, uint64(100), decoded.Height)
269+
assert.Equal(t, time.Unix(0, 0).UTC(), decoded.Timestamp)
269270
assert.Equal(t, 0, len(decoded.Blobs))
270271
}

block/internal/executing/executor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func (e *Executor) ProduceBlock(ctx context.Context) error {
583583
LastSubmittedDaHeaderHeight: e.cache.GetLastSubmittedHeaderHeight(),
584584
LastSubmittedDaDataHeight: e.cache.GetLastSubmittedDataHeight(),
585585
}
586-
if err := e.raftNode.Broadcast(e.ctx, raftState); err != nil {
586+
if err := e.raftNode.Broadcast(ctx, raftState); err != nil {
587587
return fmt.Errorf("failed to propose block to raft: %w", err)
588588
}
589589
e.logger.Debug().Uint64("height", newHeight).Msg("proposed block to raft")
@@ -609,12 +609,12 @@ func (e *Executor) ProduceBlock(ctx context.Context) error {
609609
// IMPORTANT: Header MUST be broadcast before data — the P2P layer validates
610610
// incoming data against the current and previous header, so out-of-order
611611
// delivery would cause validation failures on peers.
612-
if err := e.headerBroadcaster.WriteToStoreAndBroadcast(e.ctx, &types.P2PSignedHeader{
612+
if err := e.headerBroadcaster.WriteToStoreAndBroadcast(ctx, &types.P2PSignedHeader{
613613
SignedHeader: header,
614614
}); err != nil {
615615
e.logger.Error().Err(err).Msg("failed to broadcast header")
616616
}
617-
if err := e.dataBroadcaster.WriteToStoreAndBroadcast(e.ctx, &types.P2PData{
617+
if err := e.dataBroadcaster.WriteToStoreAndBroadcast(ctx, &types.P2PData{
618618
Data: data,
619619
}); err != nil {
620620
e.logger.Error().Err(err).Msg("failed to broadcast data")

block/internal/submitting/da_submitter_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func TestDASubmitter_SubmitHeaders_Success(t *testing.T) {
145145

146146
// Create test signer
147147
addr, pub, signer := createTestSigner(t)
148-
gen.ProposerAddress = addr
149148

150149
// Create test headers
151150
header1 := &types.SignedHeader{

block/internal/syncing/syncer.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ func (s *Syncer) Start(ctx context.Context) error {
222222

223223
s.fiRetriever = da.NewForcedInclusionRetriever(s.daClient, s.logger, s.config, s.genesis.DAStartHeight, s.genesis.DAEpochForcedInclusion)
224224
s.p2pHandler = NewP2PHandler(s.headerStore, s.dataStore, s.cache, s.genesis, s.logger)
225-
if currentHeight, err := s.store.Height(s.ctx); err != nil {
225+
if currentHeight, err := s.store.Height(ctx); err != nil {
226226
s.logger.Error().Err(err).Msg("failed to set initial processed height for p2p handler")
227227
} else {
228228
s.p2pHandler.SetProcessedHeight(currentHeight)
229229
}
230230

231231
if s.raftRetriever != nil {
232-
if err := s.raftRetriever.Start(s.ctx); err != nil {
232+
if err := s.raftRetriever.Start(ctx); err != nil {
233233
return fmt.Errorf("start raft retriever: %w", err)
234234
}
235235
}
@@ -242,7 +242,7 @@ func (s *Syncer) Start(ctx context.Context) error {
242242
s.wg.Go(s.processLoop)
243243

244244
// Start dedicated workers for DA, and pending processing
245-
s.startSyncWorkers()
245+
s.startSyncWorkers(ctx)
246246

247247
s.logger.Info().Msg("syncer started")
248248
return nil
@@ -389,11 +389,12 @@ func (s *Syncer) processLoop() {
389389
}
390390
}
391391

392-
func (s *Syncer) startSyncWorkers() {
392+
func (s *Syncer) startSyncWorkers(ctx context.Context) {
393+
_ = ctx
393394
s.wg.Add(3)
394395
go s.daWorkerLoop()
395396
go s.pendingWorkerLoop()
396-
go s.p2pWorkerLoop()
397+
go s.p2pWorkerLoop(ctx)
397398
}
398399

399400
func (s *Syncer) daWorkerLoop() {
@@ -516,7 +517,7 @@ func (s *Syncer) pendingWorkerLoop() {
516517
}
517518
}
518519

519-
func (s *Syncer) p2pWorkerLoop() {
520+
func (s *Syncer) p2pWorkerLoop(ctx context.Context) {
520521
defer s.wg.Done()
521522

522523
logger := s.logger.With().Str("worker", "p2p").Logger()
@@ -525,12 +526,12 @@ func (s *Syncer) p2pWorkerLoop() {
525526

526527
for {
527528
select {
528-
case <-s.ctx.Done():
529+
case <-ctx.Done():
529530
return
530531
default:
531532
}
532533

533-
currentHeight, err := s.store.Height(s.ctx)
534+
currentHeight, err := s.store.Height(ctx)
534535
if err != nil {
535536
logger.Error().Err(err).Msg("failed to get current height for P2P worker")
536537
if !s.sleepOrDone(50 * time.Millisecond) {
@@ -540,7 +541,7 @@ func (s *Syncer) p2pWorkerLoop() {
540541
}
541542

542543
targetHeight := currentHeight + 1
543-
waitCtx, cancel := context.WithCancel(s.ctx)
544+
waitCtx, cancel := context.WithCancel(ctx)
544545
s.setP2PWaitState(targetHeight, cancel)
545546

546547
err = s.p2pHandler.ProcessHeight(waitCtx, targetHeight, s.heightInCh)
@@ -876,7 +877,7 @@ func (s *Syncer) ValidateBlock(_ context.Context, currState types.State, data *t
876877
// Set custom verifier for aggregator node signature
877878
header.SetCustomVerifierForSyncNode(s.options.SyncNodeSignatureBytesProvider)
878879

879-
if err := header.ValidateBasicWithData(data); err != nil {
880+
if err := header.ValidateBasicWithData(data); err != nil { //nolint:contextcheck // validation API does not accept context
880881
return fmt.Errorf("invalid header: %w", err)
881882
}
882883

@@ -1308,10 +1309,7 @@ func (s *Syncer) RecoverFromRaft(ctx context.Context, raftState *raft.RaftBlockS
13081309
s.logger.Debug().Err(err).Msg("no state in store, using genesis defaults for recovery")
13091310
currentState = types.State{
13101311
ChainID: s.genesis.ChainID,
1311-
InitialHeight: s.genesis.InitialHeight,
13121312
LastBlockHeight: s.genesis.InitialHeight - 1,
1313-
LastBlockTime: s.genesis.StartTime,
1314-
DAHeight: s.genesis.DAStartHeight,
13151313
}
13161314
}
13171315
}

block/internal/syncing/syncer_backoff_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestSyncer_BackoffOnDAError(t *testing.T) {
121121
}
122122

123123
// Run sync loop
124-
syncer.startSyncWorkers()
124+
syncer.startSyncWorkers(context.Background())
125125
<-ctx.Done()
126126
syncer.wg.Wait()
127127

@@ -223,7 +223,7 @@ func TestSyncer_BackoffResetOnSuccess(t *testing.T) {
223223
go syncer.processLoop()
224224

225225
// Run workers
226-
syncer.startSyncWorkers()
226+
syncer.startSyncWorkers(context.Background())
227227
<-ctx.Done()
228228
syncer.wg.Wait()
229229

@@ -294,7 +294,7 @@ func TestSyncer_BackoffBehaviorIntegration(t *testing.T) {
294294
Return(nil, datypes.ErrBlobNotFound).Once()
295295

296296
go syncer.processLoop()
297-
syncer.startSyncWorkers()
297+
syncer.startSyncWorkers(context.Background())
298298
<-ctx.Done()
299299
syncer.wg.Wait()
300300

block/internal/syncing/syncer_benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func BenchmarkSyncerIO(b *testing.B) {
4444

4545
// run both loops
4646
go fixt.s.processLoop()
47-
fixt.s.startSyncWorkers()
47+
fixt.s.startSyncWorkers(context.Background())
4848

4949
require.Eventually(b, func() bool {
5050
processedHeight, _ := fixt.s.store.Height(b.Context())

block/internal/syncing/syncer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func TestSyncLoopPersistState(t *testing.T) {
416416
Return(nil, datypes.ErrHeightFromFuture)
417417

418418
go syncerInst1.processLoop()
419-
syncerInst1.startSyncWorkers()
419+
syncerInst1.startSyncWorkers(context.Background())
420420
syncerInst1.wg.Wait()
421421
requireEmptyChan(t, errorCh)
422422

@@ -479,7 +479,7 @@ func TestSyncLoopPersistState(t *testing.T) {
479479

480480
// when it starts, it should fetch from the last height it stopped at
481481
t.Log("sync workers on instance2 started")
482-
syncerInst2.startSyncWorkers()
482+
syncerInst2.startSyncWorkers(context.Background())
483483
syncerInst2.wg.Wait()
484484

485485
t.Log("sync workers exited")

0 commit comments

Comments
 (0)