1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Use non-batched getblock RPC

Following https://github.com/romanz/electrs/issues/373#issuecomment-785753029
This commit is contained in:
Roman Zeyde 2021-02-27 20:03:39 +02:00
parent aa40a947ea
commit b1b9525202
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 6 additions and 15 deletions

View File

@ -516,19 +516,6 @@ impl Daemon {
.get_or_else(&blockhash, || self.load_blocktxids(blockhash)) .get_or_else(&blockhash, || self.load_blocktxids(blockhash))
} }
pub fn getblocks(&self, blockhashes: &[BlockHash]) -> Result<Vec<Block>> {
let params_list: Vec<Value> = blockhashes
.iter()
.map(|hash| json!([hash.to_hex(), /*verbose=*/ false]))
.collect();
let values = self.requests("getblock", &params_list)?;
let mut blocks = vec![];
for value in values {
blocks.push(block_from_value(value)?);
}
Ok(blocks)
}
pub fn gettransaction( pub fn gettransaction(
&self, &self,
txhash: &Txid, txhash: &Txid,

View File

@ -384,9 +384,13 @@ impl Index {
let blockhashes: Vec<BlockHash> = new_headers.iter().map(|h| *h.hash()).collect(); let blockhashes: Vec<BlockHash> = new_headers.iter().map(|h| *h.hash()).collect();
let batch_size = self.batch_size; let batch_size = self.batch_size;
let fetcher = spawn_thread("fetcher", move || { let fetcher = spawn_thread("fetcher", move || {
for chunk in blockhashes.chunks(batch_size) { for blockhashes_chunk in blockhashes.chunks(batch_size) {
let blocks = blockhashes_chunk
.iter()
.map(|blockhash| daemon.getblock(blockhash))
.collect();
sender sender
.send(daemon.getblocks(&chunk)) .send(blocks)
.expect("failed sending blocks to be indexed"); .expect("failed sending blocks to be indexed");
} }
sender sender