diff --git a/Cargo.lock b/Cargo.lock index 2480e61a..fb91f917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1509,16 +1509,15 @@ dependencies = [ [[package]] name = "caryatid_module_clock" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "951c0ab316e5557315c10b75011b30faeeb032f96c88507946ec154c7f9d4ddd" +checksum = "5509d9f63ad2d973599703617120dbfeff58078b37895f433cc784b5d3890d6e" dependencies = [ "anyhow", "caryatid_sdk", "chrono", "config", "serde", - "serde_json", "tokio", "tracing", "tracing-subscriber", @@ -1526,9 +1525,9 @@ dependencies = [ [[package]] name = "caryatid_module_rest_server" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c82ea79ce5ede49ce0dde01d204f21d39165d0abd8213281a7ce163a01519df" +checksum = "a42373dd9604700e51dd07565303522f7b1d2a0002a8db7489c77d846f08c08b" dependencies = [ "anyhow", "axum", @@ -1537,7 +1536,6 @@ dependencies = [ "futures", "hyper 0.14.32", "serde", - "serde_json", "tokio", "tracing", "tracing-subscriber", @@ -1545,24 +1543,21 @@ dependencies = [ [[package]] name = "caryatid_module_spy" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b7ce84ba23710e42d1fc497b2bb36463cbcb0af8aab39b7f14942b4682763" +checksum = "0432b56f66f5b3d527a704c9c4b090c03567aaefc48350e7bf41fce286431b5d" dependencies = [ "anyhow", "caryatid_sdk", "config", - "serde", - "serde_json", - "tokio", "tracing", ] [[package]] name = "caryatid_process" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7b38bc5f68d7f2400987524d50300597b607f5f2d76773fdc40a0216d296b01" +checksum = "a5964024f9c302253bdf84b3f35dc068853ed0c643961072b59f6e69b8f83552" dependencies = [ "anyhow", "async-trait", @@ -1582,20 +1577,18 @@ dependencies = [ [[package]] name = "caryatid_sdk" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b81e3dc1a35c175c7fc27f564b9ba9840fa25d24f08785a9cdfe2c2182965c77" +checksum = "fceb8e403d1123e3a69fe108ea36d3e24c81f98605d2f15ca58f500774e956b0" dependencies = [ "anyhow", "async-trait", "caryatid_macros", - "chrono", "config", "futures", "hex", "rand 0.9.2", "serde", - "serde_json", "tokio", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index 0ad4e54a..a980a49f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,11 +40,11 @@ members = [ resolver = "2" [workspace.dependencies] -caryatid_sdk = "0.13" -caryatid_process = "0.13" -caryatid_module_rest_server = "0.15" -caryatid_module_clock = "0.13" -caryatid_module_spy = "0.13" +caryatid_sdk = "0.14.0" +caryatid_process = "0.13.1" +caryatid_module_rest_server = "0.15.1" +caryatid_module_clock = "0.13.1" +caryatid_module_spy = "0.13.1" anyhow = "1.0" chrono = "0.4" clap = { version = "4.5", features = ["derive", "string"] } diff --git a/common/Cargo.toml b/common/Cargo.toml index 63473f4e..30118734 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -14,6 +14,7 @@ caryatid_module_clock = { workspace = true } caryatid_module_rest_server = { workspace = true } anyhow = { workspace = true } +config = { workspace = true } bech32 = "0.11" bigdecimal = "0.4.8" bitmask-enum = "2.2" diff --git a/common/src/configuration.rs b/common/src/configuration.rs new file mode 100644 index 00000000..a33eeb17 --- /dev/null +++ b/common/src/configuration.rs @@ -0,0 +1,35 @@ +use config::Config; +use serde::Deserialize; +use std::fmt::{Display, Formatter, Result}; + +pub const CONFIG_KEY_STARTUP_METHOD: &str = "startup.method"; + +#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum StartupMethod { + Mithril, + Snapshot, +} + +impl StartupMethod { + pub fn from_config(config: &Config) -> Self { + config.get::(CONFIG_KEY_STARTUP_METHOD).unwrap_or(StartupMethod::Mithril) + } + + pub fn is_mithril(&self) -> bool { + matches!(self, StartupMethod::Mithril) + } + + pub fn is_snapshot(&self) -> bool { + matches!(self, StartupMethod::Snapshot) + } +} + +impl Display for StartupMethod { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + match self { + StartupMethod::Mithril => write!(f, "mithril"), + StartupMethod::Snapshot => write!(f, "snapshot"), + } + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index daa6dda7..2ffc099a 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -5,6 +5,7 @@ pub mod calculations; pub mod cbor; pub mod cip19; pub mod commands; +pub mod configuration; pub mod crypto; pub mod genesis_values; pub mod hash; diff --git a/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs b/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs index 1a1a91e1..bb77243b 100644 --- a/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs +++ b/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs @@ -2,6 +2,7 @@ //! Fetches a snapshot from Mithril and replays all the blocks in it use acropolis_common::{ + configuration::StartupMethod, genesis_values::GenesisValues, messages::{CardanoMessage, Message, RawBlockMessage}, BlockHash, BlockInfo, BlockStatus, Era, @@ -395,6 +396,16 @@ impl MithrilSnapshotFetcher { /// Main init function pub async fn init(&self, context: Arc>, config: Arc) -> Result<()> { + // Check if this module is the selected startup method + let startup_method = StartupMethod::from_config(&config); + if !startup_method.is_mithril() { + info!( + "Mithril Snapshot Fetcher not enabled (startup.method = '{}')", + startup_method + ); + return Ok(()); + } + let bootstrapped_subscribe_topic = config .get_string(DEFAULT_BOOTSTRAPPED_SUBSCRIBE_TOPIC.0) .unwrap_or(DEFAULT_BOOTSTRAPPED_SUBSCRIBE_TOPIC.1.to_string()); diff --git a/modules/snapshot_bootstrapper/src/bootstrapper.rs b/modules/snapshot_bootstrapper/src/bootstrapper.rs index b931b898..753dac7a 100644 --- a/modules/snapshot_bootstrapper/src/bootstrapper.rs +++ b/modules/snapshot_bootstrapper/src/bootstrapper.rs @@ -6,10 +6,11 @@ mod publisher; use crate::configuration::{ConfigError, NetworkConfig, SnapshotConfig, SnapshotFileMetadata}; use crate::downloader::{DownloadError, SnapshotDownloader}; use crate::publisher::SnapshotPublisher; -use acropolis_common::genesis_values::GenesisValues; -use acropolis_common::snapshot::streaming_snapshot::StreamingSnapshotParser; use acropolis_common::{ + configuration::StartupMethod, + genesis_values::GenesisValues, messages::{CardanoMessage, Message}, + snapshot::streaming_snapshot::StreamingSnapshotParser, BlockHash, BlockInfo, BlockStatus, Era, }; use anyhow::{bail, Result}; @@ -48,6 +49,16 @@ pub struct SnapshotBootstrapper; impl SnapshotBootstrapper { /// Initializes the snapshot bootstrapper. pub async fn init(&self, context: Arc>, config: Arc) -> Result<()> { + // Check if this module is the selected startup method + let startup_method = StartupMethod::from_config(&config); + if !startup_method.is_snapshot() { + info!( + "Snapshot bootstrapper not enabled (startup.method = '{}')", + startup_method + ); + return Ok(()); + } + let cfg = SnapshotConfig::try_load(&config)?; info!("Snapshot bootstrapper initializing"); diff --git a/processes/omnibus/omnibus.toml b/processes/omnibus/omnibus.toml index 4b25d34e..3acbabb0 100644 --- a/processes/omnibus/omnibus.toml +++ b/processes/omnibus/omnibus.toml @@ -3,7 +3,7 @@ # ============================================================================ # Startup Configuration # ============================================================================ -[startup] +[global.startup] method = "mithril" # Options: "mithril" | "snapshot" topic = "cardano.sequence.start" diff --git a/processes/omnibus/src/main.rs b/processes/omnibus/src/main.rs index 49f2cea3..18b6fd26 100644 --- a/processes/omnibus/src/main.rs +++ b/processes/omnibus/src/main.rs @@ -45,10 +45,6 @@ use tracing_opentelemetry::OpenTelemetryLayer; use tracing_subscriber::prelude::*; use tracing_subscriber::{filter, fmt, EnvFilter, Registry}; -const STARTUP_METHOD_MITHRIL: &str = "mithril"; -const STARTUP_METHOD_SNAPSHOT: &str = "snapshot"; -const CONFIG_KEY_STARTUP_METHOD: &str = "startup.method"; - #[cfg(not(target_env = "msvc"))] use tikv_jemallocator::Jemalloc; #[cfg(not(target_env = "msvc"))] @@ -102,35 +98,12 @@ pub async fn main() -> Result<()> { ); // Create the process - let mut process = Process::::create(config.clone()).await; - - // Get startup method from config - let startup_method = config - .get_string(CONFIG_KEY_STARTUP_METHOD) - .unwrap_or_else(|_| STARTUP_METHOD_MITHRIL.to_string()); - - info!("Using startup method: {}", startup_method); - - // Register bootstrap modules based on the startup method - match startup_method.as_str() { - STARTUP_METHOD_MITHRIL => { - info!("Registering MithrilSnapshotFetcher"); - MithrilSnapshotFetcher::register(&mut process); - } - STARTUP_METHOD_SNAPSHOT => { - info!("Registering SnapshotBootstrapper"); - SnapshotBootstrapper::register(&mut process); - } - _ => { - panic!( - "Invalid startup method: {}. Must be one of: mithril, snapshot", - startup_method - ); - } - } + let mut process = Process::::create(config).await; // Register modules GenesisBootstrapper::register(&mut process); + SnapshotBootstrapper::register(&mut process); + MithrilSnapshotFetcher::register(&mut process); BlockUnpacker::register(&mut process); PeerNetworkInterface::register(&mut process); TxUnpacker::register(&mut process);