Skip to content

Commit

Permalink
Migrate MaxCoordinationFeeRate to rate (WalletWasabi#13220)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolay authored Jul 9, 2024
1 parent a6c1e14 commit 0d837c4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
41 changes: 30 additions & 11 deletions WalletWasabi.Daemon/PersistentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public record PersistentConfig
/// </remarks>
public object UseTor { get; init; } = "Enabled";

public bool TerminateTorOnExit { get; init; } = false;
public bool TerminateTorOnExit { get; init; }

public string[] TorBridges { get; init; } = [];

public bool DownloadNewVersion { get; init; } = true;

public bool StartLocalBitcoinCoreOnStartup { get; init; } = false;
public bool StartLocalBitcoinCoreOnStartup { get; init; }

public bool StopLocalBitcoinCoreOnShutdown { get; init; } = true;

Expand All @@ -53,11 +53,11 @@ public record PersistentConfig

public string JsonRpcPassword { get; init; } = "";

public string[] JsonRpcServerPrefixes { get; init; } = new[]
{
public string[] JsonRpcServerPrefixes { get; init; } =
[
"http://127.0.0.1:37128/",
"http://localhost:37128/"
};
];

public Money DustThreshold { get; init; } = Money.Coins(Constants.DefaultDustThreshold);

Expand All @@ -70,12 +70,14 @@ public record PersistentConfig
public decimal MaxCoinJoinMiningFeeRate { get; init; } = Constants.DefaultMaxCoinJoinMiningFeeRate;

public int AbsoluteMinInputCount { get; init; } = Constants.DefaultAbsoluteMinInputCount;
public int ConfigVersion { get; init; }

public bool DeepEquals(PersistentConfig other)
{
bool useTorIsEqual = Config.ObjectToTorMode(UseTor) == Config.ObjectToTorMode(other.UseTor);

return
ConfigVersion == other.ConfigVersion &&
Network == other.Network &&
MainNetBackendUri == other.MainNetBackendUri &&
TestNetBackendUri == other.TestNetBackendUri &&
Expand Down Expand Up @@ -161,21 +163,38 @@ public string GetBackendUri()
throw new NotSupportedNetworkException(Network);
}

public bool MigrateOldDefaultBackendUris([NotNullWhen(true)] out PersistentConfig? newConfig)
public PersistentConfig Migrate()
{
if (ConfigVersion == 0)
{
return MigrateMaxCoordinationFeeRate().MigrateOldDefaultBackendUris() with
{
ConfigVersion = 1
};
}

return this;
}

private PersistentConfig MigrateMaxCoordinationFeeRate()
{
bool hasChanged = false;
newConfig = null;
return this with
{
MaxCoordinationFeeRate = MaxCoordinationFeeRate / 100.0m
};
}

private PersistentConfig MigrateOldDefaultBackendUris()
{
if (MainNetBackendUri == "https://wasabiwallet.io/" || TestNetBackendUri == "https://wasabiwallet.co/")
{
hasChanged = true;
newConfig = this with
return this with
{
MainNetBackendUri = "https://api.wasabiwallet.io/",
TestNetBackendUri = "https://api.wasabiwallet.co/",
};
}

return hasChanged;
return this;
}
}
3 changes: 2 additions & 1 deletion WalletWasabi.Daemon/WasabiApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private PersistentConfig LoadOrCreateConfigs()
{
PersistentConfig persistentConfig = ConfigManagerNg.LoadFile<PersistentConfig>(ConfigFilePath, createIfMissing: true);

if (persistentConfig.MigrateOldDefaultBackendUris(out PersistentConfig? newConfig))
var newConfig = persistentConfig.Migrate();
if (!persistentConfig.DeepEquals(newConfig))
{
persistentConfig = newConfig;
ConfigManagerNg.ToFile(ConfigFilePath, persistentConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</TextBox>
</StackPanel>

<StackPanel ToolTip.Tip="The client will refuse to participate in rounds charging a coordination fee rate (percentage) higher than the value indicated here.">
<TextBlock Text="Max Coordination Fee (percent)" />
<CurrencyEntryBox Classes="standalone" Name="CoordinationFeeRateTextBox" Text="{Binding MaxCoordinationFeeRate}" CurrencyCode="%" />
<StackPanel ToolTip.Tip="The client will refuse to participate in rounds charging a coordination fee rate higher than the value indicated here.">
<TextBlock Text="Max Coordination Fee Rate" />
<CurrencyEntryBox Classes="standalone" Name="CoordinationFeeRateTextBox" Text="{Binding MaxCoordinationFeeRate}"/>
</StackPanel>

<StackPanel ToolTip.Tip="The client will refuse to participate in rounds with a mining fee rate (s/vb) higher than the value indicated here.">
Expand Down
3 changes: 2 additions & 1 deletion WalletWasabi.Tests/UnitTests/Bases/ConfigManagerNgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static string GetConfigString(string localBitcoinCoreDataDir)
"CoordinatorIdentifier": "CoinJoinCoordinatorIdentifier",
"MaxCoordinationFeeRate": 0.0,
"MaxCoinJoinMiningFeeRate": 150.0,
"AbsoluteMinInputCount": 21
"AbsoluteMinInputCount": 21,
"ConfigVersion": 0
}
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ private async Task<RoundState> WaitForBlameRoundAsync(uint256 blameRoundId, Canc
throw new InvalidOperationException($"Blame Round ({roundState.Id}): Abandoning: the round is not economic.");
}

if (roundState.CoinjoinState.Parameters.CoordinationFeeRate.Rate * 100 > CoinJoinConfiguration.MaxCoordinationFeeRate)
if (roundState.CoinjoinState.Parameters.CoordinationFeeRate.Rate > CoinJoinConfiguration.MaxCoordinationFeeRate)
{
throw new InvalidOperationException($"Blame Round ({roundState.Id}): Abandoning: " +
$"the coordinator is malicious and tried to trick the client into paying a coordination fee rate of {roundState.CoinjoinState.Parameters.CoordinationFeeRate.Rate * 100}% for the blame round");
$"the coordinator is malicious and tried to trick the client into paying a coordination fee rate of {roundState.CoinjoinState.Parameters.CoordinationFeeRate.Rate} for the blame round");
}

if (roundState.CoinjoinState.Parameters.MiningFeeRate.SatoshiPerByte > CoinJoinConfiguration.MaxCoinJoinMiningFeeRate)
Expand Down Expand Up @@ -169,9 +169,9 @@ public async Task<CoinJoinResult> StartCoinJoinAsync(Func<Task<IEnumerable<Smart
currentRoundState.LogInfo(roundSkippedMessage);
throw new CoinJoinClientException(CoinjoinError.UneconomicalRound, roundSkippedMessage);
}
if (roundParameters.CoordinationFeeRate.Rate * 100 > CoinJoinConfiguration.MaxCoordinationFeeRate)
if (roundParameters.CoordinationFeeRate.Rate > CoinJoinConfiguration.MaxCoordinationFeeRate)
{
string roundSkippedMessage = $"Coordination fee rate was {roundParameters.CoordinationFeeRate.Rate * 100} but max allowed is {CoinJoinConfiguration.MaxCoordinationFeeRate}.";
string roundSkippedMessage = $"Coordination fee rate was {roundParameters.CoordinationFeeRate.Rate} but max allowed is {CoinJoinConfiguration.MaxCoordinationFeeRate}.";
currentRoundState.LogInfo(roundSkippedMessage);
throw new CoinJoinClientException(CoinjoinError.CoordinationFeeRateTooHigh, roundSkippedMessage);
}
Expand Down

0 comments on commit 0d837c4

Please sign in to comment.