2

The only way i can visualize the process is: search the blockchain for all the transactions that have the same source address as the transaction being processed, add them all up (including the trx being processed) to verify they add up to less than or equal to the source transaction amount.

Doing this for every bitcoin transaction sounds horribly inefficient.

How do they really do it?

user2223142
  • 119
  • 3
  • 8

1 Answers1

7

Miners and all full nodes do check the entire blockchain to validate a new transaction, but they are able to do it efficiently.

As they scan the blockchain starting at genesis, they update a memory structure consisting only of unspent outputs, and index that set. With the index, checking whether a new transaction's inputs have not been spent before is very fast. Currently there are about 8 million unspent transaction outputs.

Bitcoin transactions do not spend amounts from addresses. They fully spend a set of outputs, each from a specific earlier transaction. The reference to an output in an earlier transaction is not by its address: that would be ambiguous. Instead, it is by the numerical sequence of the output inside the earlier transaction.

Some web tools, notably blockchain.info, give the impression that things work differently, but they create that impression on their own, from the actual situation described above.

Tom Harding
  • 179
  • 2
  • Thank you very much Tom. The change in perspective from address to outputs and keeping an "index" of unspent amounts all makes perfect sense. – user2223142 May 25 '15 at 22:07
  • I'm still confused with your explanation, can you give me another resource? Thanks – FDuldul Apr 28 '18 at 19:00
  • 1
    You can search on "UTXO "for lots of attempts at an intuitive explanation. Most of them make things sound complicated though. Try forgetting bank balances and focusing on cash. When you spend cash, you give the ACTUAL bills and coins to the next guy. That's similar to how bitcoin works, but to spend bitcoin, you always destroy coins you were given earlier and make new ones to give to your payee. – Tom Harding Apr 29 '18 at 19:37