Merkle tree recalculation during transaction lookup
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.
- 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.
- Fetch all transactions from that block
- Calculate merkle tree
- 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.