Skip to content

Commit

Permalink
utxo: fix dust. Closes gh-107
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Aug 8, 2024
1 parent 9a29c88 commit d1bc93d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class _Estimator {
const changeFee = this.getSatoshi(changeWeight);
let fee = s.fee;
const change = total - this.amount - changeFee;
if (change > this.dust) needChange = true;
if (change > this.dust * this.opts.feePerByte) needChange = true;

This comment has been minimized.

Copy link
@conduition

conduition Aug 9, 2024

This still leaves two bugs:

  • If I set feePerByte to some large fee rate, e.g. 100 sat/vb, this will (incorrectly) drop change outputs less than 148 * 100 = 14800 sats. That's a considerable amount of money and shouldn't be thrown away. Instead of using opts.feePerByte, you should have some dustRelayFeeRate constant (or option) which is distinct from the fee rate the user is asking for on their transaction. In core, it defaults to 3 sat/vb and most nodes will also use that number.
  • this.dust is still set to default to 148 bytes, which is incorrect. See the comment in core here. 148 is the minimum input size needed to spend a non-segwit UTXO. But core also accounts for the size of the UTXO itself when computing the dust threshold, so actually you want dust = 148 + 34.

This comment has been minimized.

Copy link
@conduition

conduition Aug 9, 2024

Opened a PR with suggested fixes here: #109

let inputs = indices;
let outputs = Array.from(this.outputs);
if (needChange) {
Expand Down

0 comments on commit d1bc93d

Please sign in to comment.