From 276b6abb97306bdae4c993e9182cadf928d48549 Mon Sep 17 00:00:00 2001 From: Matthias Wright Date: Fri, 10 May 2024 16:25:57 +0800 Subject: [PATCH] feat(cli): use ContainedNode --- core/cli/src/commands/run.rs | 26 +++++++++++++------------- core/interfaces/src/syncronizer.rs | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/cli/src/commands/run.rs b/core/cli/src/commands/run.rs index b39aed2d4..658891615 100644 --- a/core/cli/src/commands/run.rs +++ b/core/cli/src/commands/run.rs @@ -1,7 +1,9 @@ use std::time::Duration; -use anyhow::{Context, Result}; +use anyhow::Result; +use lightning_interfaces::fdi::MultiThreadedProvider; use lightning_interfaces::prelude::*; +use lightning_node::ContainedNode; use lightning_utils::config::TomlConfigProvider; use lightning_utils::shutdown::ShutdownController; use resolved_pathbuf::ResolvedPathBuf; @@ -18,20 +20,20 @@ where let config = TomlConfigProvider::::load_or_write_config(config_path).await?; let app_config = config.get::<::ApplicationInterface>(); - let mut node = Node::::init(config.clone()) - .map_err(|e| anyhow::anyhow!("Node Initialization failed: {e:?}")) - .context("Could not start the node.")?; + let provider = MultiThreadedProvider::default(); + provider.insert(config.clone()); + let mut node = ContainedNode::::new(provider, None); panic_report::add_context("config", config.into_inner()); - node.start().await; + node.spawn().await??; let shutdown_future = shutdown_controller.wait_for_shutdown(); pin!(shutdown_future); loop { let syncronizer = node - .provider + .provider() .get::<::SyncronizerInterface>(); let checkpoint_fut = syncronizer.next_checkpoint_hash(); @@ -41,13 +43,12 @@ where checkpoint_hash = checkpoint_fut => { // get the checkpoint from the blockstore let checkpoint = node - .provider + .provider() .get::<::BlockstoreInterface>() .read_all_to_vec(&checkpoint_hash).await.expect("Failed to read checkpoint from blockstore"); // shutdown the node node.shutdown().await; - std::mem::drop(node); // Sleep for a bit but provide some feedback, some of our proccesses take a few milliseconds to drop from memory warn!("Preparing to load checkpoint, Restarting services"); @@ -60,11 +61,10 @@ where checkpoint_hash ).await?; - //restart the node - node = Node::::init(config.clone()) - .map_err(|e| anyhow::anyhow!("Could not start the node: {e:?}"))?; - - node.start().await; + let provider = MultiThreadedProvider::default(); + provider.insert(config.clone()); + node = ContainedNode::::new(provider, None); + node.spawn().await??; } } diff --git a/core/interfaces/src/syncronizer.rs b/core/interfaces/src/syncronizer.rs index df17d160e..277ac97ab 100644 --- a/core/interfaces/src/syncronizer.rs +++ b/core/interfaces/src/syncronizer.rs @@ -4,7 +4,7 @@ use lightning_types::Blake3Hash; use crate::collection::Collection; #[interfaces_proc::blank] -pub trait SyncronizerInterface: BuildGraph + Sized + Send { +pub trait SyncronizerInterface: BuildGraph + Sized + Send + Sync { /// Returns the blake3hash of the next checkpoint to load, after /// it has already downloaded by the blockstore server. #[pending]