Fix withdrawal fee calculation & the min relay fee problem. #6544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1.0 sat/vB withdrawals were sometimes sent at 0.995 sat/vB and rejected by the network. Fixes #6493
Description of the problem:
Fee estimation for withdrawals has a bug which can be seen if you repeatedly request the withdrawal of the same UTXO and observe the fee shown; it varies slightly.
Worse than that is when a withdrawal is started (after you've seen the preview and confirmed), Bisq re-calculates the tx using the fee calculated earler and the actual receive address, but the tx can end up being larger than what it used in the preview.
The main problem here is that in the case where user chose 1 sat/vB, the sent tx can end up being below the min relay fee (less than 1 sat/vB) and is rejected by nodes. The user is left with a corrupted wallet and has to do an SPV resync. See example reported in #6493.
Why does this happen? See the fee estimation code here:
bisq/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java
Lines 1092 to 1101 in d682d95
It creates a random receive address for purposes of calculating the fee. The problem with this is two-fold:
Fix implemented here:
The withdrawal fee estimation should use the actual address the user has chosen to send to, therefore eliminating all variability in results. The sent tx will be exactly the same as the tx used in the preview, therefore fixing the problem of lower than 1 sat/vB transactions.