Alice issues 2 transactions:
- Alice -> Bob, 5 Bitcoins (uses Input 1, Input 2)
- Alice -> Alice, 5 Bitcoins (uses Input 1, Input 2)
Initially, both of the transactions are in the state "Unordered" until one of them gets committed into the block which is generally accepted by the ecosystem. If single block would include both of them, we still have the double spending issue. Is the block making sure, each transaction it includes is valid? I.e. it consumes the particular input just once and does not allow for double spending? Is each node accepting the block verifying the block's correctness?
Miner won't accept the second transaction because the first transaction is in the mempool.
When you broadcast Tx1, miners receive it and check if it is already in mempool, and they accept Tx1 and it goes to mempool. Next, when you try to broadcast Tx2, miners won't accept it because it is going to be double spend transaction even if Tx1 is not included into a block.