From 1919fb3190fd6d52865d62fe1e1342d8f8142648 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Mon, 5 Aug 2024 16:22:06 +0100 Subject: [PATCH] cargo fmt --- consensus/src/context/alt_chains.rs | 5 +++-- consensus/src/context/task.rs | 5 ++++- consensus/src/context/weight.rs | 8 ++++++-- consensus/src/lib.rs | 13 +++++++++---- consensus/src/transactions.rs | 4 +++- storage/blockchain/src/service/free.rs | 11 ++++++++++- storage/blockchain/src/service/mod.rs | 2 +- storage/blockchain/src/service/read.rs | 16 +++++++++------- storage/blockchain/src/service/tests.rs | 19 +++++++++++++++---- storage/blockchain/src/service/types.rs | 4 +++- storage/blockchain/src/service/write.rs | 5 ++++- 11 files changed, 67 insertions(+), 25 deletions(-) diff --git a/consensus/src/context/alt_chains.rs b/consensus/src/context/alt_chains.rs index 3c3a1fa3..f0c391d6 100644 --- a/consensus/src/context/alt_chains.rs +++ b/consensus/src/context/alt_chains.rs @@ -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"); }; diff --git a/consensus/src/context/task.rs b/consensus/src/context/task.rs index 83b674cb..79ddf4c8 100644 --- a/consensus/src/context/task.rs +++ b/consensus/src/context/task.rs @@ -262,7 +262,10 @@ impl ContextTask { .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!"); diff --git a/consensus/src/context/weight.rs b/consensus/src/context/weight.rs index 5162ed2d..7cd5454e 100644 --- a/consensus/src/context/weight.rs +++ b/consensus/src/context/weight.rs @@ -297,7 +297,9 @@ async fn get_blocks_weight_in_range( 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( 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!") diff --git a/consensus/src/lib.rs b/consensus/src/lib.rs index 5bc6e313..3b7f2ae1 100644 --- a/consensus/src/lib.rs +++ b/consensus/src/lib.rs @@ -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> + Send + 'static; } - impl> - crate::Database for T + impl< + T: tower::Service< + BlockchainReadRequest, + Response = BlockchainResponse, + Error = tower::BoxError, + >, + > crate::Database for T where T::Future: Future> + Send + 'static, { diff --git a/consensus/src/transactions.rs b/consensus/src/transactions.rs index cbdabfd2..78104e95 100644 --- a/consensus/src/transactions.rs +++ b/consensus/src/transactions.rs @@ -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!"); diff --git a/storage/blockchain/src/service/free.rs b/storage/blockchain/src/service/free.rs index 65078826..21fb05ba 100644 --- a/storage/blockchain/src/service/free.rs +++ b/storage/blockchain/src/service/free.rs @@ -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), InitError> { +pub fn init( + config: Config, +) -> Result< + ( + BlockchainReadHandle, + BlockchainWriteHandle, + Arc, + ), + InitError, +> { let reader_threads = config.reader_threads; // Initialize the database itself. diff --git a/storage/blockchain/src/service/mod.rs b/storage/blockchain/src/service/mod.rs index 049a0f24..993c52db 100644 --- a/storage/blockchain/src/service/mod.rs +++ b/storage/blockchain/src/service/mod.rs @@ -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`) diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index d405ec0b..fbd9f894 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -58,7 +58,10 @@ pub fn init_read_service(env: Arc, 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, pool: Arc) -> BlockchainReadHandle { +pub fn init_read_service_with_pool( + env: Arc, + pool: Arc, +) -> BlockchainReadHandle { DatabaseReadService::new(env, pool, map_request) } @@ -74,7 +77,7 @@ pub fn init_read_service_with_pool(env: Arc, pool: Arc) /// 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::(&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) -> 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. } } diff --git a/storage/blockchain/src/service/tests.rs b/storage/blockchain/src/service/tests.rs index ae628bfd..72b60e2e 100644 --- a/storage/blockchain/src/service/tests.rs +++ b/storage/blockchain/src/service/tests.rs @@ -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; diff --git a/storage/blockchain/src/service/types.rs b/storage/blockchain/src/service/types.rs index cbc53980..9cd86e9c 100644 --- a/storage/blockchain/src/service/types.rs +++ b/storage/blockchain/src/service/types.rs @@ -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. diff --git a/storage/blockchain/src/service/write.rs b/storage/blockchain/src/service/write.rs index fefcce4f..816afc4f 100644 --- a/storage/blockchain/src/service/write.rs +++ b/storage/blockchain/src/service/write.rs @@ -23,7 +23,10 @@ pub fn init_write_service(env: Arc) -> BlockchainWriteHandle { //---------------------------------------------------------------------------------------------------- handle_bc_request /// Handle an incoming [`BlockchainWriteRequest`], returning a [`BlockchainResponse`]. -fn handle_blockchain_request(env: &ConcreteEnv, req: &BlockchainWriteRequest) -> Result { +fn handle_blockchain_request( + env: &ConcreteEnv, + req: &BlockchainWriteRequest, +) -> Result { match req { BlockchainWriteRequest::WriteBlock(block) => write_block(env, block), }