From cafd42b3322dabbef0b53d8a0d0cc0faef9c956f Mon Sep 17 00:00:00 2001 From: Ruben Buniatyan Date: Mon, 28 Oct 2024 18:15:18 +0100 Subject: [PATCH] Remove the duplicated `NETHERMIND_HIVE_ENABLED` and other obsolete env variables --- ...figProvider_FindIncorrectSettings_Tests.cs | 40 +++---------------- .../Nethermind.Config/INoCategoryConfig.cs | 28 +------------ .../Nethermind.Config/NoCategoryConfig.cs | 27 +++++-------- src/Nethermind/Nethermind.Hive/HivePlugin.cs | 2 +- .../Ethereum/Api/ApiBuilder.cs | 6 +-- 5 files changed, 21 insertions(+), 82 deletions(-) diff --git a/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs b/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs index f41ec7e1098..95473f9b57f 100644 --- a/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs +++ b/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs @@ -45,9 +45,7 @@ public void NoCategorySettings() env.GetEnvironmentVariables().Returns(new Dictionary() { { "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" }, @@ -56,29 +54,16 @@ public void NoCategorySettings() }); EnvConfigSource? envSource = new(env); - ArgsConfigSource? argsSource = new(new Dictionary() { - { "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")); } @@ -93,26 +78,19 @@ public void SettingWithTypos() }); EnvConfigSource? envSource = new(env); - ArgsConfigSource? argsSource = new(new Dictionary() { - { "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] @@ -124,22 +102,16 @@ public void IncorrectFormat() }); EnvConfigSource? envSource = new(env); - ArgsConfigSource? argsSource = new(new Dictionary() { - { "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")); } } diff --git a/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs b/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs index caf1be38bed..0d13a98e256 100644 --- a/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs +++ b/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs @@ -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; } diff --git a/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs b/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs index 56a73d77ac4..b43061f656e 100644 --- a/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs +++ b/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs @@ -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; } } diff --git a/src/Nethermind/Nethermind.Hive/HivePlugin.cs b/src/Nethermind/Nethermind.Hive/HivePlugin.cs index 62aaef0a766..d95f6c33dfd 100644 --- a/src/Nethermind/Nethermind.Hive/HivePlugin.cs +++ b/src/Nethermind/Nethermind.Hive/HivePlugin.cs @@ -36,7 +36,7 @@ public Task Init(INethermindApi api) _hiveConfig = _api.ConfigProvider.GetConfig(); _logger = _api.LogManager.GetClassLogger(); - Enabled = Environment.GetEnvironmentVariable("NETHERMIND_HIVE_ENABLED")?.ToLowerInvariant() == "true" || _hiveConfig.Enabled; + Enabled = _hiveConfig.Enabled; return Task.CompletedTask; } diff --git a/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs b/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs index 9d17ac28787..4565978b542 100644 --- a/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs +++ b/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs @@ -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; @@ -66,11 +66,11 @@ public INethermindApi Create(IEnumerable consensusPlugins) private ChainSpec LoadChainSpec(IJsonSerializer ethereumJsonSerializer) { - bool hiveEnabled = Environment.GetEnvironmentVariable("NETHERMIND_HIVE_ENABLED")?.ToLowerInvariant() == "true"; + IHiveConfig hiveConfig = _configProvider.GetConfig(); bool hiveChainSpecExists = File.Exists(_initConfig.HiveChainSpecPath); string chainSpecFile; - if (hiveEnabled && hiveChainSpecExists) + if (hiveConfig.Enabled && hiveChainSpecExists) chainSpecFile = _initConfig.HiveChainSpecPath; else chainSpecFile = _initConfig.ChainSpecPath;