Bitcoin Forum
May 28, 2024, 10:51:18 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How does the bitcoin client verify that an address has enough coins...  (Read 450 times)
fizgig (OP)
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
June 26, 2013, 01:08:55 AM
 #1

...for the transaction it is a part of (assuming it is the input)?

Does it have to look through the entire block chain to find every instance of that address and see what has been sent to it and what has been taken out of it?  If so, man is that going to get processor intensive in the future?  It can't be the case but I can't find out how this is accomplished anywhere.
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
June 26, 2013, 01:13:55 AM
 #2

...for the transaction it is a part of (assuming it is the input)?

Does it have to look through the entire block chain to find every instance of that address and see what has been sent to it and what has been taken out of it?  If so, man is that going to get processor intensive in the future?  It can't be the case but I can't find out how this is accomplished anywhere.

Addresses don't have coins.  Bitcoin works on the concept of outputs.  The input of all transactions is the output of a prior one.  The transaction ID of the output being spent is part of the transaction.  The bitcoin network simply looks up the transaction and verifies that it hasn't been spent before.

Your wallet doesn't need to do any checking to see "how much is taken out" because an output can only have two states.  Spent or unspent.  The client keeps a set of all unspent outputs (which is generally significantly smaller than the entire blockchain) called the UXTO.  It can quickly look for outputs to your addresses there and take the sum of those outputs.

When your wallet says "you have 13 BTC" what it means it "I have searched the UXTO and found a number of unspent outputs to addresses for which I have the private key, the sum of those unspent outputs is 13 BTC".

The efficiency of the verification of transactions and the computation of wallet value depends not on the blockchain but on the size of the UXTO.  This generally increases linearly with the number of users.   This is one reason why things like preventing uneconomical dust are important.   If the value of an output is less than the cost to spend it, it won't be spent and thus it will remain in the UXTO.  This reduces the efficiency of all nodes.
fizgig (OP)
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
June 26, 2013, 01:30:27 AM
 #3

Thank you for the reply.  Just fascinating.

So when I'm running bitcoin-qt, not only do I have the blockchain downloaded to my harddrive,  I also have the entire UXTO list (not just the UXTO that relate to me).  I guess it builds that list itself as it downloads the blockchain initially?
sabahgamemaker
Newbie
*
Offline Offline

Activity: 33
Merit: 0


View Profile
June 26, 2013, 02:28:16 AM
 #4

Thank you for the reply.  Just fascinating.

So when I'm running bitcoin-qt, not only do I have the blockchain downloaded to my harddrive,  I also have the entire UXTO list (not just the UXTO that relate to me).  I guess it builds that list itself as it downloads the blockchain initially?



yeah, the first time you synchronize it download the whole block. it resynchronizes every 10 mins and only download the latest block.
fizgig (OP)
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
June 26, 2013, 03:03:33 AM
 #5

That I get but I'm wondering about the UXTO list.  Is that created by the client after analyzing the block chain it downloads?  Does it keep the entire UXTO list (for the whole world) in a separate database or does it just keep transactions that relate to addresses in your wallet? 
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
June 26, 2013, 12:26:08 PM
 #6

That I get but I'm wondering about the UXTO list.  Is that created by the client after analyzing the block chain it downloads?  Does it keep the entire UXTO list (for the whole world) in a separate database or does it just keep transactions that relate to addresses in your wallet? 

There is no separate database but there is a UXTO index which allows quick lookup of transactions.  In theory one could prune the database such that only tx in the UXTO remain.  Your client updates the UXTO in realtime.  As it learns of new confirmed txs (via block notification) the inputs are removed from the UXTO and the new outputs are added.  The client attempts to cache the UXTO to memory (for faster verification) and flush spent outputs only to disk.  If you have sufficient memory available the overhead should be negligible and it allows near instantaneous lookup and valdation.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!