Skip to content

Commit

Permalink
filter out empty modules (#7897)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruben Buniatyan <[email protected]>
  • Loading branch information
LukaszRozmej and rubo authored Dec 12, 2024
1 parent 7361b13 commit 951c5de
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Cipher": "test"
},
"JsonRpc": {
"EnabledModules": "Eth,Debug"
"EnabledModules": "Eth,Debug,"
},
"Discovery": {
"Concurrency": "4",
Expand All @@ -14,4 +14,4 @@
{
"IndexLevelBucketSizes" : [16, 16, 16]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void EnableModule<TOther>() 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();
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocketMessageStream>.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<WebSocketMessageStream>.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);

Expand Down

0 comments on commit 951c5de

Please sign in to comment.