Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 10 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 35 additions & 0 deletions common/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -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::<StartupMethod>(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"),
}
}
}
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -395,6 +396,16 @@ impl MithrilSnapshotFetcher {

/// Main init function
pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> 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());
Expand Down
15 changes: 13 additions & 2 deletions modules/snapshot_bootstrapper/src/bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -48,6 +49,16 @@ pub struct SnapshotBootstrapper;
impl SnapshotBootstrapper {
/// Initializes the snapshot bootstrapper.
pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> 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");
Expand Down
2 changes: 1 addition & 1 deletion processes/omnibus/omnibus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ============================================================================
# Startup Configuration
# ============================================================================
[startup]
[global.startup]
method = "mithril" # Options: "mithril" | "snapshot"
topic = "cardano.sequence.start"

Expand Down
33 changes: 3 additions & 30 deletions processes/omnibus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -102,35 +98,12 @@ pub async fn main() -> Result<()> {
);

// Create the process
let mut process = Process::<Message>::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::<Message>::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);
Expand Down