<blockquote>
  <p>A mobile connects to a node using rpc.</p>
</blockquote>

<p>Nodes don't connect each other using RPC. RPC is for node owners, and usually has a long password.</p>

<blockquote>
  <p>The mobile then asks the node, to give him a set of transactions for a set of public keys.</p>
</blockquote>

<p>Not exactly. First of all, block headers have a part that's named "Merkle root" that allows clients to check if a transaction was in the block. In theory, as described in the whitepaper, SPV nodes can keep block headers, and ask other nodes for Merkle proof of their transaction. In practice, it's more complicated. Currently 99% of the SPV nodes use <a href="https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki" rel="nofollow noreferrer">BIP 37</a>. Besides, better SPV methods such as <a href="https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki" rel="nofollow noreferrer">BIP 157</a> and <a href="https://github.com/Roasbeef/bips/blob/master/gcs_light_client.mediawiki" rel="nofollow noreferrer">Neutrino</a> are being researched.</p>

<blockquote>
  <p>Also, when the node receives a request, it needs to scan the blockchain all over again, to get the transaction history?</p>
</blockquote>

<p>Nodes do need to scan the whole blockchain for a transaction if they don't know its block height, unless they use <code>txindex=1</code>, etc... If they do, accessing it is trivial.</p>

CC BY-SA 4.0
2018-06-18T13:50:03.383Z
If mobile/light clients do not use rpc, how is it possible for them to query nodes using commands like gettxout? Or other people to query nodes using gettxout?

Also, if I give the node the public key and not a transaction then it would need to scan the whole chain? Because light wallets give public keys to the full node and not transactions to my understanding
Kyle Graham
CC BY-SA 4.0
2018-06-18T14:05:52.403Z
They don't use `gettxout`. Here's [what they use](https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#new-messages). Furthermore, SPVs never hand out the public keys, that'd damage privacy.
MCCCS
CC BY-SA 4.0
2018-06-18T14:12:40.683Z
Oh, I thought filteradd was a rpc command. If they do not hand out public keys, then when an spv has gone away for a while, he will download the headers once he is back and then what does he send to the node, to get the relevant information? I see data in filteradd, but what is the data? Thanks again for the help
Kyle Graham
CC BY-SA 4.0
2018-06-18T14:50:42.017Z
Actually, my mistake. They do hand out public keys along with some fake public keys. (Only pre-Bip37 download-everything nodes don't share public keys, aka "pruned".) As described in the table below `merkleblock`, the nodes send [all transactions in those blocks]'s hashes. Filteradd tells the nodes which pubkeys the SPV is interested in. If the block didn't pass the bloom filter, the nodes can omit tx hashes and save data. May give some more details: https://bitcoin.stackexchange.com/a/11721/38618
MCCCS
CC BY-SA 4.0
2018-06-18T15:15:24.720Z
Ahh alright, the table is very helpful. Thanks for the information
Kyle Graham
CC BY-SA 4.0
2018-06-18T13:46:41.167Z
2018-06-18T14:03:21.263Z
2018-06-18T14:03:21.263Z
MCCCS
<p>Here is what I have so far:</p>

<ol>
<li>A mobile connects to a node using rpc. </li>
<li>The mobile then asks the node, to give him a set of transactions for a set of public keys.</li>
<li>The node, then looks for any transactions that match the public keys given and returns it back to the mobile.</li>
</ol>

<p>The mobile can setup a bloom filter, so that some of keys included are not his?</p>

<p>Also, when the node receives a request, it needs to scan the blockchain all over again, to get the transaction history?</p>

<spv><bip37-bloom-filter>
How exactly does SPV work?
Kyle Graham
# How exactly does SPV work?

(Asked by: username_0 on 2018-06-18)

Here is what I have so far:

1. A mobile connects to a node using rpc.
2. The mobile then asks the node, to give him a set of transactions for a set of public keys.
3. The node, then looks for any transactions that match the public keys given and returns it back to the mobile.

The mobile can setup a bloom filter, so that some of keys included are not his?

Also, when the node receives a request, it needs to scan the blockchain all over again, to get the transaction history?

**Tags:** spv, bip37-bloom-filter


---

## 1 answers

### Answer by username_1 on 2018-06-18. Score: 1

> A mobile connects to a node using rpc.

Nodes don't connect each other using RPC. RPC is for node owners, and usually has a long password.

> The mobile then asks the node, to give him a set of transactions for a set of public keys.

Not exactly. First of all, block headers have a part that's named "Merkle root" that allows clients to check if a transaction was in the block. In theory, as described in the whitepaper, SPV nodes can keep block headers, and ask other nodes for Merkle proof of their transaction. In practice, it's more complicated. Currently 99% of the SPV nodes use [BIP 37](https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki). Besides, better SPV methods such as [BIP 157](https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki) and [Neutrino](https://github.com/Roasbeef/bips/blob/master/gcs_light_client.mediawiki) are being researched.

> Also, when the node receives a request, it needs to scan the blockchain all over again, to get the transaction history?

Nodes do need to scan the whole blockchain for a transaction if they don't know its block height, unless they use `txindex=1`, etc... If they do, accessing it is trivial.

> **Comments:**
> **username_0**: If mobile/light clients do not use rpc, how is it possible for them to query nodes using commands like gettxout? Or other people to query nodes using gettxout?  Also, if I give the node the public key and not a transaction then it would need to scan the whole chain? Because light wallets give public keys to the full node and not transactions to my understanding  
> **username_1**: They don't use `gettxout`. Here's [what they use](https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#new-messages). Furthermore, SPVs never hand out the public keys, that'd damage privacy.  
> **username_0**: Oh, I thought filteradd was a rpc command. If they do not hand out public keys, then when an spv has gone away for a while, he will download the headers once he is back and then what does he send to the node, to get the relevant information? I see data in filteradd, but what is the data? Thanks again for the help  
> **username_1**: Actually, my mistake. They do hand out public keys along with some fake public keys. (Only pre-Bip37 download-everything nodes don't share public keys, aka "pruned".) As described in the table below `merkleblock`, the nodes send [all transactions in those blocks]'s hashes. Filteradd tells the nodes which pubkeys the SPV is interested in. If the block didn't pass the bloom filter, the nodes can omit tx hashes and save data. May give some more details: https://bitcoin.stackexchange.com/a/11721/38618  
> **username_0**: Ahh alright, the table is very helpful. Thanks for the information  

---

