txrules: add threshold function in order to reuse it in lnd
This commit is contained in:
parent
504b045332
commit
5785ca17cc
1 changed files with 13 additions and 7 deletions
|
@ -17,10 +17,9 @@ import (
|
||||||
// DefaultRelayFeePerKb is the default minimum relay fee policy for a mempool.
|
// DefaultRelayFeePerKb is the default minimum relay fee policy for a mempool.
|
||||||
const DefaultRelayFeePerKb btcutil.Amount = 1e3
|
const DefaultRelayFeePerKb btcutil.Amount = 1e3
|
||||||
|
|
||||||
// IsDustAmount determines whether a transaction output value and script length would
|
// GetDustThreshold is used to define the amount below which output will be
|
||||||
// cause the output to be considered dust. Transactions with dust outputs are
|
// determined as dust. Threshold is determined as 3 times the relay fee.
|
||||||
// not standard and are rejected by mempools with default policies.
|
func GetDustThreshold(scriptSize int, relayFeePerKb btcutil.Amount) btcutil.Amount {
|
||||||
func IsDustAmount(amount btcutil.Amount, scriptSize int, relayFeePerKb btcutil.Amount) bool {
|
|
||||||
// Calculate the total (estimated) cost to the network. This is
|
// Calculate the total (estimated) cost to the network. This is
|
||||||
// calculated using the serialize size of the output plus the serial
|
// calculated using the serialize size of the output plus the serial
|
||||||
// size of a transaction input which redeems it. The output is assumed
|
// size of a transaction input which redeems it. The output is assumed
|
||||||
|
@ -30,9 +29,16 @@ func IsDustAmount(amount btcutil.Amount, scriptSize int, relayFeePerKb btcutil.A
|
||||||
totalSize := 8 + wire.VarIntSerializeSize(uint64(scriptSize)) +
|
totalSize := 8 + wire.VarIntSerializeSize(uint64(scriptSize)) +
|
||||||
scriptSize + 148
|
scriptSize + 148
|
||||||
|
|
||||||
// Dust is defined as an output value where the total cost to the network
|
byteFee := relayFeePerKb / 1000
|
||||||
// (output size + input size) is greater than 1/3 of the relay fee.
|
relayFee := btcutil.Amount(totalSize) * byteFee
|
||||||
return int64(amount)*1000/(3*int64(totalSize)) < int64(relayFeePerKb)
|
return 3 * relayFee
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDustAmount determines whether a transaction output value and script length would
|
||||||
|
// cause the output to be considered dust. Transactions with dust outputs are
|
||||||
|
// not standard and are rejected by mempools with default policies.
|
||||||
|
func IsDustAmount(amount btcutil.Amount, scriptSize int, relayFeePerKb btcutil.Amount) bool {
|
||||||
|
return amount < GetDustThreshold(scriptSize, relayFeePerKb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDustOutput determines whether a transaction output is considered dust.
|
// IsDustOutput determines whether a transaction output is considered dust.
|
||||||
|
|
Loading…
Reference in a new issue