Skip to content

feat!: origin attestations are namespace-scoped, expiring and required to serve - #2921

Merged
thiras merged 5 commits into
mainfrom
claude/attestation-ttl-config-b2a4bc
Nov 22, 2026
Merged

thiras merged 5 commits into
mainfrom
claude/attestation-ttl-config-b2a4bc

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2914.

What changes

Attestation type. An origin attestation is its own EIP-712 struct, OriginAttestation(bytes32 hash,uint256 namespaceId,uint64 timestampUs,uint32 ttlSec). A seated origin signs it with its operator key under the SlashJudge domain. Only nodes check it; no contract reads it. The StreamResponse type and SlashJudge do not change. The origin stamps the timestamp from its own clock, so the request-timestamp bound plays no part in the attestation's lifetime.

Validity. An attestation is valid when all of these hold:

  • its namespace is not 0;
  • its signer holds a seat in that namespace (seats are tracked per (namespace, operator));
  • the deny-set does not name the signer;
  • ttlSec is in [3600, 86400];
  • now − ttl < timestamp ≤ now + 30 s.

TTL. Each origin sets its TTL in cache.attestation_ttl_sec (default 12 h, range 1 h to 24 h) and signs it into every attestation. Every verifier then reads the same expiry, and no on-chain parameter is needed. The publisher sets its takedown latency through the config of the origins it seats.

Serving gate. A node serves a hash only while it holds a live attestation for it. A cache hit, whole or partial, without one is refused Declined, under the new reason Unattested. A seated origin signs its own attestation for content its backend holds. Every ok: true response carries the node's attestation in StreamResponseExt.origin_attestation. A puller that holds no live attestation of its own for the hash drops an upstream whose served answer has no valid attestation, before it ranks or pays it. A later leg that hits the same check is a transient refusal, never scored Unreachable. Pinned hashes follow the same rule. The empty blob is exempt because it has no content.

The node checks the rule again at two later points:

  • When it signs a served answer. The open-time check can go stale during funding and fill work, a miss that joins a fill in progress does no handshake of its own, and a buffered fill from the node's own origin lands a blob without an attestation. So sign_served reads the live attestation once and signs it into the answer. With none, it signs nothing and the node refuses Unattested. Every fill tier also runs the gate once its blob lands, so a seated origin signs its own there.
  • Before each frame of a delivery. A lapse mid-stream resets the stream with NO_ERROR, as a takedown does. A lapse is an attestation that expired with no fresher one found, or whose signer lost its seat or came onto the origin deny-set. The check reads no signature: the store keeps the signer it recovered when it accepted the attestation.

Refresh (node_origin/attestation_refresh.rs). Refresh starts at TTL/2 plus a per-hash jitter of up to TTL/4. Sources are tried in this order:

  1. the node's own seat, if its backend holds the hash;
  2. the freshest valid attestation in the DHT records, if it is still short of its own half-life;
  3. a voucher-less discovery open to a seated origin of the namespace. The node keeps the attestation the answer carries and cancels the stream, so the origin pays one signature and no egress.

A refresh runs only while the node holds the blob. An attestation for a blob the node does not hold (a pull that never landed, an eviction) is dropped instead of refreshed. A failed refresh retries after 10 min. Each tick runs up to 256 jobs, 8 at a time: live attestations first, soonest to expire first, then expired ones, then wanted hashes. A stop cancels a tick in flight. When an attestation expires with nothing fresher found, the node stops serving and publishing that hash, keeps the expired attestation, and keeps retrying, so the hash serves again once an origin of its namespace returns.

Wanted hashes. A node can hold a blob with no attestation at all, for example after it loses its attestation store. A request for such a hash is refused Unattested, and the node marks the hash wanted. The refresh task looks it up in the DHT at most every 10 min and keeps the freshest valid attestation it finds. The node tracks at most 4,096 wanted hashes, and stops wanting one once it keeps an attestation or no longer holds the blob.

Store (attestations.rs). The store compares and replaces under one write lock, so a concurrent older offer never displaces a newer attestation. File writes go one at a time, and each writes the entry in memory at that moment. At load, only files named for their hash load. Leftover .tmp files, old-format files and files whose stored signer does not recover from the signature are removed, with one warning.

DHT. STORE rejects attestations that are not live. A re-publish keeps the valid attestation that expires last, so a valid replacement always wins over a dead one that expires later. FIND_VALUE leaves out records whose attestation is no longer valid. The larger attestation (113 B at its widest) pushes MAX_DHT_FRAME from 64 KiB to 72 KiB.

Metrics:

  • decdn_serve_stream_rejected_unattested_total
  • decdn_serve_stream_terminated_unattested_total (a delivery stopped mid-stream by a lapse)
  • decdn_attestation_refreshed_{self,dht,origin}_total
  • decdn_attestation_refresh_failed_total
  • decdn_attestation_expired_total (counted once per expiry)

Docs. ADRs 001, 002, 005, 011, 013, 014, 017, 019, 022 and 040, plus the observability appendix, architecture and glossary.

Wire-breaking for the DHT and StreamResponseExt, with no compatibility path (pre-mainnet).

Where this differs from the issue text

  • Separate EIP-712 type instead of adding namespace to the signed StreamResponse body. This leaves SlashJudge and every stream response unchanged. It also means an origin cannot get a long-lived attestation by echoing a requester's future timestamp.
  • The node serves a hash under any live attestation, not only one for the request's namespace. The bytes are content-addressed and the request's namespace is a routing hint (ADR 002). Every hash a node serves still traces to a seated origin, and namespace-0 requests keep working.

Testing

  • cargo nextest run on node, protocol, incentive, common, client and cli: 5280 passed.
  • Anvil e2e subset (smoke, g_origin_01, node_to_node_coalesce, cli_fetch_multi_source, origin_blacklist_compliance, node_pull_topup): 9/9 passed. Three passed on retry. Their first runs failed together at 35 s with a contract-artifact EOF while parsing from a fresh submodule checkout, which this change does not touch.
  • Both clippy variants, fmt, cargo doc with warnings denied, crate-edges, and the ADR hygiene hooks pass.
  • The e2e NodeFixture now seats each onboarded operator as an origin of a fresh namespace.
  • Review fixes (4472820): cargo nextest run -p decdn-node passes 1684/1684. Workspace clippy (--all-targets --all-features), fmt, cargo doc with warnings denied and make -C adr check-refs pass. New tests cover concurrent keeps, the compare-and-remove on expiry, an expired attestation kept for a held blob, refresh ordering, a forged signer at load, and sign_served with and without a live attestation.
  • Second review round (b1ff849, five reviewers): node, cache, CLI, protocol and client pass 5037/5037. New tests cover mid-stream termination when the attesting origin is unseated (it fails with the per-frame check removed), an expired STORE refused, keep and DHT re-publish replacing a later-expiring dead attestation, the empty blob served with no attestation, the wanted-hash lifecycle, .tmp cleanup at load, and the unattested-leg verdict.
  • The anvil e2e subset was not re-run after either round of fixes.

Follow-ups

🤖 Generated with Claude Code

…d to serve (#2914)

An origin attestation is its own EIP-712 type, OriginAttestation(bytes32
hash,uint256 namespaceId,uint64 timestampUs,uint32 ttlSec), signed by a
seated origin under the SlashJudge domain and checked off-chain only. It is
valid while its signer holds a seat in the attested namespace, its TTL lies
in [1 h, 24 h], and it is live. The origin picks the TTL with
cache.attestation_ttl_sec (default 12 h), so every verifier agrees on
expiry with no on-chain parameter.

A node serves a hash only while it holds a live attestation for it; a hit
without one is Declined (Unattested). A seated origin attests its own
backend content on demand. Every ok: true carries the node's attestation,
and the pull path drops an upstream that offers none. From TTL/2 plus up to
TTL/4 of per-hash jitter, a holder refreshes from its own seat, the
freshest attestation in the DHT, or a voucher-less open to a seated origin
of the namespace; an attestation that expires with nothing fresher is
dropped. DHT STORE rejects expired attestations, a re-publish keeps the
one that expires last, and FIND_VALUE leaves out expired records.
MAX_DHT_FRAME grows to 72 KiB for the larger attestation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

github-code-quality Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 7879ec1 claude/attestation-t... b1ff849 +/-
77% 77% 0%
View coverage of the 10 most impacted files.
File main 7879ec1 claude/attestation-t... b1ff849 +/-
crates/node/src...ent/dispatch.rs 84% 83% -1%
crates/node/src...gin/pull_leg.rs 85% 84% -1%
crates/client/src/opened.rs 96% 95% -1%
crates/node/src...lient/window.rs 75% 75% 0%
crates/node/src.../client/wire.rs 91% 91% 0%
crates/node/src...e_origin/mod.rs 88% 88% 0%
crates/node/src/dht/publish.rs 77% 79% +2%
crates/node/src...attestations.rs 92% 94% +2%
crates/node/src...tion_refresh.rs 0% 42% +42%
crates/incentiv..._attestation.rs 0% 98% +98%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 22, 2026 01:36 UTC

… the protocol API snapshot

A node whose own backend holds a hash it cannot attest asks for an early
seat-set read (rate-limited to one a minute), so an operator seated after
boot attests its content without waiting out the 10-minute interval. The
G-NODE-01 journey seats its operator once `decdn setup` bonds it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

🟡 Changes recommended

Expired or revoked attestations can still allow successful served responses and continued delivery because validity is not rechecked at the response and pre-send boundaries.

5 open issues
What changed in this PR

This PR makes origin attestations namespace-scoped and time-limited, connecting deCDN’s serving and discovery rules to live origin authorization. It changes the wire format without changing the signed StreamResponse body or contracts.

Changes:

  • Adds a separate EIP-712 attestation type with a configurable 1–24-hour lifetime.
  • Adds serving and upstream-selection gates, attestation refresh, DHT expiry filtering, and metrics.
  • Updates protocol bounds, tests, onboarding fixtures, configuration, and architecture documentation.
File Description
crates/​protocol/​tests/​snapshots/​public_api__public_api.snap Updates the public attestation API snapshot.
crates/​protocol/​src/​lib.rs Exports attestation lifetime constants.
crates/​protocol/​src/​dht/​tests.rs Tests lifetime bounds and larger frames.
crates/​protocol/​src/​dht.rs Defines expiring attestations and raises the frame ceiling.
crates/​protocol/​src/​client/​tests.rs Updates response-size assertions.
crates/​protocol/​src/​client.rs Documents forwarding live attestations.
crates/​node/​tests/​support/​mod.rs Supplies valid fixture attestations.
crates/​node/​tests/​sighup_signal.rs Adds TTL to configuration fixtures.
crates/​node/​tests/​partial_serve.rs Registers payloads for fixture attestations.
crates/​node/​tests/​origin_range_pull.rs Attests range-test payloads.
crates/​node/​tests/​node_origin_pull.rs Includes attestations in served fixtures.
crates/​node/​tests/​dht_loopback.rs Adapts record-validation callbacks.
crates/​node/​tests/​dht_bootstrap.rs Seeds attestations for publishing tests.
crates/​node/​tests/​client_loopback.rs Attests partial-serving payloads.
crates/​node/​tests/​anvil_bringup_shutdown_e2e.rs Adds TTL to daemon configuration.
crates/​node/​src/​runtime/​tests.rs Updates runtime configuration fixtures.
crates/​node/​src/​runtime/​reload/​tests.rs Updates reload configuration fixtures.
crates/​node/​src/​runtime/​reload.rs Marks attestation TTL as restart-required.
crates/​node/​src/​runtime/​mod.rs Wires TTL and the refresh task.
crates/​node/​src/​origin_seat_watcher/​tests.rs Tests namespace-specific seat checks.
crates/​node/​src/​node_origin/​timed_source/​tests.rs Tests invalid-attestation rejection.
crates/​node/​src/​node_origin/​timed_source.rs Gates source opens on attestation availability.
crates/​node/​src/​node_origin/​tests.rs Covers unattested discovery-drop accounting.
crates/​node/​src/​node_origin/​pull_leg.rs Checks attestations during pull handshakes.
crates/​node/​src/​node_origin/​mod.rs Adds attestation checks to upstream selection.
crates/​node/​src/​node_origin/​attestation_refresh/​tests.rs Tests self-refresh, retries, and expiry.
crates/​node/​src/​node_origin/​attestation_refresh.rs Refreshes from self, DHT, or origins.
crates/​node/​src/​metrics/​tests.rs Tests rejection and refresh counters.
crates/​node/​src/​metrics.rs Defines attestation lifecycle metrics.
crates/​node/​src/​handlers/​dht.rs Validates attestation lifetime and namespace seats.
crates/​node/​src/​handlers/​client/​wire.rs Checks serve eligibility and forwards live attestations.
crates/​node/​src/​handlers/​client/​tests.rs Tests the Unattested refusal mapping.
crates/​node/​src/​handlers/​client/​outcome/​tests.rs Covers unattested outcome accounting.
crates/​node/​src/​handlers/​client/​outcome.rs Labels and meters unattested refusals.
crates/​node/​src/​handlers/​client/​mod.rs Adds Unattested and documents handler wiring.
crates/​node/​src/​handlers/​client/​dispatch.rs Gates cache hits and own-backend serving.
crates/​node/​src/​dht/​seated_origins/​tests.rs Tests namespace isolation and seat selection.
crates/​node/​src/​dht/​seated_origins.rs Exposes namespace-scoped seat queries.
crates/​node/​src/​dht/​records/​tests.rs Tests latest-expiry record retention.
crates/​node/​src/​dht/​records.rs Retains later-expiring attestations on republish.
crates/​node/​src/​dht/​publish.rs Requires live attestations for publishing.
crates/​node/​src/​dht/​lookup.rs Collects the latest-expiring valid attestation.
crates/​node/​src/​dht/​attestation/​tests.rs Tests namespace, expiry, skew, and TTL validity.
crates/​node/​src/​dht/​attestation/​test_support.rs Provides live namespace-scoped fixtures.
crates/​node/​src/​dht/​attestation.rs Implements shared signing and validity checks.
crates/​node/​src/​attestations/​tests.rs Tests retention, refresh timing, and persistence.
crates/​node/​src/​attestations.rs Stores live attestations and refresh scheduling state.
crates/​incentive/​src/​stream_sig.rs Removes response-derived attestation recovery.
crates/​incentive/​src/​origin_attestation/​tests.rs Tests typed signatures and field binding.
crates/​incentive/​src/​origin_attestation.rs Implements dedicated EIP-712 attestation signatures.
crates/​incentive/​src/​lib.rs Exports attestation signing helpers.
crates/​e2e/​tests/​g_node_01_onboarding.rs Seats the operator before testing serving.
crates/​e2e/​src/​node.rs Seats onboarded fixture operators as origins.
crates/​common/​src/​config/​types.rs Adds the optional attestation TTL setting.
crates/​common/​src/​config/​tests.rs Tests TTL defaults and bounds.
crates/​common/​src/​config/​resolved.rs Carries the resolved TTL.
crates/​common/​src/​config/​mod.rs Resolves and validates TTL configuration.
crates/​client/​src/​opened.rs Uses only explicit forwarded attestations.
crates/​client/​src/​lib.rs Documents upstream attestation requirements.
crates/​cli/​tests/​config_validate.rs Updates resolved configuration fixtures.
crates/​cli/​tests/​admin_rpc.rs Updates DHT attestation fixtures.
crates/​cli/​src/​commands/​config/​tests.rs Checks template coverage for TTL.
crates/​cli/​src/​commands/​config.rs Adds TTL to the configuration template.
adr/​glossary.md Updates namespace and attestation definitions.
adr/​architecture.md Summarizes attestation-based serving and discovery.
adr/​appendix-observability.md Documents rejection and refresh metrics.
adr/​040-cache-policy.md Clarifies that pins do not grant serve rights.
adr/​019-node-onboarding.md Documents origin-seat requirements.
adr/​017-privacy.md Updates attestation data-exposure analysis.
adr/​014-on-chain-verification.md Distinguishes attestations from stream signatures.
adr/​013-schema-evolution.md Updates frame sizes and memory bounds.
adr/​011-content-takedown.md Describes expiry and unseating consequences.
adr/​005-protocol.md Defines serving gates and attestation forwarding.
adr/​002-content-addressing.md Explains namespace scope and availability dependencies.
adr/​001-network.md Conditions cached serving on live attestations.

Review effort: Balanced

Comment thread crates/node/src/handlers/client/wire.rs Resolved
Comment thread crates/node/src/attestations.rs Resolved
…eep a lapsed one for a held blob

- sign_served reads the live attestation once and refuses Unattested when
  none remains, so no ok: true answer goes out without one. The buffered
  fill tiers now pass the serving rule before they answer.
- pre_send_checks stops a delivery whose attestation lapsed, counted on
  decdn_serve_stream_terminated_unattested_total.
- The store compares and replaces under one write lock, serializes its
  file writes, and skips a file whose signer does not recover at load.
- A failed refresh keeps an expired attestation while the node holds the
  blob and retries it; it drops one only when the held entry is still
  expired and the blob is gone. Live refreshes run before lapsed ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
thiras and others added 2 commits November 22, 2026 03:56
…l-config-b2a4bc

# Conflicts:
#	adr/appendix-observability.md
- A DHT re-publish keeps the held attestation only while it is still
  valid, so a valid replacement wins over a later-expiring dead one.
- Refresh runs only while the node holds the blob; an attestation for a
  blob it does not hold is dropped (compare-and-remove) instead.
- A served hash with no attestation at all is marked wanted, and the
  refresh task recovers one from the DHT (at most 4,096 wanted hashes,
  one lookup per 10 min each).
- Each refresh tick runs up to 256 jobs, 8 at a time, and a stop cancels
  a tick in flight.
- An upstream leg with no valid attestation is a typed error ruled a
  transient refusal, never scored Unreachable.
- A failed re-sign past half-life falls back to the live attestation.
- The store loads only files named for their hash and removes leftover
  .tmp, old-format and forged files with one warning.
- Docs: qualify the upstream-refusal claim, document the unseated-origin
  and empty-blob exemptions, the hash-to-namespace exposure, the deny-set
  in rejection lists, and fix stale frame-size and error text.
- Tests: mid-stream termination on unseating, expired STORE refusal,
  keep replacing a dead attestation, empty-blob serving, wanted hashes,
  .tmp cleanup, and the unattested-leg verdict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras enabled auto-merge (squash) November 22, 2026 01:31
@thiras
thiras merged commit ff7868f into main Nov 22, 2026
37 checks passed
@thiras
thiras deleted the claude/attestation-ttl-config-b2a4bc branch November 22, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Origin attestations: namespace-scoped, expiring, required to serve

3 participants