比特幣核心的 nLocktime
我在做一些研究時正在閱讀這篇文章:https ://github.com/achow101/wallet-fingerprinting/blob/main/fingerprints.md並且有一些問題:
Bitcoin Core 中交易的預設 nLocktime 是多少?
它是否曾經改變過,因為我記得它在某個時候為零?
Bitcoin Core 中交易的預設 nLocktime 是多少?
錢包原始碼
在 23.0 版中,
wallet\spend.c
包括此/** * Return a height-based locktime for new transactions (uses the height of the * current chain tip unless we are not synced with the current chain */ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height) { uint32_t locktime; // Discourage fee sniping. // // For a large miner the value of the transactions in the best block and // the mempool can exceed the cost of deliberately attempting to mine two // blocks to orphan the current best block. By setting nLockTime such that // only the next block can include the transaction, we discourage this // practice as the height restricted and limited blocksize gives miners // considering fee sniping fewer options for pulling off this attack. // // A simple way to think about this is from the wallet's point of view we // always want the blockchain to move forward. By setting nLockTime this // way we're basically making the statement that we only want this // transaction to appear in the next block; we don't want to potentially // encourage reorgs by allowing transactions to appear at lower heights // than the next block in forks of the best chain. // // Of course, the subsidy is high enough, and transaction volume low // enough, that fee sniping isn't a problem yet, but by implementing a fix // now we ensure code won't be written that makes assumptions about // nLockTime that preclude a fix later. if (IsCurrentForAntiFeeSniping(chain, block_hash)) { locktime = block_height;
因此比特幣核心將鎖定時間設置為目前區塊高度以阻止費用狙擊。
發行說明
0.11 版的發行說明(2015 年 8 月更新)說
錢包
#2340 811c71d 不鼓勵使用 nLockTime 狙擊費用
使用 RPC 時
使用 RPC
createpsbt
或等手動創建事務時,鎖定時間為零createrawtransaction
。否則,比特幣核心使用隨機最近的塊高度。(來源:OP實驗)鎖定時間的記錄含義
考慮鎖定時間的含義可能會有所幫助
協議文件說
該交易解鎖的區塊號或時間戳:
如果所有 TxIn 輸入都具有最終 (0xffffffff) 序列號,則 lock_time 無關緊要。否則,直到 lock_time 之後,事務才可能被添加到塊中(請參閱 NLockTime)。
如果我們查看區塊 654,915 中的一些交易,我們可以看到大多數交易要麼沒有鎖(0),要麼沒有區塊號……
C> 區塊鏈-文件 blk02300.dat -block 100
塊 000000000000000000002FC97B15D50E38CEB0C6A83DA4344CE836B01FC841EEA 中的交易
我猜大多數錢包都設置了預設值 0,因為我快速查看這個塊似乎顯示了大約 90% 的值。
腳註:如果我們假設鎖定時間中塊高度的一般使用與比特幣核心中的方法一致,我們可能可以使用它來查看費率如何影響交易探勘的延遲。上面的交易 17 和 18 挖得很快,交易 19 大概要等 52 個區塊?(8-9 小時?)