2

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

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?

3

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). 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.

  • 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. – TomS Aug 28 at 12:30
  • 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 Aug 28 at 12:34
  • 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? – TomS Aug 28 at 12:44
  • @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 Aug 28 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.