Skip to content

Commit 924a3d0

Browse files
authored
Merge pull request #1276 from input-output-hk/ensemble/1185/add-spo-tickers-in-explorer
Add signers ticker automatic import process + `/signers/tickers` route to aggregator http server
2 parents 4ba02f9 + 5f01ab7 commit 924a3d0

File tree

21 files changed

+1280
-108
lines changed

21 files changed

+1280
-108
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
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.107"
3+
version = "0.3.108"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/commands/serve_command.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use anyhow::Context;
22
use clap::Parser;
33
use config::{builder::DefaultState, ConfigBuilder, Map, Source, Value, ValueKind};
44
use mithril_common::StdResult;
5-
use slog_scope::{crit, debug, info};
5+
use slog_scope::{crit, debug, info, warn};
6+
use std::time::Duration;
67
use std::{net::IpAddr, path::PathBuf};
78
use tokio::{sync::oneshot, task::JoinSet};
89

@@ -132,6 +133,36 @@ impl ServeCommand {
132133

133134
Ok(())
134135
});
136+
137+
// Create a SignersImporter only if the `cexplorer_pools_url` is provided in the config.
138+
if let Some(cexplorer_pools_url) = config.cexplorer_pools_url {
139+
match dependencies_builder
140+
.create_signer_importer(&cexplorer_pools_url)
141+
.await
142+
{
143+
Ok(service) => {
144+
join_set.spawn(async move {
145+
// Wait 5s to let the other services the time to start before running
146+
// the first import.
147+
tokio::time::sleep(Duration::from_secs(5)).await;
148+
service
149+
.run_forever(Duration::from_secs(
150+
// Import interval are in minutes
151+
config.signer_importer_run_interval * 60,
152+
))
153+
.await;
154+
Ok(())
155+
});
156+
}
157+
Err(error) => {
158+
warn!(
159+
"Failed to build the `SignersImporter`:\n url to import `{}`\n Error: {:?}",
160+
cexplorer_pools_url, error
161+
);
162+
}
163+
}
164+
}
165+
135166
join_set.spawn(async { tokio::signal::ctrl_c().await.map_err(|e| e.to_string()) });
136167
dependencies_builder.vanish();
137168

mithril-aggregator/src/configuration.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ pub struct Configuration {
121121
/// Specific parameters when [snapshot_compression_algorithm][Self::snapshot_compression_algorithm]
122122
/// is set to [zstandard][CompressionAlgorithm::Zstandard].
123123
pub zstandard_parameters: Option<ZstandardCompressionParameters>,
124+
125+
/// Url to CExplorer list of pools to import as signer in the database.
126+
pub cexplorer_pools_url: Option<String>,
127+
128+
/// Time interval at which the signers in [Self::cexplorer_pools_url] will be imported (in minutes).
129+
pub signer_importer_run_interval: u64,
124130
}
125131

126132
/// Uploader needed to copy the snapshot once computed.
@@ -188,6 +194,8 @@ impl Configuration {
188194
era_reader_adapter_params: None,
189195
snapshot_compression_algorithm: CompressionAlgorithm::Zstandard,
190196
zstandard_parameters: Some(ZstandardCompressionParameters::default()),
197+
cexplorer_pools_url: None,
198+
signer_importer_run_interval: 1,
191199
}
192200
}
193201

@@ -262,6 +270,9 @@ pub struct DefaultConfiguration {
262270

263271
/// Use CDN domain to construct snapshot urls default setting (if snapshot_uploader_type is Gcp)
264272
pub snapshot_use_cdn_domain: String,
273+
274+
/// Signer importer run interval default setting
275+
pub signer_importer_run_interval: u64,
265276
}
266277

267278
impl Default for DefaultConfiguration {
@@ -279,6 +290,7 @@ impl Default for DefaultConfiguration {
279290
disable_digests_cache: "false".to_string(),
280291
snapshot_compression_algorithm: "zstandard".to_string(),
281292
snapshot_use_cdn_domain: "false".to_string(),
293+
signer_importer_run_interval: 720,
282294
}
283295
}
284296
}
@@ -370,6 +382,13 @@ impl Source for DefaultConfiguration {
370382
ValueKind::from(myself.snapshot_use_cdn_domain),
371383
),
372384
);
385+
result.insert(
386+
"signer_importer_run_interval".to_string(),
387+
Value::new(
388+
Some(&namespace),
389+
ValueKind::from(myself.signer_importer_run_interval),
390+
),
391+
);
373392

374393
Ok(result)
375394
}

mithril-aggregator/src/database/migration.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,5 +591,15 @@ update signed_entity
591591
where signed_entity.signed_entity_type_id = 2;
592592
"#,
593593
),
594+
// Migration 19
595+
// Alter `signer` table to add `last_registered_at` field with base value copied from the
596+
// `created_at` field.
597+
SqlMigration::new(
598+
19,
599+
r#"
600+
alter table signer add column last_registered_at text null;
601+
update signer set last_registered_at = created_at;
602+
"#,
603+
),
594604
]
595605
}

0 commit comments

Comments
 (0)