erigontech / erigontech/erigon

rpc: reuse snapshot-coherent state caches for committed replay

Open
#23,425 0 comments 0 reactions 1 assignee Claimed by @yperbasis View on GitHub
RPC
Dominant language
Go
Stars
3.6k
Forks
1.5k
Avg merge
1d 16h
Merged PRs (30d)
455

Description

## Problem

#22533 keeps state and history replay on one committed transaction. It uses uncached state readers because the embedded execution cache and `LatestBatchCache` can expose a newer published state than that transaction.

That correctness rule also bypasses `kvcache.Coherent` in a remote rpcdaemon started with `--state.cache > 0`. `Coherent.View` selects a cache root from the transaction's own `PlainStateVersion` and falls through to the same transaction, so it can preserve the committed snapshot while avoiding repeated remote state reads.

The state-reader code cannot currently distinguish a cache whose view is bound to the supplied transaction from a latest-state cache. Unconditionally using the cache is incorrect; unconditionally bypassing it loses safe hits and can add gRPC round trips to trace requests.

## Proposed direction

- Add an explicit cache capability that states whether `View(tx)` is snapshot-bound to `tx`.
- Let committed replay helpers use a cache only when that capability is present.
- Keep the embedded execution cache and `LatestBatchCache` disabled for committed replay.
- Do not use concrete type switches in RPC code.
- Measure latest-block and historical tracing with remote rpcdaemon before and after the change.

#23240 must be resolved first, or this work must demonstrate that failed pre-commit state-change publication cannot poison a `Coherent` root selected by a committed transaction.

## Acceptance criteria

- [ ] Committed replay never reads a state generation newer than its database transaction.
- [ ] Remote `kvcache.Coherent` hits remain available when they are bound to the transaction state version.
- [ ] Embedded and latest-batch caches cannot opt in accidentally.
- [ ] Tests cover a cache publication newer than the request transaction and a matching coherent cache root.
- [ ] Benchmarks report cache hits, misses, and remote-read cost for representative trace requests.

## Related

- #22533
- #21314
- #23082
- #23240

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.