Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Thekool1s on September 15, 2017, 11:39:12 AM



Title: Smart inputs?
Post by: Thekool1s on September 15, 2017, 11:39:12 AM
I have a question regarding inputs, let's say i have 3 inputs, two of them have 0.015 btc and one has 0.03 btc, let's say i have to send 0.03 btc, my question is are the wallets like electrum smart enough to use the single input or they will use the inputs randomly.


Title: Re: Smart inputs?
Post by: onnz423 on September 15, 2017, 12:30:48 PM
I think that at least electrum spends one input at time, and also allows you to set custom fees as well. The transaction currently should not be too costly, since you can merge inputs at a very affordable fee currently. I usually pay around 5sat/byte on electrum as a fee, because recentlt the mempool has been pretty empty, and no matter how much you pay fee, you can expect confirmation time within few blocks.


Title: Re: Smart inputs?
Post by: mocacinno on September 15, 2017, 12:35:57 PM
If have no idear which algorithm electrum uses for the selection of suitable unspent outputs... I can only imagine it's comparable to bitcoin core's algorithm:
https://github.com/bitcoin/bitcoin/blob/c22a53cd6351b3f0e96de971b001ad712b83fc47/src/wallet/wallet.cpp#L2303

IIRC, core does the following steps

1) if it finds one unspent output with the exact value, it will be used
else
2) if the sum of all unspent outputs smaller than the target value is equal to the target value, they will all be used
else
3) if the sum of all unspent outputs < target, the smallest unspent output that is larget than the target is used
else
4) bitcoin just starts to randomly combine unspent outputs untill a combination is found that is bigger than the target (i think the exact value is also ok)


Title: Re: Smart inputs?
Post by: ranochigo on September 15, 2017, 12:38:32 PM
I have a question regarding inputs, let's say i have 3 inputs, two of them have 0.015 btc and one has 0.03 btc, let's say i have to send 0.03 btc, my question is are the wallets like electrum smart enough to use the single input or they will use the inputs randomly.
Most wallets treats inputs differently, they are smart enough to figure out which one should they use.

For the reference clients, they use an algorithm to determine it. If the reference client finds an input that matches the intended send plus transaction fees, they will use it. Otherwise, if there isn't such a UXTO that fits, they will attempt to find another set of UXTOs that can match the send amount. Otherwise, they will attempt to pair the UXTO up together till they can find a set of UXTO to use that will spend the least number of UXTOs.

For Electrum, they have the privacy and priority settings. Privacy means that all the inputs will be spent, increasing the privacy and reduces the UXTO bloat. This will result you in having to pay more fees in each transaction since you are using more UXTOs in every transaction. For priority, they sort out the UXTOs and use the oldest UXTOs first.


Title: Re: Smart inputs?
Post by: buwaytress on September 15, 2017, 04:31:43 PM
I can't recall really testing how Electrum chooses inputs but I suspect that mocacinno's post describes it accurately. I can remember exact inputs being used when they equal the spend, but I haven't since very early on had a lot of inputs to see how their behaviour works. But if you want to ensure that smaller inputs are used up first (which I'm sure is something we all want to do to keep our wallets lean), you can always use the freeze feature in Electrum.

Just right click on the addresses in the list tab and choose freeze, you can use Ctrl+click to select multiples. The amount of coins available in balance will update automatically. Then when you make the spend, only inputs from addresses not frozen will be used. You can always unfreeze when you want to use them up later.


Title: Re: Smart inputs?
Post by: HCP on September 16, 2017, 05:09:02 AM
Or you can actually just go to the "coins" tab and select the exact coins you want to use... Ctrl+click each UTXO you want to include, then right click and select "spend"...

Honestly, the coin control options (like the fee options) in Electrum are pretty comprehensive!