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

Register converters for socket's JSON RPC #3539

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Nethermind/Nethermind.Runner/Ethereum/Steps/StartRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Nethermind.JsonRpc.WebSockets;
using Nethermind.Logging;
using Nethermind.Runner.JsonRpc;
using Nethermind.Serialization.Json;

namespace Nethermind.Runner.Ethereum.Steps
{
Expand Down Expand Up @@ -51,23 +52,24 @@ public async Task Execute(CancellationToken cancellationToken)
_api.LogManager);

JsonRpcService jsonRpcService = new(_api.RpcModuleProvider, _api.LogManager);
IJsonSerializer jsonSerializer = CreateJsonSerializer(jsonRpcService);

JsonRpcProcessor jsonRpcProcessor = new(
jsonRpcService,
_api.EthereumJsonSerializer,
jsonSerializer,
jsonRpcConfig,
_api.FileSystem,
_api.LogManager);

if (initConfig.WebSocketsEnabled)
{
JsonRpcWebSocketsModule webSocketsModule = new (jsonRpcProcessor, jsonRpcService, jsonRpcLocalStats, _api.LogManager, _api.EthereumJsonSerializer);
JsonRpcWebSocketsModule webSocketsModule = new (jsonRpcProcessor, jsonRpcService, jsonRpcLocalStats, _api.LogManager, jsonSerializer);
_api.WebSocketsManager!.AddModule(webSocketsModule, true);
}

Bootstrap.Instance.JsonRpcService = jsonRpcService;
Bootstrap.Instance.LogManager = _api.LogManager;
Bootstrap.Instance.JsonSerializer = _api.EthereumJsonSerializer;
Bootstrap.Instance.JsonSerializer = jsonSerializer;
Bootstrap.Instance.JsonRpcLocalStats = jsonRpcLocalStats;
JsonRpcRunner? jsonRpcRunner = new(
jsonRpcProcessor,
Expand All @@ -82,7 +84,7 @@ public async Task Execute(CancellationToken cancellationToken)
logger.Error("Error during jsonRpc runner start", x.Exception);
}, cancellationToken);

JsonRpcIpcRunner jsonIpcRunner = new(jsonRpcProcessor, jsonRpcService, _api.ConfigProvider, _api.LogManager, jsonRpcLocalStats, _api.EthereumJsonSerializer, _api.FileSystem);
JsonRpcIpcRunner jsonIpcRunner = new(jsonRpcProcessor, jsonRpcService, _api.ConfigProvider, _api.LogManager, jsonRpcLocalStats, jsonSerializer, _api.FileSystem);
jsonIpcRunner.Start(cancellationToken);

#pragma warning disable 4014
Expand All @@ -95,5 +97,12 @@ public async Task Execute(CancellationToken cancellationToken)
if (logger.IsInfo) logger.Info("Json RPC is disabled");
}
}

private IJsonSerializer CreateJsonSerializer(JsonRpcService jsonRpcService)
{
IJsonSerializer serializer = new EthereumJsonSerializer();
serializer.RegisterConverters(jsonRpcService.Converters);
return serializer;
}
}
}
15 changes: 4 additions & 11 deletions src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ namespace Nethermind.Runner.JsonRpc
{
public class Startup
{
private IJsonSerializer _jsonSerializer = CreateJsonSerializer();

private static EthereumJsonSerializer CreateJsonSerializer() => new();

public void ConfigureServices(IServiceCollection services)
{
// ReSharper disable once ASP0000
Expand Down Expand Up @@ -82,17 +78,14 @@ public void ConfigureServices(IServiceCollection services)
});
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpcProcessor jsonRpcProcessor, IJsonRpcService jsonRpcService, IJsonRpcLocalStats jsonRpcLocalStats)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpcProcessor jsonRpcProcessor, IJsonRpcService jsonRpcService, IJsonRpcLocalStats jsonRpcLocalStats, IJsonSerializer jsonSerializer)
{
long SerializeTimeoutException(IJsonRpcService service, Stream resultStream)
{
JsonRpcErrorResponse? error = service.GetErrorResponse(ErrorCodes.Timeout, "Request was canceled due to enabled timeout.");
return _jsonSerializer.Serialize(resultStream, error);
return jsonSerializer.Serialize(resultStream, error);
}

_jsonSerializer = CreateJsonSerializer();
_jsonSerializer.RegisterConverters(jsonRpcService.Converters);

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down Expand Up @@ -170,8 +163,8 @@ await foreach (JsonRpcResult result in jsonRpcProcessor.ProcessAsync(request, Js
ctx.Response.StatusCode = GetStatusCode(result);

responseSize = result.IsCollection
? _jsonSerializer.Serialize(resultStream, result.Responses)
: _jsonSerializer.Serialize(resultStream, result.Response);
? jsonSerializer.Serialize(resultStream, result.Responses)
: jsonSerializer.Serialize(resultStream, result.Response);

if (jsonRpcConfig.BufferResponses)
{
Expand Down