<p>While a miner is building a block template, they are maintaining a &quot;virtual&quot; UTXO set to keep track of the consumed UTXOs and the newly created UTXOs. A transaction can only be included in a block once all of its inputs are available for spending, so this approach is also sufficient to achieve the required topological order of transactions.</p>

CC BY-SA 4.0
2021-02-11T14:56:05.370Z
2021-02-12T10:59:21.370Z
2021-02-12T10:59:21.370Z
Murch
<p>It is mentioned in <a href="https://bitcoin.stackexchange.com/questions/28225/how-is-a-transaction-output-marked-as-spent?rq=1">this post</a> that:</p>
<blockquote>
<p>If all validation of all transactions in a block succeeds, the consumed inputs are removed from the database, and all outputs of those transactions added as fresh unspent outputs in the database, allowing them to be spent by future blocks.</p>
</blockquote>
<p>But if the UTXO set is updated only after appending a block, and a miner only checks the UTXO set for understanding the spent/unspent outputs, how will verification happen if a transaction (say tx_B) in a block spends an output of another transaction (say tx_A) in the same block? In another word, how will tx_B understand the state of the output of tx_A if the output is not stored in the UTXO set yet?</p>

CC BY-SA 4.0
2021-02-11T14:04:35.677Z
Does this answer your question? [Spending UTXO from same block](https://bitcoin.stackexchange.com/questions/84984/spending-utxo-from-same-block)
Claris
CC BY-SA 4.0
2021-02-11T14:18:22.300Z
@Anonymous No, I know that spending UTXO from the same block can happen, but my question is how the verification happens if miners are not seeing UTXO of their same block in the UTXO set.
MHT
CC BY-SA 4.0
2021-02-11T14:25:41.340Z
The answer is the same, blocks are processed sequentially and the UTXO is effectively updated after each operation. Therefor a later transaction in the same block can spend an earlier one.
Claris
CC BY-SA 4.0
2021-02-11T14:35:33.397Z
@Anonymous, Perfect! This is what I was looking for and it was missing in the other question: UTXO set is updated after verification of each transaction (not after appending a block). Thanks for your answer.
MHT
<utxo><transaction-verification><output><utxo-set>
How does a miner verify a transaction which is spending an output of another transaction in the same block?
MHT
# How does a miner verify a transaction which is spending an output of another transaction in the same block?

(Asked by: username_0 on 2021-02-11)

It is mentioned in [this post](https://bitcoin.stackexchange.com/questions/28225/how-is-a-transaction-output-marked-as-spent?rq=1) that:

> If all validation of all transactions in a block succeeds, the consumed inputs are removed from the database, and all outputs of those transactions added as fresh unspent outputs in the database, allowing them to be spent by future blocks.

But if the UTXO set is updated only after appending a block, and a miner only checks the UTXO set for understanding the spent/unspent outputs, how will verification happen if a transaction (say tx\_B) in a block spends an output of another transaction (say tx\_A) in the same block? In another word, how will tx\_B understand the state of the output of tx\_A if the output is not stored in the UTXO set yet?

**Tags:** utxo, transaction-verification, output, utxo-set

> **Comments:**
> **username_1**: Does this answer your question? [Spending UTXO from same block](https://bitcoin.stackexchange.com/questions/84984/spending-utxo-from-same-block)  
> **username_0**: @Anonymous No, I know that spending UTXO from the same block can happen, but my question is how the verification happens if miners are not seeing UTXO of their same block in the UTXO set.  
> **username_1**: The answer is the same, blocks are processed sequentially and the UTXO is effectively updated after each operation. Therefor a later transaction in the same block can spend an earlier one.  
> **username_0**: @Anonymous, Perfect! This is what I was looking for and it was missing in the other question: UTXO set is updated after verification of each transaction (not after appending a block). Thanks for your answer.  

---

## 1 answers

### Answer by username_2 on 2021-02-11. Score: 1 | Accepted answer

While a miner is building a block template, they are maintaining a "virtual" UTXO set to keep track of the consumed UTXOs and the newly created UTXOs. A transaction can only be included in a block once all of its inputs are available for spending, so this approach is also sufficient to achieve the required topological order of transactions.


---

