Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ConfigManager 2/n #11863

Merged

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Nov 3, 2023

Follow-up to #11875
Fixes #11868
Precursor for #11764

@kiminuo kiminuo force-pushed the feature/2023-11-03-Faster-ConfigManager branch from f28c65d to c97f6ec Compare November 3, 2023 14:04
…Faster-ConfigManager

# Conflicts:
#	WalletWasabi.Daemon/WasabiAppBuilder.cs
#	WalletWasabi.Fluent/Models/UI/ApplicationSettings.cs
#	WalletWasabi/Services/ConfigWatcher.cs
Comment on lines 21 to 24
bool AreDeepEqual(object otherConfig);

/// <summary>Check if the config file differs from the config if the file path of the config file is set, otherwise throw exception.</summary>
bool CheckFileChange();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to ConfigManager

@@ -0,0 +1,5 @@
namespace WalletWasabi.Interfaces;

public interface IConfigNg
Copy link
Collaborator Author

@kiminuo kiminuo Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less demanding IConfig. It's notable that it does not contain FilePath and other stuff.

public Action ExecuteWhenChanged { get; }

protected override Task ActionAsync(CancellationToken cancel)
{
if (Config.CheckFileChange())
if (ConfigManager.CheckFileChange(Config.FilePath, Config))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new ConfigManager.

@@ -38,26 +38,6 @@ public void AssertFilePathSet()
}
}

/// <inheritdoc/>
public bool CheckFileChange()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code from this file moved to ConfigManager.

using WalletWasabi.JsonConverters;
using WalletWasabi.JsonConverters.Bitcoin;

namespace WalletWasabi.Daemon;

[JsonObject(MemberSerialization.OptIn)]
public class PersistentConfig : ConfigBase
public record PersistentConfig : IConfigNg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer derive from ConfigBase to avoid having FilePath and other stuff not needed and make PersistentConfig clean "data (C#) type"

Comment on lines -26 to -28
public PersistentConfig(string filePath) : base(filePath)
{
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be gone devil.

[JsonProperty(PropertyName = "Network")]
[JsonConverter(typeof(NetworkJsonConverter))]
public Network Network { get; set; } = Network.Main;

[DefaultValue(Constants.BackendUri)]
[JsonProperty(PropertyName = "MainNetBackendUri", DefaultValueHandling = DefaultValueHandling.Populate)]
public string MainNetBackendUri { get; private set; } = Constants.BackendUri;
public string MainNetBackendUri { get; init; } = Constants.BackendUri;
Copy link
Collaborator Author

@kiminuo kiminuo Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having properites immutable is good because we don't want to change properties really. What happens (AFAIK) is that we want to store modified configs but we don't support changing config values during runtime.


[DefaultValue("CoinJoinCoordinatorIdentifier")]
[JsonProperty(PropertyName = "CoordinatorIdentifier", DefaultValueHandling = DefaultValueHandling.Populate)]
public string CoordinatorIdentifier { get; set; } = "CoinJoinCoordinatorIdentifier";

public void SetBitcoinP2pEndpoint(EndPoint endPoint)
Copy link
Collaborator Author

@kiminuo kiminuo Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiminuo kiminuo changed the title Introduce ConfigManager Introduce ConfigManager 2/n Nov 5, 2023
@@ -52,6 +52,10 @@ private void ValidateBitcoinP2PEndPoint(IValidationErrors errors)
{
errors.Add(ErrorSeverity.Error, "Invalid endpoint.");
}
else
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are to fix #11868. It's not idiomatic Avalonia code. Suggestions are welcome. Can be a standalone PR.

@@ -154,20 +131,19 @@ public EndPoint GetBitcoinP2pEndPoint()
throw new NotSupportedNetworkException(Network);
}

public bool MigrateOldDefaultBackendUris()
public bool MigrateOldDefaultBackendUris([NotNullWhenAttribute(true)] out PersistentConfig? newConfig)
Copy link
Collaborator Author

@kiminuo kiminuo Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we return a new instance of PersistentConfig through the out parameter because PersistentConfig is immutable.

Copy link
Collaborator

@adamPetho adamPetho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK, Config is saved and loaded properly. Only one question below.

Also fixes #11868 🎉


if (!createIfMissing)
{
return LoadFile<TResponse>(filePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same call is wrapped inside a try-catch block below. Shouldn't we do the same here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll address this in a follow-up PR with a test.

@kiminuo kiminuo merged commit 46684a5 into WalletWasabi:master Nov 9, 2023
7 checks passed
@kiminuo kiminuo deleted the feature/2023-11-03-Faster-ConfigManager branch November 9, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Settings] Changes of Bitcoin P2P EndPoint & Dust Threshold not saved
2 participants