Skip to content

fix(ttx): remove context.Context field from Transaction struct - #2180

Merged
adecaro merged 2 commits into
mainfrom
containedctx
Aug 11, 2026
Merged

fix(ttx): remove context.Context field from Transaction struct#2180
adecaro merged 2 commits into
mainfrom
containedctx

Conversation

@adecaro

@adecaro adecaro commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the Context context.Context field from ttx.Transaction; Bytes, Issue, Transfer, Redeem, Upgrade, Outputs, and Inputs now take ctx context.Context explicitly from the caller instead of reading a value captured once at construction time.
  • Fixes htlc.Transaction.Lock, which already accepted ctx but silently used the struct field instead — the caller's deadline/cancellation/tracing context was being dropped.
  • Threads ctx through every same-package caller (marshaller.go, auditor.go, collectactions.go, collectendorsements.go), the wrapper transaction types (htlc, nfttx, boolpolicy, multisig), ~45 integration view call sites, and doc code samples.
  • Enables the containedctx linter and resolves every resulting finding repo-wide (root + integration + cmd/* modules) — either by threading ctx through as above, or with a //nolint:containedctx plus justification for the reviewed, accepted patterns (long-lived worker/service lifecycles, a per-event struct, session-wrapper convenience defaults, and one test fake).

Test plan

  • go build ./... (root and integration module) clean
  • go vet ./... (root and integration module) clean
  • make unit-tests passing
  • make unit-tests-race passing, no new races
  • make checks clean across all modules
  • make lint-auto-fix clean across all modules (0 containedctx issues)
  • Confirmed no remaining references to the removed field via targeted grep

Fixes #2178
Fixes #2179

🤖 Generated with Claude Code

@adecaro adecaro added this to the Q3/26 milestone Aug 10, 2026
@adecaro adecaro added bug Something isn't working hardening ttx labels Aug 10, 2026
@adecaro adecaro self-assigned this Aug 10, 2026
@AkramBitar
AkramBitar self-requested a review August 10, 2026 15:54

@AkramBitar AkramBitar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@adecaro
adecaro force-pushed the containedctx branch 2 times, most recently from 71907d4 to 6d43348 Compare August 11, 2026 05:18
adecaro and others added 2 commits August 11, 2026 09:25
Transaction stored a context.Context captured once at construction,
so methods reached for t.Context instead of taking a context from
their caller. A transaction rebuilt via NewTransactionFromBytes in a
different view kept the originating view's context, and
htlc.Transaction.Lock already accepted ctx but silently used t.Context
instead, dropping the caller's deadline/cancellation/tracing context.

Bytes, Issue, Transfer, Redeem, Upgrade, Outputs, and Inputs now take
ctx explicitly, threaded through every call site in token/ and
integration/.

Also enables the containedctx linter and suppresses the pattern's
remaining, reviewed occurrences (long-lived service/worker lifecycles,
a per-event struct, session-wrapper convenience defaults, and a test
fake) with a justification comment each.

Fixes #2178
Fixes #2179

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
@adecaro
adecaro merged commit 0a45e0e into main Aug 11, 2026
153 checks passed
@adecaro
adecaro deleted the containedctx branch August 11, 2026 08:04
atharrva01 added a commit to atharrva01/panurus that referenced this pull request Aug 16, 2026
LFDT-Panurus#2180 enabled containedctx and fixed the ttx occurrence. The evm module is a
separate Go module and was not linted in that pass, so make lint has been
failing on it since.

Neither field can be dropped. Ledger.ctx exists because driver.GetStateFnc
passes no context to GetState, and fakeContext.ctx exists because it
implements view.Context, whose Context() method has to return one.

Signed-off-by: atharrva01 <atharvaborade568@gmail.com>
atharrva01 added a commit to atharrva01/panurus that referenced this pull request Aug 16, 2026
LFDT-Panurus#2180 enabled containedctx and fixed the ttx occurrence. The evm module is a
separate Go module and was not linted in that pass, so make lint has been
failing on it since.

Neither field can be dropped. Ledger.ctx exists because driver.GetStateFnc
passes no context to GetState, and fakeContext.ctx exists because it
implements view.Context, whose Context() method has to return one.

Signed-off-by: atharrva01 <atharvaborade568@gmail.com>
atharrva01 added a commit to atharrva01/panurus that referenced this pull request Aug 16, 2026
LFDT-Panurus#2180 enabled containedctx and fixed the ttx occurrence. The evm module is a
separate Go module and was not linted in that pass, so make lint has been
failing on it since.

Neither field can be dropped. Ledger.ctx exists because driver.GetStateFnc
passes no context to GetState, and fakeContext.ctx exists because it
implements view.Context, whose Context() method has to return one.

Signed-off-by: atharrva01 <atharvaborade568@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hardening ttx

Projects

None yet

2 participants