Skip to content

node/ethconfig, cmd/rpcdaemon: enable FcuBackgroundCommit and 128MB state cache by default - #22269

Draft
yperbasis wants to merge 2 commits into
yperbasis/coherent-state-cachefrom
yperbasis/fcu-bg-commit-default-on
Draft

node/ethconfig, cmd/rpcdaemon: enable FcuBackgroundCommit and 128MB state cache by default#22269
yperbasis wants to merge 2 commits into
yperbasis/coherent-state-cachefrom
yperbasis/fcu-bg-commit-default-on

Conversation

@yperbasis

@yperbasis yperbasis commented Jul 6, 2026

Copy link
Copy Markdown
Member

Flips FcuBackgroundCommit to true so the FCU response returns to the consensus client before the MDBX flush+commit lands. Stacked on #22532 (version-keyed state cache + post-commit announce, the piece this PR's 128MB default builds on). Merge-blocked on the rest of the #21293 split as well — the flip activates background commit everywhere, so it also requires #22533 (overlay/committed RPC read split), #22534 (overlay safe-close invariant), and #22535 (Busy tolerance + post-FCU WaitIdle) to land first. GitHub retargets this to main when #22532 merges; do not merge before the other three.

Sets the standalone rpcdaemon --state.cache default to 128MB. Standalone daemons use Coherent at every configured budget: positive budgets retain version-keyed entries, while 0MB retains none, disables new-block waiting, and falls back to each caller's transaction snapshot. With the FCU response returning pre-commit, this keeps reads consistent with the committed view instead of serving pre-commit state-change data against an older head. The cache runs without cross-block root carry-over (bounded warmth; re-enabling it is tracked in #22276).

Motivated by #21008 — local profiling on mainnet at tip vs release/3.4 showed p50 FCU latency regressed by ~+80 ms (mean ~+90 ms, p99 ~+160 ms) with wider burst tails. Background commit decouples the FCU response from the MDBX fsync so the CL gets ACK on the overlay-published head rather than the disk-flushed head.

The regression itself was caused by #19961 moving TxLookup / Senders / Finish into the synchronous FCU path via PipelineExecutor.RunLoop. Background commit masks this by hiding the fsync from the FCU response; the root-cause fix (move those stages back to a background StageLoop, per #21008 comment) is out of scope.

Known limitation

eth_call(latest), eth_getBalance(latest), eth_getStorageAt(latest), eth_getCode(latest) served by the embedded daemon: during the bg-commit window the header resolves to N (via overlay tables) but state reads evaluate against N-1, because the SD's domain mem batch is not exposed by the block overlay. Bounded staleness (~commit duration), not corruption. The SD-aware temporal view that closes this gap is tracked in #21314.

Test plan

  • Sanity-run on mainnet minimal node — confirm FCU latency drops back to release/3.4 levels
  • Standalone rpcdaemon during bg-commit window: confirm consistent (lagging) reads with default --state.cache, and that eth_call(latest) lag matches the documented limitation
  • CI: full test + race + hive + kurtosis

@yperbasis yperbasis added this to the 3.7.0 milestone Jul 6, 2026
yperbasis added a commit that referenced this pull request Jul 6, 2026
The flip to 128MB (Coherent by default) moves to the stacked PR #22269
together with the FcuBackgroundCommit default flip; this PR keeps the
groundwork only (the with-datadir path honors the flag, and the Coherent
cache fixes make a non-zero setting work as designed).
@yperbasis yperbasis changed the title node/ethconfig: enable FcuBackgroundCommit by default node/ethconfig, cmd/rpcdaemon: enable FcuBackgroundCommit and 128MB state cache by default Jul 6, 2026
yperbasis added a commit that referenced this pull request Jul 16, 2026
At a zero budget the eviction loop drains every insert straight back
out, so Get/GetCode took the global lock twice and churned the btree
and eviction list per read-through, and OnNewBlock fed-then-evicted
every batch entry. Skip the lookup and the add when the budget is zero;
reads fall through to the caller's tx snapshot as before. Zero budget
is the standalone rpcdaemon default until #22269 raises it.

Behavior-preserving: TestZeroBudgetRetainsNothing pins the contract
(nothing retained, reads resolve on the tx snapshot rather than
announced batch data) and was confirmed green before the change too.
yperbasis and others added 2 commits July 17, 2026 10:33
Moved from #21293: with the FCU response returning pre-commit, the
version-keyed Coherent cache is what keeps a standalone daemon's reads
consistent with its committed view instead of serving pre-commit
state-change data against an older head. --state.cache=0 remains the
no-retention escape hatch (snapshot-consistent, nothing cached).
FCU responses return to the consensus client before the MDBX flush+commit
lands, recovering the FCU latency regression tracked in #21008 (p50 ~+80ms
vs release/3.4). Groundwork — overlay/committed read split, version-keyed
rpcdaemon cache, Busy tolerance, WaitIdle races — landed separately.
@yperbasis
yperbasis force-pushed the yperbasis/fcu-bg-commit-default-on branch from 538c871 to 119677c Compare July 17, 2026 08:37
@yperbasis
yperbasis changed the base branch from alex/fcu_bg_commit_35 to yperbasis/coherent-state-cache July 17, 2026 08:37
pull Bot pushed a commit to Dustin4444/erigon that referenced this pull request Jul 18, 2026
Renames `SimpleCache` → `LatestBatchCache` (with `NewSimple` →
`NewLatestBatchCache`, `SimpleView` → `LatestBatchView`, `simple.go` →
`latest_batch.go`).

"Simple" described the implementation rather than the contract, and
suggested Simple and Coherent sit on a complexity spectrum. They
actually sit on opposite sides of a semantic fork:

- **`Coherent`** — snapshot-consistency first: entries are keyed by
`PlainStateVersion`, so a reader stays consistent with its own committed
view and never sees fresher data.
- **`LatestBatchCache`** — freshness first: version-blind, it serves the
most recent announced state-change batch on top of the caller's tx,
deliberately showing announced-but-not-yet-committed account data;
staleness is bounded to one batch by FCU serialization.

That fork is what decides which cache is safe where (in-process txpool
vs RPC reads — see erigontech#22532 / erigontech#22269), and the new name carries it:
content (the latest batch), lifetime (replaced wholesale per batch), and
the trade-off (by contrast with `Coherent`). Also updates the type doc
comment to lead with the contract.

One cleanup rider in the same spirit: the dead `Evict() int { return 0
}` stub is removed (no callers, not part of the `Cache` interface — a
`DummyCache`-era leftover).

Mechanical rename + dead-code removal, no behavior change (TDD not
applicable).

---------

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.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.

1 participant