This is a theoretical question. Assuming that a transaction (TX_A) with me on the receiving end gets added to the blockchain, I should be able to spend the amount I received. So I go on and spend it on another transaction (TX_B). What if TX_A gets orphaned due to forks? What happens to TX_B?
2 Answers
What if TX_A gets orphaned due to forks? What happens to TX_B?
It will be considered invalid, and your Bitcoin will not be spent. It will only be considered valid on the other forks, assuming they don't also invalidate the block. Usually the forks, if they are trying to play by the rules of the Bitcoin network, will also invalidate the block because the longest chain is always the valid chain.
Also, this should be referred to as an extinct block, see https://bitcoin.stackexchange.com/a/5869/60443
-
With all these invalidation of transactions, how do wallets even keep track of your available spending? – Larrrrrrrrrry Sep 28 '18 at 14:35
-
First, extinct blocks are not terribly common, though they have and will happen. However, wallets need to account for the possibility of orphaned blocks, if they don't they are putting their users at risk. Also, they typically require a minimum number of confirmations for new transactions before they allow spending. – JBaczuk Sep 28 '18 at 14:37
-
correction, this terminology is confusing, and should be referred to as extinct blocks. orphans are just blocks with an unknown parent, but not necessarily invalid. – JBaczuk Sep 28 '18 at 14:43
-
Thanks for the clarification. From what I read about confirmations, outputs can only be spent if the transaction that outputted them are 6 blocks deep in the blockchain. Does this mean that a block is invalid if a transaction's input cannot be matched with any outputs that are 6 blocks away (in the direction of the genesis block)? – Larrrrrrrrrry Sep 28 '18 at 14:51
-
1The 6 blocks deep is not a rule of Bitcoin, but decided by the wallet or user, so no. – JBaczuk Sep 28 '18 at 15:00
-
Note that most of the time, competing blocks at the same height will include a largely overlapping set of transactions as almost every miner selects their transactions by picking the transactions with the highest fee rate from their mempool. -- Thus, if there are no shenanigans such as doublespend attempts, your transaction should get included in the other chaintip at the same height or briefly later. – Murch Sep 28 '18 at 23:06
The way I understand your question, you are asking:
Assuming I get paid by a transaction
tx_a
that gets included in a block. I spend my output in another transactiontx_b
. What happens totx_b
iftx_a
gets unconfirmed in a reorganization?
When the node reorganizes to another chaintip, all transactions that were confirmed in the block that confirmed tx_a
get added back to the mempool. Some of these transactions may already also be confirmed in the chaintip that the node is reorganizing to, but otherwise both tx_a
and tx_b
are now in the mempool. It is permitted to spend outputs of unconfirmed transactions, so that is not an issue at all, unless another transaction spent some of the inputs of tx_a
in a doublespend that made tx_a
permanently invalid. In that case, tx_b
would of course also be discarded, since tx_a
could never be part of the best chain given that some of its inputs were already spent.

- 75,206
- 34
- 186
- 622