diff --git a/tapfreighter/wallet.go b/tapfreighter/wallet.go index c00978ea8..842a57b66 100644 --- a/tapfreighter/wallet.go +++ b/tapfreighter/wallet.go @@ -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",