<p>I want add a clarification inside your good post by Jose Fonseca, the UTXO is a TransactionOutput, this structure has only 2 value, the amount and the scriptPubKey. The link to the previous transaction is inside the TransactionInput so, the TransactionInput and the transaction output is contained inside the Raw transaction.</p>

<p>So inside the cache is present only the UTXO (TransactionOutput).</p>

<p>I have created this schema for my document, I hope it can help you.</p>

<p><a href="https://i.sstatic.net/bDNu2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bDNu2.png" alt="enter image description here"></a></p>

<p>This image tries to simplify how bitcoin transactions are generated.
The terms that are used are generalized, for example, you do not enter the public key in the output transaction but the address or hash160 of public key, this depend to the type of script is used.</p>

<p>In the image is not represented but there is a data type called Outpoint that refers to the previous raw transaction.</p>

<p>Still, for my project I rebuilt the data structures used in Bitcoin core (Except for the scriptWitness) if you haven't looked at the code, they can give you a general idea. you can find it <a href="https://palazzovincenzo.gitlab.io/structure-bitcoin-core/" rel="nofollow noreferrer">here</a></p>

<p>ps: I'm developing this documentation, it can contain some error, please verify it.</p>

CC BY-SA 4.0
2019-10-12T21:11:29.580Z
2019-10-21T18:01:08.200Z
2019-10-21T18:01:08.200Z
vincenzopalazzo
<p>Once spent, the wallet removes the UTXO from its <em>cache</em> of unspent transactions. The transaction is not removed from the general database (the blockchain or block index). Full nodes running with txindex=1 keep every transaction forever. Some wallets though optimize the database to recover disk space - but this is a wallet-specific optimization and not part of how Bitcoin works.</p>

<p>For instance, Bitcoin Core has many caches and optimizations. One of them is the UTXO cache. The reason to have this cache is kind of obvious: if you had to search the entire blockchain for your own unspent coins before every transaction, that could potentially take hours. So Bitcoin Core keeps track of your UTXO's. Your UTXO's output amounts add up and become the balance you see on the wallet software.</p>

<p>The UTXO cache never points to previous transactions - it's just an optimization cache that makes it easy for Bitcoin Core to find TX's. The algorithm which builds the UTXO cache knows which transaction the UTXO came from, but the cache never points anywhere except to the TX index where the unspent output is located.</p>

<p>The pointer to a previous transaction only exists when you spend a UTXO and then a new input TX is created on that transaction. That input will point to the previously unspent transaction and that former UTXO will become spent. A new UTXO is then created after this transaction is mined. This UTXO becomes part of the Bitcoin balance of the recipient, just like the UTXO was part of your balance before you spent it.</p>

<p>This image (courtesy of bitcoin.org) might help illustrate how it works:
<a href="https://i.sstatic.net/FWSkM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FWSkM.png" alt="enter image description here"></a></p>

<p>See those UTXO's dangling without a new TX ahead of them? Until they're spent, they remain as UTXO.</p>

<p>The arrows in that illustration show the money flow direction, but technically the arrows point the other way around : the inputs point back at some previous UTXO output. Once an input points at an output that output is no longer a UTXO, it is a committed TX. The input links the previous TX to a new UTXO and the previous one is marked spent. Bitcoin Core then removes this previous UTXO from the cache.</p>

CC BY-SA 4.0
2019-10-21T20:06:01.870Z
The chainstate (Bitcoin Core's database with unspent transaction outputs) is not just a cache though. It is the authoritative set of all unspent outputs, and spending a missing entries from it imply a transaction is invalid. It's also not an index, as you can delete the actual block data for old blocks after applying their effects on the UTXO set. Lastly, there is a cache on top of the chainstate in memory, with lots of optimizations, but those are independent of the chainstate itself.
Pieter Wuille
CC BY-SA 4.0
2019-10-12T19:12:04.863Z
2019-10-12T19:12:04.863Z
Jose Fonseca
<p>In <a href="https://bitcoin.stackexchange.com/questions/77331/state-of-transaction-and-utxo">this</a> post it is explained that the UTXO are removed after they are spent. This makes sense because they are not "unspent" anymore. </p>

<p>But don't all UTXOs have a reference/connection to their previous transaction? Is there a second "list" in the blockchain where all transactions from the past are stored? Because if not, where does that reference point to if the previous transaction is not in the UTXO list anymore. </p>

<p>The whole UTXO Model confuses me a little bit, so thank you for the clarification.</p>

<bitcoin-core><transactions><utxo><utxo-set>
Other database besides UTXO?
Nui
# Other database besides UTXO?

(Asked by: username_0 on 2019-10-12)

In [this](https://bitcoin.stackexchange.com/questions/77331/state-of-transaction-and-utxo) post it is explained that the UTXO are removed after they are spent. This makes sense because they are not "unspent" anymore.

But don't all UTXOs have a reference/connection to their previous transaction? Is there a second "list" in the blockchain where all transactions from the past are stored? Because if not, where does that reference point to if the previous transaction is not in the UTXO list anymore.

The whole UTXO Model confuses me a little bit, so thank you for the clarification.

**Tags:** bitcoin-core, transactions, utxo, utxo-set


---

## 2 answers

### Answer by username_2 on 2019-10-12. Score: 4 | Accepted answer

Once spent, the wallet removes the UTXO from its *cache* of unspent transactions. The transaction is not removed from the general database (the blockchain or block index). Full nodes running with txindex=1 keep every transaction forever. Some wallets though optimize the database to recover disk space - but this is a wallet-specific optimization and not part of how Bitcoin works.

For instance, Bitcoin Core has many caches and optimizations. One of them is the UTXO cache. The reason to have this cache is kind of obvious: if you had to search the entire blockchain for your own unspent coins before every transaction, that could potentially take hours. So Bitcoin Core keeps track of your UTXO's. Your UTXO's output amounts add up and become the balance you see on the wallet software.

The UTXO cache never points to previous transactions - it's just an optimization cache that makes it easy for Bitcoin Core to find TX's. The algorithm which builds the UTXO cache knows which transaction the UTXO came from, but the cache never points anywhere except to the TX index where the unspent output is located.

The pointer to a previous transaction only exists when you spend a UTXO and then a new input TX is created on that transaction. That input will point to the previously unspent transaction and that former UTXO will become spent. A new UTXO is then created after this transaction is mined. This UTXO becomes part of the Bitcoin balance of the recipient, just like the UTXO was part of your balance before you spent it.

This image (courtesy of bitcoin.org) might help illustrate how it works:
[![enter image description here](https://i.sstatic.net/FWSkM.png)](https://i.sstatic.net/FWSkM.png)

See those UTXO's dangling without a new TX ahead of them? Until they're spent, they remain as UTXO.

The arrows in that illustration show the money flow direction, but technically the arrows point the other way around : the inputs point back at some previous UTXO output. Once an input points at an output that output is no longer a UTXO, it is a committed TX. The input links the previous TX to a new UTXO and the previous one is marked spent. Bitcoin Core then removes this previous UTXO from the cache.

> **Comments:**
> **username_3**: The chainstate (Bitcoin Core's database with unspent transaction outputs) is not just a cache though. It is the authoritative set of all unspent outputs, and spending a missing entries from it imply a transaction is invalid. It's also not an index, as you can delete the actual block data for old blocks after applying their effects on the UTXO set. Lastly, there is a cache on top of the chainstate in memory, with lots of optimizations, but those are independent of the chainstate itself.  

---

### Answer by username_1 on 2019-10-12. Score: 1

I want add a clarification inside your good post by username_2 username_2, the UTXO is a TransactionOutput, this structure has only 2 value, the amount and the scriptPubKey. The link to the previous transaction is inside the TransactionInput so, the TransactionInput and the transaction output is contained inside the Raw transaction.

So inside the cache is present only the UTXO (TransactionOutput).

I have created this schema for my document, I hope it can help you.

[![enter image description here](https://i.sstatic.net/bDNu2.png)](https://i.sstatic.net/bDNu2.png)

This image tries to simplify how bitcoin transactions are generated.
The terms that are used are generalized, for example, you do not enter the public key in the output transaction but the address or hash160 of public key, this depend to the type of script is used.

In the image is not represented but there is a data type called Outpoint that refers to the previous raw transaction.

Still, for my project I rebuilt the data structures used in Bitcoin core (Except for the scriptWitness) if you haven't looked at the code, they can give you a general idea. you can find it [here](https://palazzovincenzo.gitlab.io/structure-bitcoin-core/)

ps: I'm developing this documentation, it can contain some error, please verify it.


---

