Verifying transation inputs

5

1

I have a question about practical implementation of one part of Bitcoin protocol.

I'm reading the Protocol Rules for Bitcoin - "tx" messages and point 14 states that "For each input, if the referenced output has already been spent by a transaction in the main branch, reject this transaction".

How does the client validate that output has not been spent? It seems that it should remember all transations and amount of Bitcoins for all known addresses. This would take a lot of memory to store them all. Is there an optimization I'm not aware of?

wix

Posted 2012-12-10T21:14:27.437

Reputation: 53

Answers

3

Actually, that is exactly what happens, and it is the reason why synchronizing the block chain is so slow: we download all blocks, with all transaction history in it, and build and maintain an index that states which transaction output was spent or not, and even where it was spent.

As of 0.8, the reference client will switch to a new model where no such index is maintained anymore. Instead, it will maintain a copy of the set of transactions, but only with their not-yet-spent outputs, which is much smaller than the full data (around 150 MiB as of writing, december 10, 2012).

Pieter Wuille

Posted 2012-12-10T21:14:27.437

Reputation: 54 032

1

Thank you for detailed answer. Is there a commit or a file in https://github.com/bitcoin/bitcoin that shows current and/or new transation behavior?

wix 2012-12-11T09:27:27.073