Skip to content

Commit 964806f

Browse files
authored
Merge pull request #40 from rustaceanrob/8-19-ibd
node: Add more configurable IBD params
2 parents a3a6c5e + 99e80ed commit 964806f

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

node/README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ To start fast IBD:
99
cargo run --bin ibd --release -- <args>
1010
```
1111

12-
1312
```
1413
Arguments:
15-
--hintfile The path to your `bitcoin.hints` file that will be
16-
used for IBD
17-
--blocks-dir Directory where you would like to store the bitcoin
18-
blocks
19-
--network The bitcoin network to operate on. Options are `
20-
bitcoin` or `signet`
21-
--ping-timeout The time a peer has to respond to a `ping` message.
22-
Pings are sent aggressively throughout IBD to find
23-
slow peers.
24-
--tcp-timeout The maximum time to establish a connection
25-
--read-timeout The maximum time to read from a TCP stream until the
26-
connection is killed.
27-
--write-timeout The maximum time to write to a TCP stream until the
28-
connection is killed.
14+
15+
--hintfile The path to your `bitcoin.hints` file that will
16+
be used for IBD. Default is `./bitcoin.hints
17+
--blocks-dir Directory where you would like to store the
18+
bitcoin blocks. Default `./blockfiles`
19+
--network The bitcoin network to operate on. Default `
20+
bitcoin`. Options are `bitcoin` or `signet`
21+
--ping-timeout The time (seconds) a peer has to respond to a `
22+
ping` message. Pings are sent aggressively
23+
throughout IBD to find slow peers.
24+
--tcp-timeout The maximum time (seconds) to establish a
25+
connection
26+
--read-timeout The maximum time (seconds) to read from a TCP
27+
stream until the connection is killed.
28+
--write-timeout The maximum time (seconds) to write to a TCP
29+
stream until the connection is killed.
30+
--min-blocks-per-sec The minimum rate a peer has to respond to block
31+
requests.
32+
--tasks The number of tasks to download blocks. Default
33+
is 64. Each task uses two OS threads.
2934
```

node/config_spec.toml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,52 @@
22
name = "hintfile"
33
type = "String"
44
default = "\"./bitcoin.hints\".into()"
5-
doc = "The path to your `bitcoin.hints` file that will be used for IBD"
5+
doc = "The path to your `bitcoin.hints` file that will be used for IBD. Default is `./bitcoin.hints"
66

77
[[param]]
88
name = "blocks_dir"
99
type = "String"
1010
default = "\"./blockfiles\".into()"
11-
doc = "Directory where you would like to store the bitcoin blocks"
11+
doc = "Directory where you would like to store the bitcoin blocks. Default `./blockfiles`"
1212

1313
[[param]]
1414
name = "network"
1515
type = "String"
1616
default = "\"bitcoin\".into()"
17-
doc = "The bitcoin network to operate on. Options are `bitcoin` or `signet`"
17+
doc = "The bitcoin network to operate on. Default `bitcoin`. Options are `bitcoin` or `signet`"
1818

1919
[[param]]
2020
name = "ping_timeout"
2121
type = "u64"
2222
default = "15"
23-
doc = "The time a peer has to respond to a `ping` message. Pings are sent aggressively throughout IBD to find slow peers."
23+
doc = "The time (seconds) a peer has to respond to a `ping` message. Pings are sent aggressively throughout IBD to find slow peers."
2424

2525
[[param]]
2626
name = "tcp_timeout"
2727
type = "u64"
2828
default = "2"
29-
doc = "The maximum time to establish a connection"
29+
doc = "The maximum time (seconds) to establish a connection"
3030

3131
[[param]]
3232
name = "read_timeout"
3333
type = "u64"
3434
default = "2"
35-
doc = "The maximum time to read from a TCP stream until the connection is killed."
35+
doc = "The maximum time (seconds) to read from a TCP stream until the connection is killed."
3636

3737
[[param]]
3838
name = "write_timeout"
3939
type = "u64"
4040
default = "2"
41-
doc = "The maximum time to write to a TCP stream until the connection is killed."
41+
doc = "The maximum time (seconds) to write to a TCP stream until the connection is killed."
42+
43+
[[param]]
44+
name = "min_blocks_per_sec"
45+
type = "f64"
46+
default = "1."
47+
doc = "The minimum rate a peer has to respond to block requests."
48+
49+
[[param]]
50+
name = "tasks"
51+
type = "usize"
52+
default = "64"
53+
doc = "The number of tasks to download blocks. Default is 64. Each task uses two OS threads."

node/src/bin/ibd.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use node::{
1515
};
1616
use p2p::net::TimeoutParams;
1717

18-
const TASKS: usize = 256;
1918
const PING_INTERVAL: Duration = Duration::from_secs(15);
2019

2120
configure_me::include_config!();
@@ -29,6 +28,8 @@ fn main() {
2928
.parse::<Network>()
3029
.expect("invalid network string");
3130
let ping_timeout = Duration::from_secs(config.ping_timeout);
31+
let block_per_sec = config.min_blocks_per_sec;
32+
let task_num = config.tasks;
3233
let tcp_timeout = Duration::from_secs(config.tcp_timeout);
3334
let read_timeout = Duration::from_secs(config.read_timeout);
3435
let write_timeout = Duration::from_secs(config.write_timeout);
@@ -73,7 +74,7 @@ fn main() {
7374
let acc_task = std::thread::spawn(move || accumulator_state.verify());
7475
let peers = Arc::new(Mutex::new(peers));
7576
let mut tasks = Vec::new();
76-
let chunk_size = chain.best_header().height() as usize / TASKS;
77+
let chunk_size = chain.best_header().height() as usize / task_num;
7778
let hashes = hashes_from_chain(Arc::clone(&chain), chunk_size);
7879
for (task_id, chunk) in hashes.into_iter().enumerate() {
7980
let chain = Arc::clone(&chain);
@@ -85,6 +86,7 @@ fn main() {
8586
get_blocks_for_range(
8687
task_id as u32,
8788
timeout_conf,
89+
block_per_sec,
8890
ping_timeout,
8991
network,
9092
&block_file_path,

node/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub fn sync_block_headers(
152152
pub fn get_blocks_for_range(
153153
task_id: u32,
154154
timeout_params: TimeoutParams,
155+
blocks_per_sec: f64,
155156
ping_timeout: Duration,
156157
network: Network,
157158
block_dir: &Path,
@@ -271,7 +272,7 @@ pub fn get_blocks_for_range(
271272
let Some(rate) = message_rate.messages_per_secs(Instant::now()) else {
272273
continue;
273274
};
274-
if rate < 2. {
275+
if rate < blocks_per_sec {
275276
tracing::warn!("Disconnecting from {task_id} for stalling");
276277
break;
277278
}

0 commit comments

Comments
 (0)