mempool: introduce GetDustThreshold to export dust limit calculation
This commit modifies no behavior and would allow other projects to retrieve the dust limit for a particular output type before the amount of the output is known. This is particularly useful in the Lightning Network for channel negotiation.
This commit is contained in:
parent
5e6736aad5
commit
f8e6854197
1 changed files with 19 additions and 12 deletions
|
@ -172,17 +172,10 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDust returns whether or not the passed transaction output amount is
|
// GetDustThreshold calculates the dust limit for a *wire.TxOut by taking the
|
||||||
// considered dust or not based on the passed minimum transaction relay fee.
|
// size of a typical spending transaction and multiplying it by 3 to account
|
||||||
// Dust is defined in terms of the minimum transaction relay fee. In
|
// for the minimum dust relay fee of 3000sat/kvb.
|
||||||
// particular, if the cost to the network to spend coins is more than 1/3 of the
|
func GetDustThreshold(txOut *wire.TxOut) int64 {
|
||||||
// minimum transaction relay fee, it is considered dust.
|
|
||||||
func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
|
||||||
// Unspendable outputs are considered dust.
|
|
||||||
if txscript.IsUnspendable(txOut.PkScript) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// The total serialized size consists of the output and the associated
|
// The total serialized size consists of the output and the associated
|
||||||
// input script to redeem it. Since there is no input script
|
// input script to redeem it. Since there is no input script
|
||||||
// to redeem it yet, use the minimum size of a typical input script.
|
// to redeem it yet, use the minimum size of a typical input script.
|
||||||
|
@ -253,6 +246,20 @@ func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||||
totalSize += 107
|
totalSize += 107
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 3 * int64(totalSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDust returns whether or not the passed transaction output amount is
|
||||||
|
// considered dust or not based on the passed minimum transaction relay fee.
|
||||||
|
// Dust is defined in terms of the minimum transaction relay fee. In
|
||||||
|
// particular, if the cost to the network to spend coins is more than 1/3 of the
|
||||||
|
// minimum transaction relay fee, it is considered dust.
|
||||||
|
func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||||
|
// Unspendable outputs are considered dust.
|
||||||
|
if txscript.IsUnspendable(txOut.PkScript) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// The output is considered dust if the cost to the network to spend the
|
// The output is considered dust if the cost to the network to spend the
|
||||||
// coins is more than 1/3 of the minimum free transaction relay fee.
|
// coins is more than 1/3 of the minimum free transaction relay fee.
|
||||||
// minFreeTxRelayFee is in Satoshi/KB, so multiply by 1000 to
|
// minFreeTxRelayFee is in Satoshi/KB, so multiply by 1000 to
|
||||||
|
@ -265,7 +272,7 @@ func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||||
//
|
//
|
||||||
// The following is equivalent to (value/totalSize) * (1/3) * 1000
|
// The following is equivalent to (value/totalSize) * (1/3) * 1000
|
||||||
// without needing to do floating point math.
|
// without needing to do floating point math.
|
||||||
return txOut.Value*1000/(3*int64(totalSize)) < int64(minRelayTxFee)
|
return txOut.Value*1000/GetDustThreshold(txOut) < int64(minRelayTxFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkTransactionStandard performs a series of checks on a transaction to
|
// checkTransactionStandard performs a series of checks on a transaction to
|
||||||
|
|
Loading…
Add table
Reference in a new issue