Skip to content

fix: batch three hygiene issues (#1311, #1265, #1292) - #1334

Merged
thiras merged 5 commits into
mainfrom
fix/hygiene-batch-1311-1265-1292
Jul 20, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/hygiene-batch-1311-1265-1292

Conversation

@thiras

@thiras thiras commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Four commits. The first three are unassigned hygiene issues that share a shape: the code behaves correctly, but a surface around it misrepresents what it does. The fourth is a doc-rot sweep surfaced by review. Each commit is independent and can be reviewed or reverted separately.

fix(contracts) — #1311: enforce the relief-counter invariant

Five sites released a fast-tracked appeal's interim-relief slot with a clamped decrement. fastTrackBlacklistAppeal is the sole increment site and runs exactly once per entry into FastTracked, and every release is gated on that status, so the clamps were unreachable by construction — which is the problem. If one ever fired, the accounting had already diverged, and the clamp hid it at precisely the moment it mattered.

Collapsed into _releaseReliefSlot, which reverts with a new ReliefAccountingUnderflow. Per review, the helper caches both counters in locals so the guard and decrement share one warm SLOAD each — −214 gas per release across all five paths (measured, not assumed).

Size: deduplication more than pays for the new error — ContentBlacklist drops 14,920 → 14,348 bytes (10,228 bytes of EIP-170 headroom). CapacityBond, not this contract, is the one near the ceiling.

Regression signal: no existing assertion changed; the new revert branch is unreachable and will show as uncovered (the @notice says so).

docs(gossip) — #1265: stop promising a metrics label that cannot exist

inc_published / inc_received were documented as "labelled by topic". No implementor uses the argument. The exported series were correct; the docs were wrong.

Per review, the doc is now precise about why: the backend is not the constraint (iroh-metrics supports labels via Family<L, M> — the node uses one for streams_active). The real constraint is that a Family needs a statically typed closed EncodeLabelSet, while a &str topic is open-ended, so exporting it would put unbounded cardinality in the label position. A breakdown would mean a label type or sibling counters; neither is wired.

Beyond the issue: the topic argument genuinely varies — announce paths pass a dynamic name, three sites pass the reputation-topic const — so these counters merge at least two topic families. Now documented.

refactor(node) — #1292: name the empty origin-directory fallback + warn on an armed gate

ConfigOriginDirectory read as an operator-facing config surface, but static_origins has zero hits repo-wide. The runtime's non-chain arm always built it empty.

Resolved in favour of intended: ChainOriginDirectory is the only production path. ADR 022 supports this — its "deterministic fallback" is the on-chain origin directory, and §FIND_VALUE spells out the exact namespaceOf → getOrigins → nodeIdOf chain. So no ADR edit was needed.

  • New EmptyOriginDirectory (zero-sized) installed in the runtime fallback arm.
  • ConfigOriginDirectory → StaticOriginDirectory, documented as a test fixture. Mirrors StaticNodeAddressDirectory one module over.
  • Dropped dead empty() / len() / is_empty(), and a stale doc claim about a resolver that never existed.

New in this revision (per review): the empty fallback doesn't just go inert — it hard-denies, and two of the three denials are invisible (prefetch.require_authorized_origin skips every hash as Unauthorized; pull_through_require_authorized_origin returns a wire NotFound the code itself calls indistinguishable from a plain miss). The runtime now warns at bring-up when either gate is armed over the empty fallback. The load-bearing subtlety: require_authorized_origin defaults on, so the prefetch warning is guarded on prefetch also being enabled — else it would fire on every chain-less node. Gating is extracted into armed_origin_gates_over_empty_fallback and unit-tested.

Not feature-gated: #[cfg(test)] cannot work (the type is used from integration tests in tests/, which compile against the crate externally).

docs(metrics) — #1265 review: correct pre-existing label-claim rot

The review of #1265 revealed the same wrong "iroh_metrics has no label support" claim in ~10 pre-existing field/module docs across node, incentive, and client-pull. All reworded to the accurate reason (a plain counter field carries no label; a labeled series needs a Family). Docs only, no metric or layout change.

Deliberately out of scope

  • --no-keep-blobs re-pays for a file duplicated at two bundle paths #1306 (--no-keep-blobs re-pays for a duplicated file) — verified real, but every option amends ADR 012 § Blob retention, a spec change on the voucher-paying path. Correction for whoever takes it: appendix-bundles has no literal "entries are independent" guarantee — its "independently" is scoped strictly to node selection.
  • Chunk part directories are unguarded across processes #1303 (cross-process part-dir race) — verified real but mis-scoped. The total_bytes guard is size-only, so a same-length part swap defeats it (repo's own test documents this at file_manifest.rs:623). The real defect is a verify→concat TOCTOU window; a lockfile alone would not close it.

Verification

Gate Result
forge fmt --check + FOUNDRY_PROFILE=ci forge build --sizes --deny warnings pass, no warnings
forge test 753 passed, 0 failed
slither (fail-on: medium) / aderyn (fail-on: high) exit 0, no findings on new code
cargo fmt --check / cargo clippy --all-targets -D warnings pass
RUSTDOCFLAGS="-D warnings" cargo doc pass
cargo nextest run 2504 passed, 0 skipped

Closes #1311
Closes #1265
Closes #1292

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved interim-relief accounting for fast-tracked appeal resolution by ensuring both per-region and per-filer counters stay consistent.
    • Fast-tracked paths now fail fast with a clear underflow error if relief counters are unexpectedly zero.
  • Improvements

    • Origin-directory handling is now more explicit: empty and fixed in-memory modes replace the prior fallback model.
    • When origin configuration is missing, startup emits a warning when authorized-origin gates become effectively inert.
  • Documentation

    • Clarified gossip metrics labeling behavior and rejection/reconnection observability notes.

Copilot AI review requested due to automatic review settings July 20, 2026 18:22
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 41 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: 95530aa0-dcfc-40c0-ae98-50591c91fd38

📥 Commits

Reviewing files that changed from the base of the PR and between 8e03e9c and e5eb5d0.

📒 Files selected for processing (1)
  • contracts/.gas-snapshot

Walkthrough

The PR centralizes relief-slot accounting checks, introduces explicit empty and static origin-directory implementations, updates runtime and test wiring, and clarifies metrics documentation without changing metric behavior.

Changes

Relief accounting enforcement

Layer / File(s) Summary
Centralized relief slot release
contracts/src/ContentBlacklist.sol
Fast-tracked appeal resolution paths use _releaseReliefSlot, which reverts with ReliefAccountingUnderflow when either relief counter is zero before decrementing both counters.

Origin directory implementations

Layer / File(s) Summary
Origin directory types and exports
crates/node/src/dht/origin.rs, crates/node/src/dht/mod.rs
ConfigOriginDirectory is replaced by EmptyOriginDirectory and StaticOriginDirectory, with updated implementations, tests, documentation, and exports.
Runtime empty-directory fallback
crates/node/src/runtime/mod.rs
Unconfigured chain origin settings now use EmptyOriginDirectory, retain no watcher, and emit warnings when authorized-origin gates are armed.
Origin directory test wiring
crates/node/src/handlers/client/mod.rs, crates/node/src/prefetch/*, crates/node/src/node_origin.rs, crates/node/tests/*
Authorization, prefetch, DHT loopback, and node-origin tests use the new origin-directory implementations.

Metrics documentation

Layer / File(s) Summary
Gossip metrics contract
crates/gossip/src/metrics.rs
Trait documentation states that topic arguments are not exported as labels and explains rejection, reconnection, and peer-table metric semantics.
Counter labeling documentation
crates/client-pull/..., crates/incentive/..., crates/node/src/metrics.rs
Comments describe per-class counters, absent label dimensions, sibling counters, and Family requirements.

Estimated code review effort: 3 (Moderate) | ~25 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

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.94% (2500/2811 lines)
▼ -0.03pp vs base (88.96% → 88.94%)
Run: 29777365689

@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 ContentBlacklist contract to consolidate relief slot release logic into a new _releaseReliefSlot helper, and restructures the DHT origin directory implementation by splitting ConfigOriginDirectory into StaticOriginDirectory (for tests) and EmptyOriginDirectory (as the unconfigured fallback). Additionally, gossip metrics documentation was updated. The review feedback suggests two valuable improvements: optimizing gas in _releaseReliefSlot by caching storage reads to avoid warm SLOADs, and adding a startup warning in the node runtime if prefetch is enabled while using the empty origin directory fallback to prevent silent failures.

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 thread contracts/src/ContentBlacklist.sol Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved

Copilot AI 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.

Pull request overview

This PR batches three independent “surface honesty” fixes across contracts, gossip docs, and node internals: it (1) enforces an appeal interim-relief accounting invariant on-chain, (2) corrects gossip metrics documentation to stop implying a non-existent per-topic label, and (3) clarifies the node’s non-chain origin-directory fallback by giving it explicit types/names.

Changes:

  • contracts: Replace unreachable relief-counter underflow clamps with a single _releaseReliefSlot invariant guard that reverts on divergence.
  • gossip (docs): Update GossipMetrics docs to state that topic is accepted but not exported as an OpenMetrics label (current implementation uses unlabeled counters).
  • node: Rename ConfigOriginDirectory → StaticOriginDirectory, add EmptyOriginDirectory for the runtime fallback path, and update runtime/tests/docs accordingly.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
contracts/src/ContentBlacklist.sol Deduplicates relief-slot release logic and enforces the relief-counter invariant via a new revert.
crates/gossip/src/metrics.rs Updates GossipMetrics trait docs to clarify topic is not exported as a metrics label.
crates/node/src/dht/origin.rs Introduces EmptyOriginDirectory + renames the static map implementation to StaticOriginDirectory; updates module docs and tests.
crates/node/src/dht/mod.rs Updates re-exports to expose EmptyOriginDirectory/StaticOriginDirectory instead of ConfigOriginDirectory.
crates/node/src/runtime/mod.rs Switches the non-chain fallback from an empty config directory to EmptyOriginDirectory.
crates/node/src/handlers/client/mod.rs Adjusts tests to reflect the new empty-fallback type and updated static directory name.
crates/node/src/node_origin.rs Updates internal commentary to reference StaticOriginDirectory in test contexts.
crates/node/src/prefetch/mod.rs Updates prefetch tests to use StaticOriginDirectory.
crates/node/src/prefetch/decision.rs Updates decision tests to use StaticOriginDirectory.
crates/node/tests/dht_loopback.rs Updates integration test to use StaticOriginDirectory.
crates/node/tests/node_origin_pull.rs Updates integration tests/builders to use StaticOriginDirectory and updated imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/dht/origin.rs Resolved
Comment thread crates/gossip/src/metrics.rs Resolved
@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.71% (was 81.71%, ● 0.00%) — 51095/62529 lines

File Coverage Lines Δ
crates/client-pull/src/buyer_channel.rs 45.87% 100/218 ● 0.00%
crates/gossip/src/metrics.rs 50.00% 3/6 ● 0.00%
crates/incentive/src/channel_open_error.rs 96.05% 73/76 ● 0.00%
crates/node/src/dht/origin.rs 94.74% 54/57 ▼ 0.09%
crates/node/src/handlers/client/mod.rs 87.83% 570/649 ● 0.00%
crates/node/src/metrics.rs 94.33% 998/1058 ● 0.00%
crates/node/src/node_origin.rs 90.55% 968/1069 ● 0.00%
crates/node/src/prefetch/decision.rs 96.18% 151/157 ● 0.00%
crates/node/src/prefetch/mod.rs 96.59% 170/176 ● 0.00%
crates/node/src/runtime/mod.rs 46.24% 1106/2392 ▲ +0.55%
History
Commit Total Δ vs base
5a9acb4 81.72% ● 0.00%
8e03e9c 81.72% ▲ +0.01%
e5eb5d0 (HEAD) 81.71% ● 0.00%

thiras and others added 4 commits July 20, 2026 23:17
…1311)

Five sites released a fast-tracked appeal's interim-relief slot with a
clamped decrement:

    if (regionActiveReliefCount[r] != 0) regionActiveReliefCount[r] -= 1;

`fastTrackBlacklistAppeal` is the sole increment site and runs exactly
once per entry into `FastTracked`, and every release is gated on that
status -- so both counters are provably nonzero at each site and the
clamps are unreachable by construction. That is the problem: if one ever
fired, the relief-cap accounting had already diverged, and the clamp hid
it at precisely the moment it mattered. The failure would be silent and
permanent, throttling future legitimate fast-tracks in that region.

Collapse the ten inline decrements into `_releaseReliefSlot`, which
reverts with a new `ReliefAccountingUnderflow` rather than clamping. The
helper caches both counters in locals so the guard and the decrement
share one warm SLOAD each (-214 gas per release across all five paths).
Its `@dev` names the invariant that makes the branch unreachable so a
future reader does not mistake it for handling a live case, and notes
that it is expected to show as uncovered.

Deduplicating the call sites more than pays for the new error:
ContentBlacklist deployed size drops 14,920 -> 14,348 bytes (10,228
bytes of EIP-170 headroom).

No existing assertion changes -- the five decrement tests
(test_filerReliefCap_decrementsOn{Reject,Perjury,Ratify,Reverse,Cleanup})
already assert via the public getters and none exercised the `== 0`
branch. 753 contract tests pass; slither and aderyn clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…1265)

`GossipMetrics::inc_published` and `inc_received` were documented as
"labelled by topic", and `inc_reconnected` took a topic and said nothing
either way. No implementor uses the argument -- not `NoopMetrics`, not
the node's `NodeGossipMetrics`, not the test doubles. The node forwards
the topic faithfully and it is dropped one layer down, where the recorder
macro binds `_topic` and never reads it.

So the exported series are correct and the docs were wrong, in the way
most likely to mislead someone wiring a dashboard or extending the trait.

Document the actual contract: name each backing counter's
operator-visible series and say it is unlabeled. Be precise about *why*,
since the backend is not the constraint: `iroh-metrics` 1.x does support
labels via `Family<L, M>` (the node uses one for `streams_active`), but a
`Family` needs a statically typed closed `EncodeLabelSet`, and a `&str`
topic is open-ended -- exporting it directly would put unbounded
cardinality in the label position. A per-topic breakdown would therefore
mean either enumerating topics into a label type or one sibling counter
per topic (the established convention for small closed splits, e.g.
`dispatch_rejected_{global,per_source}`). Neither is wired today. The
`topic` parameter stays, its doc now saying why it is accepted and
discarded.

Also records what the issue did not note: the topic argument genuinely
varies -- announce paths pass a dynamic name, three sites pass the
reputation-topic const -- so these counters merge at least two topic
families. That is the fact an operator reading the series most needs.

`inc_rejected(reason)` is untouched: the node does branch on `reason`.
Docs only, no signature change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…med gate (#1292)

`ConfigOriginDirectory` read as an operator-facing config surface but no
config key ever populated it -- `static_origins` has zero hits repo-wide,
in the schema, the resolver, or the example TOML. The runtime's non-chain
arm always built it empty, so it was an empty stub with a name that
promised otherwise.

Resolve the behavior question the issue raised in favour of "intended":
`ChainOriginDirectory` is the only production path. ADR 022 supports this
rather than contradicting it -- the issue suspected its "deterministic
fallback" language implied an operator-supplied map, but every occurrence
(§FIND_VALUE Flow, §Bootstrap, §Prefetch Decision) says *the on-chain
origin directory*, and §FIND_VALUE spells out the exact
namespaceOf -> getOrigins -> nodeIdOf read chain. So no ADR edit is needed.

- Add `EmptyOriginDirectory`, a zero-sized directory that resolves
  nothing, and install it in the runtime fallback arm so the production
  path constructs a type that names its own behavior.
- Rename `ConfigOriginDirectory` -> `StaticOriginDirectory` and document
  it as a test/known-set fixture. This mirrors `StaticNodeAddressDirectory`
  one module over, which is likewise public, test-only, and ungated --
  the same `Chain*` / `Static*` pairing.
- Drop the dead `empty()`, `len()`, and `is_empty()`, and a stale doc
  claim that a resolver pre-filtered malformed entries at construction. No
  such resolver exists.

The empty fallback is not merely inert -- it hard-denies, and two of the
three denials are invisible. With `prefetch.require_authorized_origin`
every hash skips as `Unauthorized`; with
`cache.pull_through_require_authorized_origin` every cache miss returns a
wire `NotFound` the code itself calls indistinguishable from a plain
miss. An operator can enable either without chain addresses and get a
permanently dead path with no signal. So the runtime now warns at
bring-up when either gate is armed over the empty fallback. The gating is
extracted into `armed_origin_gates_over_empty_fallback` and unit-tested:
the load-bearing case is that `require_authorized_origin` defaults on, so
the prefetch warning must be guarded on prefetch also being *enabled* --
otherwise it would fire on every chain-less node. (The switch to the
`if let` form is what clippy's `single_match_else` wants once the else
arm grows a body.)

Not feature-gated: `#[cfg(test)]` cannot work here (the type is used from
integration tests in tests/, which compile against the crate externally),
so a gate would need a dev-dependency self-reference for no gain the
rename does not already provide.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Surfaced by review of #1265. Ten field/module docs across three crates
justified their sibling-counter layout by claiming `iroh_metrics` "has no
label support" / "has no labels" / "no per-field labels". That is wrong:
`iroh-metrics` 1.x supports labels via `Family<L, M>`, and this very crate
uses one for `streams_active` (keyed on `StreamDirection`).

The accurate reason a plain `Counter`/`Gauge` field carries no label is
that a labeled series needs a `Family`-typed field with a statically typed
closed `EncodeLabelSet` -- which is why these open-ended or
not-worth-the-machinery splits stay as sibling counters by the
`dispatch_rejected_*` convention. Reword all ten to say that instead,
without changing any metric or its layout.

Sites: crates/node/src/metrics.rs (7), crates/incentive/src/channel_open_error.rs
(2), crates/client-pull/src/buyer_channel.rs (1). Docs only.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras force-pushed the fix/hygiene-batch-1311-1265-1292 branch from 5a9acb4 to 8e03e9c Compare July 20, 2026 20:24
The `_releaseReliefSlot` SLOAD caching in the #1311 commit lowered gas on
every ContentBlacklist appeal-resolution path and, transitively, on the
tests that deploy or cross-call ContentBlacklist (DeployProtocol,
GenesisBuyback, CapacityBondRegionE2E). Regenerated with
`FOUNDRY_PROFILE=ci forge snapshot --snap .gas-snapshot` (forge 1.7.1,
solc 0.8.28 — the CI pins), which reproduces CI's fresh values exactly.
The deterministic entries are the only meaningful diff; the fuzz `runs:`
lines are machine-dependent and stripped by the CI freshness gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 01996a3 into main Jul 20, 2026
22 of 23 checks passed
@thiras
thiras deleted the fix/hygiene-batch-1311-1265-1292 branch July 20, 2026 20:56
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