<p>You have a few things wrong.</p>

<blockquote>
  <p>1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.</p>
</blockquote>

<p>Alice probably already has the Merkle root, since it is part of the block header.  The first step in validating a transaction is making sure that block that contains it is real.  Even <a href="https://en.bitcoin.it/wiki/Thin_Client_Security" rel="nofollow noreferrer">SPV clients</a> store all the block headers of the entire chain, so they already have every Merkle root.</p>

<blockquote>
  <p>2) Some miners among her peer nodes will locate the block that includes the transaction</p>
</blockquote>

<p>This is more or less correct, except that the nodes do <em>not</em> have to be miners.  There are plenty of full nodes with full copies of the blockchain on the network that can be queried for these hashes.</p>

<blockquote>
  <p>3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions</p>
</blockquote>

<p>Full nodes store all transactions, and returning the hashes of the Merkle tree is not too computationally intensive.  You can read more about this in the <a href="https://bitcoin.org/en/developer-guide#transaction-data" rel="nofollow noreferrer">Transaction Data section of the Developer Guide</a>.</p>

<blockquote>
  <p>4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.</p>
</blockquote>

<p>Again, it is not necessarily (or even usually) miners who will send the hashes of the Merkle path that are needed.  It will usually be non-mining full nodes.  And as mentioned before, the block header and Merkle root do not need to be requested.</p>

<p>In the end, Alice is the one validating her transaction, but doing so by using additional information provided by full nodes on the network.  The work that the full nodes do to supply this data is important, yet not too computationally intensive.  For example, my Raspberry Pi 2 works just fine as a full node.  As for who pays the full nodes for their service...well...nobody.  This has been a topic of much debate.</p>

<p>In the end, however, people operate full nodes for several reasons.  Off the top of my head:</p>

<ul>
<li>so they can operate trustlessly</li>
<li>as a service to the overall health of the network (which, in turn, protects their own investments)</li>
<li>for research or business purposes</li>
</ul>

<p>So even though supplying the required data for thin clients to do transaction verification can be viewed as charity, in reality there are incentives for participating...even if not directly financial.</p>

CC BY-SA 3.0
2017-02-09T20:23:01.230Z
I read the "Transaction Data section of the Developer Guide" and then go to the SPV section (https://bitcoin.org/en/developer-guide#simplified-payment-verification-spv). Now I understand this. Thanks for explaining the motivations that why people want to run full nodes.
zhanxw
CC BY-SA 3.0
2017-02-09T16:57:39.123Z
2017-02-09T16:57:39.123Z
Jestin
<blockquote>
  <p>Suppose Alice wants to validate a transaction</p>
  
  <p>suppose her has not downloaded all transaction history.</p>
</blockquote>

<p>That's not possible. In order to validate a transaction you must have the entire state of the ledger before that point. Either you validated the entire history yourself, or you copied the result of that history (the chainstate, who owns which coins and how much are they worth) from someone you ultimately trust.</p>

<blockquote>
  <p>1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.</p>
</blockquote>

<p>That's not what happens when validating a transaction, but what lightweight (non-validating) clients do in order to check the transaction exists. It relies on the fact that miners will not produce a block with invalid transaction, and thus implicitly trust that when it appears in a block, it is valid.</p>

<p>Also, the request is not really "give me all the data necessary to prove transaction X exists". The request is "give me all transactions that match criteria A, and include the proofs that they're real. See BIP37 for more information, but know that now it is known that this method has very bad privacy implications.</p>

<blockquote>
  <p>2) Some miners among her peer nodes will locate the block that includes the transaction</p>
</blockquote>

<p>Miners only have a function in creating blocks, not looking things up in it. After a block is created, and propagated across the network, any node can look things up in it.</p>

<blockquote>
  <p>3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions</p>
</blockquote>

<p>Miners do that at the time they create a block, but every fully-validating node does that to when they receive a block. It's not done separately for each transaction.</p>

<blockquote>
  <p>4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.</p>
</blockquote>

<p>Again, not miners. Any full node that Alice is connected to and supports BIP37 will do that.</p>

<blockquote>
  <p>Since the step 3 requires computational resources, my questions is why some nodes want to perform these computations for Alice? It seems that these nodes will not get paid for validating an old transaction.</p>
</blockquote>

<p>Step 3 requires some resources, but they vanish compared to the work of actually validating transactions (validating signatures, checking that no coins are double spent). However, all of these steps are only done by nodes that fully validate.</p>

<p>Most of your question does not seem to be about validation, but about BIP37 as a means for a lightweight clients to obtain assurance that what their peers tell them about new transactions it is correct. That does have a cost, but the cost is mostly in scanning through the blockchain to find transactions Alice is interested in. This costs CPU and disk accesses, but only very little memory. In recent versions of Bitcoin Core, BIP37 support was made optional for that reason.</p>

CC BY-SA 3.0
2017-02-09T20:24:15.613Z
Thanks. It is very help for me to understand BIP37 (https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki).
zhanxw
CC BY-SA 3.0
2017-02-09T16:59:17.260Z
2017-02-09T16:59:17.260Z
Pieter Wuille
<p>Suppose Alice wants to validate a transaction (check this transaction does exist, not make a new transaction), 
and suppose her has not downloaded all transaction history.</p>

<p>My understanding is,</p>

<p>1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.</p>

<p>2) Some miners among her peer nodes will locate the block that includes the transaction</p>

<p>3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions</p>

<p>4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.</p>

<p>Since the step 3 requires computational resources, my questions is why some nodes want to perform these computations for Alice? 
It seems that these nodes will not get paid for validating an old transaction.</p>

<transaction-verification>
Who pays for the computational cost when validating a transaction
zhanxw
# Who pays for the computational cost when validating a transaction

(Asked by: username_0 on 2017-02-09)

Suppose Alice wants to validate a transaction (check this transaction does exist, not make a new transaction),
and suppose her has not downloaded all transaction history.

My understanding is,

1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.

2) Some miners among her peer nodes will locate the block that includes the transaction

3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions

4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.

Since the step 3 requires computational resources, my questions is why some nodes want to perform these computations for Alice?
It seems that these nodes will not get paid for validating an old transaction.

**Tags:** transaction-verification


---

## 2 answers

### Answer by username_1 on 2017-02-09. Score: 3 | Accepted answer

You have a few things wrong.

> 1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.

Alice probably already has the Merkle root, since it is part of the block header. The first step in validating a transaction is making sure that block that contains it is real. Even [SPV clients](https://en.bitcoin.it/wiki/Thin_Client_Security) store all the block headers of the entire chain, so they already have every Merkle root.

> 2) Some miners among her peer nodes will locate the block that includes the transaction

This is more or less correct, except that the nodes do *not* have to be miners. There are plenty of full nodes with full copies of the blockchain on the network that can be queried for these hashes.

> 3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions

Full nodes store all transactions, and returning the hashes of the Merkle tree is not too computationally intensive. You can read more about this in the [Transaction Data section of the Developer Guide](https://bitcoin.org/en/developer-guide#transaction-data).

> 4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.

Again, it is not necessarily (or even usually) miners who will send the hashes of the Merkle path that are needed. It will usually be non-mining full nodes. And as mentioned before, the block header and Merkle root do not need to be requested.

In the end, Alice is the one validating her transaction, but doing so by using additional information provided by full nodes on the network. The work that the full nodes do to supply this data is important, yet not too computationally intensive. For example, my Raspberry Pi 2 works just fine as a full node. As for who pays the full nodes for their service...well...nobody. This has been a topic of much debate.

In the end, however, people operate full nodes for several reasons. Off the top of my head:

* so they can operate trustlessly
* as a service to the overall health of the network (which, in turn, protects their own investments)
* for research or business purposes

So even though supplying the required data for thin clients to do transaction verification can be viewed as charity, in reality there are incentives for participating...even if not directly financial.

> **Comments:**
> **username_0**: I read the "Transaction Data section of the Developer Guide" and then go to the SPV section (https://bitcoin.org/en/developer-guide#simplified-payment-verification-spv). Now I understand this. Thanks for explaining the motivations that why people want to run full nodes.  

---

### Answer by username_2 on 2017-02-09. Score: 3

> Suppose Alice wants to validate a transaction
>
> suppose her has not downloaded all transaction history.

That's not possible. In order to validate a transaction you must have the entire state of the ledger before that point. Either you validated the entire history yourself, or you copied the result of that history (the chainstate, who owns which coins and how much are they worth) from someone you ultimately trust.

> 1) Alice will send a request to all her peer computer nodes and ask for the root the Merkel tree and hashes required to validate the transaction.

That's not what happens when validating a transaction, but what lightweight (non-validating) clients do in order to check the transaction exists. It relies on the fact that miners will not produce a block with invalid transaction, and thus implicitly trust that when it appears in a block, it is valid.

Also, the request is not really "give me all the data necessary to prove transaction X exists". The request is "give me all transactions that match criteria A, and include the proofs that they're real. See BIP37 for more information, but know that now it is known that this method has very bad privacy implications.

> 2) Some miners among her peer nodes will locate the block that includes the transaction

Miners only have a function in creating blocks, not looking things up in it. After a block is created, and propagated across the network, any node can look things up in it.

> 3) As block only stores Merkle tree root, not internal nodes, these miners will have to construct a Merkle tree from all transactions

Miners do that at the time they create a block, but every fully-validating node does that to when they receive a block. It's not done separately for each transaction.

> 4) The miners send block header and hashes (Merkle tree root and hashes on the authentication path) back to Alice.

Again, not miners. Any full node that Alice is connected to and supports BIP37 will do that.

> Since the step 3 requires computational resources, my questions is why some nodes want to perform these computations for Alice? It seems that these nodes will not get paid for validating an old transaction.

Step 3 requires some resources, but they vanish compared to the work of actually validating transactions (validating signatures, checking that no coins are double spent). However, all of these steps are only done by nodes that fully validate.

Most of your question does not seem to be about validation, but about BIP37 as a means for a lightweight clients to obtain assurance that what their peers tell them about new transactions it is correct. That does have a cost, but the cost is mostly in scanning through the blockchain to find transactions Alice is interested in. This costs CPU and disk accesses, but only very little memory. In recent versions of Bitcoin Core, BIP37 support was made optional for that reason.

> **Comments:**
> **username_0**: Thanks. It is very help for me to understand BIP37 (https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki).  

---

