Skip to content

Commit

Permalink
feat(cli): use ContainedNode
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed May 10, 2024
1 parent 6f64437 commit 276b6ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions core/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,20 +20,20 @@ where
let config = TomlConfigProvider::<C>::load_or_write_config(config_path).await?;
let app_config = config.get::<<C as Collection>::ApplicationInterface>();

let mut node = Node::<C>::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::<C>::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::<<C as Collection>::SyncronizerInterface>();

let checkpoint_fut = syncronizer.next_checkpoint_hash();
Expand All @@ -41,13 +43,12 @@ where
checkpoint_hash = checkpoint_fut => {
// get the checkpoint from the blockstore
let checkpoint = node
.provider
.provider()
.get::<<C as Collection>::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");
Expand All @@ -60,11 +61,10 @@ where
checkpoint_hash
).await?;

//restart the node
node = Node::<C>::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::<C>::new(provider, None);
node.spawn().await??;

}
}
Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/src/syncronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lightning_types::Blake3Hash;
use crate::collection::Collection;

#[interfaces_proc::blank]
pub trait SyncronizerInterface<C: Collection>: BuildGraph + Sized + Send {
pub trait SyncronizerInterface<C: Collection>: BuildGraph + Sized + Send + Sync {
/// Returns the blake3hash of the next checkpoint to load, after
/// it has already downloaded by the blockstore server.
#[pending]
Expand Down

0 comments on commit 276b6ab

Please sign in to comment.