From ebabf3791b7ba27c19c7be22a5deaed71c4f0670 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 25 Oct 2024 09:36:05 -0500 Subject: [PATCH] golangci-lint: --fix nolintlint issues --- .../ccip/ccipevm/encodingUtilsAbi.json | 1 + core/capabilities/ccip/ccipevm/rmncrypto.go | 7 +++-- .../integration_tests/keystone/setup.go | 2 +- .../evm/client/simulated_backend_client.go | 6 +++- core/chains/evm/label/label.go | 1 - core/chains/evm/logpoller/log_poller.go | 4 +-- core/chains/evm/txmgr/client.go | 2 +- core/cmd/shell_local.go | 1 - core/config/app_config.go | 1 - core/logger/null_logger.go | 1 - .../keystore/keys/ocr2key/key_bundle.go | 2 -- .../llo/evm/report_codec_premium_legacy.go | 31 +++++++++++++------ core/services/llo/keyring.go | 11 +++++-- core/services/llo/keyring_test.go | 7 +++-- core/services/llo/mercurytransmitter/orm.go | 4 +-- .../onchain_channel_definition_cache_test.go | 2 +- core/services/llo/telemetry.go | 10 ++++-- core/services/ocr/database.go | 2 +- core/services/ocr2/database.go | 2 +- .../ccip/testhelpers/integration/chainlink.go | 4 +-- .../testhelpers_1_4_0/chainlink.go | 4 +-- core/services/ocrcommon/adapters.go | 2 +- .../relay/evm/chain_components_test.go | 3 +- ...n_reader_historical_client_wrapper_test.go | 3 +- core/services/relay/evm/codec/codec_test.go | 9 +++--- core/services/relay/evm/evm.go | 2 +- .../chain_components_interface_tester.go | 3 +- .../relay/evm/evmtesting/run_tests.go | 2 +- .../v1/reportcodec/report_codec_test.go | 2 +- core/services/relay/relay.go | 2 +- core/store/migrate/migrate.go | 2 -- .../migrations/0036_external_job_id.go | 2 -- .../migrations/0054_remove_legacy_pipeline.go | 2 -- .../migrate/migrations/0056_multichain.go | 2 -- ...d_not_null_to_evm_chain_id_in_job_specs.go | 2 -- core/utils/big_math/big_math.go | 1 - core/utils/files.go | 1 - core/utils/utils.go | 2 -- core/web/middleware.go | 24 +++++++------- deployment/ccip/changeset/test_helpers.go | 4 +-- .../environment/clo/don_nodeset_test.go | 2 +- .../ccip-tests/load/ccip_loadgen.go | 2 +- .../contracts/ccipreader_test.go | 4 +-- 43 files changed, 99 insertions(+), 84 deletions(-) create mode 100644 core/capabilities/ccip/ccipevm/encodingUtilsAbi.json diff --git a/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json b/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json new file mode 100644 index 00000000000..4ebb363bffe --- /dev/null +++ b/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json @@ -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"}] \ No newline at end of file diff --git a/core/capabilities/ccip/ccipevm/rmncrypto.go b/core/capabilities/ccip/ccipevm/rmncrypto.go index 1b97f5cc3bb..37b909dabe2 100644 --- a/core/capabilities/ccip/ccipevm/rmncrypto.go +++ b/core/capabilities/ccip/ccipevm/rmncrypto.go @@ -3,6 +3,7 @@ package ccipevm import ( "bytes" "context" + _ "embed" "errors" "fmt" "math/big" @@ -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 ( diff --git a/core/capabilities/integration_tests/keystone/setup.go b/core/capabilities/integration_tests/keystone/setup.go index b9b98baaf7e..f4b29323537 100644 --- a/core/capabilities/integration_tests/keystone/setup.go +++ b/core/capabilities/integration_tests/keystone/setup.go @@ -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), diff --git a/core/chains/evm/client/simulated_backend_client.go b/core/chains/evm/client/simulated_backend_client.go index c44cebe0840..a67670df318 100644 --- a/core/chains/evm/client/simulated_backend_client.go +++ b/core/chains/evm/client/simulated_backend_client.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math" "math/big" "strings" "testing" @@ -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, diff --git a/core/chains/evm/label/label.go b/core/chains/evm/label/label.go index 4cca89f93fb..b6e80acfadf 100644 --- a/core/chains/evm/label/label.go +++ b/core/chains/evm/label/label.go @@ -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/` diff --git a/core/chains/evm/logpoller/log_poller.go b/core/chains/evm/logpoller/log_poller.go index 3848c44da82..6ef4fefecee 100644 --- a/core/chains/evm/logpoller/log_poller.go +++ b/core/chains/evm/logpoller/log_poller.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" "math/big" - "math/rand" + "math/rand/v2" "sort" "strings" "sync" @@ -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 { diff --git a/core/chains/evm/txmgr/client.go b/core/chains/evm/txmgr/client.go index 9b2bcab6ebc..9ec175048d3 100644 --- a/core/chains/evm/txmgr/client.go +++ b/core/chains/evm/txmgr/client.go @@ -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 } diff --git a/core/cmd/shell_local.go b/core/cmd/shell_local.go index bead4ba5afd..f769cedee16 100644 --- a/core/cmd/shell_local.go +++ b/core/cmd/shell_local.go @@ -686,7 +686,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)) diff --git a/core/config/app_config.go b/core/config/app_config.go index 4cb7f1f610c..3f2a5472b24 100644 --- a/core/config/app_config.go +++ b/core/config/app_config.go @@ -8,7 +8,6 @@ import ( "go.uber.org/zap/zapcore" ) -// nolint var ( ErrEnvUnset = pkgerrors.New("env var unset") ) diff --git a/core/logger/null_logger.go b/core/logger/null_logger.go index 9bddd9b336f..e3e841e138c 100644 --- a/core/logger/null_logger.go +++ b/core/logger/null_logger.go @@ -4,7 +4,6 @@ import ( "go.uber.org/zap/zapcore" ) -// nolint var NullLogger Logger = &nullLogger{} type nullLogger struct{} diff --git a/core/services/keystore/keys/ocr2key/key_bundle.go b/core/services/keystore/keys/ocr2key/key_bundle.go index 2c25a159fef..a08bd84ac30 100644 --- a/core/services/keystore/keys/ocr2key/key_bundle.go +++ b/core/services/keystore/keys/ocr2key/key_bundle.go @@ -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 @@ -108,7 +107,6 @@ func (kb keyBundleBase) GoString() string { return kb.String() } -// nolint type Raw []byte func (raw Raw) Key() (kb KeyBundle) { diff --git a/core/services/llo/evm/report_codec_premium_legacy.go b/core/services/llo/evm/report_codec_premium_legacy.go index e38f6db7781..fdbad6aead9 100644 --- a/core/services/llo/evm/report_codec_premium_legacy.go +++ b/core/services/llo/evm/report_codec_premium_legacy.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "math" "math/big" "github.com/ethereum/go-ethereum/common" @@ -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" @@ -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) @@ -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 } diff --git a/core/services/llo/keyring.go b/core/services/llo/keyring.go index dee223b4531..d4bf615711c 100644 --- a/core/services/llo/keyring.go +++ b/core/services/llo/keyring.go @@ -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: @@ -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: diff --git a/core/services/llo/keyring_test.go b/core/services/llo/keyring_test.go index 3a0f8c5650b..b50e8d169c0 100644 --- a/core/services/llo/keyring_test.go +++ b/core/services/llo/keyring_test.go @@ -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" @@ -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) { diff --git a/core/services/llo/mercurytransmitter/orm.go b/core/services/llo/mercurytransmitter/orm.go index ed8c8843f4c..045161395b5 100644 --- a/core/services/llo/mercurytransmitter/orm.go +++ b/core/services/llo/mercurytransmitter/orm.go @@ -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), @@ -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 }) } diff --git a/core/services/llo/onchain_channel_definition_cache_test.go b/core/services/llo/onchain_channel_definition_cache_test.go index fa5a26237e5..e6ea3264273 100644 --- a/core/services/llo/onchain_channel_definition_cache_test.go +++ b/core/services/llo/onchain_channel_definition_cache_test.go @@ -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") }) diff --git a/core/services/llo/telemetry.go b/core/services/llo/telemetry.go index bb86679dc52..0b315d78d2b 100644 --- a/core/services/llo/telemetry.go +++ b/core/services/llo/telemetry.go @@ -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, @@ -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 { diff --git a/core/services/ocr/database.go b/core/services/ocr/database.go index b5f890565f1..b570c89e5a2 100644 --- a/core/services/ocr/database.go +++ b/core/services/ocr/database.go @@ -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, diff --git a/core/services/ocr2/database.go b/core/services/ocr2/database.go index 919d8ff5741..11de288432f 100644 --- a/core/services/ocr2/database.go +++ b/core/services/ocr2/database.go @@ -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") } diff --git a/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go b/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go index fb59c0d0783..ddae5241883 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go @@ -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" @@ -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 diff --git a/core/services/ocr2/plugins/ccip/testhelpers/testhelpers_1_4_0/chainlink.go b/core/services/ocr2/plugins/ccip/testhelpers/testhelpers_1_4_0/chainlink.go index c80b376a2af..30aaebd4e9e 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/testhelpers_1_4_0/chainlink.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/testhelpers_1_4_0/chainlink.go @@ -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" @@ -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 diff --git a/core/services/ocrcommon/adapters.go b/core/services/ocrcommon/adapters.go index 33e4971bc82..c27a276669b 100644 --- a/core/services/ocrcommon/adapters.go +++ b/core/services/ocrcommon/adapters.go @@ -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) diff --git a/core/services/relay/evm/chain_components_test.go b/core/services/relay/evm/chain_components_test.go index 3efa50d1ec5..f8174017c22 100644 --- a/core/services/relay/evm/chain_components_test.go +++ b/core/services/relay/evm/chain_components_test.go @@ -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) diff --git a/core/services/relay/evm/chain_reader_historical_client_wrapper_test.go b/core/services/relay/evm/chain_reader_historical_client_wrapper_test.go index d0aa4a21332..31122c8a5c4 100644 --- a/core/services/relay/evm/chain_reader_historical_client_wrapper_test.go +++ b/core/services/relay/evm/chain_reader_historical_client_wrapper_test.go @@ -13,12 +13,13 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types" - . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" + + . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint:revive // dot-imports ) // ClientWithContractHistory makes it possible to modify client.Client CallContract so that it returns historical data. diff --git a/core/services/relay/evm/codec/codec_test.go b/core/services/relay/evm/codec/codec_test.go index 2da88abaac1..66fc45a3037 100644 --- a/core/services/relay/evm/codec/codec_test.go +++ b/core/services/relay/evm/codec/codec_test.go @@ -16,14 +16,15 @@ import ( commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/evmtesting" - looptestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils" //nolint common practice to import test mods with . + looptestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils" commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" - . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/chain_reader_tester" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" + + . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint:revive // dot-imports ) const anyExtraValue = 3 @@ -288,8 +289,8 @@ func packArgs(t *testing.T, allArgs []any, oargs abi.Arguments, request *EncodeR } if request.MissingField { - args = args[1:] //nolint we know it's non-zero len - allArgs = allArgs[1:] //nolint we know it's non-zero len + args = args[1:] + allArgs = allArgs[1:] } bytes, err := args.Pack(allArgs...) diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 1a4af826046..cb97155473f 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -87,7 +87,7 @@ func init() { } } -var _ commontypes.Relayer = &Relayer{} //nolint:staticcheck +var _ commontypes.Relayer = &Relayer{} // The current PluginProvider interface does not support an error return. This was fine up until CCIP. // CCIP is the first product to introduce the idea of incomplete implementations of a provider based on diff --git a/core/services/relay/evm/evmtesting/chain_components_interface_tester.go b/core/services/relay/evm/evmtesting/chain_components_interface_tester.go index 9655fb78457..33f2d1ff9dd 100644 --- a/core/services/relay/evm/evmtesting/chain_components_interface_tester.go +++ b/core/services/relay/evm/evmtesting/chain_components_interface_tester.go @@ -16,7 +16,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/codec" clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types" - . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" @@ -32,6 +31,8 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" + + . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint:revive // dot-imports ) const ( diff --git a/core/services/relay/evm/evmtesting/run_tests.go b/core/services/relay/evm/evmtesting/run_tests.go index 5f3cdbb2fd7..b6abffdcb2f 100644 --- a/core/services/relay/evm/evmtesting/run_tests.go +++ b/core/services/relay/evm/evmtesting/run_tests.go @@ -18,7 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/read" - . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . + . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint:revive // dot-imports ) const ( diff --git a/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go b/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go index b24e69ce387..f5e2c7453e8 100644 --- a/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go +++ b/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go @@ -157,7 +157,7 @@ func (r *ReportCodec) ValidFromBlockNumFromReport(report ocrtypes.Report) (int64 if n > math.MaxInt64 { return 0, fmt.Errorf("ValidFromBlockNum=%d overflows max int64", n) } - return int64(n), nil //nolint:gosec // G115 + return int64(n), nil } func Test_ReportCodec_ValidFromBlockNumFromReport(t *testing.T) { diff --git a/core/services/relay/relay.go b/core/services/relay/relay.go index 913923a9b2f..0b1293c8d79 100644 --- a/core/services/relay/relay.go +++ b/core/services/relay/relay.go @@ -37,7 +37,7 @@ type ServerAdapter struct { } // NewServerAdapter returns a new ServerAdapter. -func NewServerAdapter(r types.Relayer) *ServerAdapter { //nolint:staticcheck +func NewServerAdapter(r types.Relayer) *ServerAdapter { return &ServerAdapter{Relayer: r} } diff --git a/core/store/migrate/migrate.go b/core/store/migrate/migrate.go index 7c3d3deaaf0..c8d4a0e9621 100644 --- a/core/store/migrate/migrate.go +++ b/core/store/migrate/migrate.go @@ -105,8 +105,6 @@ func ensureMigrated(ctx context.Context, db *sql.DB, p *goose.Provider, provider } // insert records for existing migrations - //nolint - sql := fmt.Sprintf(`INSERT INTO %s (version_id, is_applied) VALUES ($1, true);`, providerTableName) return sqlutil.TransactDataSource(ctx, sqlxDB, nil, func(tx sqlutil.DataSource) error { for _, name := range names { diff --git a/core/store/migrate/migrations/0036_external_job_id.go b/core/store/migrate/migrations/0036_external_job_id.go index e8012da5e78..47442124a33 100644 --- a/core/store/migrate/migrations/0036_external_job_id.go +++ b/core/store/migrate/migrations/0036_external_job_id.go @@ -31,7 +31,6 @@ const ( ` ) -// nolint func Up36(ctx context.Context, tx *sql.Tx) error { // Add the external ID column and remove type specific ones. if _, err := tx.ExecContext(ctx, up36_1); err != nil { @@ -68,7 +67,6 @@ func Up36(ctx context.Context, tx *sql.Tx) error { return nil } -// nolint func Down36(ctx context.Context, tx *sql.Tx) error { if _, err := tx.ExecContext(ctx, down36); err != nil { return err diff --git a/core/store/migrate/migrations/0054_remove_legacy_pipeline.go b/core/store/migrate/migrations/0054_remove_legacy_pipeline.go index 6d3cb20b73d..fb4c473bdb2 100644 --- a/core/store/migrate/migrations/0054_remove_legacy_pipeline.go +++ b/core/store/migrate/migrations/0054_remove_legacy_pipeline.go @@ -32,7 +32,6 @@ type queryer interface { QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row } -// nolint func Up54(ctx context.Context, tx *sql.Tx) error { if err := CheckNoLegacyJobs(ctx, tx); err != nil { return err @@ -43,7 +42,6 @@ func Up54(ctx context.Context, tx *sql.Tx) error { return nil } -// nolint func Down54(ctx context.Context, tx *sql.Tx) error { return errors.New("irreversible migration") } diff --git a/core/store/migrate/migrations/0056_multichain.go b/core/store/migrate/migrations/0056_multichain.go index c56ff0397f1..39d7ec70b2b 100644 --- a/core/store/migrate/migrations/0056_multichain.go +++ b/core/store/migrate/migrations/0056_multichain.go @@ -44,7 +44,6 @@ DROP TABLE nodes; DROP TABLE evm_chains; ` -// nolint func Up56(ctx context.Context, tx *sql.Tx) error { if _, err := tx.ExecContext(ctx, up56); err != nil { return err @@ -71,7 +70,6 @@ func Up56(ctx context.Context, tx *sql.Tx) error { return nil } -// nolint func Down56(ctx context.Context, tx *sql.Tx) error { _, err := tx.ExecContext(ctx, down56) if err != nil { diff --git a/core/store/migrate/migrations/0195_add_not_null_to_evm_chain_id_in_job_specs.go b/core/store/migrate/migrations/0195_add_not_null_to_evm_chain_id_in_job_specs.go index a2ecb50a1c9..a689cd750eb 100644 --- a/core/store/migrate/migrations/0195_add_not_null_to_evm_chain_id_in_job_specs.go +++ b/core/store/migrate/migrations/0195_add_not_null_to_evm_chain_id_in_job_specs.go @@ -33,7 +33,6 @@ const ( ` ) -// nolint func Up195(ctx context.Context, tx *sql.Tx) error { chainID, set := os.LookupEnv(env.EVMChainIDNotNullMigration0195) if set { @@ -58,7 +57,6 @@ func Up195(ctx context.Context, tx *sql.Tx) error { return errors.Wrap(err, "failed to add null constraints") } -// nolint func Down195(ctx context.Context, tx *sql.Tx) error { if _, err := tx.ExecContext(ctx, dropNullConstraintsFromSpecs); err != nil { return err diff --git a/core/utils/big_math/big_math.go b/core/utils/big_math/big_math.go index a82621b92f5..013991480ca 100644 --- a/core/utils/big_math/big_math.go +++ b/core/utils/big_math/big_math.go @@ -58,7 +58,6 @@ func Accumulate(s []*big.Int) (r *big.Int) { return } -// nolint var ( Zero = big.NewInt(0) One = big.NewInt(1) diff --git a/core/utils/files.go b/core/utils/files.go index 71b52a0ea0a..9736e1f6926 100644 --- a/core/utils/files.go +++ b/core/utils/files.go @@ -104,7 +104,6 @@ func EnsureFilepathMaxPerms(filepath string, perms os.FileMode) (err error) { // FileSize repesents a file size in bytes. type FileSize uint64 -// nolint const ( KB = 1000 MB = 1000 * KB diff --git a/core/utils/utils.go b/core/utils/utils.go index 7ac97fabb21..98c2607baff 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -595,8 +595,6 @@ func (eb *ErrorBuffer) SetCap(cap int) { } // UnwrapError returns a list of underlying errors if passed error implements joinedError or return the err in a single-element list otherwise. -// -//nolint:errorlint // error type checks will fail on wrapped errors. Disabled since we are not doing checks on error types. func UnwrapError(err error) []error { joined, ok := err.(interface{ Unwrap() []error }) if !ok { diff --git a/core/web/middleware.go b/core/web/middleware.go index 6e9378e618f..aacb912dca7 100644 --- a/core/web/middleware.go +++ b/core/web/middleware.go @@ -2,7 +2,6 @@ package web import ( "embed" - "errors" "fmt" "io/fs" "net/http" @@ -40,7 +39,7 @@ const ( // ServeFileSystem wraps a http.FileSystem with an additional file existence check type ServeFileSystem interface { http.FileSystem - Exists(prefix string, path string) bool + Exists(prefix string, path string) (bool, error) } // EmbedFileSystem implements the ServeFileSystem interface using an embed.FS @@ -60,23 +59,19 @@ func NewEmbedFileSystem(efs embed.FS, pathPrefix string) ServeFileSystem { } // Exists implements the ServeFileSystem interface. -func (e *EmbedFileSystem) Exists(prefix string, filepath string) bool { - found := false +func (e *EmbedFileSystem) Exists(prefix string, filepath string) (found bool, err error) { if p := path.Base(strings.TrimPrefix(filepath, prefix)); len(p) < len(filepath) { - //nolint:errcheck - fs.WalkDir(e.FS, ".", func(fpath string, d fs.DirEntry, err error) error { + err = fs.WalkDir(e.FS, ".", func(fpath string, d fs.DirEntry, err error) error { fileName := path.Base(fpath) if fileName == p { found = true - // Return an error so that we terminate the search early. - // Otherwise, the search will continue for the rest of the file tree. - return errors.New("file found") + return fs.SkipAll } return nil }) } - return found + return } // Open implements the http.FileSystem interface. @@ -147,7 +142,9 @@ func (f *gzipFileHandler) findBestFile(w http.ResponseWriter, r *http.Request, f ext := extensionForEncoding(posenc) fname := fpath + ext - if f.root.Exists("/", fname) { + if ok, err := f.root.Exists("/", fname); err != nil { + return nil, nil, err + } else if ok { available = append(available, posenc) } } @@ -230,7 +227,10 @@ func ServeGzippedAssets(urlPrefix string, fs ServeFileSystem, lggr logger.Logger fileserver = http.StripPrefix(urlPrefix, fileserver) } return func(c *gin.Context) { - if fs.Exists(urlPrefix, c.Request.URL.Path) { + if ok, err := fs.Exists(urlPrefix, c.Request.URL.Path); err != nil { + lggr.Errorw("Failed to search for file", "err", err) + c.AbortWithStatus(http.StatusInternalServerError) + } else if ok { fileserver.ServeHTTP(c.Writer, c.Request) c.Abort() } else { diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index ea1cea2c790..955b395bc97 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -566,11 +566,11 @@ func ToPackedFee(execFee, daFee *big.Int) *big.Int { const ( // MockLinkAggregatorDescription This is the description of the MockV3Aggregator.sol contract - // nolint:lll + //nolint:lll // https://github.com/smartcontractkit/chainlink/blob/a348b98e90527520049c580000a86fb8ceff7fa7/contracts/src/v0.8/tests/MockV3Aggregator.sol#L76-L76 MockLinkAggregatorDescription = "v0.8/tests/MockV3Aggregator.sol" // MockWETHAggregatorDescription WETH use description from MockETHUSDAggregator.sol - // nolint:lll + //nolint:lll // https://github.com/smartcontractkit/chainlink/blob/a348b98e90527520049c580000a86fb8ceff7fa7/contracts/src/v0.8/automation/testhelpers/MockETHUSDAggregator.sol#L19-L19 MockWETHAggregatorDescription = "MockETHUSDAggregator" ) diff --git a/deployment/environment/clo/don_nodeset_test.go b/deployment/environment/clo/don_nodeset_test.go index b576e95835a..fab9a81690b 100644 --- a/deployment/environment/clo/don_nodeset_test.go +++ b/deployment/environment/clo/don_nodeset_test.go @@ -61,7 +61,7 @@ func TestGenerateNopNodesData(t *testing.T) { require.NotEmpty(t, ksNops) b, err := json.MarshalIndent(ksNops, "", " ") require.NoError(t, err) - require.NoError(t, os.WriteFile("testdata/keystone_nops.json", b, 0644)) // nolint: gosec + require.NoError(t, os.WriteFile("testdata/keystone_nops.json", b, 0644)) //nolint:gosec } keystoneNops := loadTestNops(t, "testdata/keystone_nops.json") diff --git a/integration-tests/ccip-tests/load/ccip_loadgen.go b/integration-tests/ccip-tests/load/ccip_loadgen.go index 3ce770d31bc..d562cce88b2 100644 --- a/integration-tests/ccip-tests/load/ccip_loadgen.go +++ b/integration-tests/ccip-tests/load/ccip_loadgen.go @@ -300,7 +300,7 @@ func (c *CCIPE2ELoad) Call(_ *wasp.Generator) *wasp.Response { } // the msg is no longer needed, so we can clear it to avoid holding extra data during load - // nolint:ineffassign,staticcheck + //nolint:ineffassign,staticcheck msg = router.ClientEVM2AnyMessage{} txConfirmationTime := time.Now().UTC() diff --git a/integration-tests/contracts/ccipreader_test.go b/integration-tests/contracts/ccipreader_test.go index 10363d46da5..2f0a0b9a71b 100644 --- a/integration-tests/contracts/ccipreader_test.go +++ b/integration-tests/contracts/ccipreader_test.go @@ -101,7 +101,7 @@ func setupGetCommitGTETimestampTest(ctx context.Context, t *testing.T, finalityD func emitCommitReports(ctx context.Context, t *testing.T, s *testSetupData, numReports int, tokenA common.Address, onRampAddress common.Address) uint64 { var firstReportTs uint64 - for i := 0; i < numReports; i++ { + for i := uint8(0); i < numReports; i++ { _, err := s.contract.EmitCommitReportAccepted(s.auth, ccip_reader_tester.OffRampCommitReport{ PriceUpdates: ccip_reader_tester.InternalPriceUpdates{ TokenPriceUpdates: []ccip_reader_tester.InternalTokenPriceUpdate{ @@ -122,7 +122,7 @@ func emitCommitReports(ctx context.Context, t *testing.T, s *testSetupData, numR SourceChainSelector: uint64(chainS1), MinSeqNr: 10, MaxSeqNr: 20, - MerkleRoot: [32]byte{uint8(i) + 1}, //nolint:gosec // this won't overflow + MerkleRoot: [32]byte{i + 1}, OnRampAddress: common.LeftPadBytes(onRampAddress.Bytes(), 32), }, },