0

By verification I do not mean the puzzle solving/hash calculating part but the part involving searching all of the blocks to check if the transaction is valid or not?

For example if A transferred some coins to B ten years ago and after that A didn't make any transaction. Now A wants to make some transaction. To verify this transaction, the miners need to know A's balance which was last updated ten years ago. To do this the miners have to traverse through huge number of blocks to the block of then, won't it take much time?

2 Answers 2

1

To do this the miners have to traverse through huge number of blocks to the block of then, won't it take much time?

When A wants to make a payment, he would reference the transaction txid and n in the input from where he earnt the bitcoins that he now wishes to spend. Full nodes generate an indexed database of all unspent transaction outputs (UTXOs), and refers to it when checking transactions for validity. This data is stored in $DATADIR/chainstate and aggressively cached in memory. Thus the nodes do not have to go through all the blocks prior to that, because they have all the unspent outputs handy. This functionality also allows full nodes to prune the blockchain to a desired size without losing the capability of verifying the transactions independently.

4
  • Does Merkle tree plays any role in this?
    – abhishek
    Apr 17, 2019 at 12:24
  • @abhisheksingla Merkle tree is basically constructed by grouping and hashing the txids of the transactions in the block until you get to the root. It can no way tell, if that transaction has been spent earlier. They can be used to inform, say a simplified node, that a particular transaction has been included in the block by providing them a merkle path.
    – Ugam Kamat
    Apr 17, 2019 at 12:27
  • can we say that merkle tree reduces the time to reach a particular transaction by providing the merkle path which should be the order of O(log(n)) being a binary tree? or is it a totally different thing and only "aggressively cached in memory" is responsible for verifying faster?
    – abhishek
    Apr 17, 2019 at 13:05
  • @abhisheksingla the latter. Caching UTXOs in the RAM is what allows faster transaction validation. If you do not have the UTXO set, you have to go through the entire blockchain to see that the transaction and vout referenced has not been spent earlier. In fact, when you initialize a full node, this UTXO set is built from scratch by checking all the way up from the genesis block.
    – Ugam Kamat
    Apr 17, 2019 at 13:17
0

Miners check the validity of a transaction by checking if its in the UTXO set. UTXO set are all the transaction that are unspent. Miners and every full node maintains the UTXO set in level db (I think!). So in order to see if a transaction is unspent or not, miner just need to check if the transaction is in UTXO set by using the transaction id.

2
  • Does Merkle tree plays any role in this?
    – abhishek
    Apr 17, 2019 at 12:23
  • I don't think merkle tree play any role in verifying an unspent transaction. Merkle tree is formed by the transactions that is included in a specific block.
    – spyder
    Apr 17, 2019 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.