I have seen transactions on a block explorer where the transaction is in mempool (unconfirmed) but one of the outputs already appears as spent, I am curious how this works. This question is a duplicate of this question, but the answer there doesn't quite satisfy my confusion. I am thinking about how this process is permissible in conjunction with the protocol rules for 'tx' messages listed here, particularly rule 9, 10, 12.
For each input, if the referenced output exists in any other tx in the pool, reject this transaction.
For each input, look in the main branch and the transaction pool to find the referenced output transaction. If the output transaction is missing for any input, this will be an orphan transaction. Add to the orphan transactions, if a matching transaction is not in there already.
- For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this transaction
- Part of what might be causing confusion is the definition of "spent" on the block explorer - when it claims an output is spent does this equate to "there exists a transaction at least in mempool that uses the output as an input"?
- The ability to broadcast a tx message that uses the output of an unconfirmed tx as an input seems to explicitly violate rule 9. Does it not?
- Rule 9 & 10 seem to be at odds with each other. Rule 9 says to reject if the output is in a tx in mempool, rule 10 says to check mempool for the output (as though it is permissible). Are they not?
- It is my belief that full nodes keep a "UTXO" set for validating some of these criterium - is the UTXO set updated once a transaction hits mempool (i.e not waiting for a confirmation)?
- Is mempool relative to one node? I.e, if I broadcast a transaction and a node accepts it as valid does it then pass the transaction around so that other nodes can add it to "their" mempool, or is there somehow a "central mempool" that any validated transaction can get sent to.
- Is it possible to cancel a tx message that has been added to mempool? I am not asking if typical software has this feature - but is it theoretically possible for a power user or is it "permissible behavior" within the bitcoin protocol.