commitment: replace trace bool with io.Writer for structured trace output#20316
Closed
awskii wants to merge 5 commits into
Closed
commitment: replace trace bool with io.Writer for structured trace output#20316awskii wants to merge 5 commits into
awskii wants to merge 5 commits into
Conversation
…tput Replace hph.trace bool with hph.traceW io.Writer across the commitment package. nil = disabled (zero-cost check), non-nil = writes trace output to the provided writer. Update Trie interface SetTrace -> SetTraceWriter, convert all 78 trace sites, and update all callers.
All tasks done: replaced hph.trace bool with hph.traceW io.Writer for structured trace output across the commitment package.
- Add syncWriter mutex wrapper in ConcurrentPatriciaHashed.SetTraceWriter to prevent data races when concurrent mount goroutines write to the same io.Writer (e.g. *bytes.Buffer from CommitmentCapture) - Capture traceW in local var in foldMounted defer to prevent latent nil-dereference if writer is reset before deferred func runs - Revert commented-out debug lines from fmt.Fprintf(hph.traceW,...) back to fmt.Printf to avoid nil-panic trap if uncommented without guard - Reset captureBuf at start of ComputeCommitment to prevent stale data accumulation across consecutive calls - Fix residual //hph.trace = true comment to //hph.SetTraceWriter(os.Stderr) - Remove leftover plan.md from repo root (duplicate of docs/plans/completed/) - Strengthen BufferCapturesOutput test: count [proc] lines, use precise fold pattern match
Member
Author
|
Superseded by #21859 — clean reimplementation on current main (this branch was ~800 commits behind and conflicting). |
pull Bot
pushed a commit
to Dustin4444/erigon
that referenced
this pull request
Jul 3, 2026
…ch#21859) Reimplements erigontech#20316 on current `main` (that branch was ~800 commits behind and conflicting); supersedes it. Replaces the commitment trie's `trace`/`traceDomain`/`capture []string` + `fmt.Printf` tracing with a single `traceW io.Writer`. ## Changes - `Trie` interface: `SetTrace`/`SetTraceDomain`/`SetCapture`/`GetCapture` collapse to `SetTraceWriter(io.Writer)`; `nil` disables tracing, and the `traceW != nil` guard keeps disabled tracing free (no perf change). `SharedDomains` no longer carries trace state. Callers pass `os.Stderr`, a file, or a `bytes.Buffer` to capture. - Covers every trie engine: `HexPatriciaHashed`, `ParallelPatriciaHashed`, `StreamingCommitter`, and the deep-storage fold. - Parallel/streaming trace is attributable: concurrent workers share one mutex-guarded writer, so whole lines never interleave. Deep-storage fold workers prefix each line with the parent account address — grep one address to follow that account's whole storage fold out of the interleaved output; account and split workers prefix by nibble. - `TrieContext.trace` also becomes an `io.Writer`, wired from the commitment context, so branch reads and writes trace as `[SDC]` lines on the same writer. --------- Co-authored-by: Alexey Sharov <AskAlexSharov@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the scattered
hph.trace bool+fmt.Printfpattern with a singlehph.traceW io.Writerfield. Trace output is zero-cost whentraceW == nil.Changes
hph.trace bool→hph.traceW io.WriteronHexPatriciaHashedSetTrace(bool)→SetTraceWriter(io.Writer)on Trie interfaceif hph.trace { fmt.Printf(...) }sites →if hph.traceW != nil { fmt.Fprintf(hph.traceW, ...) }[witness]fmt.Printf sites wrapped in traceW guardHexConcurrentPatriciaHashedpropagates SetTraceWriter to root + 16 mountscommitment_context.goupdated to use SetTraceWriterBenefits
&bytes.Buffer{}to capture trace for assertionsRelated