Skip to content

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

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

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

Conversation

@redsh4de

@redsh4de redsh4de commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

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
@redsh4de
redsh4de force-pushed the feat/graceful-shutdown-pt2 branch 2 times, most recently from d699845 to 2910ab2 Compare August 5, 2026 21:44
@redsh4de
redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from ef31fa6 to 4e46c1c Compare August 14, 2026 22:18
Move block and transaction specific validation failures into BlockError and TransactionError, leaving ExtendedConsensusError responsible only for distinguishing consensus errors from database failures.

Flatten TxValidationError into IncomingTxError to avoid redundancy
return missing alt-chain context as None so consensus handles it as a invalid parent instead of a db error
@github-actions github-actions Bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file. A-consensus Area: Related to consensus. labels Aug 17, 2026
@redsh4de

redsh4de commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

fwiw after these changes i kind of want to rename ExtendedConsensusError to ConsensusServiceError, as now its just used in service calls to differentiate whether a error is a consensus validation, or a service failure. easier to reason as well, but seperate pr

@redsh4de
redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from b1b0410 to 164e9ea Compare August 19, 2026 14:44
@Boog900 Boog900 added this to the cuprated v0.1.0 preview 2 milestone Aug 20, 2026

@Boog900 Boog900 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits

Comment thread binaries/cuprated/src/blockchain/manager/handler.rs Outdated
Comment thread binaries/cuprated/src/p2p/request_handler.rs Outdated
Comment thread binaries/cuprated/src/p2p.rs
@redsh4de
redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 7878dcc to d873658 Compare August 23, 2026 23:38
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-consensus Area: Related to consensus. A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-p2p Area: Related to P2P. A-types Area: Related to types. A-workspace Area: Changes to a root workspace file or general repo file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants