From 8ad5983e983d008c387ac5518b0517a108d81589 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Wed, 4 Dec 2024 18:58:50 +0000 Subject: [PATCH] todo --- Cuprated.toml | 67 --------------------- binaries/cuprated/Cuprated.toml | 2 +- binaries/cuprated/src/blockchain/manager.rs | 4 ++ binaries/cuprated/src/main.rs | 7 ++- storage/blockchain/src/service/free.rs | 25 +++++++- storage/blockchain/src/service/mod.rs | 2 +- storage/txpool/src/service.rs | 2 +- storage/txpool/src/service/free.rs | 18 ++++++ storage/txpool/src/service/read.rs | 2 +- 9 files changed, 54 insertions(+), 75 deletions(-) delete mode 100644 Cuprated.toml diff --git a/Cuprated.toml b/Cuprated.toml deleted file mode 100644 index 9a55ddae..00000000 --- a/Cuprated.toml +++ /dev/null @@ -1,67 +0,0 @@ -# ____ _ -# / ___| _ _ __ _ __ __ _| |_ ___ -# | | | | | | '_ \| '__/ _` | __/ _ \ -# | |__| |_| | |_) | | | (_| | || __/ -# \____\__,_| .__/|_| \__,_|\__\___| -# |_| -# - -## The network to run on, valid values: "Mainnet", "Testnet", "Stagenet". -network = "Mainnet" - -## Tracing config. -[tracing.stdout] -## The minimum level for log events to be displayed. -level = "info" - -## Clear-net config. -[p2p.clear_net] -## The number of outbound connections we should make and maintain. -outbound_connections = 64 -## The number of extra connections we should make under load from the rest of Cuprate, i.e. when syncing. -extra_outbound_connections = 8 -## The maximum number of incoming we should allow. -max_inbound_connections = 128 -## The percent of outbound connections that should be to nodes we have not connected to before. -gray_peers_percent = 0.7 -## The port to accept connections on, if left `0` no connections will be accepted. -p2p_port = 0 -## The IP address to listen to connections on. -listen_on = "0.0.0.0" - -## The Clear-net addressbook config. -[p2p.clear_net.address_book_config] -## The size of the white peer list, which contains peers we have made a connection to before. -max_white_list_length = 1_000 -## The size of the gray peer list, which contains peers we have not made a connection to before. -max_gray_list_length = 5_000 -## The amount of time between address book saves. -peer_save_period = { secs = 90, nanos = 0 } - -## The block downloader config. -[p2p.block_downloader] -## The size of the buffer of sequential blocks waiting to be verified and added to the chain (bytes). -buffer_size = 50_000_000 -## The size of the queue of blocks which are waiting for a parent block to be downloaded (bytes). -in_progress_queue_size = 50_000_000 -## The target size of a batch of blocks (bytes), must not exceed 100MB. -target_batch_size = 5_000_000 -## The amount of time between checking the pool of connected peers for free peers to download blocks. -check_client_pool_interval = { secs = 30, nanos = 0 } - -## Storage config -[storage] -## The amount of reader threads to spawn. -reader_threads = "OnePerThread" - -## Txpool storage config. -[storage.txpool] -## The database sync mode for the txpool. -sync_mode = "Async" -## The maximum size of all the txs in the pool (bytes). -max_txpool_byte_size = 100_000_000 - -## Blockchain storage config. -[storage.blockchain] -## The database sync mode for the blockchain. -sync_mode = "Async" diff --git a/binaries/cuprated/Cuprated.toml b/binaries/cuprated/Cuprated.toml index d248ce1f..c9d9de6e 100644 --- a/binaries/cuprated/Cuprated.toml +++ b/binaries/cuprated/Cuprated.toml @@ -17,7 +17,7 @@ level = "info" ## Clear-net config. [p2p.clear_net] ## The number of outbound connections we should make and maintain. -outbound_connections = 64 +outbound_connections = 32 ## The number of extra connections we should make under load from the rest of Cuprate, i.e. when syncing. extra_outbound_connections = 8 ## The maximum number of incoming we should allow. diff --git a/binaries/cuprated/src/blockchain/manager.rs b/binaries/cuprated/src/blockchain/manager.rs index 210c078a..609634c9 100644 --- a/binaries/cuprated/src/blockchain/manager.rs +++ b/binaries/cuprated/src/blockchain/manager.rs @@ -133,11 +133,15 @@ impl BlockchainManager { ) { loop { tokio::select! { + /* Some(batch) = block_batch_rx.recv() => { self.handle_incoming_block_batch( batch, ).await; } + + */ + Some(incoming_command) = command_rx.recv() => { self.handle_command(incoming_command).await; } diff --git a/binaries/cuprated/src/main.rs b/binaries/cuprated/src/main.rs index 812a8fc7..75db7408 100644 --- a/binaries/cuprated/src/main.rs +++ b/binaries/cuprated/src/main.rs @@ -47,10 +47,12 @@ fn main() { let rt = init_tokio_rt(); + let db_thread_pool = cuprate_database_service::init_thread_pool(cuprate_database_service::ReaderThreads::Percent(0.3)); + let (mut blockchain_read_handle, mut blockchain_write_handle, _) = - cuprate_blockchain::service::init(config.blockchain_config()).unwrap(); + cuprate_blockchain::service::init_with_pool(config.blockchain_config(), db_thread_pool.clone()).unwrap(); let (txpool_read_handle, txpool_write_handle, _) = - cuprate_txpool::service::init(config.txpool_config()).unwrap(); + cuprate_txpool::service::init_with_pool(config.txpool_config(), db_thread_pool).unwrap(); rt.block_on(async move { blockchain::check_add_genesis( @@ -105,6 +107,7 @@ fn main() { fn init_tokio_rt() -> tokio::runtime::Runtime { tokio::runtime::Builder::new_multi_thread() + .worker_threads(13) .enable_all() .build() .unwrap() diff --git a/storage/blockchain/src/service/free.rs b/storage/blockchain/src/service/free.rs index 7cc8da8a..75e98616 100644 --- a/storage/blockchain/src/service/free.rs +++ b/storage/blockchain/src/service/free.rs @@ -2,14 +2,14 @@ //---------------------------------------------------------------------------------------------------- Import use std::sync::Arc; - +use rayon::ThreadPool; use cuprate_database::{ConcreteEnv, InitError}; use cuprate_types::{AltBlockInformation, VerifiedBlockInformation}; use crate::{ config::Config, service::{ - init_read_service, init_write_service, + init_read_service, init_write_service, init_read_service_with_pool, types::{BlockchainReadHandle, BlockchainWriteHandle}, }, }; @@ -46,6 +46,27 @@ pub fn init( Ok((readers, writer, db)) } +pub fn init_with_pool( + config: Config, + pool: Arc, +) -> Result< + ( + BlockchainReadHandle, + BlockchainWriteHandle, + Arc, + ), + InitError, +> { + // Initialize the database itself. + let db = Arc::new(crate::open(config)?); + + // Spawn the Reader thread pool and Writer. + let readers = init_read_service_with_pool(Arc::clone(&db), pool); + let writer = init_write_service(Arc::clone(&db)); + + Ok((readers, writer, db)) +} + //---------------------------------------------------------------------------------------------------- Compact history /// Given a position in the compact history, returns the height offset that should be in that position. /// diff --git a/storage/blockchain/src/service/mod.rs b/storage/blockchain/src/service/mod.rs index d6a811bd..abe66f27 100644 --- a/storage/blockchain/src/service/mod.rs +++ b/storage/blockchain/src/service/mod.rs @@ -128,7 +128,7 @@ mod write; pub use write::init_write_service; mod free; -pub use free::init; +pub use free::{init, init_with_pool}; mod types; pub use types::{BlockchainReadHandle, BlockchainWriteHandle}; diff --git a/storage/txpool/src/service.rs b/storage/txpool/src/service.rs index 03ce2f03..08981a40 100644 --- a/storage/txpool/src/service.rs +++ b/storage/txpool/src/service.rs @@ -128,5 +128,5 @@ mod read; mod types; mod write; -pub use free::init; +pub use free::{init, init_with_pool}; pub use types::{TxpoolReadHandle, TxpoolWriteHandle}; diff --git a/storage/txpool/src/service/free.rs b/storage/txpool/src/service/free.rs index 003da552..67e656e6 100644 --- a/storage/txpool/src/service/free.rs +++ b/storage/txpool/src/service/free.rs @@ -1,5 +1,7 @@ use std::sync::Arc; +use rayon::ThreadPool; + use cuprate_database::{ConcreteEnv, InitError}; use crate::{ @@ -10,6 +12,7 @@ use crate::{ }, Config, }; +use crate::service::read::init_read_service_with_pool; //---------------------------------------------------------------------------------------------------- Init #[cold] @@ -35,3 +38,18 @@ pub fn init( Ok((readers, writer, db)) } + +pub fn init_with_pool( + config: Config, + pool: Arc, +) -> Result<(TxpoolReadHandle, TxpoolWriteHandle, Arc), InitError> { + // Initialize the database itself. + let db = Arc::new(crate::open(config)?); + + // Spawn the Reader thread pool and Writer. + let readers = init_read_service_with_pool(Arc::clone(&db), pool); + let writer = init_write_service(Arc::clone(&db)); + + Ok((readers, writer, db)) +} + diff --git a/storage/txpool/src/service/read.rs b/storage/txpool/src/service/read.rs index 44a29b3c..8e6b47e3 100644 --- a/storage/txpool/src/service/read.rs +++ b/storage/txpool/src/service/read.rs @@ -44,7 +44,7 @@ pub(super) fn init_read_service(env: Arc, threads: ReaderThreads) - /// Should be called _once_ per actual database. #[cold] #[inline(never)] // Only called once. -fn init_read_service_with_pool(env: Arc, pool: Arc) -> TxpoolReadHandle { +pub(super) fn init_read_service_with_pool(env: Arc, pool: Arc) -> TxpoolReadHandle { DatabaseReadService::new(env, pool, map_request) }