Skip to content

Commit 93d84ec

Browse files
authored
Merge pull request #1236 from input-output-hk/damien/798/implement-anyhow-context-for-aggregator-configuration
Implement anyhow context for aggregator configuration
2 parents b6eccdb + 494efdf commit 93d84ec

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.3.91"
3+
version = "0.3.92"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/configuration.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
use anyhow::anyhow;
12
use config::{ConfigError, Map, Source, Value, ValueKind};
23
use mithril_common::crypto_helper::ProtocolGenesisSigner;
34
use mithril_common::era::adapters::EraReaderAdapterType;
45
use serde::{Deserialize, Serialize};
56
use std::path::PathBuf;
67
use std::str::FromStr;
7-
use std::sync::Arc;
88

99
use mithril_common::entities::{
1010
CompressionAlgorithm, HexEncodedGenesisVerificationKey, ProtocolParameters,
1111
};
1212
use mithril_common::{CardanoNetwork, StdResult};
1313

14-
use crate::tools::GcpFileUploader;
15-
use crate::{LocalSnapshotUploader, RemoteSnapshotUploader, SnapshotUploader};
16-
1714
/// Different kinds of execution environments
1815
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
1916
pub enum ExecutionEnvironment {
@@ -199,30 +196,10 @@ impl Configuration {
199196
format!("http://{}:{}/", self.server_ip, self.server_port)
200197
}
201198

202-
/// Create a snapshot uploader from configuration settings.
203-
pub fn build_snapshot_uploader(&self) -> StdResult<Arc<dyn SnapshotUploader>> {
204-
match self.snapshot_uploader_type {
205-
SnapshotUploaderType::Gcp => {
206-
let bucket = self.snapshot_bucket_name.to_owned().ok_or_else(|| {
207-
ConfigError::Message("missing snapshot bucket name".to_string())
208-
})?;
209-
Ok(Arc::new(RemoteSnapshotUploader::new(
210-
Box::new(GcpFileUploader::new(bucket.clone())),
211-
bucket,
212-
self.snapshot_use_cdn_domain,
213-
)))
214-
}
215-
SnapshotUploaderType::Local => Ok(Arc::new(LocalSnapshotUploader::new(
216-
self.get_server_url(),
217-
&self.snapshot_directory,
218-
))),
219-
}
220-
}
221-
222199
/// Check configuration and return a representation of the Cardano network.
223-
pub fn get_network(&self) -> Result<CardanoNetwork, ConfigError> {
200+
pub fn get_network(&self) -> StdResult<CardanoNetwork> {
224201
CardanoNetwork::from_code(self.network.clone(), self.network_magic)
225-
.map_err(|e| ConfigError::Message(e.to_string()))
202+
.map_err(|e| anyhow!(ConfigError::Message(e.to_string())))
226203
}
227204

228205
/// Return the file of the SQLite stores. If the directory does not exist, it is created.

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ impl DependenciesBuilder {
469469
let cli_runner = CardanoCliRunner::new(
470470
self.configuration.cardano_cli_path.clone(),
471471
self.configuration.cardano_node_socket_path.clone(),
472-
self.configuration.get_network()?,
472+
self.configuration.get_network().with_context(|| {
473+
"Dependencies Builder can not get Cardano network while building cardano cli runner"
474+
})?,
473475
);
474476

475477
Ok(Box::new(cli_runner))
@@ -488,7 +490,9 @@ impl DependenciesBuilder {
488490
let beacon_provider = BeaconProviderImpl::new(
489491
self.get_chain_observer().await?,
490492
self.get_immutable_file_observer().await?,
491-
self.configuration.get_network()?,
493+
self.configuration.get_network().with_context(|| {
494+
"Dependencies Builder can not get Cardano network while building beacon provider"
495+
})?,
492496
);
493497

494498
Ok(Arc::new(beacon_provider))
@@ -1045,7 +1049,9 @@ impl DependenciesBuilder {
10451049

10461050
let config = AggregatorConfig::new(
10471051
self.configuration.run_interval,
1048-
self.configuration.get_network()?,
1052+
self.configuration.get_network().with_context(|| {
1053+
"Dependencies Builder can not get Cardano network while creating aggregator runner"
1054+
})?,
10491055
&self.configuration.db_directory.clone(),
10501056
);
10511057
let runtime = AggregatorRuntime::new(
@@ -1087,7 +1093,9 @@ impl DependenciesBuilder {
10871093

10881094
/// Create [TickerService] instance.
10891095
pub async fn build_ticker_service(&mut self) -> Result<Arc<dyn TickerService>> {
1090-
let network = self.configuration.get_network()?;
1096+
let network = self.configuration.get_network().with_context(|| {
1097+
"Dependencies Builder can not get Cardano network while building ticker service"
1098+
})?;
10911099
let chain_observer = self.get_chain_observer().await?;
10921100
let immutable_observer = self.get_immutable_file_observer().await?;
10931101

0 commit comments

Comments
 (0)