cargo fmt
Some checks failed
Audit / audit (push) Has been cancelled
Deny / audit (push) Has been cancelled

This commit is contained in:
Boog900 2024-08-05 16:22:06 +01:00
parent d4bd18ca57
commit 1919fb3190
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
11 changed files with 67 additions and 25 deletions

View file

@ -100,8 +100,9 @@ impl AltChainMap {
}
// find the block with hash == prev_id.
let BlockchainResponse::FindBlock(res) =
database.oneshot(BlockchainReadRequest::FindBlock(prev_id)).await?
let BlockchainResponse::FindBlock(res) = database
.oneshot(BlockchainReadRequest::FindBlock(prev_id))
.await?
else {
panic!("Database returned wrong response");
};

View file

@ -262,7 +262,10 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
.database
.ready()
.await?
.call(BlockchainReadRequest::BlockHash(self.chain_height - 1, Chain::Main))
.call(BlockchainReadRequest::BlockHash(
self.chain_height - 1,
Chain::Main,
))
.await?
else {
panic!("Database returned incorrect response!");

View file

@ -297,7 +297,9 @@ async fn get_blocks_weight_in_range<D: Database + Clone>(
tracing::info!("getting block weights.");
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(range, chain))
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(
range, chain,
))
.await?
else {
panic!("Database sent incorrect response!")
@ -319,7 +321,9 @@ async fn get_long_term_weight_in_range<D: Database + Clone>(
tracing::info!("getting block long term weights.");
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(range, chain))
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(
range, chain,
))
.await?
else {
panic!("Database sent incorrect response!")

View file

@ -94,8 +94,8 @@ pub mod __private {
/// ```
pub trait Database:
tower::Service<
BlockchainReadRequest,
Response =BlockchainResponse,
BlockchainReadRequest,
Response = BlockchainResponse,
Error = tower::BoxError,
Future = Self::Future2,
>
@ -103,8 +103,13 @@ pub mod __private {
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
}
impl<T: tower::Service<BlockchainReadRequest, Response =BlockchainResponse, Error = tower::BoxError>>
crate::Database for T
impl<
T: tower::Service<
BlockchainReadRequest,
Response = BlockchainResponse,
Error = tower::BoxError,
>,
> crate::Database for T
where
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
{

View file

@ -343,7 +343,9 @@ where
let BlockchainResponse::FilterUnknownHashes(known_hashes) = database
.ready()
.await?
.call(BlockchainReadRequest::FilterUnknownHashes(verified_at_block_hashes))
.call(BlockchainReadRequest::FilterUnknownHashes(
verified_at_block_hashes,
))
.await?
else {
panic!("Database returned wrong response!");

View file

@ -21,7 +21,16 @@ use crate::{
///
/// # Errors
/// This will forward the error if [`crate::open`] failed.
pub fn init(config: Config) -> Result<(BlockchainReadHandle, BlockchainWriteHandle, Arc<ConcreteEnv>), InitError> {
pub fn init(
config: Config,
) -> Result<
(
BlockchainReadHandle,
BlockchainWriteHandle,
Arc<ConcreteEnv>,
),
InitError,
> {
let reader_threads = config.reader_threads;
// Initialize the database itself.

View file

@ -37,7 +37,7 @@
//! - The last [`BlockchainWriteHandle`] is dropped => writer thread exits
//!
//! TODO: update this when `ConcreteEnv` is removed
//!
//!
//! Upon dropping the [`cuprate_database::ConcreteEnv`]:
//! - All un-processed database transactions are completed
//! - All data gets flushed to disk (caused by [`Drop::drop`] impl on `ConcreteEnv`)

View file

@ -58,7 +58,10 @@ pub fn init_read_service(env: Arc<ConcreteEnv>, threads: ReaderThreads) -> Block
/// is the correct way to get multiple handles to the database.
#[cold]
#[inline(never)] // Only called once.
pub fn init_read_service_with_pool(env: Arc<ConcreteEnv>, pool: Arc<ThreadPool>) -> BlockchainReadHandle {
pub fn init_read_service_with_pool(
env: Arc<ConcreteEnv>,
pool: Arc<ThreadPool>,
) -> BlockchainReadHandle {
DatabaseReadService::new(env, pool, map_request)
}
@ -74,7 +77,7 @@ pub fn init_read_service_with_pool(env: Arc<ConcreteEnv>, pool: Arc<ThreadPool>)
/// 2. Handler function is called
/// 3. [`BlockchainResponse`] is returned
fn map_request(
env: &ConcreteEnv, // Access to the database
env: &ConcreteEnv, // Access to the database
request: BlockchainReadRequest, // The request we must fulfill
) -> ResponseResult {
use BlockchainReadRequest as R;
@ -281,10 +284,9 @@ fn generated_coins(env: &ConcreteEnv, height: u64) -> ResponseResult {
let tx_ro = env_inner.tx_ro()?;
let table_block_infos = env_inner.open_db_ro::<BlockInfos>(&tx_ro)?;
Ok(BlockchainResponse::GeneratedCoins(cumulative_generated_coins(
&height,
&table_block_infos,
)?))
Ok(BlockchainResponse::GeneratedCoins(
cumulative_generated_coins(&height, &table_block_infos)?,
))
}
/// [`BlockchainReadRequest::Outputs`].
@ -405,7 +407,7 @@ fn key_images_spent(env: &ConcreteEnv, key_images: HashSet<KeyImage>) -> Respons
.find_any(|result| !matches!(result, Ok(false)))
{
None | Some(Ok(false)) => Ok(BlockchainResponse::KeyImagesSpent(false)), // Key image was NOT found.
Some(Ok(true)) => Ok(BlockchainResponse::KeyImagesSpent(true)), // Key image was found.
Some(Ok(true)) => Ok(BlockchainResponse::KeyImagesSpent(true)), // Key image was found.
Some(Err(e)) => Err(e), // A database error occurred.
}
}

View file

@ -148,7 +148,9 @@ async fn test_template(
))
};
let cumulative_generated_coins = Ok(BlockchainResponse::GeneratedCoins(cumulative_generated_coins));
let cumulative_generated_coins = Ok(BlockchainResponse::GeneratedCoins(
cumulative_generated_coins,
));
let num_req = tables
.outputs_iter()
@ -186,8 +188,14 @@ async fn test_template(
BlockchainReadRequest::BlockExtendedHeader(1),
extended_block_header_1,
),
(BlockchainReadRequest::BlockHash(0, Chain::Main), block_hash_0),
(BlockchainReadRequest::BlockHash(1, Chain::Main), block_hash_1),
(
BlockchainReadRequest::BlockHash(0, Chain::Main),
block_hash_0,
),
(
BlockchainReadRequest::BlockHash(1, Chain::Main),
block_hash_1,
),
(
BlockchainReadRequest::BlockExtendedHeaderInRange(0..1, Chain::Main),
range_0_1,
@ -201,7 +209,10 @@ async fn test_template(
BlockchainReadRequest::GeneratedCoins(test_chain_height),
cumulative_generated_coins,
),
(BlockchainReadRequest::NumberOutputsWithAmount(num_req), num_resp),
(
BlockchainReadRequest::NumberOutputsWithAmount(num_req),
num_resp,
),
(BlockchainReadRequest::KeyImagesSpent(ki_req), ki_resp),
] {
let response = reader.clone().oneshot(request).await;

View file

@ -3,7 +3,9 @@
//---------------------------------------------------------------------------------------------------- Use
use cuprate_database::RuntimeError;
use cuprate_database_service::{DatabaseReadService, DatabaseWriteHandle};
use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest};
use cuprate_types::blockchain::{
BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest,
};
//---------------------------------------------------------------------------------------------------- Types
/// The actual type of the response.

View file

@ -23,7 +23,10 @@ pub fn init_write_service(env: Arc<ConcreteEnv>) -> BlockchainWriteHandle {
//---------------------------------------------------------------------------------------------------- handle_bc_request
/// Handle an incoming [`BlockchainWriteRequest`], returning a [`BlockchainResponse`].
fn handle_blockchain_request(env: &ConcreteEnv, req: &BlockchainWriteRequest) -> Result<BlockchainResponse, RuntimeError> {
fn handle_blockchain_request(
env: &ConcreteEnv,
req: &BlockchainWriteRequest,
) -> Result<BlockchainResponse, RuntimeError> {
match req {
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
}