diff --git a/node/README.md b/node/README.md index e920130..b850ced 100644 --- a/node/README.md +++ b/node/README.md @@ -19,13 +19,16 @@ cargo run --bin ibd --release -- ``` Arguments: - --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` + be used for IBD. Default is `./bitcoin.hints` + --blocks-dir Optional directory to store the blocks. Used + only to measure performance. --network The bitcoin network to operate on. Default ` bitcoin`. Options are `bitcoin` or `signet` + --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. --ping-timeout The time (seconds) a peer has to respond to a ` ping` message. Pings are sent aggressively throughout IBD to find slow peers. @@ -35,8 +38,4 @@ Arguments: 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 acb48ef..90d64ea 100644 --- a/node/config_spec.toml +++ b/node/config_spec.toml @@ -2,13 +2,13 @@ name = "hintfile" type = "String" default = "\"./bitcoin.hints\".into()" -doc = "The path to your `bitcoin.hints` file that will be used for IBD. Default is `./bitcoin.hints" +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. Default `./blockfiles`" +optional = true +doc = "Optional directory to store the blocks. Used only to measure performance." [[param]] name = "network" @@ -16,6 +16,18 @@ type = "String" default = "\"bitcoin\".into()" doc = "The bitcoin network to operate on. Default `bitcoin`. Options are `bitcoin` or `signet`" +[[param]] +name = "min_blocks_per_sec" +type = "f64" +default = "3." +doc = "The minimum rate a peer has to respond to block requests." + +[[param]] +name = "tasks" +type = "usize" +default = "32" +doc = "The number of tasks to download blocks. Default is 64. Each task uses two OS threads." + [[param]] name = "ping_timeout" type = "u64" @@ -40,14 +52,3 @@ type = "u64" default = "2" 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 = "3." -doc = "The minimum rate a peer has to respond to block requests." - -[[param]] -name = "tasks" -type = "usize" -default = "32" -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 256716d..447779b 100644 --- a/node/src/bin/ibd.rs +++ b/node/src/bin/ibd.rs @@ -45,8 +45,10 @@ fn main() { let mut hintfile = File::open(hint_path).expect("invalid hintfile path"); let hints = Arc::new(Hints::from_file(&mut hintfile)); elapsed_time(hintfile_start_time); - let block_file_path = PathBuf::from(&blocks_dir); - std::fs::create_dir(&block_file_path).expect("could not create block file directory"); + let block_file_path = blocks_dir.map(PathBuf::from); + if let Some(block_file_path) = block_file_path.as_ref() { + std::fs::create_dir(block_file_path).expect("could not create block file directory"); + } let stop_hash = consensus::deserialize::(&hints.stop_hash()).expect("stop hash is not valid"); tracing::info!("Assume valid hash: {stop_hash}"); @@ -88,7 +90,7 @@ fn main() { block_per_sec, ping_timeout, network, - &block_file_path, + block_file_path, chain, &hints, peers, diff --git a/node/src/lib.rs b/node/src/lib.rs index 47c1b91..8118611 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -3,7 +3,7 @@ use std::{ fs::File, io::Write, net::{IpAddr, Ipv4Addr, SocketAddr}, - path::Path, + path::PathBuf, sync::{ mpsc::{Receiver, Sender}, Arc, Mutex, @@ -170,7 +170,7 @@ pub fn get_blocks_for_range( blocks_per_sec: f64, _ping_timeout: Duration, network: Network, - block_dir: &Path, + block_dir: Option, chain: Arc, hints: &Hints, peers: Arc>>, @@ -222,19 +222,22 @@ pub fn get_blocks_for_range( let unspent_indexes: HashSet = hints.get_indexes(block_height).into_iter().collect(); // tracing::info!("{task_id} -> {block_height}:{hash}"); - let file_path = block_dir.join(format!("{hash}.block")); - let file = File::create_new(file_path); - let mut file = match file { - Ok(file) => file, - Err(e) => { - tracing::warn!("Conflicting open files at: {}", block_height); - tracing::warn!("{e}"); - panic!("files cannot conflict"); - } - }; - let block_bytes = consensus::serialize(&block); - file.write_all(&block_bytes) - .expect("failed to write block file"); + if let Some(block_dir) = block_dir.as_ref() { + let file_path = block_dir.join(format!("{hash}.block")); + let file = File::create_new(file_path); + let mut file = match file { + Ok(file) => file, + Err(e) => { + tracing::warn!("Conflicting open files at: {}", block_height); + tracing::warn!("{e}"); + panic!("files cannot conflict"); + } + }; + let block_bytes = consensus::serialize(&block); + file.write_all(&block_bytes) + .expect("failed to write block file"); + file.sync_data().expect("could not sync file with OS"); + } // tracing::info!("Wrote {hash} to file"); let (_, transactions) = block.into_parts(); let mut output_index = 0;