Skip to content

cuprated: Add graceful shutdown, pt2: service error propagation#586

Open
redsh4de wants to merge 5 commits into
Cuprate:mainfrom
redsh4de:feat/graceful-shutdown-pt2
Open

cuprated: Add graceful shutdown, pt2: service error propagation#586
redsh4de wants to merge 5 commits into
Cuprate:mainfrom
redsh4de:feat/graceful-shutdown-pt2

Conversation

@redsh4de
Copy link
Copy Markdown
Contributor

@redsh4de redsh4de commented Feb 20, 2026

What

Depends on pt1, PR #585

Building on part 1, this replaces the panic-on-error patterns in cuprated's services with error propagation that makes use of the graceful shutdown mechanism

Why

So we dont panic and insta-crash upon a error, shutdown should be graceful. Internal errors still caused panics before this via PANIC_CRITICAL_SERVICE_ERROR

Where

  • cuprated:
    • blockchain/error.rs (new):

      Type Kind Variants
      BlockValidationError peer-fault (ban) HardFork(HardForkError), Other(ExtendedConsensusError)
      BlockManagerError manager union Validation(BlockValidationError), Internal(#[from] tower::BoxError)
      IncomingBlockError interface union Validation(BlockValidationError), Internal(tower::BoxError), Orphan, UnknownTransactions(_, _), TooManyTxs, ChannelClosed
    • txpool/error.rs (new):

      Type Kind Variants
      TxValidationError peer-fault (ban) Parse(io::Error), Consensus(ExtendedConsensusError), DuplicateTransaction, RelayRule(RelayRuleError)
      IncomingTxError union Validation(#[from] TxValidationError), Internal(#[from] tower::BoxError)
    • monitor.rs - add TaskExecutor::spawn_critical, panic_message helper.

    • logging.rs - return the log guard, hold it until shutdown completes.

    • constants.rs - rename PANIC_CRITICAL_SERVICE_ERROR to CRITICAL_SERVICE_ERROR

    • lib.rs - Node::launch returns Result; on init failure it cancels partially spawned subsystems before returning the error.

    • blockchain.rs - check_add_genesis returns Result.

    • blockchain/manager.rs - run loop returns Result, spawn_critical for syncer + manager.

    • blockchain/manager/handler.rs - .expect(...) -> ? throughout, handlers return Result<_, BlockManagerError> or Result<_, tower::BoxError>, handle_command routes Internal via ? and Validation via response channel. Invariant violations kept as panics.

    • txpool/manager.rs - uniform DB-error escalation: all 6 handlers propagate TxPoolError via ?. Reorder promote_tx and remove_tx_from_pool to write to DB first, then apply in memory.

    • txpool/incoming_tx.rs - IncomingTxHandler::init returns Result.

    • tor.rs, p2p.rs - transport_*_config / initialize_clearnet_p2p / initialize_tor_p2p return Result, Tor logs+skips on failure.

    • rpc/server.rs - init_rpc_servers returns Result, per-server task uses spawn - If a RPC server fails to start, the error is logged but doesn't initiate shutdown.

  • cuprate-types
    • TxConversionError re-exported.

How

1. spawn_critical wraps each subsystem's future:

Outcome Action
Ok(()) normal exit if shutdown was requested, else logged as a bug -> trigger shutdown
Err(_) log w/ subsystem name -> trigger shutdown
panic log via panic_message -> trigger shutdown

2. Added layered errors.

Per subsystem: a typed ValidationError for peer-fault paths, plus a union with Validation and Internal(tower::BoxError) arms. From impls route (ExtendedConsensusError::DBErr -> Internal; else -> Validation). The manager matches between the two:

Variant Route Caller's response
Internal(_) ? -> spawn_critical log + graceful shutdown
Validation(_) back via response channel ban peer / cancel downloader

@github-actions github-actions Bot added the A-binaries Area: Related to binaries. label Feb 20, 2026
@redsh4de redsh4de marked this pull request as draft February 28, 2026 14:35
@github-actions github-actions Bot added the A-p2p Area: Related to P2P. label Feb 28, 2026
@redsh4de redsh4de marked this pull request as ready for review March 1, 2026 14:41
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from aac614a to 1a41630 Compare March 15, 2026 22:15
@redsh4de redsh4de marked this pull request as draft March 17, 2026 18:13
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 91f6723 to e3d9960 Compare March 18, 2026 02:13
@github-actions github-actions Bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. and removed A-p2p Area: Related to P2P. labels Mar 18, 2026
@redsh4de redsh4de marked this pull request as ready for review March 18, 2026 02:25
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 2 times, most recently from 0cf53be to 15bc617 Compare March 19, 2026 00:42
@github-actions github-actions Bot added the A-consensus Area: Related to consensus. label Mar 19, 2026
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 4 times, most recently from 8adc7f1 to 79e3e61 Compare March 24, 2026 22:43
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 7 times, most recently from d46811f to d6c42d4 Compare April 26, 2026 19:53
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 2 times, most recently from 9bffcac to cc55d00 Compare May 5, 2026 17:01
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from cc55d00 to fdcd3c7 Compare May 12, 2026 15:58
@github-actions github-actions Bot added the A-storage Area: Related to storage. label May 12, 2026
@github-actions github-actions Bot added the A-types Area: Related to types. label May 12, 2026
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 4 times, most recently from fd7f75d to a07fe8f Compare May 18, 2026 00:50
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from a07fe8f to 8c68467 Compare May 19, 2026 22:03
@github-actions github-actions Bot removed A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-consensus Area: Related to consensus. A-storage Area: Related to storage. labels May 19, 2026
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 3 times, most recently from 56ea9f1 to 720e15f Compare May 20, 2026 18:25
Comment thread binaries/cuprated/src/blockchain/manager/handler.rs
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 9 times, most recently from ea492e5 to 34bec3d Compare May 31, 2026 12:53
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 34bec3d to d1e4a2a Compare June 2, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-binaries Area: Related to binaries. A-types Area: Related to types.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant