Transaction Ordering

Transactions in a Block are inherently ordered by virtue of their inclusion in the Merkle Tree. Furthermore, the Coinbase Transaction is required to be the first Transaction in the Block. After that, the order of any remaining Transactions in the block is dependent on when that Block was mined. For new blocks, the Canonical Transaction Ordering rule is in effect. For historic blocks, see Topological Transaction Ordering.

Canonical Transaction Ordering

With canonical transaction ordering (CTOR), the transactions after the coinbase transaction are required to be sorted in strictly ascending numerical order of their transaction id (txid), with each txid interpreted as a 256-bit little-endian integer. This is the same as ascending lexicographical order of the txids in their usual (byte-reversed) hexadecimal display form. Because the order is strict, a block containing two transactions with the same txid is invalid. CTOR was scheduled to activate at median-time-past time 1542300000; block 556766 was the last block under the old rules, and CTOR is enforced from block height 556767 (inclusive) on mainnet. After activation, blocks that do not follow this constraint will be rejected by the network.

Since CTOR, the topological ordering rule no longer applies: a transaction may spend outputs of a transaction that appears later in the same block. Validators must therefore make all outputs created in the block available before checking inputs (e.g. add all outputs first, then spend all inputs), and must still reject blocks that spend the same output more than once.

CTOR is also sometimes referred to as LTOR (lexicographical transaction ordering).

See HF20181115 for more information on this change.

Topological Transaction Ordering

With topological transaction ordering, Transactions after the Coinbase Transaction were required to abide by the following constraint: if a transaction B spends outputs created by transaction A, transaction B must appear after transaction A in the block. Otherwise, transactions could appear in any order.

Before CTOR activated (block height <= 556766) this was the required transaction order.