-
Notifications
You must be signed in to change notification settings - Fork 695
Expand file tree
/
Copy pathRpcModules.cs
More file actions
120 lines (106 loc) · 5.66 KB
/
RpcModules.cs
File metadata and controls
120 lines (106 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using Autofac;
using Nethermind.Api;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Filters;
using Nethermind.Config;
using Nethermind.Consensus.Stateless;
using Nethermind.Consensus.Tracing;
using Nethermind.Core;
using Nethermind.Core.Timers;
using Nethermind.Facade;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Simulate;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Modules;
using Nethermind.JsonRpc.Modules.Admin;
using Nethermind.JsonRpc.Modules.DebugModule;
using Nethermind.JsonRpc.Modules.Eth;
using Nethermind.JsonRpc.Modules.Eth.FeeHistory;
using Nethermind.JsonRpc.Modules.LogIndex;
using Nethermind.JsonRpc.Modules.Net;
using Nethermind.JsonRpc.Modules.Parity;
using Nethermind.JsonRpc.Modules.Personal;
using Nethermind.JsonRpc.Modules.Proof;
using Nethermind.JsonRpc.Modules.Rpc;
using Nethermind.JsonRpc.Modules.Subscribe;
using Nethermind.JsonRpc.Modules.Trace;
using Nethermind.JsonRpc.Modules.TxPool;
using Nethermind.JsonRpc.Modules.Web3;
using Nethermind.Network;
using Nethermind.Network.Config;
using Nethermind.Sockets;
using Nethermind.Specs.ChainSpecStyle;
using Nethermind.State;
using Nethermind.TxPool;
namespace Nethermind.Init.Modules;
public class RpcModules(IJsonRpcConfig jsonRpcConfig) : Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
builder
.AddSingleton<IEthSyncingInfo, EthSyncingInfo>()
.AddSingleton<IRpcModuleProvider, RpcModuleProvider>()
.AddSingleton<IJsonRpcLocalStats, JsonRpcLocalStats>()
.AddSingleton<IWebSocketsManager, WebSocketsManager>()
// Smallish RPCs
.AddSingleton<INetBridge, NetBridge>()
.RegisterSingletonJsonRpcModule<INetRpcModule, NetRpcModule>()
.RegisterSingletonJsonRpcModule<IParityRpcModule, ParityRpcModule>()
.RegisterSingletonJsonRpcModule<IWeb3RpcModule, Web3RpcModule>()
.RegisterSingletonJsonRpcModule<IPersonalRpcModule, PersonalRpcModule>()
.RegisterSingletonJsonRpcModule<IRpcRpcModule, RpcRpcModule>()
.RegisterSingletonJsonRpcModule<ILogIndexRpcModule, LogIndexRpcModule>()
// Txpool rpc
.RegisterSingletonJsonRpcModule<ITxPoolRpcModule, TxPoolRpcModule>()
.AddSingleton<ITxPoolInfoProvider, IChainHeadInfoProvider, ITxPool>(
(chainHeadInfoProvider, txPool) => new TxPoolInfoProvider(chainHeadInfoProvider, txPool))
// Subscriptions
.RegisterBoundedJsonRpcModule<ISubscribeRpcModule, AutoRpcModuleFactory<ISubscribeRpcModule>>(2, jsonRpcConfig.Timeout)
.AddScoped<ISubscribeRpcModule, SubscribeRpcModule>()
.AddSingleton<IReceiptMonitor, ReceiptCanonicalityMonitor>()
.AddSingleton<ISubscriptionFactory, SubscriptionFactory>()
.AddSingleton<ISubscriptionManager, SubscriptionManager>()
// Admin
.RegisterBoundedJsonRpcModule<IAdminRpcModule, AutoRpcModuleFactory<IAdminRpcModule>>(2, jsonRpcConfig.Timeout)
.AddScoped<IAdminRpcModule>(CreateAdminRpcModule)
// Eth and its dependencies
.RegisterBoundedJsonRpcModule<IEthRpcModule, EthModuleFactory>(jsonRpcConfig.EthModuleConcurrentInstances ?? Environment.ProcessorCount, jsonRpcConfig.Timeout)
.AddSingleton<IBlockchainBridgeFactory, BlockchainBridgeFactory>()
.AddScoped<IBlockchainBridge>((ctx) => ctx.Resolve<IBlockchainBridgeFactory>().CreateBlockchainBridge())
.AddSingleton<IFeeHistoryOracle, FeeHistoryOracle>()
.AddSingleton<IEthCapabilitiesProvider, EthCapabilitiesProvider>()
.AddSingleton<FilterStore, ITimerFactory, IJsonRpcConfig>((timerFactory, rpcConfig) => new FilterStore(timerFactory, rpcConfig.FiltersTimeout))
.AddSingleton<FilterManager>()
.AddSingleton<IWitnessGeneratingBlockProcessingEnvFactory, WitnessGeneratingBlockProcessingEnvFactory>()
.AddSingleton<ISimulateReadOnlyBlocksProcessingEnvFactory, SimulateReadOnlyBlocksProcessingEnvFactory>()
// Proof
.RegisterBoundedJsonRpcModule<IProofRpcModule, ProofModuleFactory>(2, jsonRpcConfig.Timeout)
.AddScoped<IProofRpcModule, ProofRpcModule>()
// Trace
.RegisterBoundedJsonRpcModule<ITraceRpcModule, TraceModuleFactory>(2, jsonRpcConfig.Timeout)
.AddScoped<ITraceRpcModule, TraceRpcModule>()
// Debug
.RegisterBoundedJsonRpcModule<IDebugRpcModule, DebugModuleFactory>(Environment.ProcessorCount, jsonRpcConfig.Timeout)
.AddScoped<GethStyleTracer.BlockProcessingComponents>()
.AddScoped<IDebugBridge, DebugBridge>()
.AddScoped<IDebugRpcModule, DebugRpcModule>()
.AddScoped<IGethStyleTracer, GethStyleTracer>()
;
}
private IAdminRpcModule CreateAdminRpcModule(IComponentContext ctx) => new AdminRpcModule(
ctx.Resolve<IBlockTree>(),
ctx.Resolve<INetworkConfig>(),
ctx.Resolve<IPeerPool>(),
ctx.Resolve<IStaticNodesManager>(),
ctx.Resolve<IStateReader>(),
ctx.Resolve<IEnode>(),
ctx.Resolve<IInitConfig>().BaseDbPath, // IInitConfig not accessible from IAdminRpcModule, so we construct it manually here
ctx.Resolve<ChainSpec>().Parameters,
ctx.Resolve<ITrustedNodesManager>(),
ctx.Resolve<ISubscriptionManager>(),
ctx.Resolve<IJsonRpcConfig>());
}