Skip to content

Commit c9a9377

Browse files
authored
Allow higher rpcworkqueue limit conf (ordinals#3615)
1 parent 2038575 commit c9a9377

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/index/updater.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<'index> Updater<'index> {
250250
// Default rpcworkqueue in bitcoind is 16, meaning more than 16 concurrent requests will be rejected.
251251
// Since we are already requesting blocks on a separate thread, and we don't want to break if anything
252252
// else runs a request, we keep this to 12.
253-
const PARALLEL_REQUESTS: usize = 12;
253+
let parallel_requests: usize = settings.bitcoin_rpc_limit() as usize;
254254

255255
thread::spawn(move || {
256256
let rt = tokio::runtime::Builder::new_multi_thread()
@@ -273,8 +273,8 @@ impl<'index> Updater<'index> {
273273
outpoints.push(outpoint);
274274
}
275275
// Break outpoints into chunks for parallel requests
276-
let chunk_size = (outpoints.len() / PARALLEL_REQUESTS) + 1;
277-
let mut futs = Vec::with_capacity(PARALLEL_REQUESTS);
276+
let chunk_size = (outpoints.len() / parallel_requests) + 1;
277+
let mut futs = Vec::with_capacity(parallel_requests);
278278
for chunk in outpoints.chunks(chunk_size) {
279279
let txids = chunk.iter().map(|outpoint| outpoint.txid).collect();
280280
let fut = fetcher.get_transactions(txids);

src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct Options {
2121
help = "Authenticate to Bitcoin Core RPC as <BITCOIN_RPC_USERNAME>."
2222
)]
2323
pub(crate) bitcoin_rpc_username: Option<String>,
24+
#[arg(long, help = "Max <N> requests in flight. [default: 12]")]
25+
pub(crate) bitcoin_rpc_limit: Option<u32>,
2426
#[arg(long = "chain", value_enum, help = "Use <CHAIN>. [default: mainnet]")]
2527
pub(crate) chain_argument: Option<Chain>,
2628
#[arg(

src/settings.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {super::*, bitcoincore_rpc::Auth};
44
#[serde(default, deny_unknown_fields)]
55
pub struct Settings {
66
bitcoin_data_dir: Option<PathBuf>,
7+
bitcoin_rpc_limit: Option<u32>,
78
bitcoin_rpc_password: Option<String>,
89
bitcoin_rpc_url: Option<String>,
910
bitcoin_rpc_username: Option<String>,
@@ -108,6 +109,7 @@ impl Settings {
108109
pub(crate) fn or(self, source: Settings) -> Self {
109110
Self {
110111
bitcoin_data_dir: self.bitcoin_data_dir.or(source.bitcoin_data_dir),
112+
bitcoin_rpc_limit: self.bitcoin_rpc_limit.or(source.bitcoin_rpc_limit),
111113
bitcoin_rpc_password: self.bitcoin_rpc_password.or(source.bitcoin_rpc_password),
112114
bitcoin_rpc_url: self.bitcoin_rpc_url.or(source.bitcoin_rpc_url),
113115
bitcoin_rpc_username: self.bitcoin_rpc_username.or(source.bitcoin_rpc_username),
@@ -147,6 +149,7 @@ impl Settings {
147149
pub(crate) fn from_options(options: Options) -> Self {
148150
Self {
149151
bitcoin_data_dir: options.bitcoin_data_dir,
152+
bitcoin_rpc_limit: options.bitcoin_rpc_limit,
150153
bitcoin_rpc_password: options.bitcoin_rpc_password,
151154
bitcoin_rpc_url: options.bitcoin_rpc_url,
152155
bitcoin_rpc_username: options.bitcoin_rpc_username,
@@ -230,6 +233,7 @@ impl Settings {
230233

231234
Ok(Self {
232235
bitcoin_data_dir: get_path("BITCOIN_DATA_DIR"),
236+
bitcoin_rpc_limit: get_u32("BITCOIN_RPC_LIMIT")?,
233237
bitcoin_rpc_password: get_string("BITCOIN_RPC_PASSWORD"),
234238
bitcoin_rpc_url: get_string("BITCOIN_RPC_URL"),
235239
bitcoin_rpc_username: get_string("BITCOIN_RPC_USERNAME"),
@@ -262,6 +266,7 @@ impl Settings {
262266
bitcoin_rpc_password: None,
263267
bitcoin_rpc_url: Some(rpc_url.into()),
264268
bitcoin_rpc_username: None,
269+
bitcoin_rpc_limit: None,
265270
chain: Some(Chain::Regtest),
266271
commit_interval: None,
267272
config: None,
@@ -320,6 +325,7 @@ impl Settings {
320325

321326
Ok(Self {
322327
bitcoin_data_dir: Some(bitcoin_data_dir),
328+
bitcoin_rpc_limit: Some(self.bitcoin_rpc_limit.unwrap_or(12)),
323329
bitcoin_rpc_password: self.bitcoin_rpc_password,
324330
bitcoin_rpc_url: Some(
325331
self
@@ -550,6 +556,10 @@ impl Settings {
550556
}
551557
}
552558

559+
pub(crate) fn bitcoin_rpc_limit(&self) -> u32 {
560+
self.bitcoin_rpc_limit.unwrap()
561+
}
562+
553563
pub(crate) fn server_url(&self) -> Option<&str> {
554564
self.server_url.as_deref()
555565
}
@@ -978,6 +988,7 @@ mod tests {
978988
fn from_env() {
979989
let env = vec![
980990
("BITCOIN_DATA_DIR", "/bitcoin/data/dir"),
991+
("BITCOIN_RPC_LIMIT", "12"),
981992
("BITCOIN_RPC_PASSWORD", "bitcoin password"),
982993
("BITCOIN_RPC_URL", "url"),
983994
("BITCOIN_RPC_USERNAME", "bitcoin username"),
@@ -1010,6 +1021,7 @@ mod tests {
10101021
Settings::from_env(env).unwrap(),
10111022
Settings {
10121023
bitcoin_data_dir: Some("/bitcoin/data/dir".into()),
1024+
bitcoin_rpc_limit: Some(12),
10131025
bitcoin_rpc_password: Some("bitcoin password".into()),
10141026
bitcoin_rpc_url: Some("url".into()),
10151027
bitcoin_rpc_username: Some("bitcoin username".into()),
@@ -1055,6 +1067,7 @@ mod tests {
10551067
Options::try_parse_from([
10561068
"ord",
10571069
"--bitcoin-data-dir=/bitcoin/data/dir",
1070+
"--bitcoin-rpc-limit=12",
10581071
"--bitcoin-rpc-password=bitcoin password",
10591072
"--bitcoin-rpc-url=url",
10601073
"--bitcoin-rpc-username=bitcoin username",
@@ -1081,6 +1094,7 @@ mod tests {
10811094
),
10821095
Settings {
10831096
bitcoin_data_dir: Some("/bitcoin/data/dir".into()),
1097+
bitcoin_rpc_limit: Some(12),
10841098
bitcoin_rpc_password: Some("bitcoin password".into()),
10851099
bitcoin_rpc_url: Some("url".into()),
10861100
bitcoin_rpc_username: Some("bitcoin username".into()),

tests/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn default() {
77
.stdout_regex(
88
r#"\{
99
"bitcoin_data_dir": ".*(Bitcoin|bitcoin)",
10+
"bitcoin_rpc_limit": 12,
1011
"bitcoin_rpc_password": null,
1112
"bitcoin_rpc_url": "127.0.0.1:8332",
1213
"bitcoin_rpc_username": null,

0 commit comments

Comments
 (0)