Bitcoin-Core
為什麼 1000 sat/kb 的 minRelayTxFee 不等於 250 sat/kw?
天真地,我們期望 1000 sat/kb 的 minRelayTxFee 對應於 250 sat/kw。但是,根據這個問題(ACINQ)顯然不是這樣,它也引用了這個問題(c-lightning)。
/** * why 253 and not 250 since feerate-per-kw is feerate-per-kb / 250 and the minimum relay fee rate is 1000 satoshi/Kb ? * * because bitcoin core uses neither the actual tx size in bytes or the tx weight to check fees, but a "virtual size" * which is (3 * weight) / 4 ... * so we want : * fee > 1000 * virtual size * feerate-per-kw * weight > 1000 * (3 * weight / 4) * feerate_per-kw > 250 + 3000 / (4 * weight) * with a conservative minimum weight of 400, we get a minimum feerate_per-kw of 253 * * see https://github.com/ElementsProject/lightning/pull/1251 **/ val MinimumFeeratePerKw = 253
我認為 vbytes 等於重量單位除以 4 並四捨五入,所以我不明白從何
(3 * weight) / 4
而來。
我認為 vbytes 等於重量單位除以 4
它是 [1],但四捨五入到下一個整數,所以實現
bitcoind
是:int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop) { return (std::max(nWeight, nSigOpCost * bytes_per_sigop) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR; }
(哪裡
WITNESS_SCALE_FACTOR = 4
)。此外,
bitcoind
不僅vbyte
使用者界面使用 s,記憶體池邏輯也使用 s,DEFAULT_MIN_RELAY_TX_FEE
常量設置在vbyte
s 中:static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
為了檢查它的標準性,
bitcoind
將計算您的交易規模向上取整(如果不是 的倍數4
),並將您的交易費率記錄為向下取整。然後它會將其與最小
1000
中繼250
費率4
(使用程式碼可能會更清楚,這是一個說明此行為的 Python 函式:
>>> def bitcoind_fun(tx_weight, feerate_perkw): ... fees = tx_weight * feerate_perkw // 1000 ... print("Your transaction will pay {} sats of fees, is {} WU large (a feerate of {}sat/Kw)".format(fees, tx_weight, feerate_perkw)) ... tx_vbytes_for_bitcoind = (tx_weight + 3) // 4 ... tx_feerate_vbytes_for_bitcoind = fees * 1000 // tx_vbytes_for_bitcoind ... print("bitcoind reads your transaction as paying {} sats of fees for a transaction of {} vbytes, so a {}sat/perKvb feerate".format(fees, tx_vbytes_for_bitcoind, tx_feerate_vbytes_for_bitcoind))
如果您使用 a
tx_weight
which is a multiple of4
將通過,否則它將不會:>>> bitcoind_fun(1600, 250) Your transaction will pay 400 sats of fees, is 1600 WU large (a feerate of 250sat/Kw) bitcoind reads your transaction as paying 400 sats of fees for a transaction of 400 vbytes, so a 1000sat/perKvb feerate >>> bitcoind_fun(1601, 250) Your transaction will pay 400 sats of fees, is 1601 WU large (a feerate of 250sat/Kw) bitcoind reads your transaction as paying 400 sats of fees for a transaction of 401 vbytes, so a 997sat/perKvb feerate >>> bitcoind_fun(1602, 250) Your transaction will pay 400 sats of fees, is 1602 WU large (a feerate of 250sat/Kw) bitcoind reads your transaction as paying 400 sats of fees for a transaction of 401 vbytes, so a 997sat/perKvb feerate
所以我們使用 253 作為最安全的地板:
>>> bitcoind_fun(1600, 253) Your transaction will pay 404 sats of fees, is 1600 WU large (a feerate of 253sat/Kw) bitcoind reads your transaction as paying 404 sats of fees for a transaction of 400 vbytes, so a 1010sat/perKvb feerate >>> bitcoind_fun(1601, 253) Your transaction will pay 405 sats of fees, is 1601 WU large (a feerate of 253sat/Kw) bitcoind reads your transaction as paying 405 sats of fees for a transaction of 401 vbytes, so a 1009sat/perKvb feerate >>> bitcoind_fun(1602, 253) Your transaction will pay 405 sats of fees, is 1602 WU large (a feerate of 253sat/Kw) bitcoind reads your transaction as paying 405 sats of fees for a transaction of 401 vbytes, so a 1009sat/perKvb feerate
順便說一句,您輸入的程式碼中的註釋是錯誤的:不是
(3 * weight) / 4
但是(3 + weight) / 4
。[1] 排除人為增加虛擬大小以進一步防止 DOS 的 sig OPs 限制。
PS:同樣,請參閱<https://github.com/bitcoin/bitcoin/issues/13283>。