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

[refactor] Client Config: Pass path around to prepare for extraction from Config #11860

Merged

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Nov 3, 2023

Currently Config class has FilePath property but it has downsides:

  • One must check whether that file path is actually passed or not.
  • File path can end up serialized config JSON.
  • It's not synchronized properly.

This PR passes the path for persistent config separately and avoids all these issues. The PR is meant to be a precursor for #11764 and to slowly move towards a better design.

No change in behavior is intended.

@@ -149,7 +151,7 @@ public ApplicationSettings(PersistentConfig persistentConfig, Config config, UiC
.Where(value => value && string.IsNullOrEmpty(LocalBitcoinCoreDataDir))
.Subscribe(_ => LocalBitcoinCoreDataDir = EnvironmentHelpers.GetDefaultBitcoinCoreDataDirOrEmptyString());

// Apply RunOnSystenStartup
// Apply RunOnSystemStartup
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Typo

Comment on lines -21 to -24
else
{
return Money.Parse(stringValue);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unrelated. Yet simpler.

Comment on lines +33 to +34
ConfigFilePath = Path.Combine(Config.DataDir, "Config.json");
Directory.CreateDirectory(Config.DataDir);
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 here from the LoadOrCreateConfigs method.

@kiminuo kiminuo changed the title Client Config: Pass path around to prepare for extraction from Config. [refactor] Client Config: Pass path around to prepare for extraction from Config Nov 3, 2023
@@ -122,7 +122,7 @@ private static IClientConfig CreateConfig()

private static IApplicationSettings CreateApplicationSettings()
{
return new ApplicationSettings(Services.PersistentConfig, Services.Config, Services.UiConfig);
return new ApplicationSettings(Services.PersistentConfigFilePath, Services.PersistentConfig, Services.Config, Services.UiConfig);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pass the config file path on.

{
_startupConfig = new PersistentConfig(persistentConfig.FilePath);
_persistentConfigFilePath = persistentConfigFilePath;
_startupConfig = new PersistentConfig(persistentConfigFilePath);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The important thing here is that we do not access the config path using persistentConfig.FilePath but rather persistentConfigFilePath. That's what we want.

@kiminuo kiminuo marked this pull request as ready for review November 3, 2023 09:06
Comment on lines -13 to -14
Config = Guard.NotNull(nameof(config), config);
ExecuteWhenChanged = Guard.NotNull(nameof(executeWhenChanged), executeWhenChanged);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unrelated but a trivial change to remove unneeded code (plus if one wants it makes it easier to unit test this class actually).

Copy link
Collaborator

@turbolay turbolay left a comment

Choose a reason for hiding this comment

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

tACK
Thanks for your comments, it made the review much easier.

What about UiConfig and Logs, and mostly all other cases where we need Path.Combine(DataDir, ...) ?

@kiminuo
Copy link
Collaborator Author

kiminuo commented Nov 3, 2023

tACK Thanks for your comments, it made the review much easier.

👍

What about UiConfig and Logs, and mostly all other cases where we need Path.Combine(DataDir, ...) ?

I don't think we need to get rid of all Path.Combine(DataDir, ...) per se1. Or I'm not sure if it brings some advantages. This PR is more about removing relying on Config.FilePath which I think is an API design flaw that prevents us from having the code clean.

Footnotes

  1. Not saying I'm against if well argued. Good ideas are welcome.

Copy link
Collaborator

@yahiheb yahiheb left a comment

Choose a reason for hiding this comment

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

LGTM

@kiminuo kiminuo merged commit 5a26918 into WalletWasabi:master Nov 4, 2023
7 checks passed
@kiminuo kiminuo deleted the feature/2023-11-03-Pass-ConfigPath branch November 4, 2023 10:48
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.

None yet

3 participants