<p>When a transaction is created by your node and relayed to full nodes, they will check to ensure that the transaction is valid (no double spending is one condition amongst them). Full node maintains a set of UTXO list in the <code>chainstate</code> folder and is aggressively cached in memory. If a transaction is valid, the full nodes will remove the UTXOs that are consumed in the transaction and add the outputs of that transaction to the UTXO set. Then the node will add that transaction to the mempool and relay the transaction to other full nodes connected to it.</p>

<p>Most full nodes/mining nodes operate on first seen basis. That is if they see another transaction spending the same UTXO as to the first one, they will discard it as invalid and will not relay it further (unless it is <a href="https://en.bitcoin.it/wiki/Replace_by_fee" rel="nofollow noreferrer">RBF</a>). So if you send two transactions consuming the same UTXO then it might be the case that half of the nodes will use a different transaction in the mempool as compared to the other half. This issue will be resolved when a block is mined containing one of the two transactions. The miner will only include first transaction that it has seen in the block it mines. When the full nodes receive the mined block, the ones that had seen the other transaction will roll back the changes to the UTXO set and converge on the transaction mined in the block.</p>

<p>If you want to include the other transaction, you will now have to mine two blocks: one at the height that was just received (by removing the mined transaction and including the other) and another block incrementing that height so that nodes accept that version of the chain (since nodes accept the longest PoW chain). That is the reason PoW is very important in resolving conflicts in a decentralized P2P system that does not have a central authority to dictate which transaction is the valid one.</p>

CC BY-SA 4.0
2019-08-28T12:30:41.000Z
Thanks for that awnser! I thought a UTXO would only been changed if a block is mined. I'm trying to create a visualization of my own programmed Bitcoin Blockchain in Java. So i have to update the UTXO list everytime a transaction is added.

And if another Block uses other UTXO's for that transaction and mined it faster i have to revert the UTXO's and use these of the mined Block.

I cant give u a upvote cause im to new, but thank you very much.
Beanssss
CC BY-SA 4.0
2019-08-28T12:34:20.743Z
Yes, it is better/faster to update the UTXO list on the fly. You can reject double spending transactions outright. But when a block is received with almost 2000 transactions, you don't have to download and verify each of them all at once. You must have seen a majority of the transactions and must have applied the changes. There might be a few that you haven't seen so you can just update the UTXO set those newly seen transactions and the other conflicting ones.
Ugam Kamat
CC BY-SA 4.0
2019-08-28T12:44:03.120Z
One last Example: I have 13 BTC and send 5 btc to Anna, Node 0 will update his UTXO list. Anna Spends this 5 UTXO and sends them to Tim and Simon. And they spend them too, but the block is not mined yet. Node 100 got a transaction where i spend 10 BTC and send them to Peter. Node 100 mines the Block with the transaction immediately and sends the block to Node 0. So Node 0 has to undo every affected transaction untill i have my 13 BTC to send them to peter?
Beanssss
CC BY-SA 4.0
2019-08-28T15:38:09.510Z
@TomS That is correct. One UTXO can only be once. When the block got mined with you sending the 10 BTC UTXO to Peter, it was considered final. So node 0 discarded all transactions and its children transactions that consumed that UTXO.
Ugam Kamat
CC BY-SA 4.0
2019-08-28T12:22:25.353Z
2019-08-28T12:27:27.527Z
2019-08-28T12:27:27.527Z
Ugam Kamat
<p>If I create a transaction, my node will check my UTXO's and if i have enough BTC to do this transaction it will be mined. </p>

<p><a href="https://i.sstatic.net/TV5iK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TV5iK.png" alt="I have 13 BTC and Anna has 5 BTC"></a></p>

<p>So let's say I want to spend 12 BTC to Anna.</p>

<p>The System will check if i have enough BTC and i do. 
But the UTXO list will not be updated until my transaction is mined. </p>

<p>So what will happen if i do another transaction with 15 BTC to anna.</p>

<p>Would the System check the UTXO's again and accept the new transaction?</p>

<p>Or is there something like a second UTXO list with the spended but not mined Transactions?</p>

<transactions><doublespend><transaction-verification><utxo>
How to prevent double spending Bitcoins?
Beanssss
# How to prevent double spending Bitcoins?

(Asked by: username_0 on 2019-08-28)

If I create a transaction, my node will check my UTXO's and if i have enough BTC to do this transaction it will be mined.

[![I have 13 BTC and Anna has 5 BTC](https://i.sstatic.net/TV5iK.png)](https://i.sstatic.net/TV5iK.png)

So let's say I want to spend 12 BTC to Anna.

The System will check if i have enough BTC and i do.
But the UTXO list will not be updated until my transaction is mined.

So what will happen if i do another transaction with 15 BTC to anna.

Would the System check the UTXO's again and accept the new transaction?

Or is there something like a second UTXO list with the spended but not mined Transactions?

**Tags:** transactions, doublespend, transaction-verification, utxo


---

## 1 answers

### Answer by username_1 on 2019-08-28. Score: 3 | Accepted answer

When a transaction is created by your node and relayed to full nodes, they will check to ensure that the transaction is valid (no double spending is one condition amongst them). Full node maintains a set of UTXO list in the `chainstate` folder and is aggressively cached in memory. If a transaction is valid, the full nodes will remove the UTXOs that are consumed in the transaction and add the outputs of that transaction to the UTXO set. Then the node will add that transaction to the mempool and relay the transaction to other full nodes connected to it.

Most full nodes/mining nodes operate on first seen basis. That is if they see another transaction spending the same UTXO as to the first one, they will discard it as invalid and will not relay it further (unless it is [RBF](https://en.bitcoin.it/wiki/Replace_by_fee)). So if you send two transactions consuming the same UTXO then it might be the case that half of the nodes will use a different transaction in the mempool as compared to the other half. This issue will be resolved when a block is mined containing one of the two transactions. The miner will only include first transaction that it has seen in the block it mines. When the full nodes receive the mined block, the ones that had seen the other transaction will roll back the changes to the UTXO set and converge on the transaction mined in the block.

If you want to include the other transaction, you will now have to mine two blocks: one at the height that was just received (by removing the mined transaction and including the other) and another block incrementing that height so that nodes accept that version of the chain (since nodes accept the longest PoW chain). That is the reason PoW is very important in resolving conflicts in a decentralized P2P system that does not have a central authority to dictate which transaction is the valid one.

> **Comments:**
> **username_0**: Thanks for that awnser! I thought a UTXO would only been changed if a block is mined. I'm trying to create a visualization of my own programmed Bitcoin Blockchain in Java. So i have to update the UTXO list everytime a transaction is added.  And if another Block uses other UTXO's for that transaction and mined it faster i have to revert the UTXO's and use these of the mined Block.  I cant give u a upvote cause im to new, but thank you very much.  
> **username_1**: Yes, it is better/faster to update the UTXO list on the fly. You can reject double spending transactions outright. But when a block is received with almost 2000 transactions, you don't have to download and verify each of them all at once. You must have seen a majority of the transactions and must have applied the changes. There might be a few that you haven't seen so you can just update the UTXO set those newly seen transactions and the other conflicting ones.  
> **username_0**: One last Example: I have 13 BTC and send 5 btc to Anna, Node 0 will update his UTXO list. Anna Spends this 5 UTXO and sends them to Tim and Simon. And they spend them too, but the block is not mined yet. Node 100 got a transaction where i spend 10 BTC and send them to Peter. Node 100 mines the Block with the transaction immediately and sends the block to Node 0. So Node 0 has to undo every affected transaction untill i have my 13 BTC to send them to peter?  
> **username_1**: @TomS That is correct. One UTXO can only be once. When the block got mined with you sending the 10 BTC UTXO to Peter, it was considered final. So node 0 discarded all transactions and its children transactions that consumed that UTXO.  

---

