Skip to content

Commit f848070

Browse files
committed
tapfreighter: fail early on dusty change outputs
1 parent 0129ebf commit f848070

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tapfreighter/wallet.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,19 @@ func addAnchorPsbtInputs(btcPkt *psbt.Packet, vPkt *tappsbt.VPacket,
17021702
"change=%d) ", requiredFee, changeValue)
17031703
}
17041704

1705+
// Even if the change amount would be non-negative, it may still be
1706+
// below the dust threshold.
1707+
// TODO(jhb): Remove the change output in this case instead of failing
1708+
possibleChangeOutput := wire.NewTxOut(
1709+
changeValue-feeDelta, btcPkt.UnsignedTx.TxOut[lastIdx].PkScript,
1710+
)
1711+
err = txrules.CheckOutput(
1712+
possibleChangeOutput, txrules.DefaultRelayFeePerKb,
1713+
)
1714+
if err != nil {
1715+
return fmt.Errorf("change output is dust: %w", err)
1716+
}
1717+
17051718
btcPkt.UnsignedTx.TxOut[lastIdx].Value -= feeDelta
17061719

17071720
log.Infof("Adjusting send pkt fee by delta of %d from %d sats to %d "+

0 commit comments

Comments
 (0)