diff --git a/Cargo.lock b/Cargo.lock index d418f32fc..cda7f45a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7372,7 +7372,6 @@ dependencies = [ "clap 4.4.6", "dirs", "env_logger 0.10.0", - "figment", "flate2", "futures", "hex", @@ -7401,6 +7400,7 @@ dependencies = [ "toml 0.7.8", "tonic 0.10.2", "topos-certificate-spammer", + "topos-config", "topos-core", "topos-p2p", "topos-sequencer", @@ -7460,6 +7460,65 @@ dependencies = [ "tracing", ] +[[package]] +name = "topos-config" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "async-stream", + "async-trait", + "clap 4.4.6", + "dirs", + "env_logger 0.10.0", + "figment", + "flate2", + "futures", + "hex", + "insta", + "libp2p", + "once_cell", + "openssl", + "opentelemetry", + "opentelemetry-otlp", + "predicates 3.0.4", + "rand", + "regex", + "reqwest", + "rlp", + "rstest", + "serde", + "serde_json", + "serial_test", + "sysinfo", + "tar", + "tempfile", + "test-log", + "thiserror", + "tokio", + "tokio-util", + "toml 0.7.8", + "tonic 0.10.2", + "topos-certificate-spammer", + "topos-core", + "topos-p2p", + "topos-sequencer", + "topos-tce-api", + "topos-tce-broadcast", + "topos-tce-gatekeeper", + "topos-tce-storage", + "topos-tce-synchronizer", + "topos-tce-transport", + "topos-test-sdk", + "topos-wallet", + "tower", + "tracing", + "tracing-log", + "tracing-opentelemetry", + "tracing-subscriber", + "url", + "uuid 1.4.1", +] + [[package]] name = "topos-core" version = "0.1.0" @@ -7652,6 +7711,7 @@ dependencies = [ "tokio-stream", "tokio-util", "tonic 0.10.2", + "topos-config", "topos-core", "topos-crypto", "topos-metrics", diff --git a/crates/topos-config/Cargo.toml b/crates/topos-config/Cargo.toml new file mode 100644 index 000000000..e29b523de --- /dev/null +++ b/crates/topos-config/Cargo.toml @@ -0,0 +1,75 @@ +[package] +name = "topos-config" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +topos-p2p = { path = "../topos-p2p" } +topos-tce-transport = { path = "../topos-tce-transport" } +topos-sequencer = { path = "../topos-sequencer" } +topos-core = { workspace = true, features = ["api"] } +topos-certificate-spammer = { path = "../topos-certificate-spammer" } +topos-tce-broadcast = { path = "../topos-tce-broadcast", optional = true } +topos-wallet = { path = "../topos-wallet" } + +async-stream.workspace = true +async-trait.workspace = true +clap.workspace = true +hex.workspace = true +futures.workspace = true +opentelemetry.workspace = true +serde.workspace = true +serde_json.workspace = true +tokio = { workspace = true, features = ["full"] } +tokio-util.workspace = true +tonic.workspace = true +tower.workspace = true +tracing = { workspace = true, features = ["log"] } +tracing-opentelemetry.workspace = true +tracing-subscriber = { workspace = true, features = ["env-filter", "json", "ansi", "fmt"] } +uuid.workspace = true +rand.workspace = true +reqwest.workspace = true +thiserror.workspace = true +opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "metrics", "tls-roots"] } +figment = { version = "0.10", features = ["yaml", "toml", "env"] } +dirs = "5.0" +tracing-log = { version = "0.1.3", features = ["env_logger"] } +tar = "0.4.38" +flate2 ="1.0.26" +url = "2.3.1" +once_cell = "1.17.1" +toml = "0.7.4" +regex = "1" +rlp = "0.5.1" +openssl = { version = "0.10.61", features = ["vendored"] } + +[dev-dependencies] +topos-tce-broadcast = { path = "../topos-tce-broadcast" } +topos-tce-transport = { path = "../topos-tce-transport" } +topos-tce-synchronizer = { path = "../topos-tce-synchronizer" } +topos-tce-gatekeeper = { path = "../topos-tce-gatekeeper" } +topos-tce-api = { path = "../topos-tce-api" } +topos-tce-storage = { path = "../topos-tce-storage" } +topos-test-sdk = { path = "../topos-test-sdk" } +serde.workspace = true +serde_json.workspace = true +test-log.workspace = true +env_logger.workspace = true +rand.workspace = true +futures.workspace = true +libp2p = { workspace = true, features = ["identify"] } +assert_cmd = "2.0.6" +insta = { version = "1.21", features = ["json", "redactions"] } +rstest = { workspace = true, features = ["async-timeout"] } +tempfile = "3.8.0" +predicates = "3.0.3" +sysinfo = "0.29.11" +serial_test = {version = "0.9.0"} + + + +[lints] +workspace = true diff --git a/crates/topos/assets/genesis-example.json b/crates/topos-config/assets/genesis-example.json similarity index 100% rename from crates/topos/assets/genesis-example.json rename to crates/topos-config/assets/genesis-example.json diff --git a/crates/topos/src/config/base.rs b/crates/topos-config/src/base.rs similarity index 96% rename from crates/topos/src/config/base.rs rename to crates/topos-config/src/base.rs index 59bde8a3a..ef0938b08 100644 --- a/crates/topos/src/config/base.rs +++ b/crates/topos-config/src/base.rs @@ -6,8 +6,8 @@ use figment::{ }; use serde::{Deserialize, Serialize}; -use crate::config::node::NodeRole; -use crate::config::Config; +use crate::node::NodeRole; +use crate::Config; #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] diff --git a/crates/topos/src/config/edge.rs b/crates/topos-config/src/edge.rs similarity index 97% rename from crates/topos/src/config/edge.rs rename to crates/topos-config/src/edge.rs index 0886cbf4b..791299fb2 100644 --- a/crates/topos/src/config/edge.rs +++ b/crates/topos-config/src/edge.rs @@ -1,4 +1,4 @@ -use crate::config::Config; +use crate::Config; use figment::{ providers::{Format, Toml}, Figment, diff --git a/crates/topos/src/config/genesis/mod.rs b/crates/topos-config/src/genesis/mod.rs similarity index 100% rename from crates/topos/src/config/genesis/mod.rs rename to crates/topos-config/src/genesis/mod.rs diff --git a/crates/topos/src/config/genesis/tests.rs b/crates/topos-config/src/genesis/tests.rs similarity index 100% rename from crates/topos/src/config/genesis/tests.rs rename to crates/topos-config/src/genesis/tests.rs diff --git a/crates/topos/src/config/mod.rs b/crates/topos-config/src/lib.rs similarity index 58% rename from crates/topos/src/config/mod.rs rename to crates/topos-config/src/lib.rs index 8e6169ea1..a83ca8858 100644 --- a/crates/topos/src/config/mod.rs +++ b/crates/topos-config/src/lib.rs @@ -1,19 +1,17 @@ pub(crate) mod base; pub(crate) mod edge; -pub(crate) mod node; -pub(crate) mod sequencer; +pub mod genesis; +pub mod node; +pub mod sequencer; pub mod tce; -pub(crate) mod genesis; -use crate::components::node::commands::NodeCommands; - use std::path::Path; use figment::providers::Serialized; use figment::{error::Kind, Figment}; use serde::Serialize; -pub(crate) trait Config: Serialize { +pub trait Config: Serialize { /// The configuration type returned (should be Self). type Output; @@ -32,36 +30,40 @@ pub(crate) trait Config: Serialize { /// Convert the configuration to a TOML table. fn to_toml(&self) -> Result { - toml::Table::try_from(self) + let mut config_toml = toml::Table::new(); + + let config = toml::Table::try_from(self)?; + + // Flatten the top level + for (profile, content) in config { + config_toml.insert(profile, content); + } + + Ok(config_toml) } /// Main function to load the configuration. - /// It will load the configuration from the file and the command line (if any) + /// It will load the configuration from the file and an optional existing struct (if any) /// and then extract the configuration from the context in order to build the Config. /// The Config is then returned or an error if the configuration is not valid. - fn load(home: &Path, command: Option) -> Result { + fn load(home: &Path, config: Option) -> Result { let mut figment = Figment::new(); figment = Self::load_from_file(figment, home); - if let Some(command) = command { - match command { - NodeCommands::Up(up) => { - figment = figment.merge(Serialized::from(up, Self::profile())) - } - NodeCommands::Init(init) => { - figment = figment.merge(Serialized::from(init, Self::profile())) - } - _ => (), - } + if let Some(config) = config { + figment = figment.merge(Serialized::from(config, Self::profile())) } Self::load_context(figment) } } -pub(crate) fn load_config(node_path: &Path, command: Option) -> T::Output { - match T::load(node_path, command) { +pub(crate) fn load_config( + node_path: &Path, + config: Option, +) -> T::Output { + match T::load(node_path, config) { Ok(config) => config, Err(figment::Error { kind: Kind::MissingField(name), @@ -76,12 +78,3 @@ pub(crate) fn load_config(node_path: &Path, command: Option(config_toml: &mut toml::Table, config: T) { - let full = config.to_toml().expect("failed to convert config to toml"); - - // Flatten the top level - for (profile, content) in full { - config_toml.insert(profile, content); - } -} diff --git a/crates/topos/src/config/node.rs b/crates/topos-config/src/node.rs similarity index 66% rename from crates/topos/src/config/node.rs rename to crates/topos-config/src/node.rs index cbe61171d..4297d6434 100644 --- a/crates/topos/src/config/node.rs +++ b/crates/topos-config/src/node.rs @@ -5,10 +5,9 @@ use figment::{ Figment, }; -use crate::components::node::commands::NodeCommands; use serde::{Deserialize, Serialize}; -use crate::config::{ +use crate::{ base::BaseConfig, edge::EdgeConfig, load_config, sequencer::SequencerConfig, tce::TceConfig, Config, }; @@ -21,29 +20,29 @@ pub enum NodeRole { FullNode, } -#[derive(Serialize, Deserialize, Debug, Clone)] -pub(crate) struct NodeConfig { - pub(crate) base: BaseConfig, - pub(crate) tce: Option, - pub(crate) sequencer: Option, - pub(crate) edge: Option, +#[derive(Serialize, Deserialize, Debug)] +pub struct NodeConfig { + pub base: BaseConfig, + pub tce: Option, + pub sequencer: Option, + pub edge: Option, } impl NodeConfig { - pub fn new(home: &Path, cmd: Option) -> Self { - let base = load_config::(home, cmd); + pub fn new(home: &Path, config: Option) -> Self { + let base = load_config::(home, config); let mut config = NodeConfig { base: base.clone(), sequencer: base .need_sequencer() - .then(|| load_config::(home, None)), + .then(|| load_config::(home, None)), tce: base .need_tce() - .then(|| load_config::(home, None)), + .then(|| load_config::(home, None)), edge: base .need_edge() - .then(|| load_config::(home, None)), + .then(|| load_config::(home, None)), }; // Make the TCE DB path relative to the folder diff --git a/crates/topos/src/config/sequencer.rs b/crates/topos-config/src/sequencer.rs similarity index 98% rename from crates/topos/src/config/sequencer.rs rename to crates/topos-config/src/sequencer.rs index 6f82b9f36..907958c41 100644 --- a/crates/topos/src/config/sequencer.rs +++ b/crates/topos-config/src/sequencer.rs @@ -1,6 +1,6 @@ use std::path::Path; -use crate::config::Config; +use crate::Config; use figment::{ providers::{Format, Toml}, Figment, diff --git a/crates/topos/src/config/tce.rs b/crates/topos-config/src/tce.rs similarity index 80% rename from crates/topos/src/config/tce.rs rename to crates/topos-config/src/tce.rs index 532f9f173..22f208c0f 100644 --- a/crates/topos/src/config/tce.rs +++ b/crates/topos-config/src/tce.rs @@ -1,3 +1,4 @@ +use std::collections::HashSet; use std::path::Path; use std::{net::SocketAddr, path::PathBuf}; @@ -6,22 +7,54 @@ use figment::{ Figment, }; use serde::{Deserialize, Serialize}; +use topos_core::types::ValidatorId; +use topos_p2p::config::NetworkConfig; +use topos_tce_transport::ReliableBroadcastParams; -use crate::config::Config; +use crate::Config; use topos_p2p::{Multiaddr, PeerId}; const DEFAULT_IP: std::net::Ipv4Addr = std::net::Ipv4Addr::new(0, 0, 0, 0); -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Debug)] +pub enum AuthKey { + Seed(Vec), + PrivateKey(Vec), +} +#[derive(Default, Debug)] +pub enum StorageConfiguration { + #[default] + RAM, + RocksDB(Option), +} + +#[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct TceConfig { + #[serde(skip)] + pub auth_key: Option, + #[serde(skip)] + pub signing_key: Option, + #[serde(skip)] + pub tce_params: ReliableBroadcastParams, + #[serde(skip)] + pub boot_peers: Vec<(PeerId, Multiaddr)>, + #[serde(skip)] + pub validators: HashSet, + #[serde(skip)] + pub storage: StorageConfiguration, + + #[serde(skip)] + pub version: &'static str, + /// Storage database path, if not set RAM storage is used #[serde(default = "default_db_path")] pub db_path: PathBuf, /// Array of extra boot nodes to connect to pub extra_boot_peers: Option, /// Connection degree for the GossipSub overlay - pub minimum_tce_cluster_size: Option, + #[serde(default = "default_minimum_tce_cluster_size")] + pub minimum_tce_cluster_size: usize, /// libp2p addresses pub libp2p_api_addr: Option, @@ -47,7 +80,7 @@ pub struct TceConfig { pub otlp_service_name: Option, #[serde(default = "default_network_bootstrap_timeout")] - pub(crate) network_bootstrap_timeout: u64, + pub network_bootstrap_timeout: u64, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -60,7 +93,8 @@ pub struct P2PConfig { #[serde(default = "default_public_addresses")] pub public_addresses: Vec, - pub is_bootnode: Option, + #[serde(skip)] + pub is_bootnode: bool, } impl Default for P2PConfig { @@ -68,7 +102,7 @@ impl Default for P2PConfig { Self { listen_addresses: default_listen_addresses(), public_addresses: default_public_addresses(), - is_bootnode: None, + is_bootnode: false, } } } @@ -115,6 +149,10 @@ fn default_public_addresses() -> Vec { )] } +const fn default_minimum_tce_cluster_size() -> usize { + NetworkConfig::MINIMUM_CLUSTER_SIZE +} + const fn default_grpc_api_addr() -> SocketAddr { SocketAddr::V4(std::net::SocketAddrV4::new(DEFAULT_IP, 1340)) } diff --git a/crates/topos-tce/Cargo.toml b/crates/topos-tce/Cargo.toml index 64a30806c..31fd05c54 100644 --- a/crates/topos-tce/Cargo.toml +++ b/crates/topos-tce/Cargo.toml @@ -32,6 +32,7 @@ bytes.workspace = true prost.workspace = true tce_transport = { package = "topos-tce-transport", path = "../topos-tce-transport" } +topos-config = { path = "../topos-config" } topos-p2p = { path = "../topos-p2p" } topos-metrics = { path = "../topos-metrics" } topos-tce-api = { path = "../topos-tce-api"} diff --git a/crates/topos-tce/src/config.rs b/crates/topos-tce/src/config.rs deleted file mode 100644 index d4c5d20f4..000000000 --- a/crates/topos-tce/src/config.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::collections::HashSet; -use std::net::SocketAddr; -use std::path::PathBuf; -use std::time::Duration; - -use tce_transport::ReliableBroadcastParams; -use topos_core::types::ValidatorId; -use topos_p2p::{Multiaddr, PeerId}; - -pub use crate::AppContext; - -#[derive(Debug)] -pub enum AuthKey { - Seed(Vec), - PrivateKey(Vec), -} - -#[derive(Debug)] -pub struct TceConfiguration { - pub auth_key: Option, - pub signing_key: Option, - pub tce_params: ReliableBroadcastParams, - pub boot_peers: Vec<(PeerId, Multiaddr)>, - pub validators: HashSet, - pub api_addr: SocketAddr, - pub graphql_api_addr: SocketAddr, - pub metrics_api_addr: SocketAddr, - pub storage: StorageConfiguration, - pub network_bootstrap_timeout: Duration, - pub minimum_cluster_size: usize, - pub version: &'static str, - pub listen_addresses: Vec, - pub public_addresses: Vec, - pub is_bootnode: bool, -} - -#[derive(Debug)] -pub enum StorageConfiguration { - RAM, - RocksDB(Option), -} diff --git a/crates/topos-tce/src/lib.rs b/crates/topos-tce/src/lib.rs index 08176df60..b775ba17d 100644 --- a/crates/topos-tce/src/lib.rs +++ b/crates/topos-tce/src/lib.rs @@ -1,7 +1,7 @@ -use config::TceConfiguration; use futures::StreamExt; use opentelemetry::global; use std::process::ExitStatus; +use std::time::Duration; use std::{future::IntoFuture, sync::Arc}; use tokio::{ spawn, @@ -9,6 +9,7 @@ use tokio::{ }; use tokio_stream::wrappers::BroadcastStream; use tokio_util::sync::CancellationToken; +use topos_config::tce::TceConfig; use topos_core::api::grpc::tce::v1::synchronizer_service_server::SynchronizerServiceServer; use topos_crypto::{messages::MessageSigner, validator_id::ValidatorId}; use topos_p2p::{ @@ -28,27 +29,26 @@ use topos_tce_synchronizer::SynchronizerService; use tracing::{debug, info, warn}; mod app_context; -pub mod config; pub mod events; #[cfg(test)] mod tests; pub use app_context::AppContext; -use crate::config::{AuthKey, StorageConfiguration}; +use topos_config::tce::{AuthKey, StorageConfiguration}; // TODO: Estimate on the max broadcast throughput, could need to be override by config const BROADCAST_CHANNEL_SIZE: usize = 10_000; pub async fn run( - config: &TceConfiguration, + config: &TceConfig, shutdown: (CancellationToken, mpsc::Sender<()>), ) -> Result> { topos_metrics::init_metrics(); let key = match config.auth_key.as_ref() { - Some(AuthKey::Seed(seed)) => local_key_pair_from_slice(seed), - Some(AuthKey::PrivateKey(pk)) => topos_p2p::utils::keypair_from_protobuf_encoding(pk), + Some(AuthKey::Seed(seed)) => local_key_pair_from_slice(&seed[..]), + Some(AuthKey::PrivateKey(pk)) => topos_p2p::utils::keypair_from_protobuf_encoding(&pk[..]), None => local_key_pair(None), }; @@ -135,18 +135,18 @@ pub async fn run( let (network_client, event_stream, unbootstrapped_runtime) = topos_p2p::network::builder() .peer_key(key) - .listen_addresses(config.listen_addresses.clone()) - .minimum_cluster_size(config.minimum_cluster_size) - .public_addresses(config.public_addresses.clone()) + .listen_addresses(config.p2p.listen_addresses.clone()) + .minimum_cluster_size(config.minimum_tce_cluster_size) + .public_addresses(config.p2p.public_addresses.clone()) .known_peers(&boot_peers) .grpc_context(grpc_context) - .is_bootnode(config.is_bootnode) + .is_bootnode(config.p2p.is_bootnode) .build() .await?; debug!("Starting the p2p network"); let network_runtime = tokio::time::timeout( - config.network_bootstrap_timeout, + Duration::from_secs(config.network_bootstrap_timeout), unbootstrapped_runtime.bootstrap(), ) .await??; @@ -196,7 +196,7 @@ pub async fn run( let (api_client, api_stream, _ctx) = topos_tce_api::Runtime::builder() .with_peer_id(peer_id.to_string()) .with_broadcast_stream(broadcast_receiver.resubscribe()) - .serve_grpc_addr(config.api_addr) + .serve_grpc_addr(config.grpc_api_addr) .serve_graphql_addr(config.graphql_api_addr) .serve_metrics_addr(config.metrics_api_addr) .store(validator_store.clone()) diff --git a/crates/topos/Cargo.toml b/crates/topos/Cargo.toml index 91895ff41..46926553b 100644 --- a/crates/topos/Cargo.toml +++ b/crates/topos/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" workspace = true [dependencies] +topos-config = { path = "../topos-config/" } topos-tce = { path = "../topos-tce/" } topos-p2p = { path = "../topos-p2p" } topos-tce-transport = { path = "../topos-tce-transport" } @@ -36,19 +37,18 @@ rand.workspace = true reqwest.workspace = true thiserror.workspace = true opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "metrics", "tls-roots"] } -figment = { version = "0.10", features = ["yaml", "toml", "env"] } dirs = "5.0" tracing-log = { version = "0.1.3", features = ["env_logger"] } tar = "0.4.38" flate2 ="1.0.26" url = "2.3.1" once_cell = "1.17.1" -toml = "0.7.4" regex = "1" rlp = "0.5.1" openssl = { version = "0.10.61", features = ["vendored"] } [dev-dependencies] +toml = "0.7.4" topos-tce-broadcast = { path = "../topos-tce-broadcast" } topos-tce-transport = { path = "../topos-tce-transport" } topos-tce-synchronizer = { path = "../topos-tce-synchronizer" } diff --git a/crates/topos/src/components/node/commands/init.rs b/crates/topos/src/components/node/commands/init.rs index bdeb7cb4d..bad806672 100644 --- a/crates/topos/src/components/node/commands/init.rs +++ b/crates/topos/src/components/node/commands/init.rs @@ -1,6 +1,6 @@ -use crate::config::node::NodeRole; use clap::Args; use serde::Serialize; +use topos_config::node::NodeRole; #[derive(Args, Debug, Serialize)] #[command(about = "Setup your node", trailing_var_arg = true)] diff --git a/crates/topos/src/components/node/mod.rs b/crates/topos/src/components/node/mod.rs index aee3c4a85..028e00ca1 100644 --- a/crates/topos/src/components/node/mod.rs +++ b/crates/topos/src/components/node/mod.rs @@ -18,12 +18,10 @@ use tracing::{error, info}; use tracing_opentelemetry::OpenTelemetrySpanExt; use self::commands::{NodeCommand, NodeCommands}; -use crate::config::genesis::Genesis; use crate::edge::BINARY_NAME; -use crate::{ - config::{insert_into_toml, node::NodeConfig, node::NodeRole}, - tracing::setup_tracing, -}; +use crate::tracing::setup_tracing; +use topos_config::{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; @@ -72,9 +70,6 @@ pub(crate) async fn handle_command( std::process::exit(1); } - // Generate the configuration as per the role - let mut config_toml = toml::Table::new(); - if cmd.no_edge_process { println!("Init the node without polygon-edge process..."); } else { @@ -110,10 +105,17 @@ pub(crate) async fn handle_command( } } - let node_config = NodeConfig::new(&node_path, Some(NodeCommands::Init(Box::new(cmd)))); + let node_config = NodeConfig::new(&node_path, Some(cmd)); // Creating the TOML output - insert_into_toml(&mut config_toml, node_config); + let config_toml = match node_config.to_toml() { + Ok(config) => config, + Err(error) => { + println!("Failed to generate TOML config: {error}"); + remove_dir_all(node_path).expect("failed to remove config folder"); + std::process::exit(1); + } + }; let config_path = node_path.join("config.toml"); let mut node_config_file = OpenOptions::new() @@ -124,7 +126,7 @@ pub(crate) async fn handle_command( .expect("failed to create default node file"); node_config_file - .write_all(toml::to_string(&config_toml).unwrap().as_bytes()) + .write_all(config_toml.to_string().as_bytes()) .expect("failed to write to default node file"); println!( @@ -153,7 +155,7 @@ pub(crate) async fn handle_command( std::process::exit(1); } - let config = NodeConfig::new(&node_path, Some(NodeCommands::Up(Box::new(command)))); + let config = NodeConfig::new(&node_path, Some(command)); println!( "⚙️ Reading the configuration from {}/config.toml", node_path.display() @@ -249,7 +251,7 @@ pub(crate) async fn handle_command( if config.base.subnet == "topos" { info!("Running topos TCE service...",); processes.push(services::process::spawn_tce_process( - config.tce.clone().unwrap(), + config.tce.unwrap(), keys, genesis, (shutdown_token.clone(), shutdown_sender.clone()), diff --git a/crates/topos/src/components/node/services/process.rs b/crates/topos/src/components/node/services/process.rs index 44a1af9f2..e5678461c 100644 --- a/crates/topos/src/components/node/services/process.rs +++ b/crates/topos/src/components/node/services/process.rs @@ -1,22 +1,19 @@ -use crate::config::sequencer::SequencerConfig; -use crate::config::tce::TceConfig; use crate::edge::CommandConfig; use std::collections::HashMap; use std::path::PathBuf; use std::process::ExitStatus; -use std::time::Duration; use thiserror::Error; use tokio::{spawn, sync::mpsc, task::JoinHandle}; use tokio_util::sync::CancellationToken; -use topos_p2p::config::NetworkConfig; +use topos_config::sequencer::SequencerConfig; +use topos_config::tce::{AuthKey, StorageConfiguration, TceConfig}; use topos_p2p::Multiaddr; use topos_sequencer::SequencerConfiguration; -use topos_tce::config::{AuthKey, StorageConfiguration, TceConfiguration}; use topos_tce_transport::ReliableBroadcastParams; use topos_wallet::SecretManager; use tracing::{debug, error, info, warn}; -use crate::config::genesis::Genesis; +use topos_config::genesis::Genesis; #[derive(Error, Debug)] pub enum Errors { @@ -79,24 +76,25 @@ pub(crate) fn spawn_tce_process( genesis: Genesis, shutdown: (CancellationToken, mpsc::Sender<()>), ) -> JoinHandle> { - let boot_peers = genesis + config.boot_peers = genesis .boot_peers(Some(topos_p2p::constants::TCE_BOOTNODE_PORT)) .into_iter() .chain(config.parse_boot_peers()) .collect::>(); - let auth_key = keys.network.map(AuthKey::PrivateKey); - config.p2p.is_bootnode = if let Some(AuthKey::PrivateKey(ref k)) = auth_key { + config.auth_key = keys.network.map(AuthKey::PrivateKey); + config.signing_key = keys.validator.map(AuthKey::PrivateKey); + config.p2p.is_bootnode = if let Some(AuthKey::PrivateKey(ref k)) = config.auth_key { let peer_id = topos_p2p::utils::keypair_from_protobuf_encoding(&k[..]) .public() .to_peer_id(); - Some(boot_peers.iter().any(|(p, _)| p == &peer_id)) + config.boot_peers.iter().any(|(p, _)| p == &peer_id) } else { - None + false }; - let validators = genesis.validators().expect("Cannot parse validators"); - let tce_params = ReliableBroadcastParams::new(validators.len()); + config.validators = genesis.validators().expect("Cannot parse validators"); + config.tce_params = ReliableBroadcastParams::new(config.validators.len()); if let Some(socket) = config.libp2p_api_addr { warn!( @@ -113,29 +111,12 @@ pub(crate) fn spawn_tce_process( config.p2p.public_addresses = vec![addr]; } - let tce_config = TceConfiguration { - is_bootnode: config.p2p.is_bootnode.unwrap_or_default(), - boot_peers, - validators, - auth_key, - signing_key: keys.validator.map(AuthKey::PrivateKey), - listen_addresses: config.p2p.listen_addresses, - public_addresses: config.p2p.public_addresses, - tce_params, - api_addr: config.grpc_api_addr, - graphql_api_addr: config.graphql_api_addr, - metrics_api_addr: config.metrics_api_addr, - storage: StorageConfiguration::RocksDB(Some(config.db_path)), - network_bootstrap_timeout: Duration::from_secs(config.network_bootstrap_timeout), - minimum_cluster_size: config - .minimum_tce_cluster_size - .unwrap_or(NetworkConfig::MINIMUM_CLUSTER_SIZE), - version: env!("TOPOS_VERSION"), - }; + config.version = env!("TOPOS_VERSION"); + config.storage = StorageConfiguration::RocksDB(Some(config.db_path.clone())); - debug!("TCE args: {tce_config:?}"); + debug!("TCE args: {config:?}"); spawn(async move { - topos_tce::run(&tce_config, shutdown).await.map_err(|e| { + topos_tce::run(&config, shutdown).await.map_err(|e| { error!("TCE process terminated: {e:?}"); Errors::TceFailure }) diff --git a/crates/topos/src/main.rs b/crates/topos/src/main.rs index 7d00e4f20..d503822d3 100644 --- a/crates/topos/src/main.rs +++ b/crates/topos/src/main.rs @@ -4,7 +4,6 @@ pub(crate) mod components; pub(crate) mod options; mod tracing; -mod config; mod edge; use crate::options::ToposCommand;