Bitcoin-Core

為什麼比特幣核心預設創建時間鎖定交易?

  • September 9, 2016

我最近注意到比特幣核心正在生成具有非零鎖定時間和輸入序列號為 0xFFFFFFFE 的交易,儘管我沒有指示它這樣做。鎖定時間似乎是目前塊號。

  • 這種行為的原因是什麼?
  • 設置序列號的算法是什麼?

(我知道至少一個輸入必須具有小於 0xFFFFFFFF 的序列號。核心是設置第一個輸入還是所有輸入?我無法檢查這個,因為我沒有一個輸入以上的事務。)

謝謝您的回答!

TL;DR:目的是阻止重組並增加隱私。

wallet.cpp 中,就在設置 nLockTime 的位置上方,它說:

// 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.

txNew.nLockTime = chainActive.Height();

// Secondly occasionally randomly pick a nLockTime even further back, so
// that transactions that are delayed after signing for whatever reason,
// e.g. high-latency mix networks and some CoinJoin implementations, have
// better privacy.

if (GetRandInt(10) == 0)
 txNew.nLockTime = std::max(0, (int)txNew.nLockTime - GetRandInt(100));

正如 Martin Habovštiak 所注意到的,MAX-1每個輸入都設置了序列號。它位於前面提到的程式碼部分下方的程式碼中

引用自:https://bitcoin.stackexchange.com/questions/48384