Skip to content

feat: implement cache based rpc handling for bal endpoints#23019

Closed
Soubhik-10 wants to merge 42 commits into
paradigmxyz:bal-devnet-3from
Soubhik-10:falback-rpc
Closed

feat: implement cache based rpc handling for bal endpoints#23019
Soubhik-10 wants to merge 42 commits into
paradigmxyz:bal-devnet-3from
Soubhik-10:falback-rpc

Conversation

@Soubhik-10
Copy link
Copy Markdown
Contributor

Previously all the bals were built from scratch,
now this pr uses the bal cache to fetch and return bal, if not found, bal is still built manually

Should ideally be merged after #22952
cc @mattsse @Rimeeeeee

mattsse and others added 30 commits January 21, 2026 11:35
Introduces an in-memory LRU cache for Block Access Lists (BALs) in the
Engine API. BALs are cached when payloads are validated as VALID via
newPayload.

- Add BalCache with internal Arc for cheap cloning
- Store BALs keyed by block hash with block number index for range queries
- Implement engine_getBALsByHashV1 and engine_getBALsByRangeV1
- Add metrics for cache inserts/hits/misses

Per EIP-7928, the EL should retain BALs for the weak subjectivity period
(~3533 epochs). This initial implementation uses a configurable LRU cache
(default 1024 entries) as a starting point.
- Collapse nested if statements using let-chains
- Add backticks around BTreeMap in doc comment
Ensures caller knows returned BALs correspond to contiguous blocks
[start, start + len)
Extract num_hash and BAL before calling new_payload to avoid
cloning the entire ExecutionData payload.
Replace LRU-based cache with simpler design:
- Use HashMap<BlockHash, Bytes> for O(1) hash lookups
- Use BTreeMap<BlockNumber, BlockHash> as source of truth for eviction
- Evict oldest (lowest) block numbers when at capacity
- Handle reorgs by removing old hash when block number is replaced

This is simpler, more predictable, and removes schnellru dependency.
# Conflicts:
#	crates/rpc/rpc-engine-api/src/engine_api.rs
@github-project-automation github-project-automation Bot moved this to Backlog in Reth Tracker Mar 13, 2026
@Soubhik-10 Soubhik-10 marked this pull request as ready for review March 13, 2026 09:59
@github-actions github-actions Bot added the S-stale This issue/PR is stale and will close with no further activity label Apr 4, 2026
@github-actions github-actions Bot closed this Apr 11, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Reth Tracker Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-stale This issue/PR is stale and will close with no further activity

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants