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

View file

@ -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())

View file

@ -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 {

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 monero_serai::block::Block;

View file

@ -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:

View file

@ -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;

View file

@ -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.";