What is the meaning of the sequence number? What does the 4294967295 tell me?
nSequence is a 4 byte input level feature. The original meaning of
nSequence was to allow modification of transactions in the mempool. So, if the nSequence value of the input was less than
4294967295 in decimal), it indicated a transaction that was not yet finalized. Such a transaction would be held in the mempool until it was replaced by another transaction spending the same inputs with a higher nSequence value. Once a transaction was received whose inputs had an nSequence value of
0xFFFFFFFF it would be considered finalized and mined.
In that implementation, replacement transactions did not have to pay additional fees, so there was no direct incentive for miners to include the replacement. Also, no built-in rate limiting prevented overuse of relay node bandwidth. Hence, this feature was disabled later as it was possible for an attacker to use up all the bandwidth among full nodes at only a small cost to themselves, creating a denial-of-service vulnerability. This made it difficult for spenders to adjust their previously sent transactions to deal with unexpected confirmation delays or to perform other useful replacements.
Then came the proposal for Opt-in Full Replace-by-Fee Signaling. It considered a transaction to have opted in to allow replacement of itself, if any of its inputs have an nSequence number less than
0xFFFFFFFE. It also required a higher fee than the previous relayed transaction.
nLockTime is used to prevent the mining of a transaction until a certain date (specified in block no. or time). BIP 68 activation defined the meaning of sequence numbers for transactions with an
nSequence was repurposed as a relative locktime. That means it prevents mining of a transaction until the input that the transaction is spending has reached a certain age in blocks or timespan. If
nSequence > 0xEFFFFFFF then there us no consensus meaning to the sequence number and it can be included in any block under all currently possible circumstances. If
nSequence <= 0xEFFFFFFF, it implies relative locktime.
nSequence <=0xEFFFFFFF, then the sequence's 22nd bit determines if the relative lock-time is time-based or block based. If the bit is 1, the relative lock-time specifies a timespan in units of 512 seconds granularity. If the bit is not set (i.e. it is 0), the relative lock-time specifies a number of blocks. The value of the relative locktime, is then interpreted from the first 16 bits of the
nSequence. The below figure shows how nSequence is evaluated.
CSV is a script level opcode that is used to lock the spending of a particular output of a transaction until certain blocks/time from when the transaction containing the output was mined. When the user is spending this UTXO in a transaction input, he must set the
nSequence value in that input greater than or equal to the CSV parameter. The value in CSV must match the format in the corresponding nSequence value. If CSV is specified in terms of blocks, then so must nSequence.
nSequence = 0xFFFFFFFF, the sequence number has no effect on the transaction.
nSequence = 0xFFFFFFFE, then it implies that the transaction uses locktime but does not
nSequence=0xFFFFFFFE, because they want to use
nLocktimeto prevent miners from pulling the transactions forward. The
nLocktimeused in such transaction is set to the last mined block.
For more information on Locktime refer here.
As can be seen from the description above, a number of bits in
nSequence remain undefined. This allows the possibility to increase its granularity by a soft-fork, or to increase the maximum possible relative lock-time in the future. For example:
nSequence > 0xEFFFFFFFthen the remaining 31 bits have no meaning as this condition can be satisfied by just setting bit (1<<31).
nSequence <= 0xEFFFFFFFthen the bits 23 to 30 have no meaning.
minrelayfeewas required and hence that allowed nodes to spam the network at no cost by just incrementing
nSequence. BIP-125 actually brought the protocol that the fees should be higher than the previously relayed transaction. — Apr 29, 2019 at 17:00
External links referenced by this document:
Local articles referenced by this article: