mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
chore: centralize thread::spawn to share tokio handles (#21754)
This commit is contained in:
@@ -11,6 +11,7 @@ use reth_provider::{
|
||||
};
|
||||
use reth_prune::{PrunerError, PrunerOutput, PrunerWithFactory};
|
||||
use reth_stages_api::{MetricEvent, MetricEventsSender};
|
||||
use reth_tasks::spawn_os_thread;
|
||||
use std::{
|
||||
sync::{
|
||||
mpsc::{Receiver, SendError, Sender},
|
||||
@@ -264,14 +265,11 @@ impl<T: NodePrimitives> PersistenceHandle<T> {
|
||||
// spawn the persistence service
|
||||
let db_service =
|
||||
PersistenceService::new(provider_factory, db_service_rx, pruner, sync_metrics_tx);
|
||||
let join_handle = std::thread::Builder::new()
|
||||
.name("persistence".to_string())
|
||||
.spawn(|| {
|
||||
if let Err(err) = db_service.run() {
|
||||
error!(target: "engine::persistence", ?err, "Persistence service failed");
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
let join_handle = spawn_os_thread("persistence", || {
|
||||
if let Err(err) = db_service.run() {
|
||||
error!(target: "engine::persistence", ?err, "Persistence service failed");
|
||||
}
|
||||
});
|
||||
|
||||
PersistenceHandle {
|
||||
sender: db_service_tx,
|
||||
|
||||
@@ -37,6 +37,7 @@ use reth_provider::{
|
||||
};
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_stages_api::ControlFlow;
|
||||
use reth_tasks::spawn_os_thread;
|
||||
use reth_trie_db::ChangesetCache;
|
||||
use revm::state::EvmState;
|
||||
use state::TreeState;
|
||||
@@ -431,7 +432,7 @@ where
|
||||
changeset_cache,
|
||||
);
|
||||
let incoming = task.incoming_tx.clone();
|
||||
std::thread::Builder::new().name("engine".to_string()).spawn(|| task.run()).unwrap();
|
||||
spawn_os_thread("engine", || task.run());
|
||||
(incoming, outgoing)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ use reth_ethereum_primitives::{Block, EthPrimitives};
|
||||
use reth_evm_ethereum::MockEvmConfig;
|
||||
use reth_primitives_traits::Block as _;
|
||||
use reth_provider::test_utils::MockEthProvider;
|
||||
use reth_tasks::spawn_os_thread;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
str::FromStr,
|
||||
@@ -538,10 +539,7 @@ async fn test_tree_persist_blocks() {
|
||||
.get_executed_blocks(1..tree_config.persistence_threshold() + 2)
|
||||
.collect();
|
||||
let test_harness = TestHarness::new(chain_spec).with_blocks(blocks.clone());
|
||||
std::thread::Builder::new()
|
||||
.name("Engine Task".to_string())
|
||||
.spawn(|| test_harness.tree.run())
|
||||
.unwrap();
|
||||
spawn_os_thread("engine", || test_harness.tree.run());
|
||||
|
||||
// send a message to the tree to enter the main loop.
|
||||
test_harness.to_tree_tx.send(FromEngine::DownloadedBlocks(vec![])).unwrap();
|
||||
@@ -1989,10 +1987,7 @@ mod forkchoice_updated_tests {
|
||||
let action_rx = test_harness.action_rx;
|
||||
|
||||
// Spawn tree in background thread
|
||||
std::thread::Builder::new()
|
||||
.name("Engine Task".to_string())
|
||||
.spawn(|| test_harness.tree.run())
|
||||
.unwrap();
|
||||
spawn_os_thread("engine", || test_harness.tree.run());
|
||||
|
||||
// Send terminate request
|
||||
to_tree_tx
|
||||
|
||||
Reference in New Issue
Block a user