<p>First of all: Bitcoin Core by default does not support BIP37 anymore, because it can be used as a computational, disk I/O, and bandwidth attack (because of points you bring up), and it has very weak privacy properties to begin with. It can still be enabled using <code>-peerbloomfilters</code>, but more modern approaches shouldn't depend on it.</p>
<blockquote>
<ol>
<li>Find a block in which given transaction ID exists</li>
</ol>
</blockquote>
<p>There is no way to issue a request for arbitrary transactions in the P2P protocol. You can only ask for recently-announce transactions (by txid, or wtxid), or for confirmed blocks (by block hash).</p>
<p>In the case of BIP37, it is possible for the client to send a filter of &quot;interesting&quot; addresses/scripts/transactions to the server, and then ask for blocks. The server will then filter the block for transactions that match the filter, and respond with those. But this does require the client to request all blocks individually - it cannot ask the server to go look for a certain transaction anywhere.</p>
<blockquote>
<ol start="2">
<li>Fetch all transactions from that block</li>
<li>Calculate merkle tree</li>
<li>Return merkle path with relevant hashes necessary to confirm merkle root</li>
</ol>
</blockquote>
<p>These steps are right, for the case where a client asks for a filtered block from a server.</p>

CC BY-SA 4.0
2021-11-29T01:28:44.750Z
2021-11-29T01:28:44.750Z
Pieter Wuille
<p>When full-node receives a request from SPV client to check if given transaction exists in the blockchain - does it always re-calculate the merkle tree on the fly in order to return merkle path + block header to SPV client for given transaction ID?</p>
<p>How does it look like from performance point of view? Is there is any merkle tree caching for example? Because as I understand the node will have to do the following steps:</p>
<ol>
<li>Find a block in which given transaction ID exists</li>
<li>Fetch all transactions from that block</li>
<li>Calculate merkle tree</li>
<li>Return merkle path with relevant hashes necessary to confirm merkle root</li>
</ol>

<merkle-tree>
Merkle tree recalculation during transaction lookup
user1453428
# Merkle tree recalculation during transaction lookup

(Asked by: username_0 on 2021-11-28)

When full-node receives a request from SPV client to check if given transaction exists in the blockchain - does it always re-calculate the merkle tree on the fly in order to return merkle path + block header to SPV client for given transaction ID?

How does it look like from performance point of view? Is there is any merkle tree caching for example? Because as I understand the node will have to do the following steps:

1. Find a block in which given transaction ID exists
2. Fetch all transactions from that block
3. Calculate merkle tree
4. Return merkle path with relevant hashes necessary to confirm merkle root

**Tags:** merkle-tree


---

## 1 answers

### Answer by username_1 on 2021-11-29. Score: 0 | Accepted answer

First of all: Bitcoin Core by default does not support BIP37 anymore, because it can be used as a computational, disk I/O, and bandwidth attack (because of points you bring up), and it has very weak privacy properties to begin with. It can still be enabled using `-peerbloomfilters`, but more modern approaches shouldn't depend on it.

> 1. Find a block in which given transaction ID exists

There is no way to issue a request for arbitrary transactions in the P2P protocol. You can only ask for recently-announce transactions (by txid, or wtxid), or for confirmed blocks (by block hash).

In the case of BIP37, it is possible for the client to send a filter of "interesting" addresses/scripts/transactions to the server, and then ask for blocks. The server will then filter the block for transactions that match the filter, and respond with those. But this does require the client to request all blocks individually - it cannot ask the server to go look for a certain transaction anywhere.

> 2. Fetch all transactions from that block
> 3. Calculate merkle tree
> 4. Return merkle path with relevant hashes necessary to confirm merkle root

These steps are right, for the case where a client asks for a filtered block from a server.


---

