Skip to content

refactor(node): decompose the 1,857-line run() bring-up into ordered phase functions #1253

Closed

Description

@thiras

Problem

Runtime::run() (crates/node/src/runtime/mod.rs:437-2294) is a single ~1,857-line straight-line function carrying #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] (mod.rs:436). It is the entire daemon bring-up plus a ~270-line manual teardown block (mod.rs:2017-2287), with the wiring state expressed as dozens of ad-hoc locals: 17 oneshot stop channels, 9 CancellationTokens, 12 tasks.spawn sites, and 15+ _c/_for_buyer Arc clones threaded between sections (e.g. mod.rs:1637-1651).

This is a legibility refactor, not a line-count one — the wiring itself is legitimate (no domain-logic duplication was found; runtime is thin adapters as intended).

Proposed shape

Split into ~5 phase functions with explicit inputs/outputs, e.g.:

  1. identity / keystore / stores
  2. chain providers + watchers
  3. handlers + router
  4. background tasks (GC runners, gossip, admin)
  5. shutdown (the existing ordered teardown, kept verbatim)

Each phase returns a small struct of the handles the next phase needs, which turns today's implicit Arc-clone web into named, reviewable seams.

Constraints

Risk

Medium — mechanical but wide; the Arc-clone threading makes bad splits easy. Phase-by-phase PRs with no behavior change per step.

Activity

  1. added
    prio:medium
    rust
    on Jul 17, 2026
  2. self-assigned this
    on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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