Skip to content

feat(rpc): add lock-free cache for gas oracle tip suggestions#80

Closed
init4samwise wants to merge 1 commit intofeat/rpc-storage-scaffoldingfrom
feat/gas-oracle-cache
Closed

feat(rpc): add lock-free cache for gas oracle tip suggestions#80
init4samwise wants to merge 1 commit intofeat/rpc-storage-scaffoldingfrom
feat/gas-oracle-cache

Conversation

@init4samwise
Copy link
Contributor

Summary

Adds a lock-free cache for the gas oracle tip cap value to avoid redundant cold storage reads when multiple requests come in for the same block.

Changes

  • GasOracleCache struct (in crates/rpc/src/config/mod.rs): Uses AtomicU64 for both block number and tip value. Automatically invalidates when the block number changes.
  • StorageRpcCtxInner: Added gas_cache field
  • StorageRpcCtx: Added gas_cache() accessor method
  • suggest_tip_cap (in gas_oracle.rs): Now accepts a cache parameter, checks cache first on call, and stores result before returning
  • endpoints.rs: Updated gas_price and max_priority_fee_per_gas to pass the cache to suggest_tip_cap

Implementation Notes

  • No locks - uses only atomics (AtomicU64 with Acquire/Release ordering)
  • Cache is keyed by block number - if block advances, cache miss occurs and new value is computed
  • Tip values that exceed u64::MAX are clamped (reasonable for gas prices)

Testing

  • cargo clippy -p signet-rpc --all-features passes with no warnings
  • cargo test -p signet-rpc - all 35 tests + 2 doctests pass

Closes ENG-1898

Linear: https://linear.app/init4/issue/ENG-1898

Add GasOracleCache struct that uses atomics to cache the tip cap
value per block. This avoids redundant cold storage reads when
multiple requests for gas price or max priority fee come in for
the same block.

- Add GasOracleCache struct in config/mod.rs with atomic block/tip fields
- Add gas_cache field to StorageRpcCtxInner and accessor to StorageRpcCtx
- Modify suggest_tip_cap to accept cache parameter and check/update it
- Pass ctx.gas_cache() to suggest_tip_cap calls in endpoints

Closes ENG-1898
@init4samwise init4samwise requested a review from a team as a code owner February 16, 2026 14:55
@prestwich
Copy link
Member

[Claude Code]

Merged manually into feat/rpc-storage-scaffolding — the changes were applied on top of the refactored ctx.rs (which introduced ChainNotifier). The cache is added with pub(crate) visibility per the crate's unreachable_pub lint. All 35 RPC tests + 3 doc-tests + 52 node-tests pass.

prestwich added a commit that referenced this pull request Feb 16, 2026
… merge gas cache

- Bump signet-sdk crates from 0.16.0-rc.8 to 0.16.0-rc.11
- Migrate to new block primitives (Sealed<Header>, SealedBlock<T>)
- Replace ChainSpec with EthereumHardfork bitflags in block processor
- Restructure processor to be instantiated per-block instead of held
- Merge build_executed_block into run_evm, change map_err to wrap_err
- Fix changed flag: on_host_revert/process_committed_chain return bool
- DRY reader/last_block/drop pattern into last_rollup_block() helper
- Remove blank line between imports in gas_oracle.rs
- Merge PR #80: add lock-free GasOracleCache for tip suggestions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@prestwich
Copy link
Member

now included in #75

@prestwich prestwich closed this Feb 16, 2026
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.

2 participants