<p>When nodes start up and sync the blockchain, they create and maintain something known as the <code>utxo</code> database. This contains all transaction outputs that have not been spent.</p>

<p>As new blocks are broadcasted, the inputs being spent in the transactions in those blocks are removed from the utxo, and the new outputs that were created are added in. This will usually happen even when a tx is broadcast, before it is mined into a block. Trying to broadcast an additional tx with the same inputs will fail with a mempool-conflict.</p>

<p>This database is saved to disk, so shutting down and starting up a node is not as intensive as the first sync and scan.</p>

<p>The raw blockchain itself is simply a series of series of serialized blocks and their transactions - The UTXO set is not a separate part of it, and must be constructed by iterating over it block by block.</p>

CC BY-SA 4.0
2018-05-22T01:57:57.840Z
2018-05-22T01:57:57.840Z
Raghav Sood
<p>The ledger i.e. Block chain is stored on every computer (node) that partakes in the network. ... Block chain is stored on all the computers running Bitcoin node. There are thousands of computers running full node. Each of these node record every new transaction in the blockchain.</p>

CC BY-SA 4.0
2018-05-23T07:00:19.343Z
2018-05-23T07:00:19.343Z
Abhirup Bhattacharjee
<blockquote>
  <p>-but how do you find that hash without looking into every block on the blockchain?</p>
</blockquote>

<p>You can't. Of course, if you are smart, when you receive a block, you extract the data that you need and put it into a database where you store this information and can quickly look it up. So, starting from the beginning of the blockchain, you read through every block and every transaction, compute their hashes, and store in a separate database the hash and a pointer to where you can find the block or transaction (or something of that sort). So when you need to look up the outputs that a transaction spends, you can just lookup the txid in your database and be able to quickly find the transaction output that you need.</p>

<p>This is similar to what Bitcoin Core does. After it fully validates a block, it adds the UTXOs that are created to a separate database. That database contains the details for all of the UTXOs, so it has each UTXOs outpoint (txid + output index), the output value, and the output script. When a transaction spends a UTXO, it can be quickly found using the outpoint specified in the transaction and then the UTXO is removed from the database. The outputs of that transaction are then added to the database as new UTXOs.</p>

CC BY-SA 4.0
2018-05-22T02:04:37.937Z
"Ah-hah!" is all I can say. :)
Jazimov
CC BY-SA 4.0
2018-05-22T01:57:46.067Z
2018-05-22T01:57:46.067Z
Ava Chow
<p>I understand that each block on the Bitcoin blockchain contains a list of transactions, but let's assume (for the sake of this question) that the block in question contains only a single transaction--and that this particular transaction has a history of previous transactions (i.e., it was not a coinbase transaction). How would I figure out which block holds this single transaction's previous transaction(s)? I know that each transaction contains the hash of the previous transaction--but how do you find that hash without looking into every block on the blockchain? In other words, how can I quickly discern a transaction hash chain for a given transaction ID? Any links to explanations or previous questions would be appreciated--I tried searching and haven't seen anything that answers my question to my satisfaction. </p>

<p>Thank you.</p>

<transactions><bitcoin-core><blockchain>
How specifically is transaction history modeled in blockchain blocks?
Jazimov
# How specifically is transaction history modeled in blockchain blocks?

(Asked by: username_0 on 2018-05-22)

I understand that each block on the Bitcoin blockchain contains a list of transactions, but let's assume (for the sake of this question) that the block in question contains only a single transaction--and that this particular transaction has a history of previous transactions (i.e., it was not a coinbase transaction). How would I figure out which block holds this single transaction's previous transaction(s)? I know that each transaction contains the hash of the previous transaction--but how do you find that hash without looking into every block on the blockchain? In other words, how can I quickly discern a transaction hash chain for a given transaction ID? Any links to explanations or previous questions would be appreciated--I tried searching and haven't seen anything that answers my question to my satisfaction.

Thank you.

**Tags:** transactions, bitcoin-core, blockchain


---

## 3 answers

### Answer by username_3 on 2018-05-22. Score: 4 | Accepted answer

> -but how do you find that hash without looking into every block on the blockchain?

You can't. Of course, if you are smart, when you receive a block, you extract the data that you need and put it into a database where you store this information and can quickly look it up. So, starting from the beginning of the blockchain, you read through every block and every transaction, compute their hashes, and store in a separate database the hash and a pointer to where you can find the block or transaction (or something of that sort). So when you need to look up the outputs that a transaction spends, you can just lookup the txid in your database and be able to quickly find the transaction output that you need.

This is similar to what Bitcoin Core does. After it fully validates a block, it adds the UTXOs that are created to a separate database. That database contains the details for all of the UTXOs, so it has each UTXOs outpoint (txid + output index), the output value, and the output script. When a transaction spends a UTXO, it can be quickly found using the outpoint specified in the transaction and then the UTXO is removed from the database. The outputs of that transaction are then added to the database as new UTXOs.

> **Comments:**
> **username_0**: "Ah-hah!" is all I can say. :)  

---

### Answer by username_1 on 2018-05-22. Score: 1

When nodes start up and sync the blockchain, they create and maintain something known as the `utxo` database. This contains all transaction outputs that have not been spent.

As new blocks are broadcasted, the inputs being spent in the transactions in those blocks are removed from the utxo, and the new outputs that were created are added in. This will usually happen even when a tx is broadcast, before it is mined into a block. Trying to broadcast an additional tx with the same inputs will fail with a mempool-conflict.

This database is saved to disk, so shutting down and starting up a node is not as intensive as the first sync and scan.

The raw blockchain itself is simply a series of series of serialized blocks and their transactions - The UTXO set is not a separate part of it, and must be constructed by iterating over it block by block.


---

### Answer by username_2 on 2018-05-23. Score: 0

The ledger i.e. Block chain is stored on every computer (node) that partakes in the network. ... Block chain is stored on all the computers running Bitcoin node. There are thousands of computers running full node. Each of these node record every new transaction in the blockchain.


---

