Get rid of per-instance resolver and chain cache#388
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 35 minutes and 37 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR completes the cleanup of the per-chain Blockscout URL resolution infrastructure. The ChangesCache and Infrastructure Cleanup
Possibly Related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
.cursor/rules/110-new-mcp-tool.mdc (1)
14-24:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winRemove the stale
metadata_urlexample from this config snippet.
blockscout_mcp_server/config.pyno longer definesmetadata_url; metadata requests are built fromconfig.pro_api_base_urlinmake_metadata_request(). Leaving this example here now teaches contributors an obsolete config pattern that does not match the current server architecture.Suggested doc fix
class ServerConfig(BaseSettings): # Existing endpoints (examples) bs_timeout: float = 120.0 bens_url: str = "https://bens.services.blockscout.com" bens_timeout: float = 30.0 chainscout_url: str = "https://chains.blockscout.com" chainscout_timeout: float = 15.0 - metadata_url: str = "https://metadata.services.blockscout.com" metadata_timeout: float = 30.0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.cursor/rules/110-new-mcp-tool.mdc around lines 14 - 24, Remove the stale example config field by deleting the metadata_url and metadata_timeout entries from the ServerConfig snippet so it no longer suggests defining metadata_url; update any references in the example to rely on make_metadata_request()'s use of config.pro_api_base_url instead and ensure the ServerConfig definition only includes current fields like bs_timeout, bens_url, bens_timeout, chainscout_url, and chainscout_timeout to match the runtime behavior..cursor/rules/220-integration-testing-guidelines.mdc (1)
14-46:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winMake the helper-level example use
retry_on_network_error.This section now defines the canonical helper-level pattern, but the example still calls the live endpoint directly. That contradicts the retry guidance later in the same rule and will encourage flaky copy-paste tests.
Based on learnings: “Integration tests must be resilient to transient failures … Use the
retry_on_network_errorhelper to automatically retry these conditions.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.cursor/rules/220-integration-testing-guidelines.mdc around lines 14 - 46, Update the example test to wrap the call to make_blockscout_request with the retry_on_network_error helper so transient network failures are retried automatically; specifically, call retry_on_network_error(...) passing a lambda or coroutine that invokes make_blockscout_request (and await its result) in the test (e.g., replace the direct await make_blockscout_request(...) with awaiting retry_on_network_error that executes make_blockscout_request), and ensure the rest of the assertions remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In @.cursor/rules/110-new-mcp-tool.mdc:
- Around line 14-24: Remove the stale example config field by deleting the
metadata_url and metadata_timeout entries from the ServerConfig snippet so it no
longer suggests defining metadata_url; update any references in the example to
rely on make_metadata_request()'s use of config.pro_api_base_url instead and
ensure the ServerConfig definition only includes current fields like bs_timeout,
bens_url, bens_timeout, chainscout_url, and chainscout_timeout to match the
runtime behavior.
In @.cursor/rules/220-integration-testing-guidelines.mdc:
- Around line 14-46: Update the example test to wrap the call to
make_blockscout_request with the retry_on_network_error helper so transient
network failures are retried automatically; specifically, call
retry_on_network_error(...) passing a lambda or coroutine that invokes
make_blockscout_request (and await its result) in the test (e.g., replace the
direct await make_blockscout_request(...) with awaiting retry_on_network_error
that executes make_blockscout_request), and ensure the rest of the assertions
remain unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 639ab297-dd96-4905-8888-29935f75faea
📒 Files selected for processing (20)
.cursor/rules/110-new-mcp-tool.mdc.cursor/rules/220-integration-testing-guidelines.mdc.env.exampleAGENTS.mdDockerfileSPEC.mdblockscout_mcp_server/__init__.pyblockscout_mcp_server/cache.pyblockscout_mcp_server/config.pyblockscout_mcp_server/tools/common.pypyproject.tomlserver.jsontests/integration/chains/test_get_chains_list_real.pytests/integration/direct_api/test_address_logs_handler_real.pytests/integration/direct_api/test_transaction_logs_handler_real.pytests/integration/direct_api/test_user_operation_handler_real.pytests/integration/test_common_helpers.pytests/integration/transaction/test_get_transaction_info_real.pytests/test_cache.pytests/tools/test_chain_resolution.py
💤 Files with no reviewable changes (10)
- tests/integration/direct_api/test_user_operation_handler_real.py
- blockscout_mcp_server/config.py
- tests/integration/transaction/test_get_transaction_info_real.py
- tests/integration/direct_api/test_transaction_logs_handler_real.py
- Dockerfile
- AGENTS.md
- .env.example
- tests/integration/direct_api/test_address_logs_handler_real.py
- blockscout_mcp_server/cache.py
- tests/integration/test_common_helpers.py
metadata_url no longer exists in ServerConfig (metadata requests route through config.pro_api_base_url via make_metadata_request). Remove it from both the ServerConfig and Dockerfile snippets; keep metadata_timeout, which is still a live config field. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
#388 only removes code that was already dead and off the data path before this PR (ChainCache, the chain_cache global, get_blockscout_base_url, the chain_cache_ttl_seconds config field). The server's runtime behavior is unchanged and the cleanup is transparent to consumers, so no dev version bump is warranted. Revert the dev12 bump back to dev11. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Closes #381.
Motivation
<pro_api_base_url>/<chain_id>and validates chains throughensure_chain_supported. That left the legacy per-chain instance-URL resolver (get_blockscout_base_url) and its dedicated in-memory cache (theChainCacheclass, thechain_cacheglobal, and thechain_cache_ttl_secondsconfig field) orphaned — no production code path calls them anymore.BLOCKSCOUT_CHAIN_CACHE_TTL_SECONDS) or a pointer back to the removed resolver.This is an internal cleanup — all tool signatures and response models are unchanged, so it is transparent to consumers.
Description
ChainCache:ensure_pro_api_configintools/common.pyno longer callschain_cache.replace_success_entries(...); on a successful fetch it now does exactly two things — store the PRO snapshot and invalidate the chains-list cache. The two tests whose expectations depended on that sync were updated (thereplace_success_entriespatch andbulkassertions removed, thestore_snapshotassertions kept), and the integration test that asserted the chain cache gets warmed (test_get_chains_list_warms_cache) was deleted. The chains-list-invalidation behavior remains covered bytest_ensure_pro_api_config_success_invalidates_chains_list_cache, so no coverage gap is introduced.chain_cacheglobal: Deletedget_blockscout_base_urland thechain_cache = ChainCache()global fromtools/common.py(dropping the now-unusedChainCacheimport name;ChainNotFoundErroris retained forensure_chain_supported). Removed the seven deprecated resolver unit tests intest_chain_resolution.pyand the four helper-level resolver tests intest_common_helpers.py, plus their now-orphaned imports and fixture lines. In the four*_real.pyintegration tests that resolvedbase_urlonly to assert the per-instance URL was absent from truncation notes, both thebase_url = await get_blockscout_base_url(...)line and its paired negative assertion were removed — with no per-instance URL, that assertion has no subject. The positive<pro_api_base_url>/<chain_id>/...assertions are kept.ChainCacheclass and config field: Deleted theChainCacheclass fromcache.py, thechain_cache_ttl_secondsfield fromconfig.py, and the eleventest_chain_cache_*tests (plus theChainCacheimport) fromtest_cache.py. The surviving caches (ChainsListCache,ProApiConfigCache,ContractCache) and thepro_api_config_ttl_secondsfield are untouched.ChainCache/ instance-URL-resolution mentions fromSPEC.md, the deadBLOCKSCOUT_CHAIN_CACHE_TTL_SECONDSline from.env.example,Dockerfile, and theAGENTS.mdenvironment-variable list, the stalechain_cache_ttl_secondsfield from rule110-new-mcp-tool.mdc, and replacedget_blockscout_base_urlwith the survivingensure_chain_supportedas the example helper in rule220-integration-testing-guidelines.mdc. Per rule 900, no.cursor/AGENTS.mdupdate was needed — these are wording/example clarifications within each rule's existing applicability scope.Testing
test_common_helpers.py,test_get_chains_list_real.py,test_get_transaction_info_real.py,direct_api/) via the timeout-protected runner (scripts/run_integration_tests.py): 41 passed, 0 failed, 0 skipped, 0 timed out (a PRO API key was present, so the skip-gates did not fire and every real-data test exercised the live PRO API).ruff check .andruff format --check .: both clean.git grep -nE "get_blockscout_base_url|ChainCache|chain_cache|BLOCKSCOUT_CHAIN_CACHE_TTL_SECONDS" -- ':(exclude).ai/'returns zero matches across code, tests,SPEC.md,.env.example,Dockerfile,AGENTS.md, and the two.cursor/rulesfiles.Summary by CodeRabbit
Chores
Documentation
Refactor