peerswap
peerswap copied to clipboard
[feature request] Avoid dust outputs
Was running a this successful swap between LND v0.15.0 nodes on signet (testing the PR #79):
₿ pscli listswaps
{
"swaps": [
{
"id": "4fe4b28c2138bd75474ece52603a0e019998941df0f0fa95ef6f67fded7580a1",
"created_at": "2022-07-11 16:39:17 +0100 BST",
"type": "swap out",
"role": "sender",
"state": "State_ClaimedPreimage",
"initiator_node_id": "02bad9bbc74153e191c5852fac04000a45ac45bb4363c99e099a5402ee3beeebf0",
"peer_node_id": "020bdef67ab9fdc7575ee13851b2ffc01ca1b033de2c4af5292e3672ca5ba44be3",
"amount": "100000",
"channel_id": "98321:1:1",
"opening_tx_id": "61a5e4456fa8e7b35d432ef4a063247e069d853944f3e85341ffa4b57df82d1c",
"claim_tx_id": "f7e94ccf0f7dcdd0476648488e97d0a450136f8dcfa061e66cc30917e1a1d37c",
"cancel_message": ""
}
]
}
Got a dustsize (303 sats) change output in the first transaction: https://mempool.space/signet/tx/61a5e4456fa8e7b35d432ef4a063247e069d853944f3e85341ffa4b57df82d1c going back into the swapout receiver's onchain wallet:
₿ slncli listunspent
{
"utxos": [
{
"address_type": 0,
"address": "tb1q9wdnxyft5wn487mh3yem4hxc8xkk0urf99zfe4",
"amount_sat": 303,
"pk_script": "00142b9b33112ba3a753fb778933badcd839ad67f069",
"outpoint": "61a5e4456fa8e7b35d432ef4a063247e069d853944f3e85341ffa4b57df82d1c:0",
"confirmations": 4
},
PeerSwap should avoid creating such a tiny output onchain. Amounts below the dust limit should be added to the miner fee for both convenience and privacy.
The limit for SegWit outputs is 330 sats https://bitcoin.stackexchange.com/questions/113649/dust-threshold-for-testnet, but would be comfortable with a higher limit.
Normal wallets have only one option to avoid dust creation: Send it all to miners.
PeerSwap has another way to avoid dust creation. When you request a swap you eyeball the channel and decide you want to swap 10 million sats but you don't actually need that particular amount. What if the swap amount is allowed to be within a small range +/-. The other side could auto-negotiate the swap cost and the exact amount it wants to swap. I personally would allow a range as big as like 100k sats if it avoids the need for another output.
File this under ideas for the next protocol spec.
Concept: Option peerswap-strict-amount default to false. It would also be an field per-swap. Most swaps for the purpose of channel balancing don't care about the particular amount swapped. If swaps happen for some other purpose in a future protocol like for trade then they may insist upon a particular amount. Then the other side could accept or reject it.
We should add a dumb dust mitigation for now where a mempool policy failing tiny output would go to fees. That doesn't require any negotiation with the peer.
Later it could be optimized by making the swap amount flexible which is the better way to avoid not only dust outputs but many additional small outputs as well. This would be a significant win to the blockchain in terms of storage efficiency.
What would be a sufficient dust limit?
I would go as high as avoiding outputs less than 20k sats (the minimum LN channel size) then later a dynamically chosen amount makes sense with peerswap-strict-amount=false as described above.