diff --git a/binaries/cuprated/Cuprated.toml b/binaries/cuprated/Cuprated.toml index 7c465985..2b277ded 100644 --- a/binaries/cuprated/Cuprated.toml +++ b/binaries/cuprated/Cuprated.toml @@ -11,8 +11,10 @@ network = "Mainnet" ## Tracing config. [tracing] -## The minimum level for log events to be displayed. -level = "info" +## The stdout loggig config. +stdout = { level = "info" } +## The file output logging config. +file = { level = "debug", max_log_files = 7 } ## Clear-net config. [p2p.clear_net] @@ -49,11 +51,6 @@ target_batch_bytes= 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 = "Percent(0.25)" - ## Txpool storage config. [storage.txpool] ## The database sync mode for the txpool. diff --git a/binaries/cuprated/src/config.rs b/binaries/cuprated/src/config.rs index 8f151f03..f5343597 100644 --- a/binaries/cuprated/src/config.rs +++ b/binaries/cuprated/src/config.rs @@ -69,7 +69,7 @@ pub fn read_config_and_args() -> Config { } /// The config for all of Cuprate. -#[derive(Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct Config { /// The network we should run on. diff --git a/binaries/cuprated/src/config/fs.rs b/binaries/cuprated/src/config/fs.rs index f8f61307..96057129 100644 --- a/binaries/cuprated/src/config/fs.rs +++ b/binaries/cuprated/src/config/fs.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use cuprate_helper::fs::{CUPRATE_CACHE_DIR, CUPRATE_DATA_DIR}; -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct FileSystemConfig { pub data_directory: PathBuf, diff --git a/binaries/cuprated/src/config/p2p.rs b/binaries/cuprated/src/config/p2p.rs index 51f8d0d6..cc6b5ab9 100644 --- a/binaries/cuprated/src/config/p2p.rs +++ b/binaries/cuprated/src/config/p2p.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use cuprate_helper::{fs::address_book_path, network::Network}; /// P2P config. -#[derive(Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct P2PConfig { /// Clear-net config. @@ -18,7 +18,7 @@ pub struct P2PConfig { pub block_downloader: BlockDownloaderConfig, } -#[derive(Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct BlockDownloaderConfig { /// The size in bytes of the buffer between the block downloader and the place which @@ -56,7 +56,7 @@ impl Default for BlockDownloaderConfig { } /// The config values for P2P clear-net. -#[derive(Deserialize, Serialize)] +#[derive(Debug,Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct ClearNetConfig { /// The server config. @@ -75,7 +75,7 @@ impl Default for ClearNetConfig { } /// Network config values shared between all network zones. -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct SharedNetConfig { /// The number of outbound connections to make and try keep. @@ -111,7 +111,7 @@ impl SharedNetConfig { impl Default for SharedNetConfig { fn default() -> Self { Self { - outbound_connections: 64, + outbound_connections: 32, extra_outbound_connections: 8, max_inbound_connections: 128, gray_peers_percent: 0.7, @@ -121,7 +121,7 @@ impl Default for SharedNetConfig { } } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct AddressBookConfig { max_white_list_length: usize, @@ -134,7 +134,7 @@ impl Default for AddressBookConfig { Self { max_white_list_length: 1_000, max_gray_list_length: 5_000, - peer_save_period: Duration::from_secs(30), + peer_save_period: Duration::from_secs(90), } } } diff --git a/binaries/cuprated/src/config/rayon.rs b/binaries/cuprated/src/config/rayon.rs index 361c9573..a216fb70 100644 --- a/binaries/cuprated/src/config/rayon.rs +++ b/binaries/cuprated/src/config/rayon.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct RayonConfig { pub threads: usize, diff --git a/binaries/cuprated/src/config/storage.rs b/binaries/cuprated/src/config/storage.rs index df390fba..cd330804 100644 --- a/binaries/cuprated/src/config/storage.rs +++ b/binaries/cuprated/src/config/storage.rs @@ -7,11 +7,11 @@ use cuprate_database_service::ReaderThreads; use cuprate_helper::fs::CUPRATE_DATA_DIR; /// The storage config. -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct StorageConfig { /// The amount of reader threads to spawn between the tx-pool and blockchain. - pub reader_threads: ReaderThreads, + pub reader_threads: usize, /// The tx-pool config. pub txpool: TxpoolConfig, /// The blockchain config. @@ -21,7 +21,7 @@ pub struct StorageConfig { impl Default for StorageConfig { fn default() -> Self { Self { - reader_threads: ReaderThreads::Percent(0.25), + reader_threads: std::thread::available_parallelism().unwrap().get().div_ceil(4), txpool: Default::default(), blockchain: Default::default(), } @@ -29,7 +29,7 @@ impl Default for StorageConfig { } /// The blockchain config. -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct BlockchainConfig { #[serde(flatten)] @@ -47,7 +47,7 @@ impl Default for BlockchainConfig { } /// The tx-pool config. -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct TxpoolConfig { #[serde(flatten)] @@ -69,7 +69,7 @@ impl Default for TxpoolConfig { } /// Config values shared between the tx-pool and blockchain. -#[derive(Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct SharedStorageConfig { /// The [`SyncMode`] of the database. diff --git a/binaries/cuprated/src/config/tokio.rs b/binaries/cuprated/src/config/tokio.rs index dd215889..0063ddfd 100644 --- a/binaries/cuprated/src/config/tokio.rs +++ b/binaries/cuprated/src/config/tokio.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; /// [`tokio`] config. -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct TokioConfig { /// The amount of threads to spawn for the async thread-pool diff --git a/binaries/cuprated/src/config/tracing_config.rs b/binaries/cuprated/src/config/tracing_config.rs index 88d274af..bd96e29d 100644 --- a/binaries/cuprated/src/config/tracing_config.rs +++ b/binaries/cuprated/src/config/tracing_config.rs @@ -2,14 +2,14 @@ use serde::{Deserialize, Serialize}; use tracing::level_filters::LevelFilter; /// [`tracing`] config. -#[derive(Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct TracingConfig { pub stdout: StdoutTracingConfig, pub file: FileTracingConfig, } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct StdoutTracingConfig { /// The default minimum log level. @@ -25,7 +25,7 @@ impl Default for StdoutTracingConfig { } } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(deny_unknown_fields, default)] pub struct FileTracingConfig { /// The default minimum log level. diff --git a/binaries/cuprated/src/constants.rs b/binaries/cuprated/src/constants.rs index 057e8bd0..24d7273a 100644 --- a/binaries/cuprated/src/constants.rs +++ b/binaries/cuprated/src/constants.rs @@ -42,5 +42,7 @@ mod test { #[test] fn generate_config_text_is_valid() { let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap(); + + assert_eq!(config, Config::default()); } } diff --git a/binaries/cuprated/src/p2p/request_handler.rs b/binaries/cuprated/src/p2p/request_handler.rs index 7d72fa37..620c9df3 100644 --- a/binaries/cuprated/src/p2p/request_handler.rs +++ b/binaries/cuprated/src/p2p/request_handler.rs @@ -238,7 +238,7 @@ async fn get_chain( split_u128_into_low_high_bits(cumulative_difficulty); Ok(ProtocolResponse::GetChain(ChainResponse { - start_height: usize_to_u64(std::num::NonZero::get(start_height)), + start_height: usize_to_u64(start_height), total_height: usize_to_u64(chain_height), cumulative_difficulty_low64, cumulative_difficulty_top64, diff --git a/p2p/address-book/src/book.rs b/p2p/address-book/src/book.rs index 3e5269f5..0b1421d0 100644 --- a/p2p/address-book/src/book.rs +++ b/p2p/address-book/src/book.rs @@ -302,9 +302,12 @@ impl AddressBook { if peb.pruning_seed != peer.pruning_seed { return Err(AddressBookError::PeersDataChanged("Pruning seed")); } + /* if Z::CHECK_NODE_ID && peb.id != peer.id { return Err(AddressBookError::PeersDataChanged("peer ID")); } + + */ // TODO: cuprate doesn't need last seen timestamps but should we have them anyway? peb.last_seen = 0; peb.rpc_port = peer.rpc_port; diff --git a/p2p/p2p/src/inbound_server.rs b/p2p/p2p/src/inbound_server.rs index 0479560b..3669dfd2 100644 --- a/p2p/p2p/src/inbound_server.rs +++ b/p2p/p2p/src/inbound_server.rs @@ -115,8 +115,11 @@ where tokio::spawn( async move { let client = timeout(HANDSHAKE_TIMEOUT, fut).await; - if let Ok(Ok(peer)) = client { - drop(new_connection_tx.send(peer).await); + + match client { + Ok(Ok(peer)) => drop(new_connection_tx.send(peer).await), + Err(_) => tracing::debug!("Timed out"), + Ok(Err(e)) => tracing::debug!("error: {e:?}") } } .instrument(Span::current()), diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index 863f9ab0..45c5aa6f 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -631,7 +631,7 @@ fn next_chain_entry( }; Ok(BlockchainResponse::NextChainEntry { - start_height: std::num::NonZero::new(first_known_height), + start_height: Some(first_known_height), chain_height, block_ids, block_weights, diff --git a/types/src/blockchain.rs b/types/src/blockchain.rs index 7518935d..58a23b2a 100644 --- a/types/src/blockchain.rs +++ b/types/src/blockchain.rs @@ -288,7 +288,7 @@ pub enum BlockchainResponse { /// If all blocks were unknown `start_height` will be [`None`], the other fields will be meaningless. NextChainEntry { /// The start height of this entry, [`None`] if we could not find the split point. - start_height: Option>, + start_height: Option, /// The current chain height. chain_height: usize, /// The next block hashes in the entry.