Skip to content

Commit

Permalink
Merge pull request #8595 from nopara73/1656676832
Browse files Browse the repository at this point in the history
Bias random coin selection towards larger amounts
  • Loading branch information
molnard committed Jul 4, 2022
2 parents b3cba4f + 2e2b80a commit d553c04
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,22 @@ internal static ImmutableList<SmartCoin> SelectCoinsForRound(IEnumerable<SmartCo
var remainingLargestAmounts = bestRepGroups
.Select(x => x.OrderByDescending(x => x.Amount).First())
.ToHashSet();
var largestAmount = remainingLargestAmounts.RandomElement();

// Select randomly at first just to have a starting value.
var selectedLargeCoin = remainingLargestAmounts.RandomElement();

// Bias selection towards larger numbers.
foreach (var coin in remainingLargestAmounts.OrderByDescending(x => x.Amount))
{
if (rnd.GetInt(1, 101) <= 50)
{
selectedLargeCoin = coin;
break;
}
}

var finalCandidate = bestRepGroups
.Where(x => x.OrderByDescending(x => x.Amount).First() == largestAmount)
.Where(x => x.OrderByDescending(x => x.Amount).First() == selectedLargeCoin)
.RandomElement();

return finalCandidate?.ToShuffled()?.ToImmutableList() ?? ImmutableList<SmartCoin>.Empty;
Expand Down

0 comments on commit d553c04

Please sign in to comment.