Skip to content

Commit 122a2fc

Browse files
authored
Merge pull request #425 from input-output-hk/lowhung/add-global-config
feat: add global startup method configuration for snapshot and mithril
2 parents a4db00d + ede0b1c commit 122a2fc

File tree

9 files changed

+80
-55
lines changed

9 files changed

+80
-55
lines changed

Cargo.lock

Lines changed: 10 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ members = [
4141
resolver = "2"
4242

4343
[workspace.dependencies]
44-
caryatid_sdk = "0.13"
45-
caryatid_process = "0.13"
46-
caryatid_module_rest_server = "0.15"
47-
caryatid_module_clock = "0.13"
48-
caryatid_module_spy = "0.13"
44+
caryatid_sdk = "0.14.0"
45+
caryatid_process = "0.13.1"
46+
caryatid_module_rest_server = "0.15.1"
47+
caryatid_module_clock = "0.13.1"
48+
caryatid_module_spy = "0.13.1"
4949
anyhow = "1.0"
5050
chrono = "0.4"
5151
clap = { version = "4.5", features = ["derive", "string"] }

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ caryatid_module_clock = { workspace = true }
1414
caryatid_module_rest_server = { workspace = true }
1515

1616
anyhow = { workspace = true }
17+
config = { workspace = true }
1718
bech32 = "0.11"
1819
bigdecimal = "0.4.8"
1920
bitmask-enum = "2.2"

common/src/configuration.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use config::Config;
2+
use serde::Deserialize;
3+
use std::fmt::{Display, Formatter, Result};
4+
5+
pub const CONFIG_KEY_STARTUP_METHOD: &str = "startup.method";
6+
7+
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
8+
#[serde(rename_all = "lowercase")]
9+
pub enum StartupMethod {
10+
Mithril,
11+
Snapshot,
12+
}
13+
14+
impl StartupMethod {
15+
pub fn from_config(config: &Config) -> Self {
16+
config.get::<StartupMethod>(CONFIG_KEY_STARTUP_METHOD).unwrap_or(StartupMethod::Mithril)
17+
}
18+
19+
pub fn is_mithril(&self) -> bool {
20+
matches!(self, StartupMethod::Mithril)
21+
}
22+
23+
pub fn is_snapshot(&self) -> bool {
24+
matches!(self, StartupMethod::Snapshot)
25+
}
26+
}
27+
28+
impl Display for StartupMethod {
29+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
30+
match self {
31+
StartupMethod::Mithril => write!(f, "mithril"),
32+
StartupMethod::Snapshot => write!(f, "snapshot"),
33+
}
34+
}
35+
}

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod caryatid;
66
pub mod cbor;
77
pub mod cip19;
88
pub mod commands;
9+
pub mod configuration;
910
pub mod crypto;
1011
pub mod genesis_values;
1112
pub mod hash;

modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! Fetches a snapshot from Mithril and replays all the blocks in it
33
44
use acropolis_common::{
5+
configuration::StartupMethod,
56
genesis_values::GenesisValues,
67
messages::{CardanoMessage, Message, RawBlockMessage},
78
BlockHash, BlockInfo, BlockStatus, Era,
@@ -395,6 +396,16 @@ impl MithrilSnapshotFetcher {
395396

396397
/// Main init function
397398
pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> Result<()> {
399+
// Check if this module is the selected startup method
400+
let startup_method = StartupMethod::from_config(&config);
401+
if !startup_method.is_mithril() {
402+
info!(
403+
"Mithril Snapshot Fetcher not enabled (startup.method = '{}')",
404+
startup_method
405+
);
406+
return Ok(());
407+
}
408+
398409
let bootstrapped_subscribe_topic = config
399410
.get_string(DEFAULT_BOOTSTRAPPED_SUBSCRIBE_TOPIC.0)
400411
.unwrap_or(DEFAULT_BOOTSTRAPPED_SUBSCRIBE_TOPIC.1.to_string());

modules/snapshot_bootstrapper/src/bootstrapper.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ mod publisher;
66
use crate::configuration::{ConfigError, NetworkConfig, SnapshotConfig, SnapshotFileMetadata};
77
use crate::downloader::{DownloadError, SnapshotDownloader};
88
use crate::publisher::SnapshotPublisher;
9-
use acropolis_common::genesis_values::GenesisValues;
10-
use acropolis_common::snapshot::streaming_snapshot::StreamingSnapshotParser;
119
use acropolis_common::{
10+
configuration::StartupMethod,
11+
genesis_values::GenesisValues,
1212
messages::{CardanoMessage, Message},
13+
snapshot::streaming_snapshot::StreamingSnapshotParser,
1314
BlockHash, BlockInfo, BlockStatus, Era,
1415
};
1516
use anyhow::{bail, Result};
@@ -48,6 +49,16 @@ pub struct SnapshotBootstrapper;
4849
impl SnapshotBootstrapper {
4950
/// Initializes the snapshot bootstrapper.
5051
pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> Result<()> {
52+
// Check if this module is the selected startup method
53+
let startup_method = StartupMethod::from_config(&config);
54+
if !startup_method.is_snapshot() {
55+
info!(
56+
"Snapshot bootstrapper not enabled (startup.method = '{}')",
57+
startup_method
58+
);
59+
return Ok(());
60+
}
61+
5162
let cfg = SnapshotConfig::try_load(&config)?;
5263

5364
info!("Snapshot bootstrapper initializing");

processes/omnibus/omnibus.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ============================================================================
44
# Startup Configuration
55
# ============================================================================
6-
[startup]
6+
[global.startup]
77
method = "mithril" # Options: "mithril" | "snapshot"
88
topic = "cardano.sequence.start"
99

processes/omnibus/src/main.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ use tracing_opentelemetry::OpenTelemetryLayer;
4545
use tracing_subscriber::prelude::*;
4646
use tracing_subscriber::{filter, fmt, EnvFilter, Registry};
4747

48-
const STARTUP_METHOD_MITHRIL: &str = "mithril";
49-
const STARTUP_METHOD_SNAPSHOT: &str = "snapshot";
50-
const CONFIG_KEY_STARTUP_METHOD: &str = "startup.method";
51-
5248
#[cfg(not(target_env = "msvc"))]
5349
use tikv_jemallocator::Jemalloc;
5450
#[cfg(not(target_env = "msvc"))]
@@ -102,35 +98,12 @@ pub async fn main() -> Result<()> {
10298
);
10399

104100
// Create the process
105-
let mut process = Process::<Message>::create(config.clone()).await;
106-
107-
// Get startup method from config
108-
let startup_method = config
109-
.get_string(CONFIG_KEY_STARTUP_METHOD)
110-
.unwrap_or_else(|_| STARTUP_METHOD_MITHRIL.to_string());
111-
112-
info!("Using startup method: {}", startup_method);
113-
114-
// Register bootstrap modules based on the startup method
115-
match startup_method.as_str() {
116-
STARTUP_METHOD_MITHRIL => {
117-
info!("Registering MithrilSnapshotFetcher");
118-
MithrilSnapshotFetcher::register(&mut process);
119-
}
120-
STARTUP_METHOD_SNAPSHOT => {
121-
info!("Registering SnapshotBootstrapper");
122-
SnapshotBootstrapper::register(&mut process);
123-
}
124-
_ => {
125-
panic!(
126-
"Invalid startup method: {}. Must be one of: mithril, snapshot",
127-
startup_method
128-
);
129-
}
130-
}
101+
let mut process = Process::<Message>::create(config).await;
131102

132103
// Register modules
133104
GenesisBootstrapper::register(&mut process);
105+
SnapshotBootstrapper::register(&mut process);
106+
MithrilSnapshotFetcher::register(&mut process);
134107
BlockUnpacker::register(&mut process);
135108
PeerNetworkInterface::register(&mut process);
136109
TxUnpacker::register(&mut process);

0 commit comments

Comments
 (0)