<p>Transactions in forks are not verified completely until the node attempts to switch to that fork. Before that, only those checks are performed that don't depend on previous transactions. In the <a href="https://github.com/bitcoin/bitcoin/blob/3fd192f8b4d6db386354dfe635a8a6a105b55de8/src/main.cpp" rel="nofollow">source code</a>, there is a function <code>CheckBlock</code>, which does only some of the checks, and <code>ConnectBlock</code>, which checks everything. The latter function is called only when the block is about to be accepted into the longest chain, so the hash table of unspent outputs is available.</p>

CC BY-SA 3.0
2014-10-01T10:17:03.280Z
2014-10-01T10:17:03.280Z
abacabadabacaba
<p>In <a href="https://bitcoin.stackexchange.com/a/10602/75">this answer here</a>, it's stated that Bitcoin uses a hashtable of all currently unspent outputs, in order to verify that the inputs of transactions haven't already been spent.</p>

<p>How does this interact with forks? If the Bitcoin client receives some blocks that go at the end of a fork that isn't the longest fork (perhaps, once they have all been verified, the new fork will be longer), how does it know what outputs are unspent in the fork that the blocks are being added to? A hashtable of unspent outputs in the current longest fork won't cut it.</p>

<blockchain><block><blockchain-fork><chain-reorganization><architecture>
How are transactions in forks verified efficiently?
interfect
# How are transactions in forks verified efficiently?

(Asked by: username_0 on 2013-07-04)

In [this answer here](https://bitcoin.stackexchange.com/a/10602/75), it's stated that Bitcoin uses a hashtable of all currently unspent outputs, in order to verify that the inputs of transactions haven't already been spent.

How does this interact with forks? If the Bitcoin client receives some blocks that go at the end of a fork that isn't the longest fork (perhaps, once they have all been verified, the new fork will be longer), how does it know what outputs are unspent in the fork that the blocks are being added to? A hashtable of unspent outputs in the current longest fork won't cut it.

**Tags:** blockchain, block, blockchain-fork, chain-reorganization, architecture


---

## 1 answers

### Answer by username_1 on 2014-10-01. Score: 1

Transactions in forks are not verified completely until the node attempts to switch to that fork. Before that, only those checks are performed that don't depend on previous transactions. In the [source code](https://github.com/bitcoin/bitcoin/blob/3fd192f8b4d6db386354dfe635a8a6a105b55de8/src/main.cpp), there is a function `CheckBlock`, which does only some of the checks, and `ConnectBlock`, which checks everything. The latter function is called only when the block is about to be accepted into the longest chain, so the hash table of unspent outputs is available.


---

