more review fixes

This commit is contained in:
Boog900 2024-10-05 21:16:51 +01:00
parent 27a8acdb04
commit a21e489fdc
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
7 changed files with 18 additions and 15 deletions

View file

@ -33,7 +33,7 @@ impl Service<ChainSvcRequest> for ChainService {
cumulative_difficulty, cumulative_difficulty,
}, },
BlockchainResponse::FindFirstUnknown(res) => ChainSvcResponse::FindFirstUnknown(res), BlockchainResponse::FindFirstUnknown(res) => ChainSvcResponse::FindFirstUnknown(res),
_ => panic!("Blockchain returned wrong response"), _ => unreachable!(),
}; };
match req { match req {
@ -60,7 +60,7 @@ impl Service<ChainSvcRequest> for ChainService {
.. ..
} = res } = res
else { else {
panic!("Blockchain returned wrong response"); unreachable!()
}; };
ChainSvcResponse::CumulativeDifficulty(cumulative_difficulty) ChainSvcResponse::CumulativeDifficulty(cumulative_difficulty)

View file

@ -49,10 +49,7 @@ pub enum IncomingBlockError {
/// Try to add a new block to the blockchain. /// 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 /// On success returns [`IncomingBlockOk`].
/// ([`false`]).
///
/// If we already knew about this block or the blockchain manager is not setup yet `Ok(false)` is returned.
/// ///
/// # Errors /// # Errors
/// ///
@ -157,7 +154,7 @@ async fn block_exists(
.call(BlockchainReadRequest::FindBlock(block_hash)) .call(BlockchainReadRequest::FindBlock(block_hash))
.await? .await?
else { else {
panic!("Invalid blockchain response!"); unreachable!();
}; };
Ok(chain.is_some()) Ok(chain.is_some())

View file

@ -73,7 +73,7 @@ pub async fn init_blockchain_manager(
.await .await
.expect(PANIC_CRITICAL_SERVICE_ERROR) .expect(PANIC_CRITICAL_SERVICE_ERROR)
else { else {
panic!("Blockchain context service returned wrong response!"); unreachable!()
}; };
let manager = BlockchainManager { let manager = BlockchainManager {

View file

@ -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 std::collections::HashMap;
use monero_serai::block::Block; use monero_serai::block::Block;

View file

@ -33,6 +33,11 @@ use crate::{
impl super::BlockchainManager { impl super::BlockchainManager {
/// Handle an incoming command from another part of Cuprate. /// 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) { pub async fn handle_command(&mut self, command: BlockchainManagerCommand) {
match command { match command {
BlockchainManagerCommand::AddBlock { BlockchainManagerCommand::AddBlock {
@ -68,8 +73,10 @@ impl super::BlockchainManager {
/// ///
/// Otherwise, this function will validate and add the block to the main chain. /// 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`]) /// # Panics
/// or an alt-chain ([`false`]). ///
/// This function will panic if any internal service returns an unexpected error that we cannot
/// recover from.
pub async fn handle_incoming_block( pub async fn handle_incoming_block(
&mut self, &mut self,
block: Block, 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 /// 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. /// the alt block to the alt block cache.
/// ///
/// This function returns a [`bool`] indicating if the chain was reorganised ([`true`]) or not ([`false`]).
///
/// # Errors /// # Errors
/// ///
/// This will return an [`Err`] if: /// This will return an [`Err`] if:

View file

@ -65,7 +65,7 @@ where
.call(BlockChainContextRequest::GetContext) .call(BlockChainContextRequest::GetContext)
.await? .await?
else { else {
panic!("Blockchain context service returned wrong response!"); unreachable!();
}; };
let client_pool = clearnet_interface.client_pool(); let client_pool = clearnet_interface.client_pool();
@ -130,7 +130,7 @@ where
.oneshot(BlockChainContextRequest::GetContext) .oneshot(BlockChainContextRequest::GetContext)
.await? .await?
else { else {
panic!("Blockchain context service returned wrong response!"); unreachable!();
}; };
*old_context = ctx; *old_context = ctx;

View file

@ -14,6 +14,7 @@ pub const VERSION_BUILD: &str = if cfg!(debug_assertions) {
formatcp!("{VERSION}-release") formatcp!("{VERSION}-release")
}; };
/// The panic message used when cuprated encounters a critical service error.
pub const PANIC_CRITICAL_SERVICE_ERROR: &str = pub const PANIC_CRITICAL_SERVICE_ERROR: &str =
"A service critical to Cuprate's function returned an unexpected error."; "A service critical to Cuprate's function returned an unexpected error.";