mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-20 17:54:31 +00:00
fix small issue in block downloader more misc clean up
This commit is contained in:
parent
c657b9980d
commit
1f94a90c45
10 changed files with 18 additions and 65 deletions
|
@ -19,7 +19,7 @@ file = { level = "debug", max_log_files = 7 }
|
|||
## Clear-net config.
|
||||
[p2p.clear_net]
|
||||
## The number of outbound connections we should make and maintain.
|
||||
outbound_connections = 32
|
||||
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.
|
||||
|
@ -47,7 +47,7 @@ buffer_bytes = 50_000_000
|
|||
## The size of the queue of blocks which are waiting for a parent block to be downloaded (bytes).
|
||||
in_progress_queue_bytes = 50_000_000
|
||||
## The target size of a batch of blocks (bytes), must not exceed 100MB.
|
||||
target_batch_bytes = 15_000_000
|
||||
target_batch_bytes = 10_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 }
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ mod storage;
|
|||
mod tokio;
|
||||
mod tracing_config;
|
||||
|
||||
use crate::config::fs::FileSystemConfig;
|
||||
use crate::config::rayon::RayonConfig;
|
||||
use crate::config::tokio::TokioConfig;
|
||||
use fs::FileSystemConfig;
|
||||
use p2p::P2PConfig;
|
||||
use rayon::RayonConfig;
|
||||
use storage::StorageConfig;
|
||||
use tokio::TokioConfig;
|
||||
use tracing_config::TracingConfig;
|
||||
|
||||
/// Reads the args & config file, returning a [`Config`].
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
use std::{
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
str::from_utf8,
|
||||
};
|
||||
|
||||
use cuprate_helper::fs::{CUPRATE_CACHE_DIR, DEFAULT_CONFIG_FILE_NAME};
|
||||
|
||||
use crate::constants::EXAMPLE_CONFIG;
|
||||
|
||||
/// Creates a config file which will be named [`DEFAULT_CONFIG_FILE_NAME`] in the directory given in [`Path`].
|
||||
///
|
||||
/// This will always terminate the program, on success and failure.
|
||||
pub fn create_default_config_file(path: &Path) -> ! {
|
||||
let config_file = path.join(DEFAULT_CONFIG_FILE_NAME);
|
||||
|
||||
tracing::info!("Attempting to create new config file here: {config_file:?}");
|
||||
|
||||
let mut file = match std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&config_file)
|
||||
{
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to create config file, got error: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let config = EXAMPLE_CONFIG;
|
||||
file.write_all(config.as_bytes()).unwrap();
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{config::Config, constants::EXAMPLE_CONFIG};
|
||||
#[test]
|
||||
fn generate_config_text_is_valid() {
|
||||
let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap();
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ impl Default for BlockDownloaderConfig {
|
|||
buffer_bytes: 50_000_000,
|
||||
in_progress_queue_bytes: 50_000_000,
|
||||
check_client_pool_interval: Duration::from_secs(30),
|
||||
target_batch_bytes: 15_000_000,
|
||||
target_batch_bytes: 10_000_000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ impl SharedNetConfig {
|
|||
impl Default for SharedNetConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
outbound_connections: 32,
|
||||
outbound_connections: 64,
|
||||
extra_outbound_connections: 8,
|
||||
max_inbound_connections: 128,
|
||||
gray_peers_percent: 0.7,
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The [`rayon`] config.
|
||||
#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
pub struct RayonConfig {
|
||||
/// The number of threads to use for the [`rayon::ThreadPool`].
|
||||
pub threads: usize,
|
||||
}
|
||||
|
||||
impl Default for RayonConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// 75% available threads.
|
||||
threads: (std::thread::available_parallelism().unwrap().get() * 3).div_ceil(4),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ pub struct StorageConfig {
|
|||
impl Default for StorageConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// 25% available threads.
|
||||
reader_threads: std::thread::available_parallelism()
|
||||
.unwrap()
|
||||
.get()
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct TokioConfig {
|
|||
impl Default for TokioConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// 75% available threads.
|
||||
threads: (std::thread::available_parallelism().unwrap().get() * 3).div_ceil(4),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ pub struct FileTracingConfig {
|
|||
/// The default minimum log level.
|
||||
#[serde(with = "level_filter_serde")]
|
||||
pub level: LevelFilter,
|
||||
|
||||
/// The maximum amount of log files to keep, once this number is passed the oldest file
|
||||
/// will be deleted.
|
||||
pub max_log_files: usize,
|
||||
}
|
||||
|
||||
|
|
|
@ -302,12 +302,6 @@ impl<Z: BorshNetworkZone> AddressBook<Z> {
|
|||
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;
|
||||
|
|
|
@ -2,7 +2,6 @@ use std::collections::HashSet;
|
|||
|
||||
use monero_serai::{block::Block, transaction::Transaction};
|
||||
use rayon::prelude::*;
|
||||
use tokio::time::timeout;
|
||||
use tower::{Service, ServiceExt};
|
||||
use tracing::instrument;
|
||||
|
||||
|
@ -16,7 +15,7 @@ use cuprate_wire::protocol::{GetObjectsRequest, GetObjectsResponse};
|
|||
|
||||
use crate::{
|
||||
block_downloader::{BlockBatch, BlockDownloadError, BlockDownloadTaskResponse},
|
||||
constants::{BLOCK_DOWNLOADER_REQUEST_TIMEOUT, MAX_TRANSACTION_BLOB_SIZE, MEDIUM_BAN},
|
||||
constants::{MAX_TRANSACTION_BLOB_SIZE, MEDIUM_BAN},
|
||||
peer_set::ClientDropGuard,
|
||||
};
|
||||
|
||||
|
@ -60,17 +59,15 @@ async fn request_batch_from_peer<N: NetworkZone>(
|
|||
}));
|
||||
|
||||
// Request the blocks and add a timeout to the request
|
||||
let blocks_response = timeout(BLOCK_DOWNLOADER_REQUEST_TIMEOUT, async {
|
||||
let blocks_response = {
|
||||
let PeerResponse::Protocol(ProtocolResponse::GetObjects(blocks_response)) =
|
||||
client.ready().await?.call(request).await?
|
||||
else {
|
||||
panic!("Connection task returned wrong response.");
|
||||
};
|
||||
|
||||
Ok::<_, BlockDownloadError>(blocks_response)
|
||||
})
|
||||
.await
|
||||
.map_err(|_| BlockDownloadError::TimedOut)??;
|
||||
blocks_response
|
||||
};
|
||||
|
||||
// Initial sanity checks
|
||||
if blocks_response.blocks.len() > ids.len() {
|
||||
|
|
Loading…
Reference in a new issue