Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit 1641349

Browse files
authored
Upgrade to Go 1.24 and fix all golangci-lint issues (#117)
1 parent a84801b commit 1641349

40 files changed

Lines changed: 355 additions & 226 deletions

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: actions/checkout@v3
2525
- uses: actions/setup-go@v3
2626
with:
27-
go-version: '1.19'
27+
go-version: '1.24'
2828
# Initializes the CodeQL tools for scanning.
2929
- name: Initialize CodeQL
3030
uses: github/codeql-action/init@v2

.github/workflows/golangci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ jobs:
1717
steps:
1818
- uses: actions/setup-go@v3
1919
with:
20-
go-version: '1.19'
21-
- uses: actions/checkout@v3
22-
- uses: golangci/golangci-lint-action@v3
20+
go-version: '1.24'
21+
- uses: actions/checkout@v5
22+
- uses: golangci/golangci-lint-action@v8
2323
with:
24-
version: v1.49
25-
args: --config=.golangci.yml --timeout=10m
24+
version: v2.4.0

.github/workflows/unit_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/setup-go@v3
1717
with:
18-
go-version: '1.19'
18+
go-version: '1.24'
1919
- uses: actions/checkout@v3
2020
- name: Run Go Tests
2121
run: |
@@ -30,7 +30,7 @@ jobs:
3030
steps:
3131
- uses: actions/setup-go@v3
3232
with:
33-
go-version: '1.19'
33+
go-version: '1.24'
3434
- uses: actions/checkout@v3
3535

3636
- name: Install RocksDB dependencies
@@ -81,7 +81,7 @@ jobs:
8181
- uses: actions/checkout@v3
8282
- uses: actions/setup-go@v3
8383
with:
84-
go-version: '1.19'
84+
go-version: '1.24'
8585

8686
# Download all coverage reports from the 'tests' job
8787
- name: Download coverage reports

.golangci.yml

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,32 @@
1+
version: "2"
12
run:
23
tests: false
3-
# # timeout for analysis, e.g. 30s, 5m, default is 1m
44
timeout: 10m
55
build-tags:
66
- codeanalysis
77

88
linters:
9-
disable-all: true
9+
default: none
1010
enable:
1111
- bodyclose
1212
- dogsled
13-
- exportloopref
1413
- errcheck
1514
- goconst
16-
- gocritic
17-
- gofmt
18-
- goimports
1915
- gosec
20-
- gosimple
2116
- govet
2217
- ineffassign
2318
- misspell
24-
- nakedret
19+
- prealloc
2520
- staticcheck
26-
# - structcheck ## author abandoned project
27-
- stylecheck
28-
- revive
29-
- typecheck
3021
- unconvert
31-
- unused
32-
- unparam
3322
- misspell
34-
# - nolintlint ## does not work with IDEs like VSCode which automatically insert leading spaces
23+
exclusions:
24+
rules:
25+
- linters:
26+
- gosec
27+
text: "Use of weak random number generator"
3528

36-
issues:
37-
exclude-rules:
38-
- text: "Use of weak random number generator"
39-
linters:
40-
- gosec
41-
- text: "ST1003:"
42-
linters:
43-
- stylecheck
44-
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
45-
# https://github.com/dominikh/go-tools/issues/389
46-
- text: "ST1016:"
47-
linters:
48-
- stylecheck
29+
formatters:
30+
enable:
31+
- gofmt
32+
- goimports

common/utils/versions.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package utils
22

3+
import (
4+
"fmt"
5+
"math"
6+
)
7+
38
// NextVersion get the next version
49
func NextVersion(v int64, initialVersion uint32) int64 {
510
if v == 0 && initialVersion > 1 {
@@ -10,6 +15,9 @@ func NextVersion(v int64, initialVersion uint32) int64 {
1015

1116
// VersionToIndex converts version to rlog index based on initial version
1217
func VersionToIndex(version int64, initialVersion uint32) uint64 {
18+
if version < 0 {
19+
panic(fmt.Sprintf("version %d is out of range", version))
20+
}
1321
if initialVersion > 1 {
1422
return uint64(version) - uint64(initialVersion) + 1
1523
}
@@ -18,6 +26,12 @@ func VersionToIndex(version int64, initialVersion uint32) uint64 {
1826

1927
// IndexToVersion converts rlog index to version, reverse of versionToIndex
2028
func IndexToVersion(index uint64, initialVersion uint32) int64 {
29+
if index > math.MaxInt64 {
30+
panic(fmt.Sprintf("index %d is out of range", index))
31+
}
32+
if initialVersion > math.MaxInt32 {
33+
panic(fmt.Sprintf("initial version %d is out of range", initialVersion))
34+
}
2135
if initialVersion > 1 {
2236
return int64(index) + int64(initialVersion) - 1
2337
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/sei-protocol/sei-db
22

3-
go 1.19
3+
go 1.24.5
44

55
require (
66
github.com/alitto/pond v1.8.3

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWH
204204
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
205205
github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4=
206206
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
207+
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
207208
github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM=
208209
github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y=
209210
github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
@@ -461,6 +462,7 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
461462
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
462463
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
463464
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
465+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
464466
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
465467
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
466468
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
@@ -486,6 +488,7 @@ github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLe
486488
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
487489
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
488490
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
491+
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
489492
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
490493
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
491494
github.com/google/trillian v1.3.11/go.mod h1:0tPraVHrSDkA3BO6vKX67zgLXs6SsOAbHEivX+9mPgw=
@@ -738,6 +741,7 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
738741
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
739742
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
740743
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
744+
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
741745
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
742746
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
743747
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
@@ -1511,6 +1515,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
15111515
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
15121516
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
15131517
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
1518+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
15141519
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
15151520
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
15161521
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -1835,6 +1840,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
18351840
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18361841
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18371842
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
1843+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
18381844
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
18391845
gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
18401846
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
@@ -1884,7 +1890,9 @@ modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
18841890
modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
18851891
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
18861892
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
1893+
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
18871894
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
1895+
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
18881896
modernc.org/libc v1.24.1 h1:uvJSeCKL/AgzBo2yYIPPTy82v21KgGnizcGYfBHaNuM=
18891897
modernc.org/libc v1.24.1/go.mod h1:FmfO1RLrU3MHJfyi9eYYmZBfi/R+tqZ6+hQ3yQQUkak=
18901898
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
@@ -1898,9 +1906,11 @@ modernc.org/sqlite v1.26.0/go.mod h1:FL3pVXie73rg3Rii6V/u5BoHlSoyeZeIgKZEgHARyCU
18981906
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
18991907
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
19001908
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
1909+
modernc.org/tcl v1.15.2/go.mod h1:3+k/ZaEbKrC8ePv8zJWPtBSW0V7Gg9g8rkmhI1Kfs3c=
19011910
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
19021911
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
19031912
modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY=
1913+
modernc.org/z v1.7.3/go.mod h1:Ipv4tsdxZRbQyLq9Q1M6gdbkxYzdlrciF2Hi/lS7nWE=
19041914
mvdan.cc/gofumpt v0.3.1/go.mod h1:w3ymliuxvzVx8DAutBnVyDqYb1Niy/yCJt/lk821YCE=
19051915
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
19061916
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=

sc/memiavl/benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func BenchmarkRandomGet(b *testing.B) {
3737
require.NoError(b, err)
3838
snapshot, err := OpenSnapshot(snapshotDir)
3939
require.NoError(b, err)
40-
defer snapshot.Close()
40+
defer func() { _ = snapshot.Close() }()
4141

4242
b.Run("memiavl", func(b *testing.B) {
4343
require.Equal(b, targetValue, tree.Get(targetKey))

sc/memiavl/db.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"math"
78
"os"
89
"path/filepath"
910
"runtime"
@@ -543,7 +544,7 @@ func (db *DB) reloadMultiTree(mtree *MultiTree) error {
543544
if err := mtree.apply(db.pendingLogEntry); err != nil {
544545
return err
545546
}
546-
return db.MultiTree.ReplaceWith(mtree)
547+
return db.ReplaceWith(mtree)
547548
}
548549

549550
// rewriteIfApplicable execute the snapshot rewrite strategy according to current height
@@ -552,12 +553,12 @@ func (db *DB) rewriteIfApplicable(height int64) {
552553
return
553554
}
554555

555-
if db.snapshotInterval <= 0 || height <= 0 || height < db.MultiTree.SnapshotVersion() {
556+
if db.snapshotInterval <= 0 || height <= 0 || height < db.SnapshotVersion() {
556557
return
557558
}
558559

559560
// create snapshot when current height - last snapshot height > interval
560-
if height-db.MultiTree.SnapshotVersion() >= int64(db.snapshotInterval) {
561+
if height-db.SnapshotVersion() >= int64(db.snapshotInterval) {
561562
if err := db.rewriteSnapshotBackground(); err != nil {
562563
db.logger.Error("failed to rewrite snapshot in background", "err", err)
563564
}
@@ -913,5 +914,8 @@ func GetLatestVersion(dir string) (int64, error) {
913914
if err != nil {
914915
return 0, err
915916
}
917+
if metadata.InitialVersion < 0 || metadata.InitialVersion > math.MaxUint32 {
918+
return 0, fmt.Errorf("invalid initial version: %d", metadata.InitialVersion)
919+
}
916920
return utils.IndexToVersion(lastIndex, uint32(metadata.InitialVersion)), nil
917921
}

sc/memiavl/import.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package memiavl
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"math"
87
"os"
@@ -131,8 +130,8 @@ func (ai *TreeImporter) Close() error {
131130

132131
// doImport a stream of `types.SnapshotNode`s into a new snapshot.
133132
func doImport(dir string, version int64, nodes <-chan *types.SnapshotNode) (returnErr error) {
134-
if version > int64(math.MaxUint32) {
135-
return errors.New("version overflows uint32")
133+
if version < 0 || version > int64(math.MaxUint32) {
134+
return fmt.Errorf("version under/overflows uint32: %d", version)
136135
}
137136

138137
return writeSnapshot(context.Background(), dir, uint32(version), func(w *snapshotWriter) (uint32, error) {
@@ -167,15 +166,16 @@ type importer struct {
167166
}
168167

169168
func (i *importer) Add(n *types.SnapshotNode) error {
170-
if n.Version > int64(math.MaxUint32) {
171-
return errors.New("version overflows uint32")
169+
if n.Version < 0 || n.Version > math.MaxUint32 {
170+
return fmt.Errorf("node version under/overflows uint32: %d", n.Version)
172171
}
172+
version := uint32(n.Version)
173173

174174
if n.Height == 0 {
175175
node := &MemNode{
176176
height: 0,
177177
size: 1,
178-
version: uint32(n.Version),
178+
version: version,
179179
key: n.Key,
180180
value: n.Value,
181181
}
@@ -193,10 +193,14 @@ func (i *importer) Add(n *types.SnapshotNode) error {
193193
leftNode := i.nodeStack[len(i.nodeStack)-2]
194194
rightNode := i.nodeStack[len(i.nodeStack)-1]
195195

196+
if n.Height < 0 {
197+
return fmt.Errorf("node height under/overflows uint8: %d", n.Height)
198+
}
199+
196200
node := &MemNode{
197201
height: uint8(n.Height),
198202
size: leftNode.size + rightNode.size,
199-
version: uint32(n.Version),
203+
version: version,
200204
key: n.Key,
201205
left: leftNode,
202206
right: rightNode,
@@ -207,7 +211,14 @@ func (i *importer) Add(n *types.SnapshotNode) error {
207211
node.left = nil
208212
node.right = nil
209213

210-
preTrees := uint8(len(i.nodeStack) - 2)
214+
pt := len(i.nodeStack) - 2
215+
if pt < 0 || pt > math.MaxUint8 {
216+
return fmt.Errorf("preTrees out of range: %d", pt)
217+
}
218+
preTrees := uint8(pt)
219+
if node.size < 0 || node.size > math.MaxUint32 {
220+
return fmt.Errorf("node size under/overflows uint32: %d", node.size)
221+
}
211222
if err := i.writeBranch(node.version, uint32(node.size), node.height, preTrees, keyLeaf, nodeHash); err != nil {
212223
return err
213224
}

0 commit comments

Comments
 (0)