MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.85k stars 839 forks source link

If one output has amount below dust, throw exception instead of removing it #1182

Closed NicolasDorier closed 10 months ago

NicolasDorier commented 10 months ago

While it shouldn't really matter economically speaking to remove output with a value that is too small, it is surprising behavior for users, and give rise to several edge case.

Assuming 540 of dust, here is a summary of the changes of behavior:

Case Before Now
you send bob 600 satoshi, but substract 400 sats, the output left is 200 sats. Silently remove output Throw exception
you send bob 200 satoshi (without substract fee) Silently remove output Throw exception
you sent bob 600 satoshi, substracted 700 sats of fee Throw exception Throw exception

Before, we would silently remove such outputs in the built transaction. Now the builder will always throw an exception.

farukterzioglu commented 10 months ago

How can we differentiate the cases;

If we can differentiate the second case, user can try to send it again after fees dropped. When the fees are lower, subtracted amount will be less and remaining amount could be bigger than dust.

But the first case will be always fail.

Right now both of them throws OutputTooSmallException exception, so no way to handle them differently