Skip to content

Commit

Permalink
Remove the duplicated NETHERMIND_HIVE_ENABLED and other obsolete en…
Browse files Browse the repository at this point in the history
…v variables
  • Loading branch information
rubo committed Oct 28, 2024
1 parent 975da1c commit cafd42b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public void NoCategorySettings()
env.GetEnvironmentVariables().Returns(new Dictionary<string, string>() {
{ "NETHERMIND_CLI_SWITCH_LOCAL", "http://localhost:80" },
{ "NETHERMIND_MONITORING_JOB", "nethermindJob" },
{ "NETHERMIND_MONITORING_GROUP", "nethermindGroup" },
{ "NETHERMIND_ENODE_IPADDRESS", "1.2.3.4" },
{ "NETHERMIND_HIVE_ENABLED", "true" },
{ "NETHERMIND_URL", "http://test:80" },
{ "NETHERMIND_CORS_ORIGINS", "*" },
{ "NETHERMIND_CONFIG", "test2.json" },
Expand All @@ -56,29 +54,16 @@ public void NoCategorySettings()
});
EnvConfigSource? envSource = new(env);

ArgsConfigSource? argsSource = new(new Dictionary<string, string>() {
{ "config", "test.json" },
{ "datadir", "Data" },
{ "ConfigsDirectory", "ConfDir" },
{ "baseDbPath", "DB" },
{ "log", "info" },
{ "loggerConfigSource", "logSource" },
{ "pluginsDirectory", "Plugins" },
{ "Abc", "abc" } // not existing, should get error
});

ConfigProvider? configProvider = new();
configProvider.AddSource(envSource);
configProvider.AddSource(argsSource);

configProvider.Initialize();

(string ErrorMsg, IList<(IConfigSource Source, string Category, string Name)> Errors) res = configProvider.FindIncorrectSettings();

Assert.That(res.Errors.Count, Is.EqualTo(2));
Assert.That(res.Errors.Count, Is.EqualTo(1));
Assert.That(res.Errors[0].Name, Is.EqualTo("XYZ"));
Assert.That(res.Errors[1].Name, Is.EqualTo("Abc"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:|Name:XYZ{Environment.NewLine}ConfigType:RuntimeOption|Category:|Name:Abc"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:|Name:XYZ"));

}

Expand All @@ -93,26 +78,19 @@ public void SettingWithTypos()
});
EnvConfigSource? envSource = new(env);

ArgsConfigSource? argsSource = new(new Dictionary<string, string>() {
{ "DiscoveryConfig.BucketSize", "10" },
{ "NetworkConfig.DiscoverPort", "30301" }, // incorrect, should be NetworkConfig.DiscoveryPort
{ "Network.P2PPort", "30301" } });

ConfigProvider? configProvider = new();
configProvider.AddSource(jsonSource);
configProvider.AddSource(envSource);
configProvider.AddSource(argsSource);

configProvider.Initialize();

(string ErrorMsg, IList<(IConfigSource Source, string Category, string Name)> Errors) res = configProvider.FindIncorrectSettings();

Assert.That(res.Errors.Count, Is.EqualTo(4));
Assert.That(res.Errors.Count, Is.EqualTo(3));
Assert.That(res.Errors[0].Name, Is.EqualTo("Concurrenc"));
Assert.That(res.Errors[1].Category, Is.EqualTo("BlomConfig"));
Assert.That(res.Errors[2].Name, Is.EqualTo("MAXCANDIDATEPERCOUNT"));
Assert.That(res.Errors[3].Name, Is.EqualTo("DiscoverPort"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:JsonConfigFile|Category:DiscoveRyConfig|Name:Concurrenc{Environment.NewLine}ConfigType:JsonConfigFile|Category:BlomConfig|Name:IndexLevelBucketSizes{Environment.NewLine}ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:NETWORKCONFIG|Name:MAXCANDIDATEPERCOUNT{Environment.NewLine}ConfigType:RuntimeOption|Category:NetworkConfig|Name:DiscoverPort"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:JsonConfigFile|Category:DiscoveRyConfig|Name:Concurrenc{Environment.NewLine}ConfigType:JsonConfigFile|Category:BlomConfig|Name:IndexLevelBucketSizes{Environment.NewLine}ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:NETWORKCONFIG|Name:MAXCANDIDATEPERCOUNT"));
}

[Test]
Expand All @@ -124,22 +102,16 @@ public void IncorrectFormat()
});
EnvConfigSource? envSource = new(env);

ArgsConfigSource? argsSource = new(new Dictionary<string, string>() {
{ "DiscoveryConfig.BucketSize", "10" },
{ "NetworkConfigP2PPort", "30301" } }); // incorrect, should be Network.P2PPort

ConfigProvider? configProvider = new();
configProvider.AddSource(envSource);
configProvider.AddSource(argsSource);

configProvider.Initialize();

(string ErrorMsg, IList<(IConfigSource Source, string Category, string Name)> Errors) res = configProvider.FindIncorrectSettings();

Assert.That(res.Errors.Count, Is.EqualTo(2));
Assert.That(res.Errors.Count, Is.EqualTo(1));
Assert.That(res.Errors[0].Name, Is.EqualTo("NETWORKCONFIGMAXCANDIDATEPEERCOUNT"));
Assert.That(res.Errors[1].Name, Is.EqualTo("NetworkConfigP2PPort"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:|Name:NETWORKCONFIGMAXCANDIDATEPEERCOUNT{Environment.NewLine}ConfigType:RuntimeOption|Category:|Name:NetworkConfigP2PPort"));
Assert.That(res.ErrorMsg, Is.EqualTo($"ConfigType:EnvironmentVariable(NETHERMIND_*)|Category:|Name:NETWORKCONFIGMAXCANDIDATEPEERCOUNT"));
}

}
Expand Down
28 changes: 2 additions & 26 deletions src/Nethermind/Nethermind.Config/INoCategoryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,15 @@ namespace Nethermind.Config;
[ConfigCategory(HiddenFromDocs = true)]
public interface INoCategoryConfig : IConfig
{
//[ConfigItem(Description = "Parent directory or path for BaseDbPath, KeyStoreDirectory, LogDirectory configurations.")]
//public string DataDir { get; set; }

//[ConfigItem(Description = "Path to the JSON configuration file.")]
//public string Config { get; set; }

//[ConfigItem(Description = "Path or directory for configuration files.", DefaultValue = "configs")]
//public string ConfigsDirectory { get; set; }

//[ConfigItem(Description = "Path or directory for database files.", DefaultValue = "db")]
//public string BaseDbPath { get; set; }

//[ConfigItem(Description = "Log level override. Possible values: OFF|TRACE|DEBUG|INFO|WARN|ERROR")]
//public string Log { get; set; }

//[ConfigItem(Description = "Path to the NLog config file")]
//public string LoggerConfigSource { get; set; }

//[ConfigItem(Description = "Plugins directory")]
//public string PluginsDirectory { get; set; }
[ConfigItem(Description = "Path to the configuration file.")]
public string Config { get; set; }

[ConfigItem(Description = "Sets the job name for metrics monitoring.", EnvironmentVariable = "NETHERMIND_MONITORING_JOB")]
public string MonitoringJob { get; set; }

//[ConfigItem(Description = "Sets the default group name for metrics monitoring.", EnvironmentVariable = "NETHERMIND_MONITORING_GROUP")]
//public string MonitoringGroup { get; set; }

[ConfigItem(Description = "Sets the external IP for the node.", EnvironmentVariable = "NETHERMIND_ENODE_IPADDRESS")]
public string EnodeIpAddress { get; set; }

//[ConfigItem(Description = "Enables Hive plugin used for executing Hive Ethereum Tests.", EnvironmentVariable = "NETHERMIND_HIVE_ENABLED", DefaultValue = "false")]
//public bool HiveEnabled { get; set; }

[ConfigItem(Description = "Defines default URL for JSON RPC.", EnvironmentVariable = "NETHERMIND_URL")]
public string Url { get; set; }

Expand Down
27 changes: 9 additions & 18 deletions src/Nethermind/Nethermind.Config/NoCategoryConfig.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Config
namespace Nethermind.Config;

public class NoCategoryConfig : INoCategoryConfig
{
public class NoCategoryConfig : INoCategoryConfig
{
public string Config { get; set; } = null;
public string DataDir { get; set; }
public string ConfigsDirectory { get; set; }
public string BaseDbPath { get; set; }
public string Log { get; set; }
public string LoggerConfigSource { get; set; }
public string PluginsDirectory { get; set; }
public string MonitoringJob { get; set; }
public string MonitoringGroup { get; set; }
public string EnodeIpAddress { get; set; }
public bool HiveEnabled { get; set; }
public string Url { get; set; }
public string CorsOrigins { get; set; }
public string CliSwitchLocal { get; set; }
}
public string Config { get; set; } = null;
public string MonitoringJob { get; set; }
public string EnodeIpAddress { get; set; }
public string Url { get; set; }
public string CorsOrigins { get; set; }
public string CliSwitchLocal { get; set; }
}
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Hive/HivePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Task Init(INethermindApi api)
_hiveConfig = _api.ConfigProvider.GetConfig<IHiveConfig>();
_logger = _api.LogManager.GetClassLogger();

Enabled = Environment.GetEnvironmentVariable("NETHERMIND_HIVE_ENABLED")?.ToLowerInvariant() == "true" || _hiveConfig.Enabled;
Enabled = _hiveConfig.Enabled;

return Task.CompletedTask;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Nethermind.Config;
using Nethermind.Consensus;
using Nethermind.Core;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Hive;
using Nethermind.Logging;
using Nethermind.Serialization.Json;
using Nethermind.Specs.ChainSpecStyle;
Expand Down Expand Up @@ -66,11 +66,11 @@ public INethermindApi Create(IEnumerable<IConsensusPlugin> consensusPlugins)

private ChainSpec LoadChainSpec(IJsonSerializer ethereumJsonSerializer)
{
bool hiveEnabled = Environment.GetEnvironmentVariable("NETHERMIND_HIVE_ENABLED")?.ToLowerInvariant() == "true";
IHiveConfig hiveConfig = _configProvider.GetConfig<IHiveConfig>();
bool hiveChainSpecExists = File.Exists(_initConfig.HiveChainSpecPath);

string chainSpecFile;
if (hiveEnabled && hiveChainSpecExists)
if (hiveConfig.Enabled && hiveChainSpecExists)
chainSpecFile = _initConfig.HiveChainSpecPath;
else
chainSpecFile = _initConfig.ChainSpecPath;
Expand Down

0 comments on commit cafd42b

Please sign in to comment.