mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-25 12:05:51 +00:00
cargo fmt
This commit is contained in:
parent
d4bd18ca57
commit
1919fb3190
11 changed files with 67 additions and 25 deletions
|
@ -100,8 +100,9 @@ impl AltChainMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the block with hash == prev_id.
|
// find the block with hash == prev_id.
|
||||||
let BlockchainResponse::FindBlock(res) =
|
let BlockchainResponse::FindBlock(res) = database
|
||||||
database.oneshot(BlockchainReadRequest::FindBlock(prev_id)).await?
|
.oneshot(BlockchainReadRequest::FindBlock(prev_id))
|
||||||
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database returned wrong response");
|
panic!("Database returned wrong response");
|
||||||
};
|
};
|
||||||
|
|
|
@ -262,7 +262,10 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
|
||||||
.database
|
.database
|
||||||
.ready()
|
.ready()
|
||||||
.await?
|
.await?
|
||||||
.call(BlockchainReadRequest::BlockHash(self.chain_height - 1, Chain::Main))
|
.call(BlockchainReadRequest::BlockHash(
|
||||||
|
self.chain_height - 1,
|
||||||
|
Chain::Main,
|
||||||
|
))
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database returned incorrect response!");
|
panic!("Database returned incorrect response!");
|
||||||
|
|
|
@ -297,7 +297,9 @@ async fn get_blocks_weight_in_range<D: Database + Clone>(
|
||||||
tracing::info!("getting block weights.");
|
tracing::info!("getting block weights.");
|
||||||
|
|
||||||
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
|
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
|
||||||
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(range, chain))
|
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(
|
||||||
|
range, chain,
|
||||||
|
))
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database sent incorrect response!")
|
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.");
|
tracing::info!("getting block long term weights.");
|
||||||
|
|
||||||
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
|
let BlockchainResponse::BlockExtendedHeaderInRange(ext_headers) = database
|
||||||
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(range, chain))
|
.oneshot(BlockchainReadRequest::BlockExtendedHeaderInRange(
|
||||||
|
range, chain,
|
||||||
|
))
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database sent incorrect response!")
|
panic!("Database sent incorrect response!")
|
||||||
|
|
|
@ -94,8 +94,8 @@ pub mod __private {
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Database:
|
pub trait Database:
|
||||||
tower::Service<
|
tower::Service<
|
||||||
BlockchainReadRequest,
|
BlockchainReadRequest,
|
||||||
Response =BlockchainResponse,
|
Response = BlockchainResponse,
|
||||||
Error = tower::BoxError,
|
Error = tower::BoxError,
|
||||||
Future = Self::Future2,
|
Future = Self::Future2,
|
||||||
>
|
>
|
||||||
|
@ -103,8 +103,13 @@ pub mod __private {
|
||||||
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
|
type Future2: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: tower::Service<BlockchainReadRequest, Response =BlockchainResponse, Error = tower::BoxError>>
|
impl<
|
||||||
crate::Database for T
|
T: tower::Service<
|
||||||
|
BlockchainReadRequest,
|
||||||
|
Response = BlockchainResponse,
|
||||||
|
Error = tower::BoxError,
|
||||||
|
>,
|
||||||
|
> crate::Database for T
|
||||||
where
|
where
|
||||||
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
|
T::Future: Future<Output = Result<Self::Response, Self::Error>> + Send + 'static,
|
||||||
{
|
{
|
||||||
|
|
|
@ -343,7 +343,9 @@ where
|
||||||
let BlockchainResponse::FilterUnknownHashes(known_hashes) = database
|
let BlockchainResponse::FilterUnknownHashes(known_hashes) = database
|
||||||
.ready()
|
.ready()
|
||||||
.await?
|
.await?
|
||||||
.call(BlockchainReadRequest::FilterUnknownHashes(verified_at_block_hashes))
|
.call(BlockchainReadRequest::FilterUnknownHashes(
|
||||||
|
verified_at_block_hashes,
|
||||||
|
))
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database returned wrong response!");
|
panic!("Database returned wrong response!");
|
||||||
|
|
|
@ -21,7 +21,16 @@ use crate::{
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// This will forward the error if [`crate::open`] failed.
|
/// 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;
|
let reader_threads = config.reader_threads;
|
||||||
|
|
||||||
// Initialize the database itself.
|
// Initialize the database itself.
|
||||||
|
|
|
@ -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.
|
/// is the correct way to get multiple handles to the database.
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)] // Only called once.
|
#[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)
|
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
|
/// 2. Handler function is called
|
||||||
/// 3. [`BlockchainResponse`] is returned
|
/// 3. [`BlockchainResponse`] is returned
|
||||||
fn map_request(
|
fn map_request(
|
||||||
env: &ConcreteEnv, // Access to the database
|
env: &ConcreteEnv, // Access to the database
|
||||||
request: BlockchainReadRequest, // The request we must fulfill
|
request: BlockchainReadRequest, // The request we must fulfill
|
||||||
) -> ResponseResult {
|
) -> ResponseResult {
|
||||||
use BlockchainReadRequest as R;
|
use BlockchainReadRequest as R;
|
||||||
|
@ -281,10 +284,9 @@ fn generated_coins(env: &ConcreteEnv, height: u64) -> ResponseResult {
|
||||||
let tx_ro = env_inner.tx_ro()?;
|
let tx_ro = env_inner.tx_ro()?;
|
||||||
let table_block_infos = env_inner.open_db_ro::<BlockInfos>(&tx_ro)?;
|
let table_block_infos = env_inner.open_db_ro::<BlockInfos>(&tx_ro)?;
|
||||||
|
|
||||||
Ok(BlockchainResponse::GeneratedCoins(cumulative_generated_coins(
|
Ok(BlockchainResponse::GeneratedCoins(
|
||||||
&height,
|
cumulative_generated_coins(&height, &table_block_infos)?,
|
||||||
&table_block_infos,
|
))
|
||||||
)?))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::Outputs`].
|
/// [`BlockchainReadRequest::Outputs`].
|
||||||
|
@ -405,7 +407,7 @@ fn key_images_spent(env: &ConcreteEnv, key_images: HashSet<KeyImage>) -> Respons
|
||||||
.find_any(|result| !matches!(result, Ok(false)))
|
.find_any(|result| !matches!(result, Ok(false)))
|
||||||
{
|
{
|
||||||
None | Some(Ok(false)) => Ok(BlockchainResponse::KeyImagesSpent(false)), // Key image was NOT found.
|
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.
|
Some(Err(e)) => Err(e), // A database error occurred.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
let num_req = tables
|
||||||
.outputs_iter()
|
.outputs_iter()
|
||||||
|
@ -186,8 +188,14 @@ async fn test_template(
|
||||||
BlockchainReadRequest::BlockExtendedHeader(1),
|
BlockchainReadRequest::BlockExtendedHeader(1),
|
||||||
extended_block_header_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),
|
BlockchainReadRequest::BlockExtendedHeaderInRange(0..1, Chain::Main),
|
||||||
range_0_1,
|
range_0_1,
|
||||||
|
@ -201,7 +209,10 @@ async fn test_template(
|
||||||
BlockchainReadRequest::GeneratedCoins(test_chain_height),
|
BlockchainReadRequest::GeneratedCoins(test_chain_height),
|
||||||
cumulative_generated_coins,
|
cumulative_generated_coins,
|
||||||
),
|
),
|
||||||
(BlockchainReadRequest::NumberOutputsWithAmount(num_req), num_resp),
|
(
|
||||||
|
BlockchainReadRequest::NumberOutputsWithAmount(num_req),
|
||||||
|
num_resp,
|
||||||
|
),
|
||||||
(BlockchainReadRequest::KeyImagesSpent(ki_req), ki_resp),
|
(BlockchainReadRequest::KeyImagesSpent(ki_req), ki_resp),
|
||||||
] {
|
] {
|
||||||
let response = reader.clone().oneshot(request).await;
|
let response = reader.clone().oneshot(request).await;
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
//---------------------------------------------------------------------------------------------------- Use
|
//---------------------------------------------------------------------------------------------------- Use
|
||||||
use cuprate_database::RuntimeError;
|
use cuprate_database::RuntimeError;
|
||||||
use cuprate_database_service::{DatabaseReadService, DatabaseWriteHandle};
|
use cuprate_database_service::{DatabaseReadService, DatabaseWriteHandle};
|
||||||
use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest};
|
use cuprate_types::blockchain::{
|
||||||
|
BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest,
|
||||||
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Types
|
//---------------------------------------------------------------------------------------------------- Types
|
||||||
/// The actual type of the response.
|
/// The actual type of the response.
|
||||||
|
|
|
@ -23,7 +23,10 @@ pub fn init_write_service(env: Arc<ConcreteEnv>) -> BlockchainWriteHandle {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- handle_bc_request
|
//---------------------------------------------------------------------------------------------------- handle_bc_request
|
||||||
/// Handle an incoming [`BlockchainWriteRequest`], returning a [`BlockchainResponse`].
|
/// 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 {
|
match req {
|
||||||
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
|
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue