What really happens technically if a transaction attempts to spend the UTXO that has already been spent and how do the node identifies and invalidate such during the mempool and block validation
Is it just enough that spent UTXO are destroyed and no trace of them in the mempoo afterwards?
When a transaction tries to spend an already spent UTXO, nodes detect it by checking the UTXO set (the current chainstate). If the referenced outpoint (txid + vout) is not present in the UTXO database, validation fails immediately with a “missing inputs” error.
At mempool level, nodes also track spent outputs within the mempool itself. So if a new transaction attempts to double-spend an input that is already used by another mempool transaction, it is rejected unless it qualifies for RBF rules.
During block validation, the same principle applies: each input must reference an existing unspent output in the UTXO set as of that block’s context. Once an input is consumed, it is removed from the UTXO set and replaced with the new outputs created by the transaction.
So spent UTXOs are not “destroyed without trace” they are removed from the UTXO set but remain permanently recorded in the blockchain history. The UTXO set just represents the current spendable state.