Lines
0 %
Functions
Branches
100 %
// Copyright 2019-2025 PureStake Inc.
// This file is part of Moonbeam.
// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use moonbeam_rpc_debug::{DebugHandler, DebugRequester};
use moonbeam_rpc_trace::{CacheRequester as TraceFilterCacheRequester, CacheTask};
use substrate_prometheus_endpoint::Registry as PrometheusRegistry;
use tokio::sync::Semaphore;
#[derive(Clone)]
pub struct RpcRequesters {
pub debug: Option<DebugRequester>,
pub trace: Option<TraceFilterCacheRequester>,
}
// Spawn the tasks that are required to run a Moonbeam tracing node.
pub fn spawn_tracing_tasks<B, C, BE>(
rpc_config: &moonbeam_cli_opt::RpcConfig,
prometheus: Option<PrometheusRegistry>,
params: SpawnTasksParams<B, C, BE>,
) -> RpcRequesters
where
C: ProvideRuntimeApi<B> + BlockOf,
C: StorageProvider<B, BE>,
C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,
C: BlockchainEvents<B>,
C: Send + Sync + 'static,
C::Api: EthereumRuntimeRPCApi<B> + moonbeam_rpc_primitives_debug::DebugRuntimeApi<B>,
C::Api: BlockBuilder<B>,
B: BlockT<Hash = H256> + Send + Sync + 'static,
B::Header: HeaderT<Number = u32>,
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
{
let permit_pool = Arc::new(Semaphore::new(rpc_config.ethapi_max_permits as usize));
let (trace_filter_task, trace_filter_requester) =
if rpc_config.ethapi.contains(&EthApiCmd::Trace) {
let (trace_filter_task, trace_filter_requester) = CacheTask::create(
Arc::clone(¶ms.client),
Arc::clone(¶ms.substrate_backend),
Duration::from_secs(rpc_config.ethapi_trace_cache_duration),
Arc::clone(&permit_pool),
Arc::clone(¶ms.overrides),
prometheus,
);
(Some(trace_filter_task), Some(trace_filter_requester))
} else {
(None, None)
};
let (debug_task, debug_requester) = if rpc_config.ethapi.contains(&EthApiCmd::Debug) {
let (debug_task, debug_requester) = DebugHandler::task(
match *params.frontier_backend {
fc_db::Backend::KeyValue(ref b) => b.clone(),
fc_db::Backend::Sql(ref b) => b.clone(),
},
rpc_config.tracing_raw_max_memory_usage,
(Some(debug_task), Some(debug_requester))
// `trace_filter` cache task. Essential.
// Proxies rpc requests to it's handler.
if let Some(trace_filter_task) = trace_filter_task {
params.task_manager.spawn_essential_handle().spawn(
"trace-filter-cache",
Some("eth-tracing"),
trace_filter_task,
// `debug` task if enabled. Essential.
if let Some(debug_task) = debug_task {
"ethapi-debug",
debug_task,
RpcRequesters {
debug: debug_requester,
trace: trace_filter_requester,