Set node_key from cli args (#361)
This commit is contained in:
parent
8adb24752a
commit
e9b752aa4d
|
@ -13,6 +13,7 @@ clap = { version = "4", features = ["derive"] }
|
|||
chrono = "0.4"
|
||||
futures = "0.3"
|
||||
http = "0.2.9"
|
||||
hex = "0.4.3"
|
||||
overwatch-rs = { git = "https://github.com/logos-co/Overwatch", branch = "main" }
|
||||
overwatch-derive = { git = "https://github.com/logos-co/Overwatch", branch = "main" }
|
||||
tracing = "0.1"
|
||||
|
@ -23,6 +24,7 @@ nomos-log = { path = "../../nomos-services/log" }
|
|||
nomos-mempool = { path = "../../nomos-services/mempool", features = ["mock"] }
|
||||
nomos-http = { path = "../../nomos-services/http", features = ["http"] }
|
||||
nomos-consensus = { path = "../../nomos-services/consensus" }
|
||||
nomos-libp2p = { path = "../../nomos-libp2p", optional = true }
|
||||
metrics = { path = "../../nomos-services/metrics", optional = true }
|
||||
tracing-subscriber = "0.3"
|
||||
consensus-engine = { path = "../../consensus-engine" }
|
||||
|
@ -37,4 +39,4 @@ waku-bindings = { version = "0.1.1", optional = true }
|
|||
[features]
|
||||
default = ["waku"]
|
||||
waku = ["waku-bindings", "nomos-network/waku", "nomos-mempool/waku", "nomos-consensus/waku"]
|
||||
libp2p = ["nomos-network/libp2p", "nomos-mempool/libp2p", "nomos-consensus/libp2p"]
|
||||
libp2p = ["nomos-libp2p", "nomos-network/libp2p", "nomos-mempool/libp2p", "nomos-consensus/libp2p"]
|
||||
|
|
|
@ -13,6 +13,8 @@ use nomos_core::fountain::mock::MockFountain;
|
|||
use nomos_http::backends::axum::AxumBackend;
|
||||
use nomos_http::bridge::HttpBridgeService;
|
||||
use nomos_http::http::HttpService;
|
||||
#[cfg(feature = "libp2p")]
|
||||
use nomos_libp2p::secp256k1::SecretKey;
|
||||
use nomos_log::Logger;
|
||||
#[cfg(feature = "libp2p")]
|
||||
use nomos_mempool::network::adapters::libp2p::Libp2pAdapter as MempoolLibp2pAdapter;
|
||||
|
@ -27,6 +29,8 @@ use nomos_network::NetworkService;
|
|||
use overwatch_derive::*;
|
||||
use overwatch_rs::services::{handle::ServiceHandle, ServiceData};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "waku")]
|
||||
use waku_bindings::SecretKey;
|
||||
|
||||
pub use tx::Tx;
|
||||
|
||||
|
@ -46,6 +50,25 @@ pub struct Config {
|
|||
pub metrics: <MetricsService<MapMetricsBackend<MetricsData>> as ServiceData>::Settings,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn set_node_key(&mut self, node_key: Option<String>) -> Result<()> {
|
||||
if let Some(node_key) = node_key {
|
||||
#[cfg(feature = "waku")]
|
||||
{
|
||||
use std::str::FromStr;
|
||||
self.network.backend.inner.node_key = Some(SecretKey::from_str(&node_key)?)
|
||||
}
|
||||
#[cfg(feature = "libp2p")]
|
||||
{
|
||||
let mut key_bytes = hex::decode(node_key)?;
|
||||
self.network.backend.node_key =
|
||||
SecretKey::try_from_bytes(key_bytes.as_mut_slice())?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "waku")]
|
||||
pub type Carnot = CarnotConsensus<
|
||||
ConsensusWakuAdapter,
|
||||
|
|
|
@ -22,11 +22,16 @@ use std::sync::Arc;
|
|||
struct Args {
|
||||
/// Path for a yaml-encoded network config file
|
||||
config: std::path::PathBuf,
|
||||
/// Overrides node key in config file
|
||||
#[clap(long = "node-key")]
|
||||
node_key: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let Args { config } = Args::parse();
|
||||
let config = serde_yaml::from_reader::<_, Config>(std::fs::File::open(config)?)?;
|
||||
let Args { config, node_key } = Args::parse();
|
||||
let mut config = serde_yaml::from_reader::<_, Config>(std::fs::File::open(config)?)?;
|
||||
config.set_node_key(node_key)?;
|
||||
|
||||
let bridges: Vec<HttpBridge> = vec![
|
||||
Arc::new(Box::new(bridges::carnot_info_bridge)),
|
||||
Arc::new(Box::new(bridges::mempool_metrics_bridge)),
|
||||
|
|
Loading…
Reference in New Issue