Add SuggestedMaxAmount
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -56,7 +56,8 @@ public static class WabiSabiFactory
Network.Main,
new InsecureRandom(),
new FeeRate(100m),
- new CoordinationFeeRate(0.003m, Money.Zero)));
+ new CoordinationFeeRate(0.003m, Money.Zero),
+ Money.Zero));
round.MaxVsizeAllocationPerAlice = 11 + 31 + MultipartyTransactionParameters.SharedOverhead;
return round;
}
@@ -259,7 +260,7 @@ public static class WabiSabiFactory
}
public static BlameRound CreateBlameRound(Round round, WabiSabiConfig cfg)
- => new(new(cfg, round.Network, new InsecureRandom(), round.FeeRate, round.CoordinationFeeRate), round, round.Alices.Select(x => x.Coin.Outpoint).ToHashSet());
+ => new(new(cfg, round.Network, new InsecureRandom(), round.FeeRate, round.CoordinationFeeRate, round.SuggestedMaxAmount), round, round.Alices.Select(x => x.Coin.Outpoint).ToHashSet());
public static (IKeyChain, SmartCoin, SmartCoin) CreateCoinKeyPairs()
{

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/Rounds/MultipartyTransactionStateTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/Rounds/MultipartyTransactionStateTests.cs
using NBitcoin;
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Backend;
+using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using Xunit;
@@ -70,4 +71,26 @@ public class MultipartyTransactionStateTests
Assert.Equal(clientState3.Inputs, state3.Inputs);
Assert.Equal(clientState3.Outputs, state3.Outputs);
}
+
+ [Fact]
+ public void GetSuggestedAmountsTest()
+ {
+ Money baseAmount = Money.Coins(0.1m);
+
+ for (int i = 0; i < 100; i++)
+ {
+ var expected = i switch
+ {
+ 0 => baseAmount,
+ var n when (n % 32 == 0) => baseAmount * 100000,
+ var n when (n % 16 == 0) => baseAmount * 10000,
+ var n when (n % 8 == 0) => baseAmount * 1000,
+ var n when (n % 4 == 0) => baseAmount * 100,
+ var n when (n % 2 == 0) => baseAmount * 10,
+ _ => baseAmount,
+ };
+
+ Assert.Equal(expected, Arena.GetSuggestedMaxAmount(i));
+ }
+ }
}

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -52,6 +52,8 @@ public partial class Arena : PeriodicRunner
public event EventHandler<Transaction>? CoinJoinBroadcast;
+ private int ConnectionConfirmationStartedCounter { get; set; }
+
protected override async Task ActionAsync(CancellationToken cancel)
{
using (await AsyncLock.LockAsync(cancel).ConfigureAwait(false))
@@ -104,6 +106,7 @@ public partial class Arena : PeriodicRunner
else if (round.IsInputRegistrationEnded(Config.MaxInputCountByRound))
{
round.SetPhase(Phase.ConnectionConfirmation);
+ ConnectionConfirmationStartedCounter++;
}
}
catch (Exception ex)
@@ -329,7 +332,7 @@ public partial class Arena : PeriodicRunner
private async Task CreateBlameRoundAsync(Round round, CancellationToken cancellationToken)
{
var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancellationToken).ConfigureAwait(false)).FeeRate;
- RoundParameters parameters = new(Config, Network, Random, feeRate, round.CoordinationFeeRate);
+ RoundParameters parameters = new(Config, Network, Random, feeRate, round.CoordinationFeeRate, round.SuggestedMaxAmount);
var blameWhitelist = round.Alices
.Select(x => x.Coin.Outpoint)
.Where(x => !Prison.IsBanned(x))
@@ -345,12 +348,30 @@ public partial class Arena : PeriodicRunner
{
var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancellationToken).ConfigureAwait(false)).FeeRate;
- RoundParameters roundParams = new(Config, Network, Random, feeRate, Config.CoordinationFeeRate);
+ RoundParameters roundParams = new(Config, Network, Random, feeRate, Config.CoordinationFeeRate, GetSuggestedMaxAmount(ConnectionConfirmationStartedCounter));
Round r = new(roundParams);
Rounds.Add(r);
}
}
+ internal static Money GetSuggestedMaxAmount(int roundCounter)
+ {
+ Money baseAmount = Money.Coins(0.1m);
+
+ var suggested = roundCounter switch
+ {
+ 0 => baseAmount,
+ var n when (n % 32 == 0) => baseAmount * 100000,
+ var n when (n % 16 == 0) => baseAmount * 10000,
+ var n when (n % 8 == 0) => baseAmount * 1000,
+ var n when (n % 4 == 0) => baseAmount * 100,
+ var n when (n % 2 == 0) => baseAmount * 10,
+ _ => baseAmount,
+ };
+
+ return suggested;
+ }
+
private void TimeoutRounds()
{
foreach (var expiredRound in Rounds.Where(

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Round.cs
WalletWasabi/WabiSabi/Backend/Rounds/Round.cs
@@ -33,6 +33,7 @@ public class Round
ConnectionConfirmationTimeFrame = TimeFrame.Create(RoundParameters.ConnectionConfirmationTimeout);
OutputRegistrationTimeFrame = TimeFrame.Create(RoundParameters.OutputRegistrationTimeout);
TransactionSigningTimeFrame = TimeFrame.Create(RoundParameters.TransactionSigningTimeout);
+ SuggestedMaxAmount = roundParameters.SuggestedMaxAmount;
}
public uint256 Id => _id ??= CalculateHash();
@@ -64,6 +65,7 @@ public class Round
protected RoundParameters RoundParameters { get; }
public Script CoordinatorScript { get; set; }
+ public Money SuggestedMaxAmount { get; }
public TState Assert<TState>() where TState : MultipartyTransactionState =>
CoinjoinState switch

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/RoundParameters.cs
WalletWasabi/WabiSabi/Backend/Rounds/RoundParameters.cs
@@ -11,7 +11,8 @@ public class RoundParameters
Network network,
WasabiRandom random,
FeeRate feeRate,
- CoordinationFeeRate coordinationFeeRate)
+ CoordinationFeeRate coordinationFeeRate,
+ Money suggestedMaxAmount)
{
Network = network;
Random = random;
@@ -29,6 +30,7 @@ public class RoundParameters
OutputRegistrationTimeout = wabiSabiConfig.OutputRegistrationTimeout;
TransactionSigningTimeout = wabiSabiConfig.TransactionSigningTimeout;
BlameInputRegistrationTimeout = wabiSabiConfig.BlameInputRegistrationTimeout;
+ SuggestedMaxAmount = suggestedMaxAmount;
}
public WasabiRandom Random { get; }
@@ -44,4 +46,5 @@ public class RoundParameters
public TimeSpan OutputRegistrationTimeout { get; }
public TimeSpan TransactionSigningTimeout { get; }
public TimeSpan BlameInputRegistrationTimeout { get; }
+ public Money SuggestedMaxAmount { get; }
}

Add SuggestedMaxAmount