Skip to content

Commit

Permalink
Merge pull request #2242 from area363/fix-duplicate-publisher
Browse files Browse the repository at this point in the history
fix duplicate publisher in RPC mode
  • Loading branch information
area363 authored Sep 14, 2023
2 parents 83e5f84 + 9afd210 commit b8e793e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
31 changes: 30 additions & 1 deletion NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ IActionLoader MakeSingleActionLoader()
.AddAspNetCoreInstrumentation()
.AddPrometheusExporter());
});
hostBuilder.UseNineChroniclesNode(nineChroniclesProperties, standaloneContext);

NineChroniclesNodeService service =
NineChroniclesNodeService.Create(nineChroniclesProperties, standaloneContext);
if (headlessConfig.RpcServer)
{
var context = new RpcContext
Expand All @@ -512,13 +514,40 @@ IActionLoader MakeSingleActionLoader()
new ConcurrentDictionary<string, Sentry.ITransaction>()
);

hostBuilder.UseNineChroniclesNode(
nineChroniclesProperties,
standaloneContext,
publisher,
service);
hostBuilder.UseNineChroniclesRPC(
rpcProperties,
publisher,
standaloneContext,
configuration
);
}
else
{
var context = new RpcContext
{
RpcRemoteSever = false
};
var publisher = new ActionEvaluationPublisher(
standaloneContext.NineChroniclesNodeService!.BlockRenderer,
standaloneContext.NineChroniclesNodeService!.ActionRenderer,
standaloneContext.NineChroniclesNodeService!.ExceptionRenderer,
standaloneContext.NineChroniclesNodeService!.NodeStatusRenderer,
IPAddress.Loopback.ToString(),
0,
context,
new ConcurrentDictionary<string, Sentry.ITransaction>()
);
hostBuilder.UseNineChroniclesNode(
nineChroniclesProperties,
standaloneContext,
publisher,
service);
}

await hostBuilder.RunConsoleAsync(cancellationToken ?? Context.CancellationToken);
}
Expand Down
25 changes: 5 additions & 20 deletions NineChronicles.Headless/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ public static class HostBuilderExtensions
public static IHostBuilder UseNineChroniclesNode(
this IHostBuilder builder,
NineChroniclesNodeServiceProperties properties,
StandaloneContext context
StandaloneContext context,
ActionEvaluationPublisher actionEvaluationPublisher,
NineChroniclesNodeService service
)
{
NineChroniclesNodeService service =
NineChroniclesNodeService.Create(properties, context);
var rpcContext = new RpcContext
{
RpcRemoteSever = false
};
return builder.ConfigureServices(services =>
{
services.AddHostedService(provider => service);
Expand All @@ -53,19 +49,8 @@ StandaloneContext context
{
services.AddSingleton<LibplanetNodeServiceProperties>(provider => libplanetNodeServiceProperties);
}
services.AddSingleton(provider =>
{
return new ActionEvaluationPublisher(
context.NineChroniclesNodeService!.BlockRenderer,
context.NineChroniclesNodeService!.ActionRenderer,
context.NineChroniclesNodeService!.ExceptionRenderer,
context.NineChroniclesNodeService!.NodeStatusRenderer,
IPAddress.Loopback.ToString(),
0,
rpcContext,
provider.GetRequiredService<ConcurrentDictionary<string, ITransaction>>()
);
});

services.AddSingleton(_ => actionEvaluationPublisher);
});
}

Expand Down

0 comments on commit b8e793e

Please sign in to comment.