Skip to content

feat(cli): namespace pointers give a namespace a stable host on a public gateway - #2614

Merged
thiras merged 7 commits into
mainfrom
feat/gateway-pointer
Oct 24, 2026
Merged

thiras merged 7 commits into
mainfrom
feat/gateway-pointer

Conversation

@thiras

@thiras thiras commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2593 (PR 5 of 6). A namespace gets a stable host on a public gateway: https://<ns>.<host>/ serves the bundle its owner-signed pointer names, so the GitHub Action (#2596) and anyone else has one URL per namespace that survives each publish.

What

  • gateway/pointer.rs: the EIP-712 Pointer(uint256 namespaceId,bytes32 root,uint64 seq) record, domain decdn-pointer/1 with the PublisherRegistry as verifyingContract (ids repeat across chains and redeploys), SignedPointer sign/recover (high-s refused), and the Pointers store: one <data-dir>/pointers/<ns>.json per namespace, written through a NamedTempFile, read at start, a damaged file stops the gateway.
  • PUT /_pointer on the public bare host (and the listen address): body ≤ 64 KiB → JSON → signature → held-seq check → PublisherRegistry.ownerOf → store → 201 {namespace, root, seq, url}. 409 with the held seq for a replay (before any RPC), 422 malformed, 403 wrong owner, 404 no such namespace, 502 chain unreachable, 429 + Retry-After past the per-minute owner-lookup budget. Loopback gateways and site hosts answer 404.
  • Route::Namespace(ns) now serves the pointed bundle through the site path with the site CSP; HEAD works; the page host is <ns>.<host>.
  • Per-namespace allowance, pointer-served only: --allowance <ns>=<bytes> (repeatable) gives one namespace a bucket that replaces the shared one for requests on its own host. A ?ns= or <ns>.<hash32>. label is anyone's and keeps spending the shared bucket. Threaded through worker::Payment::Pool { namespace } into every charge/refusal site.
  • decdn publish point <ns> decdn:<hash>/ --gateway <origin> [--seq N]: signs with the publisher keystore under the resolved chain id + registry, PUTs with reqwest, prints key=value or --json; --dry-run loads no keystore. No RPC call.
  • --publisher-registry-address on decdn gateway (flag → config file → built-in testnet when the chain id matches, else an error naming the flag).
  • Metrics: decdn_gateway_pointer_updates_total.
  • Docs: adr/appendix-gateway.md § Namespace pointer, a cross-reference in appendix-bundles.md § decdn: URIs, docker/README.decdn.md, crates/cli/README.md, CHANGELOG.

Calls beyond the plan (from the review passes)

  1. Staleness is a per-signer high water, kept across ownership changes. A pointer from a signer other than the holder is checked on-chain whatever the holder's seq; if that signer owns the namespace now, it replaces the held pointer. Otherwise a former owner's high seq would hold the host forever after a transfer. Each signer's highest stored seq survives in the record, so when a namespace comes back to a former owner a captured old pointer cannot roll it back.
  2. Owner lookups are budgeted (60/min, 429 past it) and taken before a write lock that covers the owner read and the store, so a stale read cannot overtake a fresher one and a spent budget holds no lock. The lookup has a 15 s timeout. A valid signature costs nothing to produce, so without the budget an anonymous PUT flood would be an RPC amplifier against the operator's endpoint. Residual, documented in the appendix: while the budget is spent, other pointers wait for the next minute; per-client limits belong on the proxy, since the gateway does not trust X-Forwarded-* by design. A signer the gateway already stored a pointer from (so, a verified owner at some point) draws on a 10/min budget of its own per namespace instead, still read on-chain each time, so the flood does not keep a publisher from updating. An hour-long reuse of a verification was tried and reverted: it opened a stale-authorization window after a transfer for little real benefit.
  3. A namespace allowance pays for its own bundle only. /_decdn/ content from another bundle on <ns>.<host> spends the shared bucket, so strangers cannot drain a partner's budget with unrelated content.
  4. publish point refuses a --gateway with a path, reports a redirect instead of following it (reqwest would turn the PUT into a GET), and gives up after 30 s.

Tests

  • pointer/tests.rs: sign/recover, wrong chain/registry, tampered fields, malformed + high-s, JSON shape, store seq order, another-signer replacement, a returning signer's old pointer stays stale, reload after restart, bad/misnamed file fails load, dir 0o700 with no temp leftovers.
  • allowance/tests.rs: namespace bucket replaces, non-override shares.
  • gateway/tests.rs: namespace host 404 → 200 + CSP + HEAD → moves with a newer pointer; PUT /_pointer loopback/site 404, 413/422, same-signer 409 before the chain, other-signer reaches the chain, lookup budget 429, a known signer's own per-namespace budget, valid pointer → 502 with no chain; per-namespace bucket 402 with ?ns=7 in Link while the hash site still serves; /_decdn/ on the namespace host spends the shared bucket.
  • CLI parse tests (--allowance, --publisher-registry-address, publish point), outcome formats.
  • crates/e2e/tests/gateway_pointer.rs (anvil): publish namespace create → publish point → <ns>.decdn.test serves byte-exact → the 3 MiB namespace allowance refuses the second 2 MiB pull with ?ns= in Link while the bundle's site still serves → same seq exits non-zero with 409 → the operator keystore gets 403. Passes locally.

Gates run locally: clippy --workspace --all-targets --all-features -D warnings, cargo doc with warnings denied, cargo fmt --check, cargo nextest run -p decdn-cli -p decdn-common (1502 passed), make -C adr check-refs check-book-list, pre-commit run --all-files (cargo-deny advisories are pre-existing lockfile findings).

🤖 Generated with Claude Code

thiras and others added 2 commits October 24, 2026 21:59
…nce, decdn publish point

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…lic gateway

`decdn publish point <ns> decdn:<hash>/ --gateway <origin>` signs an EIP-712
pointer with the namespace owner's keystore and PUTs it to `/_pointer`; the
gateway verifies the signer against `PublisherRegistry.ownerOf`, stores it
under `<data-dir>/pointers/<ns>.json`, and serves the bundle as a website at
`<ns>.<host>`. `--allowance <ns>=<bytes>` gives a namespace its own daily
allowance for the requests its pointer serves. Part of #2593.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 19:17
Co-Authored-By: Claude Fable 5.1 <[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

Allowance isolation, persisted deployment binding, and ownership-check ordering remain unresolved.

3 open issues
What changed in this PR

Adds owner-signed namespace pointers so public gateways can serve each namespace at a stable hostname across bundle updates, using the existing paid-pull infrastructure.

Changes:

  • Adds signed pointer submission, ownership verification, persistence, and namespace-host routing.
  • Introduces namespace-specific daily allowances and pointer-update metrics.
  • Adds decdn publish point, operator documentation, and unit and end-to-end coverage.
File Description
docker/​README.decdn.md Documents stable hosts and namespace allowances.
crates/​e2e/​tests/​gateway_pointer.rs Exercises publishing, serving, allowances, and rejected updates.
crates/​common/​src/​cli/​publish/​tests.rs Tests pointer command parsing.
crates/​common/​src/​cli/​publish.rs Defines publish point arguments.
crates/​common/​src/​cli/​mod.rs Exports pointer command arguments.
crates/​common/​src/​cli/​gateway/​tests.rs Tests allowance and registry flags.
crates/​common/​src/​cli/​gateway.rs Adds namespace allowance and registry options.
crates/​cli/​src/​commands/​publish/​tests.rs Tests pointer receipt formats.
crates/​cli/​src/​commands/​publish.rs Signs and submits namespace pointers.
crates/​cli/​src/​commands/​gateway/​worker/​tests.rs Updates pool-payment fixtures.
crates/​cli/​src/​commands/​gateway/​worker.rs Carries namespace allowance selection.
crates/​cli/​src/​commands/​gateway/​tests.rs Tests pointer routing, validation, and allowances.
crates/​cli/​src/​commands/​gateway/​site/​tests.rs Tests namespace hostname construction and routing.
crates/​cli/​src/​commands/​gateway/​site.rs Constructs namespace hostnames.
crates/​cli/​src/​commands/​gateway/​pointer/​tests.rs Tests signatures, sequencing, and persistence.
crates/​cli/​src/​commands/​gateway/​pointer.rs Implements signed pointers and their store.
crates/​cli/​src/​commands/​gateway/​metrics/​tests.rs Tests pointer-update metric exposition.
crates/​cli/​src/​commands/​gateway/​metrics.rs Counts stored pointer updates.
crates/​cli/​src/​commands/​gateway/​allowance/​tests.rs Tests namespace and shared buckets.
crates/​cli/​src/​commands/​gateway/​allowance.rs Implements namespace allowance overrides.
crates/​cli/​src/​commands/​gateway.rs Integrates pointer updates, routing, and accounting.
crates/​cli/​README.md Introduces stable namespace hosts.
CHANGELOG.md Records the new gateway functionality.
adr/​appendix-gateway.md Specifies pointers, allowances, and responses.
adr/​appendix-bundles.md Links namespace hosts to pointer documentation.

Review effort: Balanced

file,
chain_id,
)?;
let pointers = Pointers::load(&root.join("pointers"))?;

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.

Confirmed: Pointers::load bound the store to nothing, so the same data dir on another chain or registry served pointers nobody there signed. Fixed in #2620: each record carries the chain id and registry the owner was read on, and the gateway refuses to start on a store written for another deployment, naming both and the way out (another --data-dir, or remove the pointers). Covered by a_store_from_another_deployment_is_refused.

Comment on lines +1220 to +1222
UriTarget::Blob => {
self.paid(&page_host, pointer, &uri, Present::Download, range)
.await

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.

Fixed in 9df2b80 (before the merge): on a namespace host, /_decdn/<hash>… charges the namespace's bucket only when <hash> is the pointed bundle itself (pointer.filter(|_| uri.hash == site.hash)), in both the navigation and the non-navigation branch. Any other blob or bundle through /_decdn/ spends the shared bucket. The namespace's own bundle keeps its own bucket there on purpose: that is the pointer's content, however the page reaches it. Covered by a_namespace_allowance_pays_for_its_own_bundle_only.

Comment on lines +1301 to +1302
let (root, seq) = (pointer.root, pointer.seq);
match public.pointers.set(pointer, signer) {

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.

Fixed in 9167b00 (before the merge): put_pointer takes Public::pointer_writes (a tokio mutex) before the ownerOf read and holds it through Pointers::set, so the owner read and the store are one step and a read from before a transfer cannot land after one from after it. The lookup has a 15 s timeout (OWNER_LOOKUP_TIMEOUT) and the lookup budget is taken before the lock, so a spent budget or a hung RPC holds no other write. One gateway-wide lock rather than per namespace: writes are bounded by the 60/min budget. No delayed-RPC regression test: the unit fixtures have no controllable RPC; this is recorded as a known gap.

thiras and others added 2 commits October 24, 2026 22:24
…ialize and are reused for an hour

A signer's highest stored seq outlives a change of hands, so a captured
pointer cannot roll a returned namespace back. The owner read and the store
run under one lock, so a read from before a transfer cannot overtake one from
after it. The holder's own next pointer within the hour reuses its
verification, so a flood on the lookup budget does not block a publisher's
updates.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…kups time out and precede the write lock

`/_decdn/` content from another bundle on a namespace host spends the shared
allowance. The owner lookup has a 15 s timeout and the budget is taken before
the write lock, so a hung RPC or a spent budget holds no other pointer write.
The hour-long reuse of a verification is gone: every stored pointer is
verified on-chain. `decdn publish point` refuses a `--gateway` with a path,
reports a redirect instead of following it, and gives up after 30 s.

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

github-code-quality Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 87c96df feat/gateway-pointer 3383cc5 +/-
77% 77% 0%
View coverage of the 10 most impacted files.
File main 87c96df feat/gateway-pointer 3383cc5 +/-
crates/cli/src/...ands/publish.rs 51% 49% -2%
crates/cli/src/...ands/gateway.rs 77% 76% -1%
crates/protocol/src/framing.rs 93% 92% -1%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/cli/src/...teway/worker.rs 82% 82% 0%
crates/cli/src/...gateway/site.rs 97% 97% 0%
crates/node/src/dht/publish.rs 78% 80% +2%
crates/cli/src/...eway/pointer.rs 0% 100% +100%
crates/common/s.../cli/gateway.rs 0% 100% +100%

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


Updated October 24, 2026 20:04 UTC

thiras and others added 2 commits October 24, 2026 22:41
…et per namespace

A flood of strangers spends the shared 60/min budget; a publisher whose
pointer the gateway already holds draws on 10/min for that namespace instead,
still read on-chain each time, so the flood does not keep it from updating.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@thiras
thiras merged commit 38353ea into main Oct 24, 2026
34 checks passed
@thiras
thiras deleted the feat/gateway-pointer branch October 24, 2026 20:07
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.

2 participants