## Does a Bitcoin node need to scan through the whole blockchain in order to be 100% sure that a transaction sent to it is genuine?

2

1

Does a Bitcoin node need to scan through the whole blockchain in order to be 100% sure that a transaction sent to it is genuine (especially when some inputs are derived from coins generated in the very early days)?

2

Yes. It doesn't have to do all the work when it receives the transaction, of course. If it's in sync with the network, it's already scanned the whole blockchain.

What do you mean by "it's already scanned the whole blockchain" ? Does the node build some kind of index of the transactions in the blockchain so that he can look it up faster than linear scan of the blockchain ? – user368507 – 2016-12-04T22:19:04.793

@user368507 Yes. What do you think it's doing when it gets all the blocks? It's building the UTXO (unspent transaction output) database. – David Schwartz – 2016-12-05T00:11:38.477

0

Yes, the whole blockchain needs to be scanned. But as David already says, it does so when it syncs/imports the whole blockchain.

So you can see it like this. When a new node is set up, it gets all the blocks from other nodes in the network and analyses them one by one. Every transaction is read and from all the transactions it creates a list of accounts that are on the network and how much bitcoins they have. So every bitcoin node has a list which more or less looks like this:

account number                               amount of bitcoins in account
-----------------------------------------------------------------------------
188CnLx8fqfS8jhFCqv7QF346L9V1136tp     |     0.329 BTC
1MmTK7DnVSeFQQJm6gd1txk8HEYZ2rQnLg     |     1.70908 BTC
15dEBJMy3GTJ8Fd2TMqaXcDB9qt9MPqNWc     |     1.299 BTC
1KoE88YBCP6ZuPq39uCTJNiBGM6XKzQZQS     |     0.393 BTC
34gRACXhU1SBR42d7B6BoJJ1U5M9mn5vXA     |     1.39899 BTC
37MEbe4MwSesFo3A4uJXuUHZ1mn4Gp6Z56     |     22.41484615 BTC
etc.


When a node receives a new transaction it can easily verify it by looking up the account number and see if it has enough bitcoins to do the transaction it wants to do.

I hope that makes it a bit more clear.

Talking about addresses as "accounts" having "balances" is extremely misleading. The node tracks Unspent Transaction Outputs (UTXOs) not "balances". – MeshCollider – 2017-07-07T10:35:12.423

@MeshCollider - yes, but the idea is the same: it knows how much can be spent from each address. This is just a beginners explanation which gives an idea of how it works. – kramer65 – 2017-07-07T11:44:17.823

That idea leads to a lot of confusion later on, for example: https://bitcoin.stackexchange.com/questions/55043/why-do-some-transactions-have-more-than-one-input

– MeshCollider – 2017-07-07T13:06:11.677