Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ As a minor extension, we have adopted a slightly different versioning convention

- Add pre-built Linux ARM binaries in the distribution for the signer, client CLI, and aggregator.

- Support for Mithril era transition in the client library, CLI and WASM.

- **UNSTABLE** :
- Support for DMQ signature publisher in the signer and signature consumer in the aggregator.

Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions docs/website/adr/004-mithril-network-update-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ sequenceDiagram
Chain->>Old Node: Era change at Epoch XX
Old Node->>User: 💀 unsupported Era, quit.
```

### Client-side era awareness

The Mithril clients do not have access to a Cardano node and therefore can not read the Era Activation Markers stored on chain. As a consequence, they rely on the current era run by the aggregator, by using the era advertised by its `/status` route.
15 changes: 15 additions & 0 deletions docs/website/root/manual/develop/nodes/mithril-client.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/client-wasm-nodejs/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 examples/client-wasm-web/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 internal/mithril-build-script/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-build-script"
version = "0.2.24"
version = "0.2.25"
description = "A toolbox for Mithril crates build scripts"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions internal/mithril-build-script/src/fake_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub type FileContent = String;
/// of the fake aggregator.
#[derive(Debug, Default)]
pub struct FakeAggregatorData {
status: FileContent,

epoch_settings: FileContent,

certificates_list: FileContent,
Expand Down Expand Up @@ -50,6 +52,9 @@ impl FakeAggregatorData {
});

match filename.as_str() {
"status.json" => {
data.status = file_content;
}
"epoch-settings.json" => {
data.epoch_settings = file_content;
}
Expand Down Expand Up @@ -155,6 +160,7 @@ impl FakeAggregatorData {
pub fn generate_code_for_all_data(self) -> String {
Self::assemble_code(
&[
generate_list_getter("status", self.status),
generate_list_getter("epoch_settings", self.epoch_settings),
generate_ids_array(
"snapshot_digests",
Expand Down
2 changes: 1 addition & 1 deletion mithril-client-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client-cli"
version = "0.12.20"
version = "0.12.21"
description = "A Mithril Client"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
28 changes: 19 additions & 9 deletions mithril-client-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ pub mod tools;

pub use deprecation::{DeprecatedCommand, Deprecation};

use std::sync::Arc;

use mithril_client::{ClientBuilder, MithrilResult};

use crate::configuration::ConfigParameters;
use crate::{configuration::ConfigParameters, utils::ForcedEraFetcher};

const CLIENT_TYPE_CLI: &str = "CLI";

pub(crate) fn client_builder(params: &ConfigParameters) -> MithrilResult<ClientBuilder> {
let builder = ClientBuilder::aggregator(
&params.require("aggregator_endpoint")?,
&params.require("genesis_verification_key")?,
)
.with_origin_tag(params.get("origin_tag"))
.with_client_type(Some(CLIENT_TYPE_CLI.to_string()));
);

Ok(builder)
Ok(finalize_builder_config(builder, params))
}

pub(crate) fn client_builder_with_fallback_genesis_key(
Expand All @@ -44,9 +44,19 @@ pub(crate) fn client_builder_with_fallback_genesis_key(
"genesis_verification_key",
fallback_genesis_verification_key,
),
)
.with_origin_tag(params.get("origin_tag"))
.with_client_type(Some(CLIENT_TYPE_CLI.to_string()));
);

Ok(finalize_builder_config(builder, params))
}

fn finalize_builder_config(mut builder: ClientBuilder, params: &ConfigParameters) -> ClientBuilder {
builder = builder
.with_origin_tag(params.get("origin_tag"))
.with_client_type(Some(CLIENT_TYPE_CLI.to_string()));

if let Some(era) = params.get("era") {
builder = builder.with_era_fetcher(Arc::new(ForcedEraFetcher::new(era.to_string())));
}

Ok(builder)
builder
}
6 changes: 6 additions & 0 deletions mithril-client-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ pub struct Args {
/// Request origin tag
#[clap(long, global = true)]
origin_tag: Option<String>,

/// Override the Mithril era
#[clap(long, global = true)]
#[example = "`pythagoras`"]
era: Option<String>,
}

impl Args {
Expand Down Expand Up @@ -208,6 +213,7 @@ impl Source for Args {
let myself = self.clone();
register_config_value_option!(map, &namespace, myself.aggregator_endpoint);
register_config_value_option!(map, &namespace, myself.origin_tag);
register_config_value_option!(map, &namespace, myself.era);

Ok(map)
}
Expand Down
44 changes: 44 additions & 0 deletions mithril-client-cli/src/utils/forced_era_fetcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use async_trait::async_trait;

use mithril_client::{
MithrilResult,
era::{EraFetcher, FetchedEra},
};

pub struct ForcedEraFetcher {
era: String,
}

impl ForcedEraFetcher {
pub fn new(era: String) -> Self {
Self { era }
}
}

#[async_trait]
impl EraFetcher for ForcedEraFetcher {
async fn fetch_current_era(&self) -> MithrilResult<FetchedEra> {
Ok(FetchedEra {
era: self.era.clone(),
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn fetch_current_era_returns_fetched_era_with_forced_era_value() {
let era_fetcher = ForcedEraFetcher::new("forced_era".to_string());

let fetched_era = era_fetcher.fetch_current_era().await.unwrap();

assert_eq!(
FetchedEra {
era: "forced_era".to_string(),
},
fetched_era
);
}
}
2 changes: 2 additions & 0 deletions mithril-client-cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod cardano_db;
mod cardano_db_download_checker;
mod expander;
mod feedback_receiver;
mod forced_era_fetcher;
mod fs;
mod github_release_retriever;
mod http_downloader;
Expand All @@ -17,6 +18,7 @@ pub use cardano_db::*;
pub use cardano_db_download_checker::*;
pub use expander::*;
pub use feedback_receiver::*;
pub use forced_era_fetcher::*;
pub use fs::*;
pub use github_release_retriever::*;
pub use http_downloader::*;
Expand Down
2 changes: 1 addition & 1 deletion mithril-client-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client-wasm"
version = "0.9.3"
version = "0.9.4"
description = "Mithril client WASM"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion mithril-client-wasm/ci-test/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-client-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mithril-dev/mithril-client-wasm",
"version": "0.9.3",
"version": "0.9.4",
"description": "Mithril client WASM",
"license": "Apache-2.0",
"collaborators": [
Expand Down
29 changes: 28 additions & 1 deletion mithril-client-wasm/src/client_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ impl MithrilClient {

Ok(serde_wasm_bindgen::to_value(&result)?)
}

/// Call the client to fetch the current Mithril era
#[wasm_bindgen]
pub async fn fetch_current_mithril_era(&self) -> WasmResult {
let result = self
.client
.mithril_era_client()
.fetch_current()
.await
.map_err(|err| format!("{err:?}"))?;

Ok(serde_wasm_bindgen::to_value(&result)?)
}
}

// Unstable functions are only available when the unstable flag is set
Expand Down Expand Up @@ -506,7 +519,7 @@ mod tests {
CardanoDatabaseSnapshot, CardanoDatabaseSnapshotListItem, CardanoStakeDistribution,
CardanoStakeDistributionListItem, CardanoTransactionSnapshot, MithrilCertificateListItem,
MithrilStakeDistribution, MithrilStakeDistributionListItem, Snapshot, SnapshotListItem,
common::ProtocolMessage,
common::ProtocolMessage, common::SupportedEra, era::FetchedEra,
};

use crate::test_data;
Expand Down Expand Up @@ -960,4 +973,18 @@ mod tests {
.await
.expect_err("get_cardano_database_v2 should fail");
}

#[wasm_bindgen_test]
async fn fetch_current_mithril_era_should_return_value_convertible_to_supported_era() {
let fetched_era_js_value = get_mithril_client_stable()
.fetch_current_mithril_era()
.await
.expect("fetch_current_mithril_era should not fail");
let fetched_era = serde_wasm_bindgen::from_value::<FetchedEra>(fetched_era_js_value)
.expect("conversion should not fail");

let era = fetched_era.to_supported_era().expect("conversion should not fail");

assert_eq!(era, SupportedEra::Pythagoras);
}
}
2 changes: 1 addition & 1 deletion mithril-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client"
version = "0.12.20"
version = "0.12.21"
description = "Mithril client library"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions mithril-client/src/aggregator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ pub enum AggregatorRequest {

/// Lists the aggregator [Cardano stake distribution][crate::CardanoStakeDistribution]
ListCardanoStakeDistributions,

/// Get information about the aggregator status
Status,
}

impl AggregatorRequest {
Expand Down Expand Up @@ -197,6 +200,7 @@ impl AggregatorRequest {
AggregatorRequest::ListCardanoStakeDistributions => {
"artifact/cardano-stake-distributions".to_string()
}
AggregatorRequest::Status => "status".to_string(),
}
}

Expand Down Expand Up @@ -668,6 +672,8 @@ mod tests {
"artifact/cardano-stake-distributions".to_string(),
AggregatorRequest::ListCardanoStakeDistributions.route()
);

assert_eq!("status".to_string(), AggregatorRequest::Status.route());
}

#[test]
Expand Down
Loading
Loading