mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Beacon chain tasks use task executor
This commit is contained in:
@@ -34,3 +34,4 @@ fnv = "1.0.6"
|
||||
rlp = "0.4.5"
|
||||
lazy_static = "1.4.0"
|
||||
lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
|
||||
environment = { path = "../../lighthouse/environment" }
|
||||
@@ -58,7 +58,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
runtime_handle: &tokio::runtime::Handle,
|
||||
runtime_handle: environment::TaskExecutor,
|
||||
log: slog::Logger,
|
||||
) -> error::Result<mpsc::UnboundedSender<RouterMessage<T::EthSpec>>> {
|
||||
let message_handler_log = log.new(o!("service"=> "router"));
|
||||
@@ -68,7 +68,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
|
||||
// Initialise a message instance, which itself spawns the syncing thread.
|
||||
let processor = Processor::new(
|
||||
runtime_handle,
|
||||
// TODO: spawn_blocking here
|
||||
&runtime_handle.runtime_handle(),
|
||||
beacon_chain,
|
||||
network_globals.clone(),
|
||||
network_send.clone(),
|
||||
@@ -84,12 +85,15 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
};
|
||||
|
||||
// spawn handler task and move the message handler instance into the spawned thread
|
||||
runtime_handle.spawn(async move {
|
||||
handler_recv
|
||||
.for_each(move |msg| future::ready(handler.handle_message(msg)))
|
||||
.await;
|
||||
debug!(log, "Network message handler terminated.");
|
||||
});
|
||||
runtime_handle.spawn(
|
||||
async move {
|
||||
handler_recv
|
||||
.for_each(move |msg| future::ready(handler.handle_message(msg)))
|
||||
.await;
|
||||
debug!(log, "Network message handler terminated.");
|
||||
},
|
||||
"router_service",
|
||||
);
|
||||
|
||||
Ok(handler_send)
|
||||
}
|
||||
|
||||
@@ -53,12 +53,11 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
pub fn start(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
config: &NetworkConfig,
|
||||
runtime_handle: &Handle,
|
||||
handle: environment::TaskExecutor,
|
||||
network_log: slog::Logger,
|
||||
) -> error::Result<(
|
||||
Arc<NetworkGlobals<T::EthSpec>>,
|
||||
mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
oneshot::Sender<()>,
|
||||
)> {
|
||||
// build the network channel
|
||||
let (network_send, network_recv) = mpsc::unbounded_channel::<NetworkMessage<T::EthSpec>>();
|
||||
@@ -75,7 +74,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
|
||||
// launch libp2p service
|
||||
let (network_globals, mut libp2p) =
|
||||
LibP2PService::new(runtime_handle, config, enr_fork_id, &network_log)?;
|
||||
LibP2PService::new(handle.runtime_handle(), config, enr_fork_id, &network_log)?;
|
||||
|
||||
for enr in load_dht::<T::Store, T::EthSpec>(store.clone()) {
|
||||
libp2p.swarm.add_enr(enr);
|
||||
@@ -88,7 +87,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
beacon_chain.clone(),
|
||||
network_globals.clone(),
|
||||
network_send.clone(),
|
||||
runtime_handle,
|
||||
handle.clone(),
|
||||
network_log.clone(),
|
||||
)?;
|
||||
|
||||
@@ -111,17 +110,18 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
propagation_percentage,
|
||||
};
|
||||
|
||||
let network_exit = spawn_service(runtime_handle, network_service)?;
|
||||
let _ = spawn_service(handle, network_service)?;
|
||||
|
||||
Ok((network_globals, network_send, network_exit))
|
||||
Ok((network_globals, network_send))
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_service<T: BeaconChainTypes>(
|
||||
handle: &tokio::runtime::Handle,
|
||||
handle: environment::TaskExecutor,
|
||||
mut service: NetworkService<T>,
|
||||
) -> error::Result<tokio::sync::oneshot::Sender<()>> {
|
||||
let (network_exit, mut exit_rx) = tokio::sync::oneshot::channel();
|
||||
) -> error::Result<()> {
|
||||
let mut exit_rx = handle.exit();
|
||||
let handle = handle.runtime_handle();
|
||||
|
||||
// spawn on the current executor
|
||||
handle.spawn(async move {
|
||||
@@ -364,7 +364,7 @@ fn spawn_service<T: BeaconChainTypes>(
|
||||
}
|
||||
});
|
||||
|
||||
Ok(network_exit)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns a `Delay` that triggers shortly after the next change in the beacon chain fork version.
|
||||
|
||||
Reference in New Issue
Block a user