wallet/txauthor: fix bug in dust calculation

In this commit, we fix a 3 year old bug in dust calculation. Before this
commit, the target fee of the transaction to be crafted would be used to
determine dust. If the target fee is very high, then this would cause
over all higher fees, as we'd base that dust computation off of that fee
rate, rather than the min relay fee.

To fix this, we always use the min relay fee at all times when computing
dust.
This commit is contained in:
Olaoluwa Osuntokun 2020-08-13 16:43:00 -07:00
parent ca24ed58cf
commit fbb3bc184d
No known key found for this signature in database
GPG key ID: BC13F65E2DC84465

View file

@ -133,7 +133,7 @@ func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount,
changeIndex := -1 changeIndex := -1
changeAmount := inputAmount - targetAmount - maxRequiredFee changeAmount := inputAmount - targetAmount - maxRequiredFee
if changeAmount != 0 && !txrules.IsDustAmount(changeAmount, if changeAmount != 0 && !txrules.IsDustAmount(changeAmount,
txsizes.P2WPKHPkScriptSize, relayFeePerKb) { txsizes.P2WPKHPkScriptSize, txrules.DefaultRelayFeePerKb) {
changeScript, err := fetchChange() changeScript, err := fetchChange()
if err != nil { if err != nil {
return nil, err return nil, err