Skip to content

Commit b352101

Browse files
authored
Merge pull request #570 from input-output-hk/jpraynaud/542-configurable-gcp-bucket
Configurable Aggregator snapshot bucket
2 parents fec5db3 + 873f947 commit b352101

File tree

11 files changed

+27
-41
lines changed

11 files changed

+27
-41
lines changed

docs/root/manual/developer-docs/nodes/mithril-aggregator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ General parameters:
299299
| `snapshot_directory` | `--snapshot-directory` | - | `SNAPSHOT_DIRECTORY` | Directory to store local snapshots of the **Cardano Node** | `.` | - | :heavy_check_mark: |
300300
| `snapshot_store_type` | - | - | `SNAPSHOT_STORE_TYPE` | Type of snapshot store to use | - | `gcp` or `local` | :heavy_check_mark: |
301301
| `snapshot_uploader_type` | - | - | `SNAPSHOT_UPLOADER_TYPE` | Type of snapshot uploader to use | - | `gcp` or `local` | :heavy_check_mark: |
302+
| `snapshot_bucket_name` | - | - | `SNAPSHOT_BUCKET_NAME` | Name of the bucket where the snapshots are stored | - | `snapshot-bucket` | :heavy_check_mark: | Required if `snapshot_uploader_type` is `gcp`
302303
| `run_interval` | - | - | `RUN_INTERVAL` | Interval between two runtime cycles in ms | - | `60000` | :heavy_check_mark: |
303304
| `url_snapshot_manifest` | - | - | `URL_SNAPSHOT_MANIFEST` | Snapshots manifest location | - | Only if `snapshot_store_type` is `gcp`, else it should be `` | :heavy_check_mark: |
304305

mithril-aggregator/config/preview.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-preview/snapshots.json",
1212
"snapshot_store_type": "local",
1313
"snapshot_uploader_type": "gcp",
14+
"snapshot_bucket_name": "cardano-testnet",
1415
"stores_directory": "./mithril-aggregator/stores",
1516
"genesis_verification_key": "5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d",
1617
"limit_keys_in_stores": 5
17-
}
18+
}

mithril-aggregator/config/testnet.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

mithril-aggregator/src/command_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl ServeCommand {
297297
debug!("SERVE command"; "config" => format!("{:?}", config));
298298
// Init dependencies
299299
let snapshot_store = config.build_snapshot_store()?;
300-
let snapshot_uploader = config.build_snapshot_uploader();
300+
let snapshot_uploader = config.build_snapshot_uploader()?;
301301

302302
let sqlite_db_path = Some(config.get_sqlite_file());
303303

mithril-aggregator/src/configuration.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct Configuration {
4949
/// Type of snapshot uploader to use
5050
pub snapshot_uploader_type: SnapshotUploaderType,
5151

52+
/// Bucket name where the snapshots are stored if snapshot_uploader_type is Gcp
53+
pub snapshot_bucket_name: Option<String>,
54+
5255
/// Server listening IP
5356
pub server_ip: String,
5457

@@ -109,7 +112,11 @@ impl Configuration {
109112
pub fn build_snapshot_store(&self) -> Result<Arc<dyn SnapshotStore>, Box<dyn Error>> {
110113
match self.snapshot_store_type {
111114
SnapshotStoreType::Gcp => Ok(Arc::new(RemoteSnapshotStore::new(
112-
Box::new(GcpFileUploader::default()),
115+
Box::new(GcpFileUploader::new(
116+
self.snapshot_bucket_name.to_owned().ok_or_else(|| {
117+
ConfigError::Message("missing snapshot bucket name".to_string())
118+
})?,
119+
)),
113120
self.url_snapshot_manifest.clone(),
114121
))),
115122
SnapshotStoreType::Local => Ok(Arc::new(LocalSnapshotStore::new(
@@ -123,15 +130,17 @@ impl Configuration {
123130
}
124131

125132
/// Create a snapshot uploader from configuration settings.
126-
pub fn build_snapshot_uploader(&self) -> Arc<dyn SnapshotUploader> {
133+
pub fn build_snapshot_uploader(&self) -> Result<Arc<dyn SnapshotUploader>, Box<dyn Error>> {
127134
match self.snapshot_uploader_type {
128-
SnapshotUploaderType::Gcp => Arc::new(RemoteSnapshotUploader::new(Box::new(
129-
GcpFileUploader::default(),
130-
))),
131-
SnapshotUploaderType::Local => Arc::new(LocalSnapshotUploader::new(
135+
SnapshotUploaderType::Gcp => Ok(Arc::new(RemoteSnapshotUploader::new(Box::new(
136+
GcpFileUploader::new(self.snapshot_bucket_name.to_owned().ok_or_else(|| {
137+
ConfigError::Message("missing snapshot bucket name".to_string())
138+
})?),
139+
)))),
140+
SnapshotUploaderType::Local => Ok(Arc::new(LocalSnapshotUploader::new(
132141
self.get_server_url(),
133142
&self.snapshot_directory,
134-
)),
143+
))),
135144
}
136145
}
137146

mithril-aggregator/src/dependency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub mod tests {
193193
.to_string(),
194194
snapshot_store_type: SnapshotStoreType::Local,
195195
snapshot_uploader_type: SnapshotUploaderType::Local,
196+
snapshot_bucket_name: None,
196197
server_ip: "0.0.0.0".to_string(),
197198
server_port: 8000,
198199
run_interval: 5000,

mithril-aggregator/src/tools/remote_file_uploader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ pub struct GcpFileUploader {
2525
bucket: String,
2626
}
2727

28-
impl Default for GcpFileUploader {
29-
fn default() -> Self {
30-
Self {
31-
bucket: "cardano-testnet".to_string(),
32-
}
28+
impl GcpFileUploader {
29+
/// GcpFileUploader factory
30+
pub fn new(bucket: String) -> Self {
31+
Self { bucket }
3332
}
3433
}
3534

mithril-aggregator/tests/test_extensions/dependency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub async fn initialize_dependencies(
3737
.to_string(),
3838
snapshot_store_type: SnapshotStoreType::Local,
3939
snapshot_uploader_type: SnapshotUploaderType::Local,
40+
snapshot_bucket_name: None,
4041
server_ip: "0.0.0.0".to_string(),
4142
server_port: 8000,
4243
run_interval: 5000,

mithril-client/config/testnet.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

mithril-infra/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ services:
6565
- URL_SNAPSHOT_MANIFEST=https://storage.googleapis.com/cardano-${NETWORK}/snapshots.json
6666
- SNAPSHOT_STORE_TYPE=local
6767
- SNAPSHOT_UPLOADER_TYPE=gcp
68+
- SNAPSHOT_BUCKET_NAME=cardano-testnet
6869
- DATA_STORES_DIRECTORY=/mithril-aggregator
6970
- STORE_RETENTION_LIMIT=5
7071
- CARDANO_NODE_SOCKET_PATH=/ipc/node.socket

0 commit comments

Comments
 (0)