feat: global runtime (#21934)

This commit is contained in:
DaniPopes
2026-02-11 04:45:09 +01:00
committed by GitHub
parent 33467ea6dd
commit 68e4ff1f7d
119 changed files with 1612 additions and 1126 deletions

View File

@@ -903,8 +903,8 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
.request_handler(self.provider().clone())
.split_with_handle();
self.executor.spawn_critical_blocking("p2p txpool", Box::pin(txpool));
self.executor.spawn_critical_blocking("p2p eth request handler", Box::pin(eth));
self.executor.spawn_critical_blocking_task("p2p txpool", Box::pin(txpool));
self.executor.spawn_critical_blocking_task("p2p eth request handler", Box::pin(eth));
let default_peers_path = self.config().datadir().known_peers();
let known_peers_file = self.config().network.persistent_peers_file(default_peers_path);

View File

@@ -324,7 +324,7 @@ mod test {
use reth_node_ethereum::EthereumNode;
use reth_payload_builder::PayloadBuilderHandle;
use reth_provider::noop::NoopProvider;
use reth_tasks::TaskManager;
use reth_tasks::Runtime;
use reth_transaction_pool::noop::NoopTransactionPool;
#[test]
@@ -345,9 +345,7 @@ mod test {
let task_executor = {
let runtime = tokio::runtime::Runtime::new().unwrap();
let handle = runtime.handle().clone();
let manager = TaskManager::new(handle);
manager.executor()
Runtime::with_existing_handle(runtime.handle().clone()).unwrap()
};
let node = NodeAdapter { components, task_executor, provider: NoopProvider::default() };

View File

@@ -107,7 +107,8 @@ where
let (payload_service, payload_service_handle) =
PayloadBuilderService::new(payload_generator, ctx.provider().canonical_state_stream());
ctx.task_executor().spawn_critical("payload builder service", Box::pin(payload_service));
ctx.task_executor()
.spawn_critical_task("payload builder service", Box::pin(payload_service));
Ok(payload_service_handle)
}
@@ -133,7 +134,7 @@ where
) -> eyre::Result<PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>> {
let (tx, mut rx) = mpsc::unbounded_channel();
ctx.task_executor().spawn_critical("payload builder", async move {
ctx.task_executor().spawn_critical_task("payload builder", async move {
#[allow(clippy::collection_is_never_read)]
let mut subscriptions = Vec::new();

View File

@@ -256,7 +256,7 @@ where
let chain_events = ctx.provider().canonical_state_stream();
let client = ctx.provider().clone();
ctx.task_executor().spawn_critical(
ctx.task_executor().spawn_critical_task(
"txpool maintenance task",
reth_transaction_pool::maintain::maintain_transaction_pool_future(
client,

View File

@@ -215,9 +215,7 @@ impl LaunchContext {
/// Configure global settings this includes:
///
/// - Raising the file descriptor limit
/// - Configuring the global rayon thread pool with available parallelism. Honoring
/// engine.reserved-cpu-cores to reserve given number of cores for O while using at least 1
/// core for the rayon thread pool
/// - Configuring the global rayon thread pool for implicit `par_iter` usage
pub fn configure_globals(&self, reserved_cpu_cores: usize) {
// Raise the fd limit of the process.
// Does not do anything on windows.
@@ -229,9 +227,7 @@ impl LaunchContext {
Err(err) => warn!(%err, "Failed to raise file descriptor limit"),
}
// Reserving the given number of CPU cores for the rest of OS.
// Users can reserve more cores by setting engine.reserved-cpu-cores
// Note: The global rayon thread pool will use at least one core.
// Configure the implicit global rayon pool for `par_iter` usage.
let num_threads = available_parallelism()
.map_or(0, |num| num.get().saturating_sub(reserved_cpu_cores).max(1));
if let Err(err) = ThreadPoolBuilder::new()
@@ -503,6 +499,7 @@ where
self.chain_spec(),
static_file_provider,
rocksdb_provider,
self.task_executor().clone(),
)?
.with_prune_modes(self.prune_modes())
.with_changeset_cache(changeset_cache);
@@ -558,7 +555,7 @@ where
let (tx, rx) = oneshot::channel();
// Pipeline should be run as blocking and panic if it fails.
self.task_executor().spawn_critical_blocking(
self.task_executor().spawn_critical_blocking_task(
"pipeline task",
Box::pin(async move {
let (_, result) = pipeline.run_as_fut(Some(unwind_target)).await;
@@ -678,7 +675,8 @@ where
debug!(target: "reth::cli", "Spawning stages metrics listener task");
let sync_metrics_listener = reth_stages::MetricsListener::new(metrics_receiver);
self.task_executor().spawn_critical("stages metrics listener task", sync_metrics_listener);
self.task_executor()
.spawn_critical_task("stages metrics listener task", sync_metrics_listener);
LaunchContextWith {
inner: self.inner,
@@ -1105,7 +1103,7 @@ where
// If engine events are provided, spawn listener for new payload reporting
let ethstats_for_events = ethstats.clone();
let task_executor = self.task_executor().clone();
task_executor.spawn(Box::pin(async move {
task_executor.spawn_task(Box::pin(async move {
while let Some(event) = engine_events.next().await {
use reth_engine_primitives::ConsensusEngineEvent;
match event {
@@ -1131,7 +1129,7 @@ where
}));
// Spawn main ethstats service
task_executor.spawn(Box::pin(async move { ethstats.run().await }));
task_executor.spawn_task(Box::pin(async move { ethstats.run().await }));
Ok(())
}

View File

@@ -213,7 +213,7 @@ where
handle
.node
.task_executor
.spawn_critical("custom debug block provider consensus client", async move {
.spawn_critical_task("custom debug block provider consensus client", async move {
rpc_consensus_client.run().await
});
} else if let Some(url) = config.debug.rpc_consensus_url.clone() {
@@ -234,7 +234,7 @@ where
Arc::new(block_provider),
);
handle.node.task_executor.spawn_critical("rpc-ws consensus client", async move {
handle.node.task_executor.spawn_critical_task("rpc-ws consensus client", async move {
rpc_consensus_client.run().await
});
} else if let Some(maybe_custom_etherscan_url) = config.debug.etherscan.clone() {
@@ -262,9 +262,12 @@ where
handle.node.add_ons_handle.beacon_engine_handle.clone(),
Arc::new(block_provider),
);
handle.node.task_executor.spawn_critical("etherscan consensus client", async move {
rpc_consensus_client.run().await
});
handle
.node
.task_executor
.spawn_critical_task("etherscan consensus client", async move {
rpc_consensus_client.run().await
});
}
if config.dev.dev {
@@ -289,7 +292,7 @@ where
};
let dev_mining_mode = handle.node.config.dev_mining_mode(pool);
handle.node.task_executor.spawn_critical("local engine", async move {
handle.node.task_executor.spawn_critical_task("local engine", async move {
LocalMiner::new(
blockchain_db,
builder,

View File

@@ -248,7 +248,7 @@ impl EngineNodeLauncher {
static_file_producer_events.map(Into::into),
);
ctx.task_executor().spawn_critical(
ctx.task_executor().spawn_critical_task(
"events task",
Box::pin(node::handle_events(
Some(Box::new(ctx.components().network().clone())),
@@ -371,7 +371,7 @@ impl EngineNodeLauncher {
let _ = exit.send(res);
};
ctx.task_executor().spawn_critical("consensus engine", Box::pin(consensus_engine));
ctx.task_executor().spawn_critical_task("consensus engine", Box::pin(consensus_engine));
let engine_events_for_ethstats = engine_events.new_listener();

View File

@@ -111,7 +111,7 @@ impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
let exex = exex.launch(context).instrument(span.clone()).await?;
// spawn it as a crit task
executor.spawn_critical(
executor.spawn_critical_task(
"exex",
async move {
info!(target: "reth::cli", "ExEx started");
@@ -140,14 +140,14 @@ impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
)
.with_wal_blocks_warning(wal_blocks_warning);
let exex_manager_handle = exex_manager.handle();
components.task_executor().spawn_critical("exex manager", async move {
components.task_executor().spawn_critical_task("exex manager", async move {
exex_manager.await.expect("exex manager crashed");
});
// send notifications from the blockchain tree to exex manager
let mut canon_state_notifications = components.provider().subscribe_to_canonical_state();
let mut handle = exex_manager_handle.clone();
components.task_executor().spawn_critical(
components.task_executor().spawn_critical_task(
"exex manager blockchain tree notifications",
async move {
while let Ok(notification) = canon_state_notifications.recv().await {

View File

@@ -992,7 +992,7 @@ where
let new_canonical_blocks = node.provider().canonical_state_stream();
let c = cache.clone();
node.task_executor().spawn_critical(
node.task_executor().spawn_critical_task(
"cache canonical blocks task",
Box::pin(async move {
cache_new_blocks_task(c, new_canonical_blocks).await;
@@ -1352,6 +1352,7 @@ where
tree_config,
invalid_block_hook,
changeset_cache,
ctx.node.task_executor().clone(),
))
}
}