Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient balance error at 0.0001 BTC, yet available balance says 0.0023 BTC #4505

Closed
314159265359879 opened this issue Nov 9, 2023 · 11 comments · Fixed by #4849
Closed
Assignees
Labels
area:bitcoin area:send bug Functionality broken bug-p2 Critical functionality broken for few users, with no clear workarounds effort:medium Expected to take 2-5 days of integration work

Comments

@314159265359879
Copy link
Contributor

bc1qzl5xt45gazvj2j4su2xdm5tftqkckgst5hhald
image

On another wallet it shows
image

I have always assumed small UTXO's causing it to be non economical to include everything but if that is the case I don't understand why the "available balance" is displayed so much higher.

I am sure the current network fees also play a role
image

I would love to see this confirmed by a developer who can mock this address. What would be the transaction size, is it that high that the transfer can't be covered by the available balance?

@314159265359879
Copy link
Contributor Author

We know that the size (and thus fee) of a transaction can increase a lot for every additional input it has. Leather is supposed to select UTXO's based on size so that the largest gets included first (because it is most cost effective).

Yet when they this user tries with Leather to send 0.0001 BTC the message is "insufficient balance" if Leather uses the biggest UTXO to cover this... it should be no more expensive to cover the fee than with the other wallet 0.00033390?

Using this API to check UTXO's on the address we do see a lot of small ones, likely not cost effective to transfer right now with 200-300 sats/vB fees. https://blockstream.info/api/address/bc1qzl5xt45gazvj2j4su2xdm5tftqkckgst5hhald/utxo but there is atleast one large UTXO in there too:
image

That UTXO alone there (blockstream API) that could cover it the transfer of 0.0001 BTC: that would be an estimated 150-200 kB transaction with a single input and output.
at 200 sat/vB still just 40000 sats total fee so ample to cover the transfer and fee.

@314159265359879 314159265359879 added the bug Functionality broken label Nov 9, 2023
@314159265359879
Copy link
Contributor Author

Another case like the one above:
With this address: bc1qy0kfxd896lvujuq4xreuv6xc85t65ljxhs2san, similarly it has a lot of small UTXO's.

https://blockstream.info/api/address/bc1qy0kfxd896lvujuq4xreuv6xc85t65ljxhs2san/utxo

The available balance in the lower right corner looks sufficient. Average network fees for the last five blocks were 30-72 sats/vB.

The bigger UTXO's look like enough to cover fee and the transfer for a small amount like 0.00006 BTC, if a single UTXO would be used to cover the fee and transfer, right?
image

image

@markmhendrickson markmhendrickson added the bug-p2 Critical functionality broken for few users, with no clear workarounds label Nov 13, 2023
@kyranjamie
Copy link
Collaborator

I wonder if this might just be a bug with the validation as I've ran into this happening illegitimately before.

I'd recommend that we try testing this feature with the wallet set to slow 3G emulation, or perhaps it's a react rendering issue where the validator is running behind what the UI is showing.

@markmhendrickson
Copy link
Collaborator

@314159265359879 can you perform such a test?

@314159265359879
Copy link
Contributor Author

@markmhendrickson I had a call about this last week with Kyran, I need some dev eyes on this.

I can't run these tests. I think it may also require mocking the addresses that were affected (address' balance state has changed since this was first reported, atleast for the first address).
bc1qzl5xt45gazvj2j4su2xdm5tftqkckgst5hhald
bc1qy0kfxd896lvujuq4xreuv6xc85t65ljxhs2san

@314159265359879
Copy link
Contributor Author

Another case like this user has a wallet with several small UTXO's but also one big one.

This address
https://mempool.space/address/bc1qdmzh8st7lfe7tk5uehu4ff8nkkcf359eq5h96s
image

the largest UTXO is 56177 sats.

When the user tried "send max" only 16k was transferrable. A high total fee is expected because currently, send max will include non-economical amounts.

Because the wallet should select the biggest UTXO's first it should also be able to send out about 43000 sats without an issue. The transaction fee would be about 12000-13000 sats at a rate of 72 sats/vB. Which means 56177 sats UTXO should be able to cover it on its own without including any small utxo's in the 600 sats range.

But the user sees this:
image

Left is "sending max" amount.

On the right is trying to send 30,000 sats.

@kyranjamie
Copy link
Collaborator

I wonder if you can provide some test cases that'll help us test this logic @314159265359879?

Ideally we can have this covered by better unit tests that consider a set of UTXOs and how much the max transferable amount should be?

@markmhendrickson
Copy link
Collaborator

Path forward here is to write integration tests for send max

@314159265359879
Copy link
Contributor Author

Test cases. Are we changing the current behavior's or keeping it as it is?

Right now it will empty the wallet at whatever cost.
Users prefer to exclude UTXO's when it costs a lot to send them out. There are still some options we can choose between:
aa. exclude when the UTXO's cost more than a certain percentage of what they're worth? (lets say 20%)
bb. include them as long as sending them out costs less then 100% of the UTXO?
cc. or perhaps do you want to exclude UTXO's with a size below 1201 sats regardless of network fees?

Goal of the test is: Are UTXO's excluded from send-max when it is not economic to send them out (based on predefined rule)

Lets assume a wallet has these UTXO's on their BTC address (native segwit, P2WPKH)

a. 0.00000600
b. 0.00000600
c. 0.00001200
d. 0.00001200
d. 0.00010000
e. 0.00010000
f. 0.00025000
g. 0.00040000
h. 0.50000000

According to this calculator adding an input increases the transaction size by 68 vB (transaction type P2WPKH).

at these fee rates .... including one more input will cost: -
A. 1 sat/vB - 68 sats per input
B. 5 sats/vB - 340 sats per input
C. 30 sats/vB - 2040 sats per input
D. 100 sats/vB - 6800 sats per input
E. 400 sats/vB - 27400 sats per input

If the only goal is to test that UTXO's are being excluded when not cost-effective to send and at least 80% of the value is sent (not spend as fee) (aa) the test should determine if at (E.) 400 sats/vB fees, the wallet does excludes UTXO a. through g. and only includes h. as cost-effective.

Further testing could help determine if the send-max also excludes part of the UTXO's with varying market fees. For example if aa. is adapted and the market fees average 30 sats/vB. Excluded UTXO should be a. through d. and included should be e. through h.

@markmhendrickson
Copy link
Collaborator

@314159265359879 your last comment here seems like a related but different UX question than this issue's original one? In that this issue deals with ensuring that users can send their entire available balance, whereas your last comment deals with providing users with warnings or optionality in regards to using non-cost-effective UTXOs?

If so, can we break the latter out into its own issue?

@markmhendrickson
Copy link
Collaborator

Also by "writing integrations tests" for this particular issue, we wouldn't aim to change the current UX, but rather fix it (along the lines of ensuring users can send their entire available balance). These automated tests would presumably help identify cases in which the bug arises, fix them, and prevent regressions in the future.

@markmhendrickson markmhendrickson added this to the Fix urgent bugs milestone Jan 2, 2024
@edgarkhanzadian edgarkhanzadian self-assigned this Jan 12, 2024
@kyranjamie kyranjamie added the effort:medium Expected to take 2-5 days of integration work label Jan 18, 2024
@edgarkhanzadian edgarkhanzadian linked a pull request Jan 23, 2024 that will close this issue
kyranjamie pushed a commit that referenced this issue Jan 26, 2024
## [6.26.0](v6.25.0...v6.26.0) (2024-01-26)

### Features

* **ui:** adds input element, ref [#4810](#4810) ([e223b0a](e223b0a))

### Bug Fixes

* filter out uneconomical utxos, closes [#4505](#4505) ([a6e116c](a6e116c))
* layout issue when stacking, ref [#4851](#4851) ([ce6c52a](ce6c52a))
* nested button tooltip error, closes [#4835](#4835) ([5b87e3d](5b87e3d))
* onboarding gate in ledger mode ([07729b5](07729b5))
* sign out of the wallet before proceeding with ledger sign in ([aa214c8](aa214c8))
* update psbt warning copy ([988e23f](988e23f))

### Internal

* add BulletSeparator story ([863a128](863a128))
* **deps:** bump vite from 5.0.11 to 5.0.12 ([4ec0cd9](4ec0cd9))
* fix ledger, ref [#4861](#4861) ([62bf0ec](62bf0ec))
* improve styles, try mnemonic ([f6bad6a](f6bad6a))
* post-release merge back ([be0d9a7](be0d9a7))
* remove dupe imports, lint ([b05f731](b05f731))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:bitcoin area:send bug Functionality broken bug-p2 Critical functionality broken for few users, with no clear workarounds effort:medium Expected to take 2-5 days of integration work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants