Skip to content

Commit

Permalink
golangci-lint: --fix nolintlint issues (#14957)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Dec 3, 2024
1 parent 3cecd5f commit 9f869fa
Show file tree
Hide file tree
Showing 43 changed files with 99 additions and 84 deletions.
1 change: 1 addition & 0 deletions core/capabilities/ccip/ccipevm/encodingUtilsAbi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DoNotDeploy","type":"error"},{"inputs":[{"internalType":"bytes32","name":"rmnReportVersion","type":"bytes32"},{"components":[{"internalType":"uint256","name":"destChainId","type":"uint256"},{"internalType":"uint64","name":"destChainSelector","type":"uint64"},{"internalType":"address","name":"rmnRemoteContractAddress","type":"address"},{"internalType":"address","name":"offrampAddress","type":"address"},{"internalType":"bytes32","name":"rmnHomeContractConfigDigest","type":"bytes32"},{"components":[{"internalType":"uint64","name":"sourceChainSelector","type":"uint64"},{"internalType":"bytes","name":"onRampAddress","type":"bytes"},{"internalType":"uint64","name":"minSeqNr","type":"uint64"},{"internalType":"uint64","name":"maxSeqNr","type":"uint64"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"internalType":"struct Internal.MerkleRoot[]","name":"destLaneUpdates","type":"tuple[]"}],"internalType":"struct RMNRemote.Report","name":"rmnReport","type":"tuple"}],"name":"_rmnReport","outputs":[],"stateMutability":"nonpayable","type":"function"}]
7 changes: 5 additions & 2 deletions core/capabilities/ccip/ccipevm/rmncrypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccipevm
import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"math/big"
Expand All @@ -18,8 +19,10 @@ import (

// encodingUtilsAbi is the ABI for the EncodingUtils contract.
// Should be imported when gethwrappers are moved from ccip repo to core.
// nolint:lll
const encodingUtilsAbiRaw = `[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DoNotDeploy","type":"error"},{"inputs":[{"internalType":"bytes32","name":"rmnReportVersion","type":"bytes32"},{"components":[{"internalType":"uint256","name":"destChainId","type":"uint256"},{"internalType":"uint64","name":"destChainSelector","type":"uint64"},{"internalType":"address","name":"rmnRemoteContractAddress","type":"address"},{"internalType":"address","name":"offrampAddress","type":"address"},{"internalType":"bytes32","name":"rmnHomeContractConfigDigest","type":"bytes32"},{"components":[{"internalType":"uint64","name":"sourceChainSelector","type":"uint64"},{"internalType":"bytes","name":"onRampAddress","type":"bytes"},{"internalType":"uint64","name":"minSeqNr","type":"uint64"},{"internalType":"uint64","name":"maxSeqNr","type":"uint64"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"internalType":"struct Internal.MerkleRoot[]","name":"destLaneUpdates","type":"tuple[]"}],"internalType":"struct RMNRemote.Report","name":"rmnReport","type":"tuple"}],"name":"_rmnReport","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
//
//go:embed encodingUtilsAbi.json
var encodingUtilsAbiRaw string

const addressEncodeAbiRaw = `[{"name":"method","type":"function","inputs":[{"name": "", "type": "address"}]}]`

var (
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/integration_tests/keystone/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func newReport(t *testing.T, feedID [32]byte, price *big.Int, timestamp int64) [
v3Codec := reportcodec.NewReportCodec(feedID, logger.TestLogger(t))
raw, err := v3Codec.BuildReport(ctx, v3.ReportFields{
BenchmarkPrice: price,
//nolint:gosec // disable G115

Timestamp: uint32(timestamp),
Bid: big.NewInt(0),
Ask: big.NewInt(0),
Expand Down
6 changes: 5 additions & 1 deletion core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strings"
"testing"
Expand Down Expand Up @@ -357,9 +358,12 @@ func (c *SimulatedBackendClient) SubscribeToHeads(
case h := <-ch:
var head *evmtypes.Head
if h != nil {
if h.Time > math.MaxInt64 {
c.t.Fatalf("time overflows int64: %d", h.Time)
}
head = &evmtypes.Head{
Difficulty: h.Difficulty,
Timestamp: time.Unix(int64(h.Time), 0), //nolint:gosec
Timestamp: time.Unix(int64(h.Time), 0), //nolint:gosec // G115 false positive
Number: h.Number.Int64(),
Hash: h.Hash(),
ParentHash: h.ParentHash,
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/label/label.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package label

// nolint
const (
MaxInFlightTransactionsWarning = `WARNING: If this happens a lot, you may need to increase EVM.Transactions.MaxInFlight to boost your node's transaction throughput, however you do this at your own risk. You MUST first ensure your ethereum node is configured not to ever evict local transactions that exceed this number otherwise the node can get permanently stuck. See the performance guide for more details: https://docs.chain.link/docs/evm-performance-configuration/`
MaxQueuedTransactionsWarning = `WARNING: Hitting EVM.Transactions.MaxQueued is a sanity limit and should never happen under normal operation. Unless you are operating with very high throughput, this error is unlikely to be a problem with your Chainlink node configuration, and instead more likely to be caused by a problem with your eth node's connectivity. Check your eth node: it may not be broadcasting transactions to the network, or it might be overloaded and evicting Chainlink's transactions from its mempool. It is recommended to run Chainlink with multiple primary and sendonly nodes for redundancy and to ensure fast and reliable transaction propagation. Increasing EVM.Transactions.MaxQueued will allow Chainlink to buffer more unsent transactions, but you should only do this if you need very high burst transmission rates. If you don't need very high burst throughput, increasing this limit is not the correct action to take here and will probably make things worse. See the performance guide for more details: https://docs.chain.link/docs/evm-performance-configuration/`
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"fmt"
"math/big"
"math/rand"
"math/rand/v2"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -687,7 +687,7 @@ func (lp *logPoller) backgroundWorkerRun() {

// Start initial prune of unmatched logs after 5-15 successful expired log prunes, so that not all chains start
// around the same time. After that, every 20 successful expired log prunes.
successfulExpiredLogPrunes := 5 + rand.Intn(10) //nolint:gosec
successfulExpiredLogPrunes := 5 + rand.IntN(10) //nolint:gosec // G404

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *evmTxmClient) SequenceAt(ctx context.Context, addr common.Address, bloc
if nonce > math.MaxInt64 {
return 0, fmt.Errorf("overflow for nonce: %d", nonce)
}
//nolint:gosec // disable G115

return evmtypes.Nonce(nonce), err
}

Expand Down
1 change: 0 additions & 1 deletion core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
nonces[i] = evmtypes.Nonce(beginningNonce + i)
}
if gasPriceWei <= math.MaxInt64 {
//nolint:gosec // disable G115
return s.errorOut(ec.ForceRebroadcast(ctx, nonces, gas.EvmFee{GasPrice: assets.NewWeiI(int64(gasPriceWei))}, address, uint64(overrideGasLimit)))
}
return s.errorOut(fmt.Errorf("integer overflow conversion error. GasPrice: %v", gasPriceWei))
Expand Down
1 change: 0 additions & 1 deletion core/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"go.uber.org/zap/zapcore"
)

// nolint
var (
ErrEnvUnset = pkgerrors.New("env var unset")
)
Expand Down
1 change: 0 additions & 1 deletion core/logger/null_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"go.uber.org/zap/zapcore"
)

// nolint
var NullLogger Logger = &nullLogger{}

type nullLogger struct{}
Expand Down
2 changes: 0 additions & 2 deletions core/services/keystore/keys/ocr2key/key_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type OCR3SignerVerifier interface {
Verify3(publicKey ocrtypes.OnchainPublicKey, cd ocrtypes.ConfigDigest, seqNr uint64, r ocrtypes.Report, signature []byte) bool
}

// nolint
type KeyBundle interface {
// OnchainKeyring is used for signing reports (groups of observations, verified onchain)
ocrtypes.OnchainKeyring
Expand Down Expand Up @@ -108,7 +107,6 @@ func (kb keyBundleBase) GoString() string {
return kb.String()
}

// nolint
type Raw []byte

func (raw Raw) Key() (kb KeyBundle) {
Expand Down
31 changes: 21 additions & 10 deletions core/services/llo/evm/report_codec_premium_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -14,11 +15,11 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2/types"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"
v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3"
"github.com/smartcontractkit/chainlink-data-streams/llo"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury"
reportcodecv3 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v3/reportcodec"
Expand Down Expand Up @@ -121,7 +122,10 @@ func (r ReportCodecPremiumLegacy) Pack(digest types.ConfigDigest, seqNr uint64,
ss = append(ss, s)
vs[i] = v
}
reportCtx := LegacyReportContext(digest, seqNr, r.donID)
reportCtx, err := LegacyReportContext(digest, seqNr, r.donID)
if err != nil {
return nil, fmt.Errorf("failed to get legacy report context: %w", err)
}
rawReportCtx := evmutil.RawReportContext(reportCtx)

payload, err := mercury.PayloadTypes.Pack(rawReportCtx, []byte(report), rs, ss, vs)
Expand Down Expand Up @@ -203,21 +207,28 @@ func LLOExtraHash(donID uint32) common.Hash {
return common.BigToHash(new(big.Int).SetUint64(combined))
}

func SeqNrToEpochAndRound(seqNr uint64) (epoch uint32, round uint8) {
func SeqNrToEpochAndRound(seqNr uint64) (epoch uint32, round uint8, err error) {
// Simulate 256 rounds/epoch
epoch = uint32(seqNr / 256) // nolint
round = uint8(seqNr % 256) // nolint
if seqNr/256 > math.MaxUint32 {
err = fmt.Errorf("epoch overflows uint32: %d", seqNr)
return
}
epoch = uint32(seqNr / 256) //nolint:gosec // G115 false positive
round = uint8(seqNr % 256) //nolint:gosec // G115 false positive
return
}

func LegacyReportContext(cd ocr2types.ConfigDigest, seqNr uint64, donID uint32) ocr2types.ReportContext {
epoch, round := SeqNrToEpochAndRound(seqNr)
func LegacyReportContext(cd ocr2types.ConfigDigest, seqNr uint64, donID uint32) (ocr2types.ReportContext, error) {
epoch, round, err := SeqNrToEpochAndRound(seqNr)
if err != nil {
return ocr2types.ReportContext{}, err
}
return ocr2types.ReportContext{
ReportTimestamp: ocr2types.ReportTimestamp{
ConfigDigest: cd,
Epoch: uint32(epoch),
Round: uint8(round),
Epoch: epoch,
Round: round,
},
ExtraHash: LLOExtraHash(donID), // ExtraHash is always zero for mercury, we use LLOExtraHash here to differentiate from the legacy plugin
}
}, nil
}
11 changes: 9 additions & 2 deletions core/services/llo/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (okr *onchainKeyring) Sign(digest types.ConfigDigest, seqNr uint64, r ocr3t
rf := r.Info.ReportFormat
if key, exists := okr.keys[rf]; exists {
// NOTE: Must use legacy Sign method for compatibility with v0.3 report verification
rc := evm.LegacyReportContext(digest, seqNr, okr.donID)
rc, err := evm.LegacyReportContext(digest, seqNr, okr.donID)
if err != nil {
return nil, fmt.Errorf("failed to get legacy report context: %w", err)
}
return key.Sign(rc, r.Report)
}
default:
Expand All @@ -102,7 +105,11 @@ func (okr *onchainKeyring) Verify(key types.OnchainPublicKey, digest types.Confi
rf := r.Info.ReportFormat
if verifier, exists := okr.keys[rf]; exists {
// NOTE: Must use legacy Verify method for compatibility with v0.3 report verification
rc := evm.LegacyReportContext(digest, seqNr, okr.donID)
rc, err := evm.LegacyReportContext(digest, seqNr, okr.donID)
if err != nil {
okr.lggr.Errorw("Verify failed; unable to get legacy report context", "err", err)
return false
}
return verifier.Verify(key, rc, r.Report, signature)
}
default:
Expand Down
7 changes: 4 additions & 3 deletions core/services/llo/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package llo

import (
"fmt"
"math/rand"
"math"
"math/rand/v2"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ocr3types "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

Expand Down Expand Up @@ -83,7 +84,7 @@ func Test_Keyring(t *testing.T) {

cd, err := ocrtypes.BytesToConfigDigest(testutils.MustRandBytes(32))
require.NoError(t, err)
seqNr := rand.Uint64()
seqNr := rand.Uint64N(math.MaxUint32 << 8)
t.Run("Sign+Verify", func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.format.String(), func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/services/llo/mercurytransmitter/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (o *orm) Insert(ctx context.Context, transmissions []*Transmission) error {
DonID: o.donID,
ServerURL: t.ServerURL,
ConfigDigest: t.ConfigDigest,
SeqNr: int64(t.SeqNr), //nolint
SeqNr: int64(t.SeqNr), //nolint:gosec // G115 false positive
Report: t.Report.Report,
LifecycleStage: string(t.Report.Info.LifeCycleStage),
ReportFormat: uint32(t.Report.Info.ReportFormat),
Expand Down Expand Up @@ -162,7 +162,7 @@ func (o *orm) Get(ctx context.Context, serverURL string) ([]*Transmission, error
}
transmission.Sigs = append(transmission.Sigs, ocrtypes.AttributedOnchainSignature{
Signature: sig,
Signer: commontypes.OracleID(signers[i]), //nolint
Signer: commontypes.OracleID(signers[i]), //nolint:gosec // G115 false positive
})
}

Expand Down
2 changes: 1 addition & 1 deletion core/services/llo/onchain_channel_definition_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func Test_ChannelDefinitionCache(t *testing.T) {
}

t.Run("nil ctx returns error", func(t *testing.T) {
_, err := cdc.fetchChannelDefinitions(nil, "notvalid://foos", [32]byte{}) //nolint
_, err := cdc.fetchChannelDefinitions(nil, "notvalid://foos", [32]byte{}) //nolint:staticcheck // SA1012 we pass nil intentionally here
assert.EqualError(t, err, "failed to create http.Request; net/http: nil Context")
})

Expand Down
10 changes: 7 additions & 3 deletions core/services/llo/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (t *telemeter) collectV3PremiumLegacyTelemetry(d TelemetryObservation) {
askPrice = v.Ask.IntPart()
ask = v.Ask.String()
}
epoch, round := evm.SeqNrToEpochAndRound(d.opts.OutCtx().SeqNr)
tea := &telem.EnhancedEAMercury{
DataSource: eaTelem.DataSource,
DpBenchmarkPrice: eaTelem.DpBenchmarkPrice,
Expand All @@ -142,12 +141,17 @@ func (t *telemeter) collectV3PremiumLegacyTelemetry(d TelemetryObservation) {
IsLinkFeed: false,
IsNativeFeed: false,
ConfigDigest: d.opts.ConfigDigest().Hex(),
Round: int64(round),
Epoch: int64(epoch),
AssetSymbol: eaTelem.AssetSymbol,
Version: uint32(1000 + mercuryutils.REPORT_V3), // add 1000 to distinguish between legacy feeds, this can be changed if necessary
DonId: t.donID,
}
epoch, round, err := evm.SeqNrToEpochAndRound(d.opts.OutCtx().SeqNr)
if err != nil {
t.eng.SugaredLogger.Warnw("Failed to convert sequence number to epoch and round", "err", err)
} else {
tea.Round = int64(round)
tea.Epoch = int64(epoch)
}

bytes, err := proto.Marshal(tea)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (d *db) StorePendingTransmission(ctx context.Context, k ocrtypes.ReportTime
}

func (d *db) PendingTransmissionsWithConfigDigest(ctx context.Context, cd ocrtypes.ConfigDigest) (map[ocrtypes.ReportTimestamp]ocrtypes.PendingTransmission, error) {
//nolint sqlclosecheck false positive
//nolint:sqlclosecheck // false positive
rows, err := d.ds.QueryContext(ctx, `
SELECT
config_digest,
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (d *db) PendingTransmissionsWithConfigDigest(ctx context.Context, cd ocrtyp
FROM ocr2_pending_transmissions
WHERE ocr2_oracle_spec_id = $1 AND config_digest = $2
`
rows, err := d.ds.QueryxContext(ctx, stmt, d.oracleSpecID, cd) //nolint sqlclosecheck false positive
rows, err := d.ds.QueryxContext(ctx, stmt, d.oracleSpecID, cd)
if err != nil {
return nil, errors.Wrap(err, "PendingTransmissionsWithConfigDigest failed to query rows")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/jmoiron/sqlx"
"github.com/onsi/gomega"
"github.com/pkg/errors"
"k8s.io/utils/ptr"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"k8s.io/utils/pointer" //nolint:staticcheck

"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
Expand Down Expand Up @@ -387,7 +387,7 @@ func setupNodeCCIP(
c.Feature.UICSAKeys = &trueRef
c.Feature.FeedsManager = &trueRef
c.OCR.Enabled = &falseRef
c.OCR.DefaultTransactionQueueDepth = pointer.Uint32(200)
c.OCR.DefaultTransactionQueueDepth = ptr.To[uint32](200)
c.OCR2.Enabled = &trueRef
c.Feature.LogPoller = &trueRef
c.P2P.V2.Enabled = &trueRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/jmoiron/sqlx"
"github.com/onsi/gomega"
"github.com/pkg/errors"
"k8s.io/utils/ptr"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"k8s.io/utils/pointer" //nolint:staticcheck

"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
Expand Down Expand Up @@ -383,7 +383,7 @@ func setupNodeCCIP(
c.Feature.UICSAKeys = &trueRef
c.Feature.FeedsManager = &trueRef
c.OCR.Enabled = &falseRef
c.OCR.DefaultTransactionQueueDepth = pointer.Uint32(200)
c.OCR.DefaultTransactionQueueDepth = ptr.To[uint32](200)
c.OCR2.Enabled = &trueRef
c.Feature.LogPoller = &trueRef
c.P2P.V2.Enabled = &trueRef
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocrcommon/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func MarshalMultichainPublicKey(ost map[string]ocrtypes.OnchainPublicKey) (ocrty
if length < 0 || length > math.MaxUint16 {
return nil, fmt.Errorf("pubKey doesn't fit into uint16")
}
if err = binary.Write(buf, binary.LittleEndian, uint16(length)); err != nil { //nolint:gosec
if err = binary.Write(buf, binary.LittleEndian, uint16(length)); err != nil {
return nil, err
}
_, _ = buf.Write(pubKey)
Expand Down
3 changes: 2 additions & 1 deletion core/services/relay/evm/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
. "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/evmtesting" //nolint common practice to import test mods with .
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"

. "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/evmtesting" //nolint:revive // dot-imports
)

const commonGasLimitOnEvms = uint64(4712388)
Expand Down
Loading

0 comments on commit 9f869fa

Please sign in to comment.