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

golangci-lint: enable containedctx #13171

Merged
merged 1 commit into from
May 22, 2024
Merged

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented May 10, 2024

https://smartcontract-it.atlassian.net/browse/BCF-3203

This PR enabled the containedctx rule and cleans up all outstanding cases.

containedctx is a linter that detects struct contained context.Context field. This is discouraged technique in favour of passing context as first argument of method or function. For rationale please read Contexts and structs the Go blog post.

Copy link
Contributor

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from 742516c to 6be0d13 Compare May 10, 2024 00:51
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from 6be0d13 to 68d65bc Compare May 10, 2024 00:56
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from 68d65bc to c620551 Compare May 10, 2024 01:01
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from c620551 to 0c504c8 Compare May 10, 2024 02:55
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from 0c504c8 to c58c3fb Compare May 10, 2024 03:04
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from c58c3fb to 84dc378 Compare May 10, 2024 11:31
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from 84dc378 to beadb40 Compare May 10, 2024 12:02
@jmank88 jmank88 force-pushed the BCF-3203-lint-containedctx branch from beadb40 to 5ab6368 Compare May 10, 2024 12:04
Comment on lines +108 to +110
ctx, cancel := r.stopCh.NewCtx()
defer cancel()
if err := r.registerEvents(ctx, client.ID().Uint64(), addr); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seem problematic. Does anyone know why this is being done from the constructor instead of Start?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@jmank88 jmank88 requested a review from a team May 15, 2024 20:13
common/client/node_lifecycle.go Outdated Show resolved Hide resolved
common/client/node_lifecycle.go Outdated Show resolved Hide resolved
core/chains/evm/client/node_lifecycle.go Outdated Show resolved Hide resolved
o.lggr.Debugw("Pruning runs", "jobID", jobID, "count", val, "every", every, "maxSuccessfulRuns", o.maxSuccessfulRuns)
defer o.wg.Done()
ctx, cancel := context.WithTimeout(sqlutil.WithoutDefaultTimeout(o.ctx), time.Minute)
ctx, cancel := o.stopCh.CtxCancel(context.WithTimeout(sqlutil.WithoutDefaultTimeout(ctx), time.Minute))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.Minute seems like something that should be configured :), out of scope

Do we want our sqlutil timeout and context timeouts to be different keys? Is that why we need both invocations here to end up with the right timeout that consumers will respect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithoutDefaultTimeout just tells the downstream WrappedDB Monitor not to apply the default timeout. Setting our own timeout is optional, and using one minute preserves the old behavior from LongQueryTimeout or whatever that was called. Normal timeouts are not communicated via key/vals, so these are not obviously combinable AFAICT. Although we could provider a helper for this kind of case where we do both 🤷

go func() {
defer close(s.done)
ctx, cancel := s.stopCh.NewCtx()
defer cancel()
ticker := time.NewTicker(utils.WithJitter(s.pollPeriod))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch


// Returns a context that contains the values of the provided context,
// and which is canceled when either the provided context or TxStore parent context is canceled.
func (o *evmTxStore) mergeContexts(ctx context.Context) (context.Context, context.CancelFunc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@jmank88 jmank88 added this pull request to the merge queue May 22, 2024
Merged via the queue into develop with commit 677abe1 May 22, 2024
106 of 107 checks passed
@jmank88 jmank88 deleted the BCF-3203-lint-containedctx branch May 22, 2024 17:28
ilija42 added a commit that referenced this pull request May 28, 2024
* Add special transmitter for OCR2 feeds

* Add ocr2FeedsTransmitter FromAddress()

* Cherry-pick some forwarders context changes from (#13171)
github-merge-queue bot pushed a commit that referenced this pull request Jun 6, 2024
* Bump version and update CHANGELOG for core v2.12.0

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>

* core/services: fix ocrWrapper saveError contexts (#13139)

(cherry picked from commit 15fab1d)

* changed spammy error log to debug (#13153)

(cherry picked from commit 3502176)

* Updating changelog for 2.12.0  with cherry pick fix

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>

* BCF-3225 - Implement forwarder fallback if forwarder not present as a transmitter on OCR2 aggregator (#13221)

* Implement forwarder OCR2 fallback if fwd not present as a transmitter

* Add changeset

* Fix panic on mercury server error (#13231) (#13256)

* Fix changelog

* Fixed CPU usage issues caused by inefficiencies in HeadTracker (#13230)

* Fixed CPU usage issues caused by inefficiencies in HeadTracker

* added comments

* revert heads back to the fix

(cherry picked from commit 6f1ebca)

* Update CHANGELOG for 2.12.0 bugfixes

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>

* Decouple ChainType from config string [SHIP-2001] (#13272)

* fix: Decouple ChainType from config string

* fix: receiver name and failing test

* test: enhance config test to test for xdai specifically

* refactor: directly unmarshal into ChainType

* fix: validation

* test: fix TestDoc/EVM

* test: add xdai to warnings.xtar

* Index only the fifth word to reduce the db size overhead (#13315)

Co-authored-by: Domino Valdano <domino.valdano@smartcontract.com>

* Add special transmitter for OCR2 feeds (#13323)
* Add special transmitter for OCR2 feeds

* Add ocr2FeedsTransmitter FromAddress()

* Cherry-pick some forwarders context changes from (#13171)

* Improve ocr2FeedsTransmitter FromAddress() fallback (#13343)

* Improve ocr2FeedsTransmitter FromAddress() fallback

* Fix forwarders test error assert

* Update 2.12.0 Changelog with bugfixes

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>

* core/services/pipeline: bridge task must continue after cancellation

* core/services/pipeline: use request context for deletion (#13404)

* core/services/pipeline: hide deadline from monitor

* Finalize date on changelog for 2.12.0

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>

* Fix merge conflicts

* Remove `overtimeThresholds`

* Return to old version of pipeline-runner

---------

Signed-off-by: Sneha Agnihotri <sneha.agnihotri@smartcontract.com>
Co-authored-by: Jordan Krage <jmank88@gmail.com>
Co-authored-by: Patrick <patrick.huie@smartcontract.com>
Co-authored-by: ilija42 <57732589+ilija42@users.noreply.github.com>
Co-authored-by: Sam <samsondav@protonmail.com>
Co-authored-by: Dmytro Haidashenko <34754799+dhaidashenko@users.noreply.github.com>
Co-authored-by: Friedemann Fürst <friedemann.fuerst@smartcontract.com>
Co-authored-by: Mateusz Sekara <mateusz.sekara@smartcontract.com>
Co-authored-by: Domino Valdano <domino.valdano@smartcontract.com>
Co-authored-by: ilija <pavlovicilija42@gmail.com>
Co-authored-by: frank zhu <fr@nkzhu.com>
Co-authored-by: george-dorin <george.dorin@smartcontract.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants