-
Notifications
You must be signed in to change notification settings - Fork 30
Description
This is especially noticeable/reproducible in the config-broadcast no
mode (introduced in #1904), in which the new transaction's summary is printed to the console without it being broadcast to the network.
E.g. when trying to create a new transaction I can see that my biggest UTXO (100k TML) is selected, but it's also accompanied by smaller UTXOs, which should not be needed.
There seem to be multiple reasons for this:
-
The selection algirithm to blame seems to be
srd
; inselect_coins_srd
we randomly select UTXOs, populating a heap, and in the end do:if selected_eff_value >= target_value { // Result found, add it. while let Some(group) = heap.pop() { result.add_input(&group.0, pay_fees)?; } return Ok(result); }
So the reason for the smaller UTXO being initially selected is that the large UTXO was selected later. But then the above-mentioned code shouldn't put the entire heap into the result; only the top items necessary to meet the target should be put there.
-
In
select_random_coins
, several algoriths (likeselect_coins_srd
) are executed and the best result is taken. And the best result selection is currently implemented asresults.into_iter().min_by_key(|res| res.waste)
In my case, the
waste
value was the same for all algorithms; and sinceselect_coins_srd
is executed first, it was always winning.
So:- probably the best result should be selected first by
waste
, but if it's equal then the UTXO count should be taken into account as well. - perhaps
waste
calculation can be improved.
- probably the best result should be selected first by