Commit bea7fd74 authored by Nadav Ivgi's avatar Nadav Ivgi
Browse files

Improve query.get_merkle_proof() performance

Query bitcoind for the list of txids in the block instead of
fetching the whole block, deserializing it and re-computing the txids.
parent 7061c53d
......@@ -474,6 +474,21 @@ impl Daemon {
pub fn getblocktxids(&self, blockhash: &Sha256dHash) -> Result<Vec<Sha256dHash>> {
json!([blockhash.be_hex_string(), /*verbose=*/ 1]),
.chain_err(|| "block missing txids")?
.chain_err(|| "invalid block txids")?
.map(|txid| {
Sha256dHash::from_hex(txid.as_str().chain_err(|| "txid not string")?)
.chain_err(|| "invalid hex")
pub fn getblocks(&self, blockhashes: &[Sha256dHash]) -> Result<Vec<Block>> {
let params_list: Vec<Value> = blockhashes
use bitcoin::blockdata::block::Block;
use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::deserialize;
use bitcoin::util::hash::Sha256dHash;
......@@ -378,8 +377,7 @@ impl Query {
.chain_err(|| format!("missing block #{}", height))?;
let block: Block =;
let mut txids: Vec<Sha256dHash> = block.txdata.iter().map(|tx| tx.txid()).collect();
let mut txids =;
let pos = txids
.position(|txid| txid == tx_hash)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment