Skip to content

Commit

Permalink
Allow higher rpcworkqueue limit conf
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRubin committed Apr 19, 2024
1 parent 3b081a2 commit 0661c10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'index> Updater<'index> {
// Default rpcworkqueue in bitcoind is 16, meaning more than 16 concurrent requests will be rejected.
// Since we are already requesting blocks on a separate thread, and we don't want to break if anything
// else runs a request, we keep this to 12.
const PARALLEL_REQUESTS: usize = 12;
let parallel_requests: usize = settings.bitcoin_rpc_limit() as usize;

thread::spawn(move || {
let rt = tokio::runtime::Builder::new_multi_thread()
Expand All @@ -273,8 +273,8 @@ impl<'index> Updater<'index> {
outpoints.push(outpoint);
}
// Break outpoints into chunks for parallel requests
let chunk_size = (outpoints.len() / PARALLEL_REQUESTS) + 1;
let mut futs = Vec::with_capacity(PARALLEL_REQUESTS);
let chunk_size = (outpoints.len() / parallel_requests) + 1;
let mut futs = Vec::with_capacity(parallel_requests);
for chunk in outpoints.chunks(chunk_size) {
let txids = chunk.iter().map(|outpoint| outpoint.txid).collect();
let fut = fetcher.get_transactions(txids);
Expand Down
3 changes: 3 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Options {
help = "Authenticate to Bitcoin Core RPC as <BITCOIN_RPC_USERNAME>."
)]
pub(crate) bitcoin_rpc_username: Option<String>,

#[arg(long, help = "Max <N> requests in flight. [default: 12]")]
pub(crate) bitcoin_rpc_limit: Option<u32>,
#[arg(long = "chain", value_enum, help = "Use <CHAIN>. [default: mainnet]")]
pub(crate) chain_argument: Option<Chain>,
#[arg(
Expand Down
10 changes: 10 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Settings {
bitcoin_rpc_password: Option<String>,
bitcoin_rpc_url: Option<String>,
bitcoin_rpc_username: Option<String>,
bitcoin_rpc_limit: Option<u32>,
chain: Option<Chain>,
commit_interval: Option<usize>,
config: Option<PathBuf>,
Expand Down Expand Up @@ -111,6 +112,7 @@ impl Settings {
bitcoin_rpc_password: self.bitcoin_rpc_password.or(source.bitcoin_rpc_password),
bitcoin_rpc_url: self.bitcoin_rpc_url.or(source.bitcoin_rpc_url),
bitcoin_rpc_username: self.bitcoin_rpc_username.or(source.bitcoin_rpc_username),
bitcoin_rpc_limit: self.bitcoin_rpc_limit.or(source.bitcoin_rpc_limit),
chain: self.chain.or(source.chain),
commit_interval: self.commit_interval.or(source.commit_interval),
config: self.config.or(source.config),
Expand Down Expand Up @@ -150,6 +152,7 @@ impl Settings {
bitcoin_rpc_password: options.bitcoin_rpc_password,
bitcoin_rpc_url: options.bitcoin_rpc_url,
bitcoin_rpc_username: options.bitcoin_rpc_username,
bitcoin_rpc_limit: options.bitcoin_rpc_limit,
chain: options
.signet
.then_some(Chain::Signet)
Expand Down Expand Up @@ -233,6 +236,7 @@ impl Settings {
bitcoin_rpc_password: get_string("BITCOIN_RPC_PASSWORD"),
bitcoin_rpc_url: get_string("BITCOIN_RPC_URL"),
bitcoin_rpc_username: get_string("BITCOIN_RPC_USERNAME"),
bitcoin_rpc_limit: get_u32("BITCOIN_RPC_LIMIT")?,
chain: get_chain("CHAIN")?,
commit_interval: get_usize("COMMIT_INTERVAL")?,
config: get_path("CONFIG"),
Expand Down Expand Up @@ -262,6 +266,7 @@ impl Settings {
bitcoin_rpc_password: None,
bitcoin_rpc_url: Some(rpc_url.into()),
bitcoin_rpc_username: None,
bitcoin_rpc_limit: None,
chain: Some(Chain::Regtest),
commit_interval: None,
config: None,
Expand Down Expand Up @@ -328,6 +333,7 @@ impl Settings {
.unwrap_or_else(|| format!("127.0.0.1:{}", chain.default_rpc_port())),
),
bitcoin_rpc_username: self.bitcoin_rpc_username,
bitcoin_rpc_limit: Some(self.bitcoin_rpc_limit.unwrap_or(12)),
chain: Some(chain),
commit_interval: Some(self.commit_interval.unwrap_or(5000)),
config: None,
Expand Down Expand Up @@ -550,6 +556,10 @@ impl Settings {
}
}

pub(crate) fn bitcoin_rpc_limit(&self) -> u32 {
self.bitcoin_rpc_limit.unwrap()
}

pub(crate) fn server_url(&self) -> Option<&str> {
self.server_url.as_deref()
}
Expand Down

0 comments on commit 0661c10

Please sign in to comment.