What happens if a transaction tries to spend a UTXO that's already been spent? How do nodes catch that in the mempool and block validation? Is it enough that spent UTXOs just vanish from the mempool?
Diving Deep into UTXO Mechanics
20 replies 302 views
So, if you use Bitcoin in a transaction, you can't use the same coins again unless it's already been spent. I mean, the receiver could send it to someone else or their own address, right?
Nodes check their UTXO set to see if the TX is trying to spend an existing UTXO. If it's already spent, they know it’s invalid.
Like ABCbits mentioned, UTXOs belong to a UTXO set, which is like a database stored by all full nodes. Once spent, it's removed. And remember, only coinbase transactions lack an input.
Expanding on that... If a node tries to push a transaction with an already spent UTXO, they’re gonna get banned by other nodes for breaking consensus rules.
Exactly! If it’s not in the UTXO set, it means it’s spent. Spent outputs are wiped off the UTXO set and create new outputs instead.
This usually happens when UTXOs were spent in a previous block, confirmed by miners. The real issue is figuring out double spends happening in the same block, like two transactions created milliseconds apart.
Bitcoin's a public ledger, meaning spent coins are marked as such. Nodes use timestamps and other data to confirm coins are legit and haven’t been spent before.
Miners have geographically diverse nodes to quickly start on new blocks after one is found. Merchants do the same to protect their nodes from attacks. Conflicting transactions won't guarantee confirmation.
Do pruned nodes reliably serve UTXO data for wallets? Are there limitations compared to archival nodes?
Edge cases exist in all engineering. If you add an address after syncing, knowing available UTXOs is tricky. Electrum won’t work with pruned nodes either. You should be fine if your wallet has the private key when syncing starts.
Yeah, sometimes they have limitations too, like accepting 0-conf TX below 500 bucks or from familiar customers.
Keep in mind, pruned nodes store UTXO data, so they can verify new blocks. However, they only send the latest blocks to others due to being node network limited.
UTXO means "Unspent Transaction Output". You can't have a "spent UTXO". Clarity helps, but what do you mean by serving UTXO data?
I meant UTXO data for light clients. ABCbits clarified it for me.
It depends on the light client. I doubt any light client uses just the UTXO set. They can show current balance but not past transactions...unless it was synced from the genesis block.
So you’re saying a pruned node can’t serve as the genesis for new nodes since it lacks the full blockchain history?
Exactly! If you have the full history, it’s trustless. With just the UTXO set, a malicious node could fake balances, and you'd have no way to check if it’s real or not.
Pruned nodes validate the entire blockchain and create the UTXO set from that, but they won’t keep the whole blockchain data.
Isn’t it true that all nodes, whether pruned or not, build their own UTXO set? They validate as they go, right?