diff --git a/binaries/cuprated/src/blockchain/chain_service.rs b/binaries/cuprated/src/blockchain/chain_service.rs index eeaf4a06..af862d1d 100644 --- a/binaries/cuprated/src/blockchain/chain_service.rs +++ b/binaries/cuprated/src/blockchain/chain_service.rs @@ -33,7 +33,7 @@ impl Service for ChainService { cumulative_difficulty, }, BlockchainResponse::FindFirstUnknown(res) => ChainSvcResponse::FindFirstUnknown(res), - _ => panic!("Blockchain returned wrong response"), + _ => unreachable!(), }; match req { @@ -60,7 +60,7 @@ impl Service for ChainService { .. } = res else { - panic!("Blockchain returned wrong response"); + unreachable!() }; ChainSvcResponse::CumulativeDifficulty(cumulative_difficulty) diff --git a/binaries/cuprated/src/blockchain/interface.rs b/binaries/cuprated/src/blockchain/interface.rs index 879103e0..985e60d8 100644 --- a/binaries/cuprated/src/blockchain/interface.rs +++ b/binaries/cuprated/src/blockchain/interface.rs @@ -49,10 +49,7 @@ pub enum IncomingBlockError { /// Try to add a new block to the blockchain. /// -/// This returns a [`bool`] indicating if the block was added to the main-chain ([`true`]) or an alt-chain -/// ([`false`]). -/// -/// If we already knew about this block or the blockchain manager is not setup yet `Ok(false)` is returned. +/// On success returns [`IncomingBlockOk`]. /// /// # Errors /// @@ -157,7 +154,7 @@ async fn block_exists( .call(BlockchainReadRequest::FindBlock(block_hash)) .await? else { - panic!("Invalid blockchain response!"); + unreachable!(); }; Ok(chain.is_some()) diff --git a/binaries/cuprated/src/blockchain/manager.rs b/binaries/cuprated/src/blockchain/manager.rs index f6c11fc0..568ed572 100644 --- a/binaries/cuprated/src/blockchain/manager.rs +++ b/binaries/cuprated/src/blockchain/manager.rs @@ -73,7 +73,7 @@ pub async fn init_blockchain_manager( .await .expect(PANIC_CRITICAL_SERVICE_ERROR) else { - panic!("Blockchain context service returned wrong response!"); + unreachable!() }; let manager = BlockchainManager { diff --git a/binaries/cuprated/src/blockchain/manager/commands.rs b/binaries/cuprated/src/blockchain/manager/commands.rs index f5890a83..643ed88c 100644 --- a/binaries/cuprated/src/blockchain/manager/commands.rs +++ b/binaries/cuprated/src/blockchain/manager/commands.rs @@ -1,4 +1,4 @@ -//! This module contains the commands for th blockchain manager. +//! This module contains the commands for the blockchain manager. use std::collections::HashMap; use monero_serai::block::Block; diff --git a/binaries/cuprated/src/blockchain/manager/handler.rs b/binaries/cuprated/src/blockchain/manager/handler.rs index d37811bc..e9e6c3c3 100644 --- a/binaries/cuprated/src/blockchain/manager/handler.rs +++ b/binaries/cuprated/src/blockchain/manager/handler.rs @@ -33,6 +33,11 @@ use crate::{ impl super::BlockchainManager { /// Handle an incoming command from another part of Cuprate. + /// + /// # Panics + /// + /// This function will panic if any internal service returns an unexpected error that we cannot + /// recover from. pub async fn handle_command(&mut self, command: BlockchainManagerCommand) { match command { BlockchainManagerCommand::AddBlock { @@ -68,8 +73,10 @@ impl super::BlockchainManager { /// /// Otherwise, this function will validate and add the block to the main chain. /// - /// On success returns a [`bool`] indicating if the block was added to the main chain ([`true`]) - /// or an alt-chain ([`false`]). + /// # Panics + /// + /// This function will panic if any internal service returns an unexpected error that we cannot + /// recover from. pub async fn handle_incoming_block( &mut self, block: Block, @@ -244,8 +251,6 @@ impl super::BlockchainManager { /// of the alt chain is higher than the main chain it will attempt a reorg otherwise it will add /// the alt block to the alt block cache. /// - /// This function returns a [`bool`] indicating if the chain was reorganised ([`true`]) or not ([`false`]). - /// /// # Errors /// /// This will return an [`Err`] if: diff --git a/binaries/cuprated/src/blockchain/syncer.rs b/binaries/cuprated/src/blockchain/syncer.rs index 8c58c54e..7e72c36c 100644 --- a/binaries/cuprated/src/blockchain/syncer.rs +++ b/binaries/cuprated/src/blockchain/syncer.rs @@ -65,7 +65,7 @@ where .call(BlockChainContextRequest::GetContext) .await? else { - panic!("Blockchain context service returned wrong response!"); + unreachable!(); }; let client_pool = clearnet_interface.client_pool(); @@ -130,7 +130,7 @@ where .oneshot(BlockChainContextRequest::GetContext) .await? else { - panic!("Blockchain context service returned wrong response!"); + unreachable!(); }; *old_context = ctx; diff --git a/binaries/cuprated/src/constants.rs b/binaries/cuprated/src/constants.rs index d4dfc1ad..2f3c7bb6 100644 --- a/binaries/cuprated/src/constants.rs +++ b/binaries/cuprated/src/constants.rs @@ -14,6 +14,7 @@ pub const VERSION_BUILD: &str = if cfg!(debug_assertions) { formatcp!("{VERSION}-release") }; +/// The panic message used when cuprated encounters a critical service error. pub const PANIC_CRITICAL_SERVICE_ERROR: &str = "A service critical to Cuprate's function returned an unexpected error.";