commitment: eliminate CellGetter callback — hashRow + pure EncodeBranch#20306
Merged
Conversation
Replace the readCell func(nibble int, skip bool) callback pattern with direct data passing: - New hph.hashRow(row, depth) feeds keccak2 and extracts [16]cellEncodeData in a single pass over the afterMap — no closure, no captured vars, no heap escapes from fmt.Printf in trace paths. - EncodeBranch(bitmap, touchMap, afterMap, *[16]cellEncodeData) is now a pure serializer with no side effects. - CollectUpdate takes *[16]cellEncodeData; nil/zero for delete cases, eliminating RetrieveCellNoop. - createCellGetter and the readCell callback type are removed. Benchmark (Benchmark_HexPatriciaHashed_Process, 10s): Before: 96208 ns/op 11121 B/op 113 allocs/op After: 99154 ns/op 10921 B/op 110 allocs/op Delta: +3% ns (noise), -200 B/op (-1.8%), -3 allocs (-2.3%) Co-authored-by: shuo <shuo@erigon.dev>
AskAlexSharov
approved these changes
Apr 9, 2026
…ce check When USE_STATE_CACHE is on, SharedDomains.GetLatest serves reads from stateCache without re-verifying against the backing tx. Under suspected cache invalidation bugs, a stale cache entry silently propagates into gas accounting (observed: tx #27 in Sepolia block 10619150 under-charged by 13680 gas). Add an ASSERT_STATE_CACHE env flag that, on every stateCache hit, fetches the authoritative value from the backing tx and panics on any divergence. This makes the bug fail loudly at the exact offending (domain, key) instead of silently flowing through execution. Set ASSERT_STATE_CACHE=true alongside USE_STATE_CACHE=true to trip the panic on first divergence; the panic message identifies the domain, key, cached value, DB value and txNum.
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
Replaces the
readCell func(nibble int, skip bool)callback pattern inBranchEncoder.CollectUpdate/EncodeBranchwith direct data passing via a newhashRowmethod onHexPatriciaHashed.Problem
createCellGettercreated a closure capturingrow,depth,b,updateKey. Because the closure body containsfmt.Printf(..., nibble, row, depth)in the trace path, Go's escape analysis moved all captured vars to the heap — even whenhph.trace == false.Solution
Removed:
createCellGetter,RetrieveCellNoop,readCell func(nibble int, skip bool)callback type.Delete/propagate call-sites pass
nilinstead ofRetrieveCellNoop.Benchmark
Benchmark_HexPatriciaHashed_Process(10s, DO-Premium-AMD):Pure code quality refactor — allocation reduction is a side effect of removing the closure.
Related