ElementsProject / elements

Open Source implementation of advanced blockchain features extending the Bitcoin protocol
MIT License
1.06k stars 380 forks source link

[Bug] Elements-23.2.2 with CT discount cannot send full balance less fee #1358

Open Impa10r opened 2 months ago

Impa10r commented 2 months ago

When sendtoaddress is called to send the whole liquid balance less margin for fee (75-200 sats) CT discount is not applied and results in:

error code: -6
error message:
Insufficient funds

https://github.com/ElementsProject/peerswap/pull/304#issuecomment-2303931071

We understand there is an option subtractfeefromamount, but prefer not to use it.

apoelstra commented 2 months ago

I'm skeptical that just changing the CT discount logic would make this work (though if you are providing a large margin for fee maybe it will). The fee estimation logic inherently overestimates during calculations and tends to fail near maximum balance.

Upstream added the sendall RPC https://github.com/bitcoin/bitcoin/pull/24118 to cover this usecase, which replaces subtractfeefromamount which was full of weird behavior.