Skip to content

refactor(node): split the 2,300-line ClientHandler impl into delivery/voucher/window submodules + a deps struct #1254

Closed

Description

@thiras

Problem

crates/node/src/handlers/client.rs (3,526 lines) concentrates paid delivery in one ~2,300-line impl ClientHandler block (client.rs:689-3005). It composes the shared primitives correctly (dispatch limiter, ThreeLayerRateLimiter, LeechGovernor via leech_admit/leech_record_pulled at client.rs:1201/1209) — there's no duplication to delete — but the impl mixes several distinct concerns:

  • entry/dispatch: serve_stream (client.rs:1438-1893, ~455 lines)
  • delivery + the voucher/payment loop: deliver (client.rs:2415-2522) + collect_voucher (client.rs:2522-2781, ~260 lines)
  • window pull-through path: serve_via_window_pull_through (client.rs:1893-2073) + window_forward_loop (client.rs:2073-2404, ~330 lines)
  • 15 one-liner attach_* builder setters (client.rs:765-889): redeem_hint, voucher_activity, region_accountant, prefetch, pull_through, local_populate, background_fill, window_pull_through, leech_governor, pull_origin_gate, …

Proposed shape

  • Extract handlers/client/{delivery,voucher,window}.rs submodules (support types like ChannelDeliveryState, WarmVerdict, ServeRejectReason move with their consumers).
  • Replace the 15 attach_* setters with a single deps/config struct taken at construction, so a handler's wiring is one reviewable literal in run() instead of a setter chain. (Coordinates with refactor(node): decompose the 1,857-line run() bring-up into ordered phase functions #1253, which names the wiring phases.)

No lines saved — this is organization and reviewability only.

Risk

Medium — the methods share &self state threaded through the mega-impl, so the module boundaries need care; behavior-preserving moves only, existing tests (client.rs:3126-3526) pin the seams.

Metadata

Metadata

Assignees

Labels

prio:mediumrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions