From aeee6f7260e9cd09a77fd5e4d575bc36c3a89735 Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Thu, 12 Dec 2024 09:25:07 +0100 Subject: [PATCH] filter out empty modules (#7897) Co-authored-by: Ruben Buniatyan --- .../SampleJson/SampleJsonConfig.json | 4 ++-- .../Modules/TestRpcModuleProvider.cs | 2 +- src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs | 11 ++++++++++- .../Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 5 +++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Config.Test/SampleJson/SampleJsonConfig.json b/src/Nethermind/Nethermind.Config.Test/SampleJson/SampleJsonConfig.json index c2e3b7535a1..7ba16ed6f9c 100644 --- a/src/Nethermind/Nethermind.Config.Test/SampleJson/SampleJsonConfig.json +++ b/src/Nethermind/Nethermind.Config.Test/SampleJson/SampleJsonConfig.json @@ -4,7 +4,7 @@ "Cipher": "test" }, "JsonRpc": { - "EnabledModules": "Eth,Debug" + "EnabledModules": "Eth,Debug," }, "Discovery": { "Concurrency": "4", @@ -14,4 +14,4 @@ { "IndexLevelBucketSizes" : [16, 16, 16] } -} \ No newline at end of file +} diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcModuleProvider.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcModuleProvider.cs index f797c9adb14..8214f6a4d41 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcModuleProvider.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcModuleProvider.cs @@ -53,7 +53,7 @@ private void EnableModule() where TOther : IRpcModule { if (!_jsonRpcConfig.EnabledModules.Contains(rpcModuleAttribute.ModuleType)) { - _jsonRpcConfig.EnabledModules = _jsonRpcConfig.EnabledModules.Union(new[] { rpcModuleAttribute.ModuleType }).ToArray(); + _jsonRpcConfig.EnabledModules = _jsonRpcConfig.EnabledModules.Union([rpcModuleAttribute.ModuleType]).ToArray(); } } } diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs index b71dd400f67..8a1f556e69e 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs @@ -11,6 +11,7 @@ public class JsonRpcConfig : IJsonRpcConfig { public static readonly JsonRpcConfig Default = new(); private int? _webSocketsPort; + private string[] _enabledModules = ModuleType.DefaultModules.ToArray(); public bool Enabled { get; set; } public string Host { get; set; } = "127.0.0.1"; public int Timeout { get; set; } = 20000; @@ -29,7 +30,15 @@ public int WebSocketsPort public string? IpcUnixDomainSocketPath { get; set; } = null; - public string[] EnabledModules { get; set; } = ModuleType.DefaultModules.ToArray(); + public string[] EnabledModules + { + get => _enabledModules; + set + { + _enabledModules = value.Where(m => !string.IsNullOrWhiteSpace(m)).ToArray(); + } + } + public string[] AdditionalRpcUrls { get; set; } = []; public long? GasCap { get; set; } = 100000000; public int ReportIntervalSeconds { get; set; } = 300; diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index 81af1e31b4f..892d32fab5f 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -30,8 +30,9 @@ public JsonRpcUrlCollection(ILogManager logManager, IJsonRpcConfig jsonRpcConfig private void BuildUrls(bool includeWebSockets) { - bool HasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)); - JsonRpcUrl defaultUrl = new(Uri.UriSchemeHttp, _jsonRpcConfig.Host, _jsonRpcConfig.Port, RpcEndpoint.Http, HasEngineApi, _jsonRpcConfig.EnabledModules, HasEngineApi ? SocketClient.MAX_REQUEST_BODY_SIZE_FOR_ENGINE_API : _jsonRpcConfig.MaxRequestBodySize); + bool hasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)); + long? maxRequestBodySize = hasEngineApi ? SocketClient.MAX_REQUEST_BODY_SIZE_FOR_ENGINE_API : _jsonRpcConfig.MaxRequestBodySize; + JsonRpcUrl defaultUrl = new(Uri.UriSchemeHttp, _jsonRpcConfig.Host, _jsonRpcConfig.Port, RpcEndpoint.Http, hasEngineApi, _jsonRpcConfig.EnabledModules, maxRequestBodySize); Add(defaultUrl.Port, defaultUrl);