Repository navigation
refactor(node): lazy on-demand origin directory (delete whole-directory mirror + watcher) - #1737
Merged
Merged
Conversation
…ity-bond registry Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ry mirror + watcher Co-Authored-By: Claude Opus 4.8 <[email protected]>
…gistry projections, ADR watchers, stale comments)
There was a problem hiding this comment.
Pull request overview
Refactors the node’s on-chain origin resolution to avoid mirroring the entire OriginAssignment directory at boot and on events, replacing it with a lazy, bounded TTL cache keyed by namespaceId. This reduces eth_call load to only the namespaces the node is actually asked to resolve, and removes the origin-directory watcher/metrics in favor of cache/miss metrics.
Changes:
- Replace the whole-directory origin mirror + background watcher with a lazy on-demand
getOrigins(namespaceId)TTL/LRU cache (LazyOriginCache) and asyncOriginDirectory::lookup_origins. - Add an always-on
operator address → NodeIdreverse projection to the sharedCapacityBondregistry watcher, eliminating per-operatornodeIdOfchain calls. - Update config schema/resolution, tests, and observability docs/metrics to reflect the new cache behavior and removed watcher.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| monitoring/prometheus-alerts.yml | Removes the origin-directory watcher stalled alert rule. |
| crates/node/tests/sighup_signal.rs | Updates resolved config seeding to include origin-directory cache TTL/capacity defaults. |
| crates/node/tests/node_origin_pull.rs | Updates test OriginDirectory impl to async. |
| crates/node/tests/anvil_bringup_shutdown_e2e.rs | Updates resolved config seeding to include origin-directory cache TTL/capacity defaults. |
| crates/node/src/runtime/reload.rs | Updates runtime reload config defaults to include origin-directory cache TTL/capacity. |
| crates/node/src/runtime/mod.rs | Switches runtime wiring to the new lazy ChainOriginDirectory (no watcher handle) and passes cache params + reverse map. |
| crates/node/src/node_origin/mod.rs | Awaits async origin_directory.lookup_origins on DHT miss fallback. |
| crates/node/src/metrics.rs | Removes origin-directory watcher metrics; adds get_origins_failures counter and cache_size gauge. |
| crates/node/src/dht/origin.rs | Makes OriginDirectory::lookup_origins async and updates implementations/tests. |
| crates/node/src/dht/mod.rs | Exposes new lazy_origin_cache module. |
| crates/node/src/dht/lazy_origin_cache.rs | Adds bounded LRU cache with split TTLs and pure resolve_active helper. |
| crates/node/src/dht/chain_projection.rs | Widens with_read visibility; removes watcher() accessor and documents watcher handle retention. |
| crates/node/src/dht/chain_origin_directory.rs | Replaces event-fed mirror with lazy TTL cache, on-demand getOrigins, and reverse-map resolution. |
| crates/node/src/dht/capacity_bond_registry.rs | Adds always-on operator_to_node reverse map projection maintained by the shared registry watcher. |
| crates/e2e/tests/cli_publish.rs | Removes node-side watcher/metric assertions; keeps on-chain getOrigins effect assertions. |
| crates/common/src/config/types.rs | Adds [blockchain] config knobs for origin-directory TTLs and cache capacity. |
| crates/common/src/config/resolved.rs | Adds resolved fields for origin-directory TTLs and cache capacity. |
| crates/common/src/config/mod.rs | Defines defaults and resolves the new config knobs (with unit tests). |
| crates/cli/tests/config_validate.rs | Updates sample resolved config with new origin-directory defaults. |
| crates/cli/src/commands/config.rs | Updates default config template and related tests to include new knobs. |
| adr/appendix-observability.md | Updates watcher count/docs; documents origin-directory metrics/alerting recommendations for lazy cache. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 80.58% (was 80.35%, ▲ +0.23%) — 57989/71967 lines
History
|
Adds DecdnOriginDirectoryLookupFailing (warning) on decdn_origin_directory_get_origins_failures_total. The lazy origin directory replaced the origin watcher, so the removed watcher-stalled alert is replaced by a fail-closed failure-rate alert rather than left with no coverage. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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
Second of the
eth_call-efficiency PRs (follows #1727). Replaces the whole-directory on-chain origin mirror with a lazy, bounded TTL cache, so a node's origin-related chain reads scale with the namespaces it actually serves — not the permissionless global namespace count.The problem
ChainOriginDirectorymirrored the entireOriginAssignmentdirectory in memory: a background watcher enumerated every namespace at boot (onegetOriginseach), re-read on every event, and fanned out anodeIdOfper operator per namespace. Namespace creation is permissionless and free (PublisherRegistry.createNamespace— no fee, no stake), so anyone can create thousands of namespaces and bloat every node in the network. And the whole mirror exists to serve a fallback path (node_origin::discoveron a DHTfind_providersmiss).The change
nodeIdOffan-out.LazyOriginCache: a bounded LRU keyed bynamespaceIdwith a positive TTL (default 300s) for populated namespaces and a shorter negative TTL (default 30s) for empty/nonexistent ones. A singlegetOrigins(ns)fires only on a cache miss for a namespace the node is actually asked to resolve. The negative TTL is the DoS bound: bogus/attacker-chosen request-namespaces can't force onegetOriginsper request.operator → NodeIdresolves locally, with zeronodeIdOfchain calls: a new always-onAddress → NodeIdreverse projection on the capacity-bond registry, derived from thegetRegisteredNodespage the registry already reads (no new chain call). An operator with no reverse-map binding is dropped (no chain fallback) — which also closes the "seat a namespace with bogus operators to force RPCs" vector. Liveness (StakerSet) is applied live at read time, so a stale cache entry can't resolve a just-deregistered node.OriginDirectory::lookup_originsbecomesasync(its sole consumer is already async). On an RPC error it fails closed (resolves nothing) and does not cache, so a transient failure isn't frozen for a TTL.Net effect
Origin resolution costs one
getOriginsper cold-namespace miss and zero per-operator reads — down from O(all namespaces) at boot + O(operators × namespaces) fan-out + a perpetual event tail.Config (new
[blockchain]knobs)origin_directory_positive_ttl_sec(default 300)origin_directory_negative_ttl_sec(default 30 — the DoS bound)origin_directory_cache_capacity(default 4096, LRU)Testing
LazyOriginCacheunit tests: split-TTL, negative-vs-miss distinction, no-TTL-refresh-on-read, LRU eviction/bump, cap clamp.resolve_active: drops unbound operators, filters inactive, sorted+deduped.ChainOriginDirectoryasync lookup: cold-miss-one-RPC (proven via call counter), cache-hit-no-RPC, negative caching, RPC-failure-fails-closed-and-not-cached, ns-0 short-circuit, live liveness re-application.decdn-node+decdn-commonsuites green (1289 tests) on latestmain.Observability
Origin-watcher metrics/alerts removed (the watcher is gone); replaced with
origin_directory_get_origins_failures_total(Counter) andorigin_directory_cache_size(Gauge), with a matching alert. ADRappendix-observability.mdupdated (four chain-event watchers, not five).Notes
get_logs/block_numberreads.🤖 Generated with Claude Code