Change CcjRoundConfig according to new conventions
MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjRoundConfig.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjRoundConfig.cs
@@ -2,6 +2,7 @@ using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
+using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading.Tasks;
@@ -20,43 +21,55 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
[JsonProperty(PropertyName = "Denomination")]
[JsonConverter(typeof(MoneyBtcJsonConverter))]
- public Money Denomination { get; internal set; }
+ public Money Denomination { get; internal set; } = Money.Coins(0.1m);
- [JsonProperty(PropertyName = "ConfirmationTarget")]
- public int? ConfirmationTarget { get; internal set; }
+ [DefaultValue(Constants.OneDayConfirmationTarget)]
+ [JsonProperty(PropertyName = "ConfirmationTarget", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public int ConfirmationTarget { get; internal set; }
- [JsonProperty(PropertyName = "ConfirmationTargetReductionRate")]
- public double? ConfirmationTargetReductionRate { get; internal set; }
+ [DefaultValue(0.7)]
+ [JsonProperty(PropertyName = "ConfirmationTargetReductionRate", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public double ConfirmationTargetReductionRate { get; internal set; }
- [JsonProperty(PropertyName = "CoordinatorFeePercent")]
- public decimal? CoordinatorFeePercent { get; internal set; }
+ [DefaultValue(0.003)] // Coordinator fee percent is per anonymity set.
+ [JsonProperty(PropertyName = "CoordinatorFeePercent", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public decimal CoordinatorFeePercent { get; internal set; }
- [JsonProperty(PropertyName = "AnonymitySet")]
- public int? AnonymitySet { get; internal set; }
+ [DefaultValue(100)]
+ [JsonProperty(PropertyName = "AnonymitySet", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public int AnonymitySet { get; internal set; }
- [JsonProperty(PropertyName = "InputRegistrationTimeout")]
- public long? InputRegistrationTimeout { get; internal set; }
+ [DefaultValue(604800)] // One week
+ [JsonProperty(PropertyName = "InputRegistrationTimeout", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public long InputRegistrationTimeout { get; internal set; }
- [JsonProperty(PropertyName = "ConnectionConfirmationTimeout")]
- public long? ConnectionConfirmationTimeout { get; internal set; }
+ [DefaultValue(60)]
+ [JsonProperty(PropertyName = "ConnectionConfirmationTimeout", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public long ConnectionConfirmationTimeout { get; internal set; }
- [JsonProperty(PropertyName = "OutputRegistrationTimeout")]
- public long? OutputRegistrationTimeout { get; internal set; }
+ [DefaultValue(60)]
+ [JsonProperty(PropertyName = "OutputRegistrationTimeout", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public long OutputRegistrationTimeout { get; internal set; }
- [JsonProperty(PropertyName = "SigningTimeout")]
- public long? SigningTimeout { get; internal set; }
+ [DefaultValue(60)]
+ [JsonProperty(PropertyName = "SigningTimeout", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public long SigningTimeout { get; internal set; }
- [JsonProperty(PropertyName = "DosSeverity")]
- public int? DosSeverity { get; internal set; }
+ [DefaultValue(1)]
+ [JsonProperty(PropertyName = "DosSeverity", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public int DosSeverity { get; internal set; }
- [JsonProperty(PropertyName = "DosDurationHours")]
- public long? DosDurationHours { get; internal set; }
+ [DefaultValue(730)] // 1 month
+ [JsonProperty(PropertyName = "DosDurationHours", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public long DosDurationHours { get; internal set; }
- [JsonProperty(PropertyName = "DosNoteBeforeBan")]
- public bool? DosNoteBeforeBan { get; internal set; }
+ [DefaultValue(true)]
+ [JsonProperty(PropertyName = "DosNoteBeforeBan", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public bool DosNoteBeforeBan { get; internal set; }
- [JsonProperty(PropertyName = "MaximumMixingLevelCount")]
- public int? MaximumMixingLevelCount { get; internal set; }
+ [DefaultValue(11)]
+ [JsonProperty(PropertyName = "MaximumMixingLevelCount", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public int MaximumMixingLevelCount { get; internal set; }
public CcjRoundConfig()
{
@@ -83,19 +96,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
{
AssertFilePathSet();
- Denomination = Money.Coins(0.1m);
- ConfirmationTarget = Constants.OneDayConfirmationTarget; // 1 day
- ConfirmationTargetReductionRate = 0.7;
- CoordinatorFeePercent = 0.003m; // Coordinator fee percent is per anonymity set.
- AnonymitySet = 100;
- InputRegistrationTimeout = 604800; // One week
- ConnectionConfirmationTimeout = 60;
- OutputRegistrationTimeout = 60;
- SigningTimeout = 60;
- DosSeverity = 1;
- DosDurationHours = 730; // 1 month
- DosNoteBeforeBan = true;
- MaximumMixingLevelCount = 11;
+ JsonConvert.PopulateObject("{}", this);
if (!File.Exists(FilePath))
{
@@ -115,18 +116,8 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
public async Task UpdateOrDefaultAsync(CcjRoundConfig config, bool toFile)
{
Denomination = config.Denomination ?? Denomination;
- ConfirmationTarget = config.ConfirmationTarget ?? ConfirmationTarget;
- ConfirmationTargetReductionRate = config.ConfirmationTargetReductionRate ?? ConfirmationTargetReductionRate;
- CoordinatorFeePercent = config.CoordinatorFeePercent ?? CoordinatorFeePercent;
- AnonymitySet = config.AnonymitySet ?? AnonymitySet;
- InputRegistrationTimeout = config.InputRegistrationTimeout ?? InputRegistrationTimeout;
- ConnectionConfirmationTimeout = config.ConnectionConfirmationTimeout ?? ConnectionConfirmationTimeout;
- OutputRegistrationTimeout = config.OutputRegistrationTimeout ?? OutputRegistrationTimeout;
- SigningTimeout = config.SigningTimeout ?? SigningTimeout;
- DosSeverity = config.DosSeverity ?? DosSeverity;
- DosDurationHours = config.DosDurationHours ?? DosDurationHours;
- DosNoteBeforeBan = config.DosNoteBeforeBan ?? DosNoteBeforeBan;
- MaximumMixingLevelCount = config.MaximumMixingLevelCount ?? MaximumMixingLevelCount;
+ var configSerialized = JsonConvert.SerializeObject(config);
+ JsonConvert.PopulateObject(configSerialized, this);
if (toFile)
{

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -204,13 +204,13 @@ namespace WalletWasabi.Services
if (runningRoundCount == 0)
{
- var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget.Value, RoundConfig.ConfirmationTargetReductionRate.Value);
+ var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate);
round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted;
round.StatusChanged += Round_StatusChangedAsync;
await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration, feePerInputs, feePerOutputs);
Rounds.Add(round);
- var round2 = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget.Value, RoundConfig.ConfirmationTargetReductionRate.Value);
+ var round2 = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate);
round2.StatusChanged += Round_StatusChangedAsync;
round2.CoinJoinBroadcasted += Round_CoinJoinBroadcasted;
await round2.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration, feePerInputs, feePerOutputs);
@@ -218,7 +218,7 @@ namespace WalletWasabi.Services
}
else if (runningRoundCount == 1)
{
- var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget.Value, RoundConfig.ConfirmationTargetReductionRate.Value);
+ var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate);
round.StatusChanged += Round_StatusChangedAsync;
round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted;
await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration, feePerInputs, feePerOutputs);
@@ -249,7 +249,7 @@ namespace WalletWasabi.Services
unconfirmedCoinJoinsCount = CoinJoins.Intersect(mempoolHashes).Count();
}
- int confirmationTarget = CcjRound.AdjustConfirmationTarget(unconfirmedCoinJoinsCount, RoundConfig.ConfirmationTarget.Value, RoundConfig.ConfirmationTargetReductionRate.Value);
+ int confirmationTarget = CcjRound.AdjustConfirmationTarget(unconfirmedCoinJoinsCount, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate);
return confirmationTarget;
}
catch (Exception ex)
@@ -257,7 +257,7 @@ namespace WalletWasabi.Services
Logger.LogWarning<CcjCoordinator>("Adjusting confirmation target failed. Falling back to default, specified in config.");
Logger.LogWarning<CcjCoordinator>(ex);
- return RoundConfig.ConfirmationTarget.Value;
+ return RoundConfig.ConfirmationTarget;
}
}

MODIFY
WalletWasabi/Services/UtxoReferee.cs
WalletWasabi/Services/UtxoReferee.cs
@@ -106,7 +106,7 @@ namespace WalletWasabi.Services
var isNoted = true;
if (!forceNoted)
{
- if (RoundConfig.DosNoteBeforeBan.Value)
+ if (RoundConfig.DosNoteBeforeBan)
{
if (foundElem != null)
{
@@ -163,7 +163,7 @@ namespace WalletWasabi.Services
{
if (BannedUtxos.TryGetValue(outpoint, out BannedUtxoRecord bannedElem))
{
- int maxBan = (int)TimeSpan.FromHours(RoundConfig.DosDurationHours.Value).TotalMinutes;
+ int maxBan = (int)TimeSpan.FromHours(RoundConfig.DosDurationHours).TotalMinutes;
int banLeftMinutes = maxBan - (int)bannedElem.BannedRemaining.TotalMinutes;
if (banLeftMinutes > 0)
{

Change CcjRoundConfig according to new conventions