Skip to content

feat(node): decdn node evict and decdn node announce (#279, #280) - #371

Merged
thiras merged 3 commits into
mainfrom
feat/node-cli-evict-announce
May 1, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/node-cli-evict-announce

Conversation

@thiras

@thiras thiras commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds two operator-facing CLI subcommands and the supporting admin RPC plumbing.

Implementation notes

  • Eviction is logical, not physical. iroh-blobs 0.99 keeps `Blobs::delete` `pub(crate)` for the GC task, so `evict` adds the hash to a guarded `HashSet` honored by `has` (returns false) and `get` (returns `NotFound`). The bytes remain on disk until iroh-blobs internal GC reclaims them — operator-visible "stop serving" semantics are immediate. Reclaim is tied to follow-up work in cache: drop double BLAKE3 hash once iroh-blobs exposes verified-insert #233.
  • Announce trigger is Notify-backed. `GossipService::spawn` now returns `GossipHandles { tasks, announce_trigger }`. The publisher `tokio::select!`s between its interval ticker and the trigger, so a manual announce fires within one select boundary. `announce_trigger` is `None` in subscribe-only mode (no region) and the RPC method maps that to a `PUBLISHER_DISABLED` error so the operator gets a specific message rather than a generic failure.
  • Hash parse hardening. `Hash::from_str` falls through to a base32 decoder that panics on short inputs (data-encoding buffer mismatch). The admin RPC uses `alloy::primitives::hex` instead so a typo'd operator input returns `INVALID_PARAMS` cleanly.
  • Admin server bind happens early (preserves startup-fail-fast on port collision); `serve` is now spawned after gossip so the new state has the announce trigger available.

Test plan

  • `cargo fmt -- --check` clean
  • `cargo clippy --workspace --all-targets -- -D warnings` clean (anti-panic policy honored: no `unwrap_used` / `expect_used` / `indexing_slicing`)
  • `cargo nextest run --workspace` — 283/283 pass
  • 3 new cache engine tests (evict blocks, unevict re-arms, evict-unknown is no-op)
  • 4 new admin RPC tests (evict round-trip, bad-hex rejection, announce fires the underlying notify, announce-without-publisher returns the right error code)

Manual end-to-end suggestions for reviewer

```
decdn run --config &
decdn node evict # status=evicted (or not present), no re-pin
decdn node evict --re-pin # status=evicted repinned=ok
decdn node announce # announce_triggered=true; observable via `decdn node peers` on a peer
```

Closes #279
Closes #280

🤖 Generated with Claude Code

Adds two operator-facing CLI subcommands for the loopback admin RPC
surface (ADR 025), plus the supporting plumbing.

`decdn node evict <hex-hash> [--re-pin]` (closes #279)
- New `admin_v1_evict` RPC. Logical eviction in `CacheEngine`: a hash
  in `Inner.evicted` is reported absent by `has` and surfaces as
  `NotFound` from `get`, so the node stops serving immediately for
  DMCA / corruption use cases. The bytes remain on disk because
  iroh-blobs 0.99 keeps `Blobs::delete` `pub(crate)` for the GC task —
  reclaim is a follow-up tied to issue #233.
- `--re-pin` clears the flag and re-pulls from the configured origin in
  one round trip; on origin failure the engine is re-evicted so a
  half-fetched copy isn't served.
- Hex parsing goes through `alloy::primitives::hex` rather than
  `Hash::from_str` because the latter falls through to a base32 path
  that **panics** on short inputs (data-encoding buffer mismatch).

`decdn node announce` (closes #280)
- New `admin_v1_announce` RPC and `AnnounceTrigger` (Notify-backed) on
  the gossip publisher. The publisher task now selects between its
  interval ticker and the trigger so an operator-driven manual
  announce fires within one select boundary.
- `GossipService::spawn` returns `GossipHandles { tasks, announce_trigger }`;
  `announce_trigger` is `None` in subscribe-only mode (no region) and
  the RPC method maps that to a `PUBLISHER_DISABLED` error so the
  operator gets a specific message rather than a generic failure.

Admin server bind happens early (preserves the startup-fail-fast
property on port collisions), but `serve` is now spawned after gossip
so the new state has the announce trigger available.

Test coverage:
- 3 cache-engine tests (evict blocks, unevict re-arms, evict-unknown).
- 4 admin RPC tests (evict round-trip, bad-hex rejection, announce
  fires the underlying notify, announce-without-publisher returns the
  right error code).

283/283 workspace tests pass; clippy & fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 1, 2026 09:16

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

Adds new operator-facing node CLI subcommands (decdn node evict, decdn node announce) by extending the node’s loopback admin JSON-RPC surface and wiring a manual announce trigger into the gossip publisher.

Changes:

  • Introduces admin RPC methods for cache eviction and one-shot gossip announce, plus matching CLI commands and argument parsing.
  • Implements logical blob eviction in CacheEngine (guarded HashSet) so evicted blobs immediately stop being served without requiring physical deletion.
  • Adds a Notify-backed AnnounceTrigger returned from GossipService::spawn, allowing immediate publishes outside the periodic interval.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/node/tests/admin_peers.rs Updates admin tests to construct AdminState with a cache engine dependency.
crates/node/src/runtime/mod.rs Binds admin listener early, spawns admin server after gossip to include optional announce trigger in state.
crates/node/src/commands/node.rs Adds node evict and node announce command implementations calling new admin RPC methods.
crates/node/src/cli/node.rs Adds clap argument structs and help text for Evict and Announce subcommands.
crates/node/src/cli/mod.rs Re-exports new CLI arg types.
crates/node/src/admin.rs Extends admin RPC trait + server implementation with evict and announce, adds request/response DTOs and error codes.
crates/gossip/src/service.rs Adds AnnounceTrigger + GossipHandles, and wires Notify into publisher task via tokio::select!.
crates/gossip/src/lib.rs Re-exports new gossip types (AnnounceTrigger, GossipHandles).
crates/cache/src/engine.rs Adds logical eviction tracking and updates has/get semantics; adds unit tests for eviction/unevict behavior.

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

Comment thread crates/node/src/admin.rs Resolved
Comment thread crates/node/src/admin.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved

@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 introduces logical cache eviction and manual gossip announcement triggers to support administrative actions like content takedowns and configuration updates. It adds new RPC methods and CLI commands, along with the necessary backend logic in the cache and gossip modules. Feedback points out that the eviction set is currently non-durable across node restarts and suggests improving the robustness of hex hash parsing by handling the '0x' prefix in a case-insensitive manner.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/node/src/admin.rs Resolved
thiras and others added 2 commits May 1, 2026 12:40
- cargo doc: disambiguate `Hash` intra-doc link to `[`struct@Hash`]`
  (`Hash` is also a derive macro at crate root — broken-intra-doc-links
  fired on the workspace doc job).

- Drop `--re-pin` flag from `decdn node evict` / `admin_v1_evict`.
  With logical eviction, `unevict + cache.get()` reads the local store
  (bytes never left iroh-blobs), so `repinned=true` could be reported
  even with the origin down. iroh-blobs 0.99 doesn't expose a way to
  force an origin-only fetch, so the flag can't be implemented honestly
  in v1. Re-add when issue #233 lands a public delete API.

- `0x` / `0X` hex prefix tolerated in `parse_hash_arg` (case-insensitive
  strip).

- Persist evicted set to `<cache_dir>/evicted.log`. DMCA takedowns and
  corruption-recovery evicts now survive `decdn run` restarts. The log
  is append-only with one lowercase-hex hash per line (POSIX append
  atomicity covers the 65-byte writes), `fsync`'d before evict()
  returns. Malformed lines are warn-logged + skipped rather than
  failing the whole open. `evict()` now returns CacheResult<()> so a
  failed fsync surfaces to the operator instead of silently degrading
  to in-memory-only.

- Removed `unevict()` from the public CacheEngine API since the
  `--re-pin` path was its only caller and unevict can't be persisted
  cleanly without a log-rewrite scheme outside this PR's scope.

- New tests: evict persists across open/close, evicted.log skips
  malformed lines, admin_evict accepts uppercase `0X` prefix.

231/231 tests pass; cargo doc, clippy, fmt clean.

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

Critical correctness:

- `CacheEngine::evict` / `is_evicted` now use
  `unwrap_or_else(PoisonError::into_inner)` instead of
  `if let Ok(...) = lock()` / `lock().ok()`. A poisoned mutex on the
  evicted set previously made `is_evicted` return false silently — the
  worst possible failure mode for a DMCA takedown, since the node would
  keep serving an evicted blob until restart. Now poison-recovers the
  guard so the in-memory commit always lands.

- `gossip::publisher_task` per-topic broadcast failure logged at
  `warn!` rather than `debug!`. A manual `decdn node announce` whose
  broadcast failed on every topic was previously invisible at default
  log levels while the CLI happily printed `triggered=true`.

- CLI now prints `announce_queued=` instead of `announce_triggered=`
  to match the doc-stated "queued, not delivered" semantic. The
  `AnnounceResponse.triggered` doc-comment also rewritten.

- Stripped all references to a `--re-pin` flag and a `Self::unevict`
  method that don't exist in the code (left over from fb33b82's
  partial revert) — `cli/node.rs`, `commands/node.rs`, `admin.rs`
  trait + error-code doc, `engine.rs::get` doc (was a broken
  intra-doc link).

Defensive bounds:

- New `MAX_EVICTED_ENTRIES = 1_000_000` cap on the evicted set, with
  `CacheError::EvictionLimitExceeded`. Bounds in-memory growth and
  on-disk `evicted.log` size against an automation gone wrong.

- `evict()` is now idempotent at the persistence layer too: a
  `contains()` short-circuit at the top means re-evicting the same
  hash doesn't append a duplicate log line.

- `parse_hex_hash` (evicted.log loader) now accepts uppercase, matching
  `parse_hash_arg` (admin RPC). Hand-edited entries from operators
  pasting hashes from access logs / takedown notices used to silently
  drop on next open. Persisted format is canonically lowercase via
  `Hash::Display::to_hex()`, so this is read-path leniency only.

- Variable names in `parse_hex_hash` corrected: first nibble is the
  high nibble of the byte (was inverted).

Gossip startup:

- `GossipService::spawn` returns
  `Result<GossipHandles, GossipSpawnError>`. Intentional
  subscribe-only mode (no global, no region) still returns `Ok` with
  empty handles. "Every topic subscribe failed" now returns
  `AllSubscribesFailed` and the runtime fails fast via `?` instead of
  soldiering on into a state where `admin_v1_announce` would later
  return `PUBLISHER_DISABLED` for the wrong reason.

Comment fixes:

- Publisher select-loop and CLI `Announce` doc-comments no longer cite
  `rate_per_mb` (lives in `ProbeResponse`, not `NodeAnnounceBody`) or
  imply `region` is hot-reloadable (it's captured by-value at task
  spawn and requires a restart to change).

- Test-helper `from_notify` reference in admin.rs corrected to
  `for_test`. Adjacent paragraph rewritten.

- `test_cache` doc says "tempdir-backed" instead of "in-memory".

New tests (8):

- cache: idempotent re-evict produces 1 log line; uppercase hex
  in evicted.log loads correctly; persistence-failure (directory at
  evicted.log path) returns Err and leaves the in-memory set
  untouched.

- gossip: `AnnounceTrigger::announce_now` wakes a parked
  `notified()`; back-to-back triggers coalesce into one permit
  (locks Notify's stored-permit semantics that publisher_task
  depends on).

- node integration: connection-refused + zero-timeout coverage for
  `cli evict` and `cli announce`, mirroring the existing
  `cli health` / `cli peers` patterns.

294/294 tests pass; cargo fmt, clippy --workspace --all-targets clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras merged commit 212f815 into main May 1, 2026
9 checks passed
@thiras
thiras deleted the feat/node-cli-evict-announce branch May 1, 2026 10:55
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