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:
parent
aa40a947ea
commit
b1b9525202
@ -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", ¶ms_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,
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user