Skip to content

Commit

Permalink
fix(coinjoin): fix two issues when creating denominations
Browse files Browse the repository at this point in the history
* denomination map count were not updated

* first loop was infinite in some cases
  • Loading branch information
HashEngineering committed Aug 22, 2024
1 parent 934c8bf commit 888d980
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public boolean process(Coin balanceToDenominate, int outputs, Result<Boolean> ad
// Add output and subtract denomination amount
if (txBuilder.addOutput(denomValue) != null) {
++nOutputs;
++currentDenomIt;
mapDenomCount.put(denomValue, ++currentDenomIt);
balanceToDenominate = balanceToDenominate.subtract(denomValue);
log.info("coinjoin: 1 - denomValue: {}, balanceToDenominate: {}, nOutputs: {}, {}",
denomValue.toFriendlyString(), balanceToDenominate.toFriendlyString(), nOutputs, txBuilder);
Expand All @@ -276,7 +276,10 @@ public boolean process(Coin balanceToDenominate, int outputs, Result<Boolean> ad
for (Map.Entry<Coin, Integer> entry : mapDenomCount.entrySet()) {
// Check if this specific denom could use another loop, check that there aren't nCoinJoinDenomsGoal of this
// denom and that our nValueLeft/balanceToDenominate is enough to create one of these denoms, if so, loop again.
if (entry.getValue() < CoinJoinClientOptions.getDenomsGoal() && txBuilder.couldAddOutput(entry.getKey()) && balanceToDenominate.isGreaterThan(Coin.ZERO)) {
Coin denom = entry.getKey();
Integer count = entry.getValue();
if (count < CoinJoinClientOptions.getDenomsGoal() && txBuilder.couldAddOutput(denom) &&
balanceToDenominate.isGreaterThan(CoinJoin.getSmallestDenomination())) {
finished = false;
log.info("coinjoin: 1 - NOT finished - denomValue: {}, count: {}, balanceToDenominate: {}, {}",
entry.getKey().toFriendlyString(), entry.getValue(), balanceToDenominate.toFriendlyString(), txBuilder);
Expand Down

0 comments on commit 888d980

Please sign in to comment.