Skip to content

Faster sync by collecting esplora ureq thread handles #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged
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
10 changes: 6 additions & 4 deletions src/blockchain/esplora/ureq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ impl WalletSync for EsploraBlockchain {
.take(self.concurrency as usize)
.cloned();

let handles = scripts.map(move |script| {
let mut handles = vec![];
for script in scripts {
let client = self.url_client.clone();
// make each request in its own thread.
std::thread::spawn(move || {
handles.push(std::thread::spawn(move || {
let mut related_txs: Vec<Tx> = client._scripthash_txs(&script, None)?;

let n_confirmed =
Expand All @@ -152,10 +153,11 @@ impl WalletSync for EsploraBlockchain {
}
}
Result::<_, Error>::Ok(related_txs)
})
});
}));
}

let txs_per_script: Vec<Vec<Tx>> = handles
.into_iter()
.map(|handle| handle.join().unwrap())
.collect::<Result<_, _>>()?;
let mut satisfaction = vec![];
Expand Down