Skip to content

refactor(node): origin-directory genesis replay hand-rolls its window walk instead of using backfill_windows #1139

Closed

Description

@thiras

Spun out of the multi-agent review on #1137 (comment-accuracy finding).

Problem

#1092 moved the shared windowing primitives into chain_events::backfill so watcher consumers can't fork their own. One consumer was missed: the origin directory's genesis ContentClaimed replay still walks its window range by hand.

crates/node/src/dht/chain_origin_directory.rs:653:

let mut from = replay_from_block;
while from <= latest {
    let to = from.saturating_add(REPLAY_WINDOW_BLOCKS - 1).min(latest);
    let logs = contracts.publisher.ContentClaimed_filter()
        .from_block(from).to_block(to).query().await ...

This is backfill_windows(from, to, span) re-implemented inline, and it carries its own span constant (REPLAY_WINDOW_BLOCKS = 9_000, :127) rather than the shared MAX_BACKFILL_BLOCK_SPAN = 10_000.

The 9k is deliberate — the hand-rolled walk is the defect

Worth stating clearly, because #1092's issue text (and, briefly, a comment in #1137 before it was corrected) framed this as accidental drift. It is not. The constant's own doc gives a real rationale:

Block-window size for the genesis ContentClaimed log replay. Kept well under the common provider eth_getLogs 10k-block cap so bootstrap works on range-limited RPCs without a per-provider knob.

So 9k is a deliberate safety margin under the 10k cap. The problem is not the value — it's that the loop is a second copy of window math that backfill_windows already owns, and it is the one remaining place a windowing bug could be fixed in chain_events and still be wrong here.

Suggested fix

backfill_windows already takes the span as a parameter, so this preserves the 9k exactly:

for (from, to) in backfill_windows(replay_from_block, latest, REPLAY_WINDOW_BLOCKS) {
    let logs = contracts.publisher.ContentClaimed_filter()
        .from_block(from).to_block(to).query().await ...
}

Keep REPLAY_WINDOW_BLOCKS where it is (its rationale is genuinely origin-directory-specific), but note in its doc that it is a deliberate override of the shared MAX_BACKFILL_BLOCK_SPAN, so the next reader doesn't "fix" the divergence by unifying it.

Separately worth deciding: if the 10k-cap safety margin is right for the genesis replay, is it right for MAX_BACKFILL_BLOCK_SPAN too? The shared constant's doc already admits 10k "could still trip a result-count limit" on dense ranges. That's a follow-up question, not part of this issue.

Note

chain_events/backfill.rs's module doc currently records this as a known open divergence (added in #1137). Closing this issue should remove that note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:low

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions