Repository navigation
chore: tech-debt batch — origin-replay window unify + Resolved address typing (#1139, #1140) - #1151
Conversation
…s typing (#1139, #1140) #1139: the origin directory's genesis ContentClaimed replay hand-rolled the same window walk that backfill_windows already owns. Route it through the shared primitive, preserving the deliberate REPLAY_WINDOW_BLOCKS = 9_000 span (a margin under the provider 10k eth_getLogs cap, not drift). Removes the "known divergence" note the backfill module doc kept to track this migration. #1140: the CLI chain_ctx Resolved* structs carried contract addresses as unvalidated String, forcing every consumer to re-parse. Move the parse into resolve / resolve_appeal / resolve_publish (fields become Address / Option<Address>), delete the four duplicate parse_address call sites, and turn the string-munging zero-address guard into `addr != Address::ZERO`. "A Resolved holds a valid address" is now true by construction. Per-subcommand "not set" messages stay in registry_ctx / assignment_ctx. Zero behavior change. Test fixtures updated to real 20-byte addresses (resolve* now parse), plus new resolve_appeal parse + zero-address-guard coverage. Closes #1139 Closes #1140 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 28 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
WalkthroughCLI address resolution now uses typed Alloy addresses throughout command wiring, with updated resolver tests. Origin-directory genesis replay now uses the shared ChangesCLI typed address resolution
Origin-directory replay windowing
Estimated code review effort: 2 (Simple) | ~10 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.71% (2452/2764 lines) |
There was a problem hiding this comment.
Code Review
This pull request refactors the CLI command resolution logic by parsing blockchain addresses into typed Address fields during the initial resolution phase rather than in the command runners. Additionally, it refactors the genesis ContentClaimed log replay in the node's DHT module to use the shared backfill_windows helper instead of a hand-rolled loop. The review feedback suggests validating the backfill range using check_backfill_range before replaying logs to ensure that transient anomalies (like RPC replication lag or reorgs) are caught and handled as retryable errors rather than silently succeeding with an incomplete cache.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| use crate::chain_events::{ | ||
| MAX_BACKFILL_BLOCK_SPAN, REORG_MARGIN_BLOCKS, WATCHER_INITIAL_BACKOFF, WATCHER_MAX_BACKOFF, | ||
| backfill_windows, | ||
| }; |
There was a problem hiding this comment.
Import check_backfill_range from crate::chain_events to validate the backfill range before replaying logs.
| use crate::chain_events::{ | |
| MAX_BACKFILL_BLOCK_SPAN, REORG_MARGIN_BLOCKS, WATCHER_INITIAL_BACKOFF, WATCHER_MAX_BACKOFF, | |
| backfill_windows, | |
| }; | |
| use crate::chain_events::{ | |
| MAX_BACKFILL_BLOCK_SPAN, REORG_MARGIN_BLOCKS, WATCHER_INITIAL_BACKOFF, WATCHER_MAX_BACKOFF, | |
| backfill_windows, check_backfill_range, | |
| }; |
References
- In blockchain or RPC watcher and backfill implementations, treat transient anomalies (such as invalid block ranges caused by replication lag) as retryable errors and propagate them to trigger backoff-and-retry.
There was a problem hiding this comment.
Same thread as the range-check suggestion below — leaving check_backfill_range out of the import here; the reasoning and the follow-up (#1152) are in the reply on the loop comment.
| let mut from = replay_from_block; | ||
| while from <= latest { | ||
| let to = from.saturating_add(REPLAY_WINDOW_BLOCKS - 1).min(latest); | ||
| for (from, to) in backfill_windows(replay_from_block, latest, REPLAY_WINDOW_BLOCKS) { |
There was a problem hiding this comment.
If replay_from_block > latest (due to RPC replication lag or a reorg), backfill_windows will silently return an empty vector, causing the bootstrap to succeed with an empty or incomplete cache. Calling check_backfill_range ensures that this range anomaly is caught and correctly propagated as an error so that the watcher can retry via the backoff path.
check_backfill_range(replay_from_block, latest)?;
for (from, to) in backfill_windows(replay_from_block, latest, REPLAY_WINDOW_BLOCKS) {References
- In blockchain or RPC watcher and backfill implementations, treat transient anomalies (such as invalid block ranges caused by replication lag) as retryable errors and propagate them to trigger backoff-and-retry.
There was a problem hiding this comment.
Not taking this as-written; tracked as a follow-up in #1152 instead.
Three reasons this PR leaves it alone:
-
Not a regression. The prior hand-rolled loop was
while from <= latest, which also executed zero iterations (silent empty/partial replay) whenreplay_from_block > latest. This refactor is behavior-preserving; refactor(node): origin-directory genesis replay hand-rolls its window walk instead of usingbackfill_windows#1139 only changed how the windows are produced. -
check_backfill_range(...)?would be fatal, not retryable here.bootstrap_cache'sErrpropagates throughChainOriginDirectory::bootstrap(...)?atcrates/node/src/runtime/mod.rs:907— one-shot, no retry loop. So?turns a transient RPC-lag anomaly into a node-startup crash, which is worse than today's graceful degradation (routing-only until re-surfaced; membership stays authoritative viagetOrigins). -
It contradicts the codebase's own pattern. The one existing
check_backfill_rangeconsumer — buyer reconcile atcrates/node/src/buyer_channel.rs:1876— doeswarn!+ skip, not propagate.
A graceful (warn + proceed) guard matching buyer reconcile is the right shape and is captured in #1152, kept out of this zero-behavior-change refactor.
Coverage reportTotal: 80.36% (was 80.28%, ▲ +0.08%) — 45295/56362 lines
History
|
…1151 review) The `.map(parse).transpose()?` on both publish address fields must surface a present-but-garbage address as Err, not silently drop it to None. Add a negative test per field so a future `.ok()`/`filter_map` rewrite that swallows the error can't ship green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Reviewed at |
Two low-risk refactors spun out of the #1137 review, batched (per the
5e75035precedent). Behavior-preserving, with one deliberate validation tightening (noted under #1140).Non-overlapping with open PR #1145 (which rewrites
node/src/buyer_channel.rs+selection.rs) — these touchcli/src/commands/chain_ctx.rs+ consumers andnode/src/dht/chain_origin_directory.rs+chain_events/backfill.rs.#1139 — genesis replay uses
backfill_windowsThe origin directory's genesis
ContentClaimedreplay hand-rolled the same window walkbackfill_windowsalready owns (#1092). Routed through the shared primitive, preserving the deliberateREPLAY_WINDOW_BLOCKS = 9_000span (a margin under the provider 10keth_getLogscap — not drift; the constant's doc now says so explicitly). Removes the "known divergence" note thebackfillmodule doc kept to track this migration. Provably equivalent, including thereplay_from_block > latestempty case.#1140 —
Resolved*structs carryAddress, notStringThe
chain_ctxResolved/ResolvedAppeal/ResolvedPublishstructs carried contract addresses as unvalidatedString, so every consumer re-parsed. Moved the parse intoresolve/resolve_appeal/resolve_publish(fields →Address/Option<Address>), deleted the four duplicateparse_addresscall sites (register/bond/setup/appeal + the two publish ctxs), and replaced the string-munging zero guard withaddr != Address::ZERO(also fixes the misleading message on an empty string). "AResolvedholds a valid address" is now true by construction. Per-subcommand "not set" messages stay inregistry_ctx/assignment_ctx.One behavior tightening:
resolve_publishnow parses both publish addresses up front, whereas before each*_ctxparsed only the one it consumed. So a config with one valid address and a present-but-unparseable sibling (e.g. a typo in an unused field) now fails fast instead of succeeding. Absent fields still stayNone. This surfaces a real misconfiguration earlier and hides nothing — kept deliberately (flagged in review by both the code-review and silent-failure passes).Follow-ups filed (kept out of this PR)
from > latestrange anomaly #1152 — origin-directory genesis replay couldwarn-guard thefrom > latestrange anomaly (out of scope for a behavior-preserving refactor; must not be a hard?— that would crash one-shot bootstrap).Tests
resolve*now parse), assertions compareAddress.resolve_appealcoverage: parses a flag address; rejects the zero address.resolve_publish_rejects_unparseable_address: a present-but-garbage address on either field surfaces asErr, guarding the.transpose()?against a future.ok()/filter_mapregression that would silently drop it.cargo clippy --all-targets -D warnings,cargo fmt --check, and the fulldecdn-cli+decdn-nodelib suites all green.Closes #1139
Closes #1140
🤖 Generated with Claude Code
Summary by CodeRabbit