Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(node): split run from main, as it will be used by many binaries #873

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions crates/papyrus_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ impl PapyrusResources {
}
}

fn build_network_manager(
network_config: Option<NetworkConfig>,
) -> anyhow::Result<(Option<NetworkManager>, String)> {
let Some(network_config) = network_config else {
return Ok((None, "".to_string()));
};
let network_manager = network_manager::NetworkManager::new(
network_config.clone(),
Some(VERSION_FULL.to_string()),
);
let local_peer_id = network_manager.get_local_peer_id();

Ok((Some(network_manager), local_peer_id))
}

#[cfg(feature = "rpc")]
async fn spawn_rpc_server(
config: &NodeConfig,
Expand Down Expand Up @@ -470,21 +485,6 @@ async fn run_threads(
Ok(())
}

fn build_network_manager(
network_config: Option<NetworkConfig>,
) -> anyhow::Result<(Option<NetworkManager>, String)> {
let Some(network_config) = network_config else {
return Ok((None, "".to_string()));
};
let network_manager = network_manager::NetworkManager::new(
network_config.clone(),
Some(VERSION_FULL.to_string()),
);
let local_peer_id = network_manager.get_local_peer_id();

Ok((Some(network_manager), local_peer_id))
}

// TODO(yair): add dynamic level filtering.
// TODO(dan): filter out logs from dependencies (happens when RUST_LOG=DEBUG)
// TODO(yair): define and implement configurable filtering.
Expand Down Expand Up @@ -520,16 +520,13 @@ fn spawn_storage_metrics_collector(
)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = NodeConfig::load_and_process(args().collect());
if let Err(ConfigError::CommandInput(clap_err)) = config {
clap_err.exit();
}

pub async fn run(
config: NodeConfig,
resources: PapyrusResources,
tasks: PapyrusTaskHandles,
) -> anyhow::Result<()> {
configure_tracing();

let config = config?;
if let Err(errors) = config_validate(&config) {
error!("{}", errors);
exit(1);
Expand All @@ -540,8 +537,18 @@ async fn main() -> anyhow::Result<()> {
.expect("This should be the first and only time we set this value.");

info!("Booting up.");
run_threads(config, resources, tasks).await
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = NodeConfig::load_and_process(args().collect());
if let Err(ConfigError::CommandInput(clap_err)) = config {
clap_err.exit();
}
let config = config?;

let resources = PapyrusResources::new(&config)?;
let tasks = PapyrusTaskHandles::default();
run_threads(config, resources, tasks).await
run(config, resources, tasks).await
}
Loading