6
1
Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?
Or is it possible to have B before A?
6
1
Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?
Or is it possible to have B before A?
5
The Bitcoin protocol requires transactions to appear in topological order in the blockchain. Given two transactions A and B where B spends an output of A:
Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.
Also see: Can multiple transactions transferring the same bitcoin be done in one block?
I am curious about unrelated transactions - how are they ordered? Surely a timestamp is insufficient? If it is a UUID, how is it ordered? – Angad – 2019-10-11T07:45:43.603
They don't need to be in a specific order, but some miners seem to keep them in the same order they selected them into the block, i.e. ordered by the transactions' fee rates paid. – Murch – 2019-10-11T14:52:21.830
I cannot understand this answer it seems to contradict itself. It says 1) all transactions in a block happen at the same time, 2) A & B can be in same block but they will stand in chronological order. 2) means that 1) is not true, 2) means that transactions in a block are considered to happen in the order they are listed, not at the same time. Fix!?!? – mwengler – 2014-08-08T22:41:46.163
They don't have to be in different blocks, i.e. they will all be timestamped at the same time. It doesn't even matter if a miner receives knowledge of B first. However, if a miner were trying to first determine the validity of B, he would find it invalid, as he doesn't know about the transaction output created by A yet. Thus, even though the transactions can happen at the in the same block, the protocol enforces that the transactions will be written out in the block in the correct order. – Murch – 2014-08-08T23:03:04.817