Skip to content

perf(node): read each signer's authorization once at admission - #2333

Merged
alpergundogdu merged 3 commits into
mainfrom
perf/node-signer-auth-cache
Oct 6, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
perf/node-signer-auth-cache

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Why

Testnet phase metrics (3 days, 7 nodes): admission is 4 ms at p50 but 391 ms at p99, and 4.5% of admissions take over 100 ms. That tail matches eth_call latency (p95 491 ms, p99 900 ms). getPool already reads from the event projection, with single-flight. The repeat cost was getAuthorization: one synchronous read per (pool, signer) every 60 s, and no coalescing of concurrent reads.

What

  • Registered reads stay cached. cap and expiry are write-once. spent is the read's value plus what the projection has folded for the signer since the read. The fold covers every provider's PoolRedeemed. The baseline is taken before the read is sent, so any error makes spent high and refuses near the cap, never over-admits.
  • Unregistered reads are re-read after one minute, or once the projection folds a redemption by the signer. A registration that pays no lane emits no event, so the timed re-read stays.
  • Single-flight for getAuthorization. The getPool in-flight slot is now generic over its key and value, and both reads use it.
  • Bounded cache eviction. At 4096 entries, the cache prunes lapsed Unregistered reads, then evicts the oldest read.
  • A read fault refuses the signer. The stale-registration fallback is gone: a registered signer never reaches the chain read.
  • Counters: decdn_serve_signer_auth_{cached,first_read,reread}_total, sibling counters that sum to all admission signer checks. They have registry rows in adr/appendix-observability.md and a stacked panel, "Admission signer checks by cache outcome", in dashboard-delivery.json.

Testing

  • cargo nextest run -p decdn-node: 1606 passed. New tests cover the freshness rules, cache eviction, coalesced reads against a hung RPC, re-read triggered by a projection fold, spent-delta accounting and counter values.
  • cargo clippy --workspace --all-targets --all-features, cargo doc with -D warnings, cargo test --no-run -p decdn-e2e --features anvil-e2e: clean.

After deploy, the new panel shows how much admission still waits on a chain read (first read + re-read).

🤖 Generated with Claude Code

The admit-path signer confirm kept a getAuthorization read for 60 s, so
a repeat client paid one synchronous eth_call a minute and concurrent
confirms each sent their own. Testnet admission p99 (391 ms) sat at
eth_call p95-p99.

A Registered read now stays cached: cap and expiry are write-once, and
spent is the read's value plus what the event projection folded for the
signer since. An Unregistered read is re-read after a minute, or once
the projection folds a redemption by the signer. Confirms of one
(pool, signer) share one in-flight read, through the single-flight that
getPool already used, now generic over its key. A full cache prunes
lapsed Unregistered reads, then evicts the oldest.

Three sibling counters split admission signer checks by cache outcome
(cached, first read, unregistered re-read), charted in a new delivery
dashboard panel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 10:15
@github-code-quality

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

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 78da23b in the perf/node-signer-aut... branch remains at 88%, unchanged from commit e1024f7 in the main branch.

Show a line coverage summary of the most impacted files.
File main e1024f7 perf/node-signer-aut... 78da23b +/-
crates/node/src...t_settlement.rs 90% 90% 0%
crates/node/src/dht/publish.rs 92% 92% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/node/src/runtime/mod.rs 53% 53% 0%
crates/client/src/streamer.rs 90% 91% +1%
crates/client/src/sink.rs 96% 97% +1%
crates/client/s...c/connection.rs 97% 98% +1%

Updated October 06, 2026 11:17 UTC

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.

Copilot review overview

🔵 Needs a closer look

The change reworks on-chain admission/authorization caching and single-flight concurrency semantics with subtle correctness/economic tradeoffs, which warrants final human review despite only one minor documentation nit found.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR cuts admission-path tail latency by changing how ResolvingPoolView reads a voucher signer's on-chain authorization. Testnet metrics tied the 4.5% of >100 ms admissions to repeated getAuthorization eth_calls (one per (pool, signer) every 60 s, with no coalescing). The fix makes a Registered read write-once-cached forever (with spent kept current from the projection's fold), re-reads only Unregistered signers (1-minute TTL or once a redemption folds), coalesces concurrent reads through a now-generic single-flight slot shared with getPool, bounds the cache at 4096 entries, and drops the stale-registration fallback so a read fault simply refuses the signer. New sibling counters and a dashboard panel make the remaining chain-read tail observable.

Changes:

  • Rework signer-auth caching: permanent Registered reads, TTL/fold-based re-reads for Unregistered, bounded eviction, and fault-refuses-signer semantics.
  • Generalize the single-flight read slot over key/value so getAuthorization reads coalesce like getPool.
  • Add decdn_serve_signer_auth_{cached,first_read,reread}_total counters, observability registry rows, and a stacked dashboard panel; wire Arc<Metrics> into ResolvingPoolView.
File Description
crates/​node/​src/​payment_settlement.rs Core refactor: AuthRead/CachedAuth, cached_auth/remember_auth, generic single-flight, read_authorization, metrics, tests.
crates/​node/​src/​metrics.rs Three new admit signer-auth counters and their recorder methods.
crates/​node/​src/​runtime/​mod.rs Pass node_metrics into ResolvingPoolView::new.
crates/​node/​src/​pool_view.rs Doc update for the new permanent-registered / fault-refuses semantics.
crates/​node/​src/​chain_events/​mod.rs Doc update: admission reads refuse rather than fall back.
adr/​appendix-observability.md Registry rows for the three new counters.
monitoring/​dashboard-delivery.json New stacked "Admission signer checks by cache outcome" panel.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/payment_settlement.rs Resolved
alpergundogdu and others added 2 commits October 6, 2026 11:26
The delegated clamp journey retried its fetch until the fetch succeeded
or the lane's outstanding amount rose above zero. In this flow the lane's
last signed amount stays zero while the node redeems, so only a
successful fetch ended the loop. The node now refuses the drained signer
at admission, so later fetches cannot succeed; the loop ends on the
first accepted voucher instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu
alpergundogdu merged commit e416a1e into main Oct 6, 2026
30 checks passed
@alpergundogdu
alpergundogdu deleted the perf/node-signer-auth-cache branch October 6, 2026 11:26
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