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; in select_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 (like select_coins_srd) are executed and the best result is taken. And the best result selection is currently implemented as
results.into_iter().min_by_key(|res| res.waste)
In my case, the waste value was the same for all algorithms; and since select_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.
This is especially noticeable/reproducible in the
config-broadcast nomode (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_srdwe randomly select UTXOs, populating a heap, and in the end do: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 asIn my case, the
wastevalue was the same for all algorithms; and sinceselect_coins_srdis executed first, it was always winning.So:
waste, but if it's equal then the UTXO count should be taken into account as well.wastecalculation can be improved.