Sequence Numbers: Replace-By-Fee and the Flexibility of the Core
Sequence Numbers: Replace-By-Fee and the Flexibility of the Core
Every input in a Bitcoin blueprint has its own Sequence Number (nSequence). Originally intended by Satoshi Nakamoto to be part of a complex "High-Frequency Update" system, the sequence number has evolved into one of the most useful tools for the modern sovereign operator. Its primary role today is to enable Replace-By-Fee (RBF). It is the "Signal of Flexibility."
RBF is a vital "Safety Valve" for the network. If you send a transaction with a fee that is too low, and it gets "Stuck" in the mempool for hours or days because the network is busy, you can use the sequence number to signal that you want the option to "Upgrade" the transaction. You draft a new version of the same movement with a higher fee, and because the sequence number indicates it is "Replaceable," the node will swap the old, stuck blueprint for the new, faster one. It is the "Negotiation with the Messenger."
Analyzing the "Replacement Logic" in the Core: The Signal
In the source code workshop (src/policy/rbf.cpp), the node checks the sequence numbers to see if a transaction can be replaced. It is the "Check for Opt-In."
/**
* This function checks if a transaction is "Signal-ing for Flexibility."
* If the sequence number is less than the maximum, it is "Replaceable."
*/
bool SignalsOptInRBF(const CTransaction &tx)
{
// 1. Iterate through every source (Input) in the blueprint.
for (const CTxIn &txin : tx.vin) {
// 2. If any input has a sequence number less than the "Ultimate No,"
// the transaction is considered "Open for Revision" by the network.
if (txin.nSequence <= MAX_BIP125_RBF_SEQUENCE) {
return true;
}
}
return false;
}
Explaining the Sequence to a Non-Coder: The Status Flag
MAX_BIP125_RBF_SEQUENCE: Think of the sequence number as a "Status Flag" on your desk. If the flag is set to the absolute maximum (usually represented as0xFFFFFFFF), it says, "This is my final word; do not change a single bit of this." If the flag is set even one digit lower, it says, "I might change my mind later; keep this blueprint replaceable if I offer a better fee." Most modern wallets set this flag automatically so that you can "Bump the Fee" if the network gets crowded. It is the "Door that Stays Unlocked for the Architect." It is the "Signal of Intent."
The Strategic Use of Flexibility: The Clock of Payment
Sequence numbers are also used for Relative Locktime (BIP 68). This is different from the global locktime we just discussed. A relative locktime says, "This specific coin cannot be spent until 1,000 blocks have passed after it was first recorded in a block." This "Chain of Waiting" is what makes the Lightning Network's security model possible—it ensures that if one party tries to cheat by broadcasting an old state, the other party has a "Window of Time" to respond and reclaim their funds.
By understanding sequence numbers, you are seeing the "Agility of the Ledger." You are seeing how a "Raw" transaction can be both "Indestructible" once mined and "Flexible" while it is still a draft. You are learning to use the "Second Seal" of the blueprint to navigate the shifting sands of the network fee market. It is the "Art of the Second Thought," the guarantee that the master craftsman always has a way to refine and improve their work before it is final. You are the "Master of the Negotiation."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: