diff --git a/node/README.md b/node/README.md index 3442a3b..f1f542f 100644 --- a/node/README.md +++ b/node/README.md @@ -9,21 +9,26 @@ To start fast IBD: cargo run --bin ibd --release -- ``` - ``` Arguments: - --hintfile The path to your `bitcoin.hints` file that will be - used for IBD - --blocks-dir Directory where you would like to store the bitcoin - blocks - --network The bitcoin network to operate on. Options are ` - bitcoin` or `signet` - --ping-timeout The time a peer has to respond to a `ping` message. - Pings are sent aggressively throughout IBD to find - slow peers. - --tcp-timeout The maximum time to establish a connection - --read-timeout The maximum time to read from a TCP stream until the - connection is killed. - --write-timeout The maximum time to write to a TCP stream until the - connection is killed. + + --hintfile The path to your `bitcoin.hints` file that will + be used for IBD. Default is `./bitcoin.hints + --blocks-dir Directory where you would like to store the + bitcoin blocks. Default `./blockfiles` + --network The bitcoin network to operate on. Default ` + bitcoin`. Options are `bitcoin` or `signet` + --ping-timeout The time (seconds) a peer has to respond to a ` + ping` message. Pings are sent aggressively + throughout IBD to find slow peers. + --tcp-timeout The maximum time (seconds) to establish a + connection + --read-timeout The maximum time (seconds) to read from a TCP + stream until the connection is killed. + --write-timeout The maximum time (seconds) to write to a TCP + stream until the connection is killed. + --min-blocks-per-sec The minimum rate a peer has to respond to block + requests. + --tasks The number of tasks to download blocks. Default + is 64. Each task uses two OS threads. ``` diff --git a/node/config_spec.toml b/node/config_spec.toml index e418eda..c39fd23 100644 --- a/node/config_spec.toml +++ b/node/config_spec.toml @@ -2,40 +2,52 @@ name = "hintfile" type = "String" default = "\"./bitcoin.hints\".into()" -doc = "The path to your `bitcoin.hints` file that will be used for IBD" +doc = "The path to your `bitcoin.hints` file that will be used for IBD. Default is `./bitcoin.hints" [[param]] name = "blocks_dir" type = "String" default = "\"./blockfiles\".into()" -doc = "Directory where you would like to store the bitcoin blocks" +doc = "Directory where you would like to store the bitcoin blocks. Default `./blockfiles`" [[param]] name = "network" type = "String" default = "\"bitcoin\".into()" -doc = "The bitcoin network to operate on. Options are `bitcoin` or `signet`" +doc = "The bitcoin network to operate on. Default `bitcoin`. Options are `bitcoin` or `signet`" [[param]] name = "ping_timeout" type = "u64" default = "15" -doc = "The time a peer has to respond to a `ping` message. Pings are sent aggressively throughout IBD to find slow peers." +doc = "The time (seconds) a peer has to respond to a `ping` message. Pings are sent aggressively throughout IBD to find slow peers." [[param]] name = "tcp_timeout" type = "u64" default = "2" -doc = "The maximum time to establish a connection" +doc = "The maximum time (seconds) to establish a connection" [[param]] name = "read_timeout" type = "u64" default = "2" -doc = "The maximum time to read from a TCP stream until the connection is killed." +doc = "The maximum time (seconds) to read from a TCP stream until the connection is killed." [[param]] name = "write_timeout" type = "u64" default = "2" -doc = "The maximum time to write to a TCP stream until the connection is killed." +doc = "The maximum time (seconds) to write to a TCP stream until the connection is killed." + +[[param]] +name = "min_blocks_per_sec" +type = "f64" +default = "1." +doc = "The minimum rate a peer has to respond to block requests." + +[[param]] +name = "tasks" +type = "usize" +default = "64" +doc = "The number of tasks to download blocks. Default is 64. Each task uses two OS threads." diff --git a/node/src/bin/ibd.rs b/node/src/bin/ibd.rs index 468b944..357321d 100644 --- a/node/src/bin/ibd.rs +++ b/node/src/bin/ibd.rs @@ -15,7 +15,6 @@ use node::{ }; use p2p::net::TimeoutParams; -const TASKS: usize = 256; const PING_INTERVAL: Duration = Duration::from_secs(15); configure_me::include_config!(); @@ -29,6 +28,8 @@ fn main() { .parse::() .expect("invalid network string"); let ping_timeout = Duration::from_secs(config.ping_timeout); + let block_per_sec = config.min_blocks_per_sec; + let task_num = config.tasks; let tcp_timeout = Duration::from_secs(config.tcp_timeout); let read_timeout = Duration::from_secs(config.read_timeout); let write_timeout = Duration::from_secs(config.write_timeout); @@ -73,7 +74,7 @@ fn main() { let acc_task = std::thread::spawn(move || accumulator_state.verify()); let peers = Arc::new(Mutex::new(peers)); let mut tasks = Vec::new(); - let chunk_size = chain.best_header().height() as usize / TASKS; + let chunk_size = chain.best_header().height() as usize / task_num; let hashes = hashes_from_chain(Arc::clone(&chain), chunk_size); for (task_id, chunk) in hashes.into_iter().enumerate() { let chain = Arc::clone(&chain); @@ -85,6 +86,7 @@ fn main() { get_blocks_for_range( task_id as u32, timeout_conf, + block_per_sec, ping_timeout, network, &block_file_path, diff --git a/node/src/lib.rs b/node/src/lib.rs index f6dea77..c0cc8d5 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -152,6 +152,7 @@ pub fn sync_block_headers( pub fn get_blocks_for_range( task_id: u32, timeout_params: TimeoutParams, + blocks_per_sec: f64, ping_timeout: Duration, network: Network, block_dir: &Path, @@ -271,7 +272,7 @@ pub fn get_blocks_for_range( let Some(rate) = message_rate.messages_per_secs(Instant::now()) else { continue; }; - if rate < 2. { + if rate < blocks_per_sec { tracing::warn!("Disconnecting from {task_id} for stalling"); break; }