Skip to content

Commit

Permalink
Merge pull request #2149 from input-output-hk/djo/2144/cardano-networ…
Browse files Browse the repository at this point in the history
…k-on-aggregator-status-and-explorer

Cardano network on aggregator status and explorer
  • Loading branch information
Alenar authored Nov 29, 2024
2 parents 379fbd1 + 9e9716c commit 44004bf
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 31 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.2.38"
version = "0.2.39"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ConnectionBuilder {
pub fn build(self) -> StdResult<ConnectionThreadSafe> {
let logger = self.base_logger.new_with_component_name::<Self>();

debug!(logger, "Opening SQLite connection"; "path" => self.connection_path.display());
debug!(logger, "Opening SQLite connection"; "path" => self.connection_path.display(), "options" => ?self.options);
let connection =
Connection::open_thread_safe(&self.connection_path).with_context(|| {
format!(
Expand All @@ -94,14 +94,12 @@ impl ConnectionBuilder {
.options
.contains(&ConnectionOptions::EnableWriteAheadLog)
{
debug!(logger, "Enabling SQLite Write Ahead Log journal mode");
connection
.execute("pragma journal_mode = wal; pragma synchronous = normal;")
.with_context(|| "SQLite initialization: could not enable WAL.")?;
}

if self.options.contains(&ConnectionOptions::EnableForeignKeys) {
debug!(logger, "Enabling SQLite foreign key support");
connection
.execute("pragma foreign_keys=true")
.with_context(|| "SQLite initialization: could not enable FOREIGN KEY support.")?;
Expand All @@ -113,7 +111,6 @@ impl ConnectionBuilder {
.options
.contains(&ConnectionOptions::ForceDisableForeignKeys)
{
debug!(logger, "Force disabling SQLite foreign key support");
connection
.execute("pragma foreign_keys=false")
.with_context(|| "SQLite initialization: could not disable FOREIGN KEY support.")?;
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.5.116"
version = "0.5.117"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
38 changes: 31 additions & 7 deletions mithril-aggregator/src/http_server/routes/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ fn status(
.and(middlewares::extract_config(router_state, |config| {
config.cardano_node_version.clone()
}))
.and(middlewares::extract_config(router_state, |config| {
config.network.to_string()
}))
.and_then(handlers::status)
}

async fn get_aggregator_status_message(
epoch_service: EpochServiceWrapper,
cardano_node_version: String,
cardano_network: String,
) -> StdResult<AggregatorStatusMessage> {
let epoch_service = epoch_service.read().await;

Expand All @@ -49,6 +53,7 @@ async fn get_aggregator_status_message(
let message = AggregatorStatusMessage {
epoch,
cardano_era,
cardano_network,
mithril_era,
cardano_node_version,
aggregator_node_version,
Expand Down Expand Up @@ -81,9 +86,11 @@ mod handlers {
logger: Logger,
epoch_service: EpochServiceWrapper,
cardano_node_version: String,
cardano_network: String,
) -> Result<impl warp::Reply, Infallible> {
let aggregator_status_message =
get_aggregator_status_message(epoch_service, cardano_node_version).await;
get_aggregator_status_message(epoch_service, cardano_node_version, cardano_network)
.await;

match aggregator_status_message {
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
Expand Down Expand Up @@ -211,11 +218,11 @@ mod tests {
..FakeEpochServiceBuilder::dummy(Epoch(3))
}
.build();
let epoch_service = Arc::new(RwLock::new(epoch_service));

let message =
get_aggregator_status_message(Arc::new(RwLock::new(epoch_service)), String::new())
.await
.unwrap();
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
.await
.unwrap();

assert_eq!(
message.protocol_parameters,
Expand All @@ -240,7 +247,7 @@ mod tests {
.build();
let epoch_service = Arc::new(RwLock::new(epoch_service));

let message = get_aggregator_status_message(epoch_service.clone(), String::new())
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
.await
.unwrap();

Expand All @@ -266,11 +273,28 @@ mod tests {
.build();
let epoch_service = Arc::new(RwLock::new(epoch_service));

let message = get_aggregator_status_message(epoch_service.clone(), String::new())
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
.await
.unwrap();

assert_eq!(message.total_stakes_signers, total_stakes_signers);
assert_eq!(message.total_next_stakes_signers, total_next_stakes_signers);
}

#[tokio::test]
async fn retrieves_node_version_and_network_from_parameters() {
let epoch_service = FakeEpochServiceBuilder::dummy(Epoch(3)).build();
let epoch_service = Arc::new(RwLock::new(epoch_service));

let message = get_aggregator_status_message(
epoch_service,
"1.0.4".to_string(),
"network".to_string(),
)
.await
.unwrap();

assert_eq!(message.cardano_node_version, "1.0.4");
assert_eq!(message.cardano_network, "network");
}
}
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.4.90"
version = "0.4.91"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions mithril-common/src/messages/aggregator_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub struct AggregatorStatusMessage {
/// Current Cardano era
pub cardano_era: CardanoEra,

/// Cardano network
pub cardano_network: String,

/// Current Mithril era
pub mithril_era: SupportedEra,

Expand Down Expand Up @@ -57,6 +60,7 @@ mod tests {
const ACTUAL_JSON: &str = r#"{
"epoch": 48,
"cardano_era": "conway",
"cardano_network": "mainnet",
"mithril_era": "pythagoras",
"cardano_node_version": "1.2.3",
"aggregator_node_version": "4.5.6",
Expand All @@ -74,6 +78,7 @@ mod tests {
AggregatorStatusMessage {
epoch: Epoch(48),
cardano_era: "conway".to_string(),
cardano_network: "mainnet".to_string(),
mithril_era: SupportedEra::Pythagoras,
cardano_node_version: "1.2.3".to_string(),
aggregator_node_version: "4.5.6".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions mithril-explorer/package-lock.json

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

2 changes: 1 addition & 1 deletion mithril-explorer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mithril-explorer",
"version": "0.7.19",
"version": "0.7.20",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function InfoGroupCard({ children, title, ...props }) {
);
}

function InfoRow({ label, children, ...props }) {
function InfoRow({ label, children, className, ...props }) {
return (
<>
<div className="d-flex justify-content-between" {...props}>
<div className={`d-flex justify-content-between ${className}`} {...props}>
<div className="me-2 flex-fill">
<em>{label}:</em>
</div>
Expand Down Expand Up @@ -120,10 +120,6 @@ export default function AggregatorStatus({ showContent = true }) {
return ((value / total) * 100).toFixed(0);
}

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

return fallbackToEpochSetting ? (
<Stack direction="horizontal">
<Collapse in={showContent}>
Expand All @@ -138,11 +134,12 @@ export default function AggregatorStatus({ showContent = true }) {
<div id="contentRow">
<Row className="d-flex flex-wrap justify-content-md-center">
<InfoGroupCard title={`Epoch ${aggregatorStatus.epoch}`}>
<InfoRow label="Cardano Network" className="text-capitalize">
{aggregatorStatus.cardano_network}
</InfoRow>
<InfoRow label="Cardano Era">{aggregatorStatus.cardano_era}</InfoRow>
<InfoRow label="Mithril Era">
{aggregatorStatus.mithril_era
? capitalizeFirstLetter(aggregatorStatus.mithril_era)
: ""}
<InfoRow label="Mithril Era" className="text-capitalize">
{aggregatorStatus.mithril_era}
</InfoRow>
</InfoGroupCard>

Expand Down
7 changes: 6 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
# `mithril-common/src/lib.rs` file. If you plan to update it
# here to reflect changes in the API, please also update the constant in the
# Rust file.
version: 0.1.37
version: 0.1.38
title: Mithril Aggregator Server
description: |
The REST API provided by a Mithril Aggregator Node in a Mithril network.
Expand Down Expand Up @@ -667,6 +667,7 @@ components:
required:
- epoch
- cardano_era
- cardano_network
- mithril_era
- cardano_node_version
- aggregator_node_version
Expand All @@ -684,6 +685,9 @@ components:
cardano_era:
description: Cardano era
type: string
cardano_network:
description: Cardano network of the aggregator
type: string
mithril_era:
description: Mithril era
type: string
Expand Down Expand Up @@ -725,6 +729,7 @@ components:
{
"epoch": 329,
"cardano_era": "Conway",
"cardano_network": "mainnet",
"mithril_era": "pythagoras",
"cardano_node_version": "1.2.3",
"aggregator_node_version": "4.5.6",
Expand Down

0 comments on commit 44004bf

Please sign in to comment.