RGB-WG / rgb

RGB smart contracts: command-line tool & wallet runtime library for desktop and mobile integration
https://rgb.tech
Apache License 2.0
129 stars 34 forks source link

Not accounting for non-RGB inputs in coin selection #113

Open nicbus opened 7 months ago

nicbus commented 7 months ago

Trying to execute a few transfers using this branch of rgb-sandbox I run into the following error:

Error: not enough funds to pay fee of 400 sats; all inputs contain 2000 sats and outputs spends 2000 sats out of them.

The wallet should have enough bitcoins as the unspents come up as:

Height     Amount, ṩ    Outpoint                                                                                                                                                                                                                                                                                               
bcrt1q06vjlq89kufjgzenwusm99l6hv5ygxhur8qun8    &9/0                                                                                                                                                                                                                                                                           
107             2000    e6cfb776a1e03165f6e739a6452231ac9d30fb20cbde0ae130ed7b10d20dc7b1:0                                                                                                                                                                                                                                     
106             2000    7a39dd007218bdbf3d6d1a2b919700d9a144a1d2cab20cace5a8ad57df2395b7:0                                                                                                                                                                                                                                     

bcrt1qwke7jgvxuwcwk8q4m4mglgmltyfzasde5c4nsj    &0/0                                                                                                                                                                                                                                                                           
105        100000000    2a0bd1672cfb051c7c0627d1295c07325974b53048a87169c80b44f8698c949e:0                                                                                                                                                                                                                                     

I guess this happens because the input selection is not adding more inputs if needed to cover fees (or outputs), but I haven't dug deeper than this.

dr-orlovsky commented 7 months ago

Yes, you are right in your assumption. I remember writing that logic, but it seems somehow it is skipped. We need to move the issue into BP wallet since it happens there.

shuimuliang commented 7 months ago

Suppose Alice has one UTXO with 2000 sats. 2000 -> 1600 -> 1200 -> 800 -> 400 (it won't be able to broadcast anymore)

dr-orlovsky commented 7 months ago

Suppose Alice has one UTXO with 2000 sats. 2000 -> 1600 -> 1200 -> 800 -> 400 (it won't be able to broadcast anymore)

It would - you just need to add more tx inputs and feed additional sats into the witness transaction

dr-orlovsky commented 5 months ago

Re-opening and changing the name as explained in https://github.com/BP-WG/bp-wallet/issues/13#issuecomment-2021330041

dr-orlovsky commented 5 months ago

Now, there is the question: when and how should we use non-RGB inputs for moving some BTCs to RGB outputs.

In other words, this situation is not a bug but a feature - however possibly bad UX. I just do not know how to make it better: I assume many wallets will differenciate BTC and RGB balances, and if some BTC are "disappearing" after RGB transactions it would be even worse UX...

nicbus commented 5 months ago

I agree that using funds from the "BTC balance" without prior user consent would be bad UX.

I propose doing something similar to what rgb-lib does to handle this. Specifically, I would:

dr-orlovsky commented 5 months ago

This is a large feature request, and since rgb cli is not a mainstream wallet I propose to postpone this for v0.12. End-users will be able to do that anyway with proper mobile and web wallets build with rgb-lib