Skip to content

chore: tech-debt batch — origin-replay window unify + Resolved address typing (#1139, #1140) - #1151

Merged
yigitdot merged 2 commits into
mainfrom
chore/tech-debt-1139-1140
Jul 15, 2026
Merged

yigitdot merged 2 commits into
mainfrom
chore/tech-debt-1139-1140

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Two low-risk refactors spun out of the #1137 review, batched (per the 5e75035 precedent). 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 touch cli/src/commands/chain_ctx.rs + consumers and node/src/dht/chain_origin_directory.rs + chain_events/backfill.rs.

#1139 — genesis replay uses backfill_windows

The origin directory's genesis ContentClaimed replay hand-rolled the same window walk backfill_windows already owns (#1092). Routed through the shared primitive, preserving the deliberate REPLAY_WINDOW_BLOCKS = 9_000 span (a margin under the provider 10k eth_getLogs cap — not drift; the constant's doc now says so explicitly). Removes the "known divergence" note the backfill module doc kept to track this migration. Provably equivalent, including the replay_from_block > latest empty case.

#1140 — Resolved* structs carry Address, not String

The chain_ctx Resolved / ResolvedAppeal / ResolvedPublish structs carried contract addresses as unvalidated String, so every consumer re-parsed. Moved the parse into resolve / resolve_appeal / resolve_publish (fields → Address / Option<Address>), deleted the four duplicate parse_address call sites (register/bond/setup/appeal + the two publish ctxs), and replaced the string-munging zero guard with addr != Address::ZERO (also fixes the misleading message on an empty string). "A Resolved holds a valid address" is now true by construction. Per-subcommand "not set" messages stay in registry_ctx/assignment_ctx.

One behavior tightening: resolve_publish now parses both publish addresses up front, whereas before each *_ctx parsed 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 stay None. 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)

Tests

  • Resolver unit-test fixtures updated to real 20-byte addresses (resolve* now parse), assertions compare Address.
  • New resolve_appeal coverage: parses a flag address; rejects the zero address.
  • New resolve_publish_rejects_unparseable_address: a present-but-garbage address on either field surfaces as Err, guarding the .transpose()? against a future .ok()/filter_map regression that would silently drop it.
  • cargo clippy --all-targets -D warnings, cargo fmt --check, and the full decdn-cli + decdn-node lib suites all green.

Closes #1139
Closes #1140

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Improved address validation and handling across CLI commands, providing clearer and more consistent configuration errors.
    • Enhanced publishing, registration, setup, bonding, and appeals workflows with reliable contract address resolution.
    • Improved blockchain event replay during origin-directory initialization for more consistent backfill processing.
  • Documentation
    • Clarified event replay windowing and block-range behavior.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yigitdot, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 11ad6336-bdb8-48da-9caa-039a5990a86d

📥 Commits

Reviewing files that changed from the base of the PR and between d3ce3a6 and c37678e.

📒 Files selected for processing (1)
  • crates/cli/src/commands/chain_ctx.rs

Walkthrough

CLI address resolution now uses typed Alloy addresses throughout command wiring, with updated resolver tests. Origin-directory genesis replay now uses the shared backfill_windows helper and documents its block-span configuration.

Changes

CLI typed address resolution

Layer / File(s) Summary
Typed address resolution contracts
crates/cli/src/commands/chain_ctx.rs
Resolved capacity-bond, appeal, publisher-registry, and origin-assignment addresses now use Address values; resolver parsing, zero-address validation, and related tests are updated.
Typed address command wiring
crates/cli/src/commands/{appeal,bond,publish,register,setup}.rs
Commands consume addresses directly from resolved values instead of reparsing strings.

Origin-directory replay windowing

Layer / File(s) Summary
Shared bootstrap replay windows
crates/node/src/{chain_events/backfill.rs,dht/chain_origin_directory.rs}
Genesis ContentClaimed replay now iterates ranges with backfill_windows, with updated documentation for the 9,000-block window.

Estimated code review effort: 2 (Simple) | ~10 minutes


Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.71% (2452/2764 lines)
▲ +0.00pp vs base (88.71% → 88.71%)
Run: 29374402281

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 104 to 107
use crate::chain_events::{
MAX_BACKFILL_BLOCK_SPAN, REORG_MARGIN_BLOCKS, WATCHER_INITIAL_BACKOFF, WATCHER_MAX_BACKOFF,
backfill_windows,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Import check_backfill_range from crate::chain_events to validate the backfill range before replaying logs.

Suggested change
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
  1. 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this as-written; tracked as a follow-up in #1152 instead.

Three reasons this PR leaves it alone:

  1. Not a regression. The prior hand-rolled loop was while from <= latest, which also executed zero iterations (silent empty/partial replay) when replay_from_block > latest. This refactor is behavior-preserving; refactor(node): origin-directory genesis replay hand-rolls its window walk instead of using backfill_windows #1139 only changed how the windows are produced.

  2. check_backfill_range(...)? would be fatal, not retryable here. bootstrap_cache's Err propagates through ChainOriginDirectory::bootstrap(...)? at crates/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 via getOrigins).

  3. It contradicts the codebase's own pattern. The one existing check_backfill_range consumer — buyer reconcile at crates/node/src/buyer_channel.rs:1876 — does warn! + 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.

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.36% (was 80.28%, ▲ +0.08%) — 45295/56362 lines

File Coverage Lines Δ
crates/cli/src/commands/appeal.rs 47.76% 96/201 ● 0.00%
crates/cli/src/commands/bond.rs 31.60% 67/212 ▲ +0.15%
crates/cli/src/commands/chain_ctx.rs 91.23% 541/593 ▲ +5.16%
crates/cli/src/commands/publish.rs 53.40% 259/485 ▲ +1.29%
crates/cli/src/commands/register.rs 27.81% 52/187 ▲ +0.15%
crates/cli/src/commands/setup.rs 43.92% 426/970 ▼ 0.06%
crates/node/src/chain_events/backfill.rs 98.11% 52/53 ● 0.00%
crates/node/src/dht/chain_origin_directory.rs 64.21% 637/992 ▲ +0.19%
History
Commit Total Δ vs base
d3ce3a6 80.38% ▲ +0.10%
c37678e (HEAD) 80.36% ▲ +0.08%

…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]>

Copy link
Copy Markdown
Contributor

Reviewed at c37678e—no blocking issues found. The typed-address changes centralize validation cleanly, and the backfill_windows migration preserves the existing replay behavior. I agree that the pre-existing replay_from_block > latest anomaly belongs in #1152 rather than adding a fatal error path here. Relevant CLI and node tests pass, and CI is green. LGTM.

@yigitdot
yigitdot requested a review from alpergundogdu July 15, 2026 16:08
@yigitdot
yigitdot merged commit 691be45 into main Jul 15, 2026
23 checks passed
@yigitdot
yigitdot deleted the chore/tech-debt-1139-1140 branch July 15, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants