Skip to content

Commit

Permalink
refactor: move edge config to config crate (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Feb 8, 2024
1 parent 10c3879 commit 23cc558
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 39 deletions.
31 changes: 29 additions & 2 deletions crates/topos-config/src/edge.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use crate::Config;
use crate::{edge::command::CommandConfig, Config};
use figment::{
providers::{Format, Toml},
Figment,
};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::Path};
use std::{
collections::HashMap,
path::{Path, PathBuf},
process::ExitStatus,
};
use tokio::{spawn, task::JoinHandle};
use tracing::{error, info};

// TODO: Provides the default arguments here
// Serde `flatten` and `default` doesn't work together yet
Expand Down Expand Up @@ -37,3 +43,24 @@ impl Config for EdgeConfig {
"edge".to_string()
}
}

pub mod command;

pub fn generate_edge_config(
edge_path: PathBuf,
config_path: PathBuf,
) -> JoinHandle<Result<ExitStatus, std::io::Error>> {
// Create the Polygon Edge config
info!("Generating the configuration at {config_path:?}");
info!("Polygon-edge binary located at: {edge_path:?}");
spawn(async move {
CommandConfig::new(edge_path)
.init(&config_path)
.spawn()
.await
.map_err(|e| {
error!("Failed to generate the edge configuration: {e:?}");
e
})
})
}
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/topos-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(crate) mod base;
pub(crate) mod edge;
pub mod edge;
pub mod genesis;
pub mod node;
pub mod sequencer;
Expand Down
20 changes: 10 additions & 10 deletions crates/topos-sequencer-subnet-runtime/tests/subnet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ async fn deploy_test_token(
"Deploying new token {} with symbol {}",
token_name, token_symbol
);
match ierc20_messaging

let deploy_query = ierc20_messaging
.deploy_token(token_encoded_params)
.legacy()
.gas(DEFAULT_GAS)
.send()
.await
.map_err(|e| {
error!("Unable deploy token: {e}");
e
})?
.await
{
.gas(DEFAULT_GAS);

let deploy_result = deploy_query.send().await.map_err(|e| {
error!("Unable deploy token: {e}");
e
})?;

match deploy_result.await {
Ok(r) => {
info!("Token deployed: {:?}", r);
}
Expand Down
5 changes: 2 additions & 3 deletions crates/topos/src/components/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use tracing::{error, info};
use tracing_opentelemetry::OpenTelemetrySpanExt;

use self::commands::{NodeCommand, NodeCommands};
use crate::edge::BINARY_NAME;
use crate::tracing::setup_tracing;
use topos_config::{genesis::Genesis, Config};
use topos_config::{edge::command::BINARY_NAME, genesis::Genesis, Config};
use topos_config::{node::NodeConfig, node::NodeRole};
use topos_core::api::grpc::tce::v1::console_service_client::ConsoleServiceClient;
use topos_wallet::SecretManager;
Expand Down Expand Up @@ -74,7 +73,7 @@ pub(crate) async fn handle_command(
println!("Init the node without polygon-edge process...");
} else {
// Generate the Edge configuration
match services::process::generate_edge_config(
match topos_config::edge::generate_edge_config(
edge_path.join(BINARY_NAME),
node_path.clone(),
)
Expand Down
23 changes: 2 additions & 21 deletions crates/topos/src/components/node/services/process.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::edge::CommandConfig;
use std::collections::HashMap;
use std::path::PathBuf;
use std::process::ExitStatus;
use thiserror::Error;
use tokio::{spawn, sync::mpsc, task::JoinHandle};
use tokio_util::sync::CancellationToken;
use topos_config::edge::command::CommandConfig;
use topos_config::sequencer::SequencerConfig;
use topos_config::tce::broadcast::ReliableBroadcastParams;
use topos_config::tce::{AuthKey, StorageConfiguration, TceConfig};
use topos_p2p::Multiaddr;
use topos_sequencer::SequencerConfiguration;
use topos_wallet::SecretManager;
use tracing::{debug, error, info, warn};
use tracing::{debug, error, warn};

use topos_config::genesis::Genesis;

Expand All @@ -25,25 +25,6 @@ pub enum Errors {
EdgeTerminated(#[from] std::io::Error),
}

pub fn generate_edge_config(
edge_path: PathBuf,
config_path: PathBuf,
) -> JoinHandle<Result<ExitStatus, Errors>> {
// Create the Polygon Edge config
info!("Generating the configuration at {config_path:?}");
info!("Polygon-edge binary located at: {edge_path:?}");
spawn(async move {
CommandConfig::new(edge_path)
.init(&config_path)
.spawn()
.await
.map_err(|e| {
error!("Failed to generate the edge configuration: {e:?}");
Errors::EdgeTerminated(e)
})
})
}

pub(crate) fn spawn_sequencer_process(
config: SequencerConfig,
keys: &SecretManager,
Expand Down
2 changes: 0 additions & 2 deletions crates/topos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pub(crate) mod components;
pub(crate) mod options;
mod tracing;

mod edge;

use crate::options::ToposCommand;
use tracing_log::LogTracer;

Expand Down

0 comments on commit 23cc558

Please sign in to comment.