Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createtx: Add change output to size estimation. #2057

Merged
merged 1 commit into from Sep 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions wallet/createtx.go
Expand Up @@ -629,11 +629,12 @@ func (w *Wallet) txToMultisigInternal(ctx context.Context, op errors.Op, dbtx wa
}
msgtx.AddTxOut(txOut)

// Add change if we need it. The case in which
// totalInput == amount+feeEst is skipped because
// we don't need to add a change output in this
// case.
feeSize := txsizes.EstimateSerializeSize(scriptSizes, msgtx.TxOut, 0)
// Add change if we need it.
changeSize := 0
if totalInput > amount+feeEstForTx {
Copy link
Member

@matheusd matheusd Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exactly right, since it could be the case that totalInput is greater than amount+feeEstForTx but lower than the dust limit, which shouldn't create a change amount, but since feeEstForTx is significantly overestimated (0.5 dcr) this shouldn't happen in ordinary usage.

Fixing this edge case (dust limit change) would require tweaking this entire function to do a proper fee estimation, so unless this is really needed, the proposed change fixes the original issue.

changeSize = txsizes.P2PKHPkScriptSize
}
feeSize := txsizes.EstimateSerializeSize(scriptSizes, msgtx.TxOut, changeSize)
feeEst := txrules.FeeForSerializeSize(w.RelayFee(), feeSize)

if totalInput < amount+feeEst {
Expand Down