Skip to content

wallet: ensure VSP payment doesn't create unmixable change#2595

Open
matthawkins90 wants to merge 2 commits intodecred:masterfrom
matthawkins90:unmixable_change
Open

wallet: ensure VSP payment doesn't create unmixable change#2595
matthawkins90 wants to merge 2 commits intodecred:masterfrom
matthawkins90:unmixable_change

Conversation

@matthawkins90
Copy link
Contributor

Summary

Buying tickets through a VSP had the possibility of creating outputs that were larger than dust, but not larger than the smallestMixChange. This change is toxic (since it is unmixable), and it also is linked to the ticket purchase. In practice, it's just more annoying than anything, because the wallet's unmixed balance will never reach zero.

Since ReserveOutputsForAmount is a public api, I created reserveOutputsForAmount to do the same thing, but also add minChange as an argument.

Then, CreateVspPayment calls that new function, and requests inputs totaling at least (fee + minMixableChange + estTxFee).

Edge Case Note

If this function uses a single input, the math works fine. However, if multiple inputs are used and they total the EXACT target (zero buffer), the actual txFee for two inputs will be higher than the estimated fee rate, and so we'll still end up with unmixable change.

I considered adding a log somewhere like:

if !txrules.IsDustAmount(dcrutil.Amount(change), txsizes.P2PKHPkScriptSize, feeRate) {
	minMixChange := smallestMixChange(feeRate)
	if dcrutil.Amount(change) < minMixChange {
		log.Warnf("VSP payment change %v is less than minimum mixable %v",
		dcrutil.Amount(change), minMixChange)
	}
	changeOut.Value = change
	tx.TxOut = append(tx.TxOut, changeOut)
	txauthor.RandomizeOutputPosition(tx.TxOut, len(tx.TxOut)-1)
}

but I figured that this might be an extreme edge case, and might be completely unnecessary?

@matthawkins90 matthawkins90 changed the title wallet: ensure VSP payent doesn't create unmixable change wallet: ensure VSP payment doesn't create unmixable change Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant