Repository navigation
perf(proxy): cache proxy implementation lookups in memory - #460
Merged
Merged
Conversation
get_current_implementation is called from several enrichment steps (source context, on-chain state, address labels, role names) and each call costs 2-4 RPC reads. Cache successful lookups per (chain_id, address) in memory for PROXY_IMPL_CACHE_TTL_SECONDS (default 60, 0 disables). Failed lookups are not cached, nothing is written to disk, and expired entries are pruned once the cache passes 1024 proxies. Upgrade alerts read the old implementation with use_cache=False so they never show a stale address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_proxy_upgrade_block gives the LLM the current implementation to diff an upgrade against. It still accepted cached lookups, so an implementation changed within the cache TTL could make the LLM compare against outdated source. Bypass the cache there, matching format_upgrade_lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
get_current_implementationis called from about 10 places, including source context, on-chain state, address labels and role-name resolution. Each call costs 2–4 RPC reads (EIP-1967/zeppelinos slots, then the beacon or getter fallback), and nothing cached the result. Explaining one transaction often looked up the same proxy several times.Successful lookups are now cached in memory per
(chain_id, address)for a short TTL.PROXY_IMPL_CACHE_TTL_SECONDSsets the TTL. The default is60, and0disables the cache.use_cache=False:format_upgrade_lines(Telegram alert lines) andai_explainer._proxy_upgrade_block(the LLM's diff baseline). Upgrade alerts and explanations never compare against a stale address, and the fresh read also refreshes the cache._read_implementation.Trade-off: the getter fallback (
implementation()and similar) ignores errors from each call. If onlyeth_callfails, the lookup returns "no implementation" and that result stays cached for up to the TTL. Failures reading the storage slots still skip the cache.Tests
tests/conftest.pyclears the cache between tests, because many tests reuse a proxy address with different mocks.tests/test_proxy_upgrade.pyadds tests for cache hits (including mixed-case addresses), chain scoping, caching of non-proxy results, failures not being cached, TTL expiry,use_cache=False, the LLM upgrade baseline bypassing the cache, a TTL of 0, pruning, and upgrade alerts reading fresh.uv run pytest -q tests/: 2081 passed, 4 skipped.ruff check,ruff format --checkandty checkall pass.🤖 Generated with Claude Code