Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: linter warnings in multiple files #956

Draft
wants to merge 17 commits into
base: v1.3-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/bls/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runs:
steps:
- uses: actions/setup-go@v2
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v2
with:
submodules: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
Expand All @@ -79,7 +79,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"

- uses: actions/checkout@v4

- name: "Check generated mocks"
run: |
set -euo pipefail

readonly MOCKERY=2.41.0 # N.B. no leading "v"
readonly MOCKERY=2.46.2 # N.B. no leading "v"
curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf -
make mockery 2>/dev/null

Expand All @@ -49,7 +49,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"

- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.7.1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
submodules: true
- uses: actions/setup-go@v5.0.1
with:
go-version: "^1.22"
go-version: "^1.23"
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -53,7 +53,7 @@ jobs:
# Required: the version of golangci-lint is required and
# must be specified without patch version: we always use the
# latest patch version.
version: v1.55
version: v1.61
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"

- name: Build
uses: goreleaser/goreleaser-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v5.0.1
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ linters:
- dogsled
- dupl
- errcheck
- exportloopref
- copyloopvar
# - funlen
# - gochecknoglobals
# - gochecknoinits
Expand Down
8 changes: 4 additions & 4 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# * compile - builds final binaries
# * image - creates final image of minimal size

ARG ALIPNE_VERSION=3.19
ARG GOLANG_VERSION=1.22
ARG ALPINE_VERSION=3.19
ARG GOLANG_VERSION=1.23
#################################
# STAGE 1: install dependencies #
#################################
FROM golang:${GOLANG_VERSION}-alpine${ALIPNE_VERSION} AS base
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS base

RUN apk update && \
apk upgrade && \
Expand Down Expand Up @@ -55,7 +55,7 @@ RUN rm -r /src/tenderdash/third_party && ln -s /src/bls/third_party /src/tenderd
########################
# STAGE 4: FINAL IMAGE #
########################
FROM alpine:${ALIPNE_VERSION} AS image
FROM alpine:${ALPINE_VERSION} AS image

LABEL maintainer="developers@dash.org"

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ format:

lint:
@echo "--> Running linter"
go run github.com/golangci/golangci-lint/cmd/golangci-lint run
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 run
.PHONY: lint

DESTINATION = ./index.html.md
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ requirements if installing from source.

| Requirement | Notes |
|-------------|------------------|
| Go version | Go1.22 or higher |
| Go version | Go1.23 or higher |

## Versioning

Expand Down
2 changes: 0 additions & 2 deletions abci/client/socket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func TestSocketClientTimeout(t *testing.T) {
logger := log.NewTestingLogger(t)

for i, tc := range testCases {
i := i
tc := tc
t.Run(tc.name, func(t *testing.T) {

// wait until all threads end, otherwise we'll get data race in t.Log()
Expand Down
9 changes: 5 additions & 4 deletions abci/example/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/dashpay/tenderdash/abci/example/code"
"github.com/dashpay/tenderdash/abci/types"
tmcrypto "github.com/dashpay/tenderdash/crypto"
tmmath "github.com/dashpay/tenderdash/libs/math"
tmtypes "github.com/dashpay/tenderdash/types"
)

Expand All @@ -34,7 +35,7 @@ func (app *Application) InitCoreChainLock(initCoreChainHeight uint32, step int32
app.CoreChainLockStep = step
app.HasCoreChainLocks = true
app.CurrentCoreChainLockHeight = initCoreChainHeight
app.lastCoreChainLock = tmtypes.NewMockChainLock(app.CurrentCoreChainLockHeight)
app.lastCoreChainLock = tmtypes.NewMockChainLock(tmmath.MustConvertUint32(app.CurrentCoreChainLockHeight))
}

func (app *Application) Info(_ context.Context, _ *types.RequestInfo) (*types.ResponseInfo, error) {
Expand All @@ -51,7 +52,7 @@ func (app *Application) CheckTx(_ context.Context, req *types.RequestCheckTx) (*
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(req.Tx):], req.Tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
if txValue < tmmath.MustConvertUint64(app.txCount) {
return &types.ResponseCheckTx{
Code: code.CodeTypeBadNonce,
}, nil
Expand Down Expand Up @@ -122,7 +123,7 @@ func (app *Application) handleTxs(txs [][]byte) []*types.ExecTxResult {
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(tx):], tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue != uint64(app.txCount) {
if txValue != tmmath.MustConvertUint64(app.txCount) {
txResults = append(txResults, &types.ExecTxResult{
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue),
Expand All @@ -138,6 +139,6 @@ func (app *Application) updateCoreChainLock() {
if !app.HasCoreChainLocks {
return
}
app.CurrentCoreChainLockHeight += uint32(app.CoreChainLockStep)
app.CurrentCoreChainLockHeight += tmmath.MustConvertUint32(app.CoreChainLockStep)
app.lastCoreChainLock = tmtypes.NewMockChainLock(app.CurrentCoreChainLockHeight)
}
14 changes: 7 additions & 7 deletions abci/example/kvstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Config struct {

// SnapshotInterval specifies the height interval at which the application
// will take state sync snapshots. Defaults to 0 (disabled).
SnapshotInterval uint64 `toml:"snapshot_interval"`
SnapshotInterval int64 `toml:"snapshot_interval"`

// RetainBlocks specifies the number of recent blocks to retain. Defaults to
// 0, which retains all blocks. Must be greater that PersistInterval,
Expand All @@ -38,7 +38,7 @@ type Config struct {
// PersistInterval specifies the height interval at which the application
// will persist state to disk. Defaults to 1 (every height), setting this to
// 0 disables state persistence.
PersistInterval uint64 `toml:"persist_interval"`
PersistInterval int64 `toml:"persist_interval"`

// ValidatorUpdates is a map of heights to validator names and their power,
// and will be returned by the ABCI application. For example, the following
Expand All @@ -58,11 +58,11 @@ type Config struct {

// Add artificial delays to each of the main ABCI calls to mimic computation time
// of the application
PrepareProposalDelayMS uint64 `toml:"prepare_proposal_delay_ms"`
ProcessProposalDelayMS uint64 `toml:"process_proposal_delay_ms"`
CheckTxDelayMS uint64 `toml:"check_tx_delay_ms"`
VoteExtensionDelayMS uint64 `toml:"vote_extension_delay_ms"`
FinalizeBlockDelayMS uint64 `toml:"finalize_block_delay_ms"`
PrepareProposalDelayMS int64 `toml:"prepare_proposal_delay_ms"`
ProcessProposalDelayMS int64 `toml:"process_proposal_delay_ms"`
CheckTxDelayMS int64 `toml:"check_tx_delay_ms"`
VoteExtensionDelayMS int64 `toml:"vote_extension_delay_ms"`
FinalizeBlockDelayMS int64 `toml:"finalize_block_delay_ms"`

// dash parameters
ThesholdPublicKeyUpdate map[string]string `toml:"threshold_public_key_update"`
Expand Down
12 changes: 7 additions & 5 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/dashpay/tenderdash/internal/libs/protoio"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
types1 "github.com/dashpay/tenderdash/proto/tendermint/types"
"github.com/dashpay/tenderdash/types"
"github.com/dashpay/tenderdash/version"
Expand Down Expand Up @@ -302,7 +303,7 @@ func (app *Application) InitChain(_ context.Context, req *abci.RequestInitChain)
if !ok {
consensusParams = types1.ConsensusParams{
Version: &types1.VersionParams{
AppVersion: uint64(app.LastCommittedState.GetHeight()) + 1,
AppVersion: tmmath.MustConvertUint64(app.LastCommittedState.GetHeight() + 1),
},
}
}
Expand Down Expand Up @@ -581,15 +582,16 @@ func (app *Application) ApplySnapshotChunk(_ context.Context, req *abci.RequestA
}
func (app *Application) appVersionForHeight(height int64) uint64 {
if app.appVersion == 0 {
return uint64(height)
return tmmath.MustConvertUint64(height)
}

return app.appVersion
}

func (app *Application) createSnapshot() error {
height := app.LastCommittedState.GetHeight()
if app.cfg.SnapshotInterval == 0 || uint64(height)%app.cfg.SnapshotInterval != 0 {

if app.cfg.SnapshotInterval == 0 || height%app.cfg.SnapshotInterval != 0 {
return nil
}
_, err := app.snapshots.Create(app.LastCommittedState)
Expand Down Expand Up @@ -851,7 +853,7 @@ func (app *Application) chainLockUpdate(height int64) (*types1.CoreChainLock, er
if err != nil {
return nil, fmt.Errorf("invalid number chainLockUpdate value %q: %w", chainLockUpdateStr, err)
}
chainLock := types.NewMockChainLock(uint32(chainLockUpdate))
chainLock := types.NewMockChainLock(tmmath.MustConvertUint32(chainLockUpdate))
return chainLock.ToProto(), nil
}

Expand Down Expand Up @@ -904,7 +906,7 @@ func (app *Application) persist() error {

// persistInterval persists application state according to persist-interval parameter
func (app *Application) persistInterval() error {
if app.cfg.PersistInterval == 0 || app.LastCommittedState.GetHeight()%int64(app.cfg.PersistInterval) != 0 {
if app.cfg.PersistInterval == 0 || app.LastCommittedState.GetHeight()%app.cfg.PersistInterval != 0 {
return nil
}
return app.persist()
Expand Down
3 changes: 2 additions & 1 deletion abci/example/kvstore/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/dashpay/tenderdash/crypto"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
"github.com/dashpay/tenderdash/libs/ds"
tmmath "github.com/dashpay/tenderdash/libs/math"
)

const (
Expand Down Expand Up @@ -118,7 +119,7 @@ func (s *SnapshotStore) Create(state State) (abci.Snapshot, error) {
}

snapshot := abci.Snapshot{
Height: uint64(height),
Height: tmmath.MustConvertUint64(height),
Version: 1,
Hash: hasher.Sum(nil),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/abcidump/cmd/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (captureCmd *CaptureCmd) Command() *cobra.Command {
Short: "capture TCP traffic, parse as ABCI protocol and display it in JSON format",

RunE: captureCmd.RunE,
PostRun: func(cmd *cobra.Command, args []string) {
PostRun: func(_ *cobra.Command, _ []string) {
if captureCmd.Input != nil {
if closer, ok := captureCmd.Input.(io.Closer); ok {
closer.Close()
Expand Down
2 changes: 1 addition & 1 deletion cmd/abcidump/cmd/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (cborCmd *CborCmd) Command() *cobra.Command {
Short: "Decode a CBOR-encoded message",
PreRunE: cborCmd.PreRunE,
RunE: cborCmd.RunE,
PostRun: func(cmd *cobra.Command, args []string) {
PostRun: func(_ *cobra.Command, _ []string) {
if cborCmd.Input != nil {
if closer, ok := cborCmd.Input.(io.Closer); ok {
closer.Close()
Expand Down
2 changes: 1 addition & 1 deletion cmd/abcidump/cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (parseCmd *ParseCmd) Command() *cobra.Command {

PreRunE: parseCmd.PreRunE,
RunE: parseCmd.RunE,
PostRun: func(cmd *cobra.Command, args []string) {
PostRun: func(_ *cobra.Command, _ []string) {
if parseCmd.Input != nil {
if closer, ok := parseCmd.Input.(io.Closer); ok {
closer.Close()
Expand Down
2 changes: 1 addition & 1 deletion cmd/abcidump/cmd/rootcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func MakeRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "abcidump",
Short: "Parse dump of protobuf communication between two nodes",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
PersistentPreRunE: func(_ *cobra.Command, _ []string) (err error) {
logger, err = log.NewDefaultLogger(log.LogFormatPlain, logLevel)
if err != nil {
return fmt.Errorf("cannot initialize logging: %w", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/tenderdash/commands/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func compactGoLevelDBs(rootDir string, logger log.Logger) {
wg := sync.WaitGroup{}

for _, dbName := range dbNames {
dbName := dbName
wg.Add(1)
go func() {
defer wg.Done()
Expand Down
3 changes: 2 additions & 1 deletion cmd/tenderdash/commands/debug/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/dashpay/tenderdash/config"
"github.com/dashpay/tenderdash/libs/cli"
"github.com/dashpay/tenderdash/libs/log"
"github.com/dashpay/tenderdash/libs/math"
rpchttp "github.com/dashpay/tenderdash/rpc/client/http"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ if enabled.`,
}
dumpDebugData(ctx, logger, rpc, dumpArgs)

ticker := time.NewTicker(time.Duration(frequency) * time.Second)
ticker := time.NewTicker(time.Duration(math.MustConvert[uint, int64](frequency)) * time.Second)
for range ticker.C {
dumpDebugData(ctx, logger, rpc, dumpArgs)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tenderdash/commands/debug/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ func writeStateJSONToFile(state interface{}, dir, filename string) error {
return fmt.Errorf("failed to encode state dump: %w", err)
}

return os.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
return os.WriteFile(path.Join(dir, filename), stateJSON, 0600)
}
2 changes: 1 addition & 1 deletion cmd/tenderdash/commands/debug/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ func dumpProfile(dir, addr, profile string, debug int) error {
return fmt.Errorf("failed to read %s profile response body: %w", profile, err)
}

return os.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
return os.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, 0600)
}
Loading
Loading