Bitcoin Anti-Fee-Sniping Locktime: Wallet Construction and Block Height
Bitcoin wallets may use nLockTime as an anti-fee-sniping measure. Instead of making every newly created transaction immediately eligible for any historical block height, a wallet can choose a recent block-height threshold. This limits where miners can include the transaction, which may reduce the fees available to a miner attempting to replace an earlier block.
The height-based mechanism
A transaction's nLockTime field is a 32-bit unsigned integer. Values below 500,000,000 represent block heights; values at or above that threshold represent timestamps. The locktime is effective only when at least one input's nSequence is not 0xffffffff. Otherwise the transaction is treated as final regardless of its nLockTime value.
A height-based locktime is evaluated against the height of the block that would include the transaction. A transaction with locktime equal to a given height becomes final only when the candidate block height is greater than that locktime, following Bitcoin's strict comparison rule. In mempool policy, the next-block context matters; the exact chain tip may move between construction and broadcast.
Example: a recent-height locktime
Suppose the best chain tip is height 900,000. A wallet might construct a transaction with nLockTime = 900000 and a nonfinal input sequence. Such a transaction can be eligible for a block at height 900,001, but not for an alternative block at height 900,000. This makes it less useful for a miner trying to replace the block at height 900,000 with a competing block at that same height.
This is a simplified example, not a universal recommendation to set every transaction to the exact tip. Wallet implementations may apply randomized backward offsets or other heuristics to reduce transaction fingerprinting and handle stale chain-tip information. The correct implementation depends on wallet software and its transaction-construction policy.
Important limitations
This technique does not prevent miners from reorganizing the chain, does not stop double spending, and does not make unconfirmed payments safe. A miner can still mine transactions in eligible future blocks. A wallet with a stale or incorrect chain height may also create transactions that are nonfinal longer than intended.
Absolute locktime is different from BIP68 relative sequence locks and BIP112 OP_CHECKSEQUENCEVERIFY. An anti-fee-sniping locktime typically relies on the ordinary transaction-level nLockTime field, not on a specialized spending script.
Implementation checklist
Constructors should use a trusted view of the current chain, select a suitable locktime, ensure at least one input sequence enables locktime, and preserve compatibility with the wallet's RBF policy. Before broadcast, test whether the transaction is final and acceptable under the intended node's mempool rules. Do not assume the mere presence of a nonzero locktime makes the transaction nonfinal.
Primary references
Bitcoin Developer Reference — Transactions: https://developer.bitcoin.org/reference/transactions.html
BIP125 — Opt-in Full Replace-by-Fee Signaling: https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki
Bitcoin Core source repository: https://github.com/bitcoin/bitcoin
