Skip to content

Commit

Permalink
tapfreighter: fail early on dusty change outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Dec 12, 2023
1 parent e724f68 commit 935db82
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,20 @@ func addAnchorPsbtInputs(btcPkt *psbt.Packet, vPkt *tappsbt.VPacket,
"sats", requiredFee, changeValue)
}

// Even if the change amount would be non-negative, it may still be
// below the dust threshold.
// TODO(jhb): Remove the change output in this case instead of failing
possibleChangeOutput := wire.NewTxOut(
btcPkt.UnsignedTx.TxOut[lastIdx].Value-feeDelta,
btcPkt.UnsignedTx.TxOut[lastIdx].PkScript,
)
err = txrules.CheckOutput(
possibleChangeOutput, txrules.DefaultRelayFeePerKb,
)
if err != nil {
return fmt.Errorf("change output is dust: %w", err)
}

btcPkt.UnsignedTx.TxOut[lastIdx].Value -= feeDelta

log.Infof("Adjusting send pkt by delta of %d from %d sats to %d sats",
Expand Down

0 comments on commit 935db82

Please sign in to comment.