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
35 changes: 20 additions & 15 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ To start fast IBD:
cargo run --bin ibd --release -- <args>
```


```
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.
```
26 changes: 19 additions & 7 deletions node/config_spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
6 changes: 4 additions & 2 deletions node/src/bin/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand All @@ -29,6 +28,8 @@ fn main() {
.parse::<Network>()
.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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
Loading