Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ cargo run --bin ibd --release -- <args>

```
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.
Expand All @@ -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.
```
29 changes: 15 additions & 14 deletions node/config_spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
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"
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"
Expand All @@ -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."
8 changes: 5 additions & 3 deletions node/src/bin/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BlockHash>(&hints.stop_hash()).expect("stop hash is not valid");
tracing::info!("Assume valid hash: {stop_hash}");
Expand Down Expand Up @@ -88,7 +90,7 @@ fn main() {
block_per_sec,
ping_timeout,
network,
&block_file_path,
block_file_path,
chain,
&hints,
peers,
Expand Down
33 changes: 18 additions & 15 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
fs::File,
io::Write,
net::{IpAddr, Ipv4Addr, SocketAddr},
path::Path,
path::PathBuf,
sync::{
mpsc::{Receiver, Sender},
Arc, Mutex,
Expand Down Expand Up @@ -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<PathBuf>,
chain: Arc<ChainstateManager>,
hints: &Hints,
peers: Arc<Mutex<Vec<SocketAddr>>>,
Expand Down Expand Up @@ -222,19 +222,22 @@ pub fn get_blocks_for_range(
let unspent_indexes: HashSet<u64> =
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;
Expand Down