View Issue Details

IDProjectCategoryView StatusLast Update
0011099Talerwallet-corepublic2026-03-20 23:55
ReporterFlorian Dold Assigned ToFlorian Dold Resolution deadline
ImplementerReviewer 
Release signed byDeployed by 
VerifierCommunicator 
Data protection authority notification requiredNo  
CSIRT notification requiredNo  
Estimated effort (hours)Actual effort (hours)0 
Fast-trackNo
Work packagenone
PrioritynormalSeveritytweakReproducibilityhave not tried
Status closedResolutionfixed 
Product Versiongit (master) 
Target Version1.5Fixed in Version1.5 
Summary0011099: coin selection should minimize small coins [3h]
DescriptionAccording to experiments by one of Mikolai's student's, the current coin selection results in a large number of small coins that aren't spent. We should try to spend small coins earlier.
TagsNo tags attached.

Required notifications

Address or linkRemarkAdded byNotifiedActions

Relationships

related to 0011274 informingFlorian Dold implement full DD91 coin selection in wallet-core [8h] 

Activities

Christian Grothoff

2026-03-12 17:36

manager   ~0028119

I have an algorithm to propose. 3 passes:

(0) Only consider coins/denominations that are eligible (exchange, age restriction, etc.).
(1) In ascending denomination order, add coins until we are at or above the total amount. If multiple coins of the same denomination are available, start with the ones that expire first. [now we have for sure >= total amount]
(2) In descending denomination order, remove coins that would cause the total to remain at or above the total amount. If removing the smallest coin in the selection would cause us to fall below the total amount, obtain change for that coin. [now we have for sure == total amount]
(3) If total fees exceed what would be paid by the merchant *and* we do not have an imbalanced wallet with > 5*F_D coins per denomination D on average (except the largest denomination) [where "D" is the factor in the amount of a coin of denomination D and the next larger denomination D+1], then in ascending denomination order see if we can replace the selection of multiple small coins with larger coins to reduce deposit fees (like using 2 cents instead of 2x 1 cent, or 4 cents instead of 4x 1 cent [F_D=2], or if denominations are not powers of 2 also 3x 1 cent for 3 cents (F_D=3)). Stop early if the total fees fall below what the merchant pays.

This way we have:
* linear coin selection cost
* spent old coins first
* minimize small coins: reduce storage, ensure fast selection (few coins to choose from)
* reasonably minimize deposit fees (if possible)
* avoid getting change unnecessarily

Disadvantages:
* does not strictly minimize number of fresh coins in refresh (but spends old coins faster)
* ???

Florian Dold

2026-03-12 18:43

manager   ~0028122

Sounds reasonable, I guess how we should proceed is:

* Immediately implement a simplified version of this algorithm that does (0)+(1) partially (2)
  * That's already done, adjusting tests for differing amounts right now
* Flesh out the above algorithm in a DD
* Implement the full algorithm (with low prio in 1.5, possibly later)

Florian Dold

2026-03-20 12:45

manager   ~0028203

Some improvements to the coin selection are already implemented, but full implementation will be done in 0011274.

Issue History

Date ModifiedUsernameFieldChange
2026-02-17 21:58Florian DoldNew Issue
2026-02-19 17:46Christian GrothoffSeverityminor => tweak
2026-02-19 17:46Christian GrothoffStatusnew => implementing
2026-02-19 17:46Christian GrothoffProduct Version => git (master)
2026-02-19 17:46Christian GrothoffTarget Version => 1.8
2026-03-12 13:52Florian DoldTarget Version1.8 => 1.5
2026-03-12 13:52Florian DoldSummarycoin selection should minimize small coins => coin selection should minimize small coins [3h]
2026-03-12 14:15Florian DoldAssigned To => Florian Dold
2026-03-12 14:15Florian DoldStatusimplementing => assigned
2026-03-12 17:36Christian GrothoffNote Added: 0028119
2026-03-12 18:43Florian DoldNote Added: 0028122
2026-03-20 12:43Florian DoldRelationship addedrelated to 0011274
2026-03-20 12:45Florian DoldStatusassigned => informing
2026-03-20 12:45Florian DoldResolutionopen => fixed
2026-03-20 12:45Florian DoldNote Added: 0028203
2026-03-20 23:47Christian GrothoffFixed in Version => 1.5
2026-03-20 23:55Christian GrothoffStatusinforming => closed