From 0d417f3aef27fa07514bf269479fbff7f18b6a1a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 3 Sep 2024 18:07:49 +0200 Subject: [PATCH 1/9] feat: add 'unstable' option for WASM client in 'ClientOptions' This new feature will allow the usage of 'unstable' features by the WASM client. --- mithril-client/src/client.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mithril-client/src/client.rs b/mithril-client/src/client.rs index 2f4ffd3ffe3..25ee3e3f113 100644 --- a/mithril-client/src/client.rs +++ b/mithril-client/src/client.rs @@ -27,12 +27,27 @@ use crate::MithrilResult; pub struct ClientOptions { /// HTTP headers to include in the client requests. pub http_headers: Option>, + + /// Whether to enable unstable features in the WASM client. + #[cfg(target_family = "wasm")] + #[cfg_attr(target_family = "wasm", serde(default))] + pub unstable: bool, } impl ClientOptions { /// Instantiate a new [ClientOptions]. pub fn new(http_headers: Option>) -> Self { - Self { http_headers } + Self { + http_headers, + #[cfg(target_family = "wasm")] + unstable: false, + } + } + + /// Enable unstable features in the WASM client. + #[cfg(target_family = "wasm")] + pub fn with_unstable_features(self, unstable: bool) -> Self { + Self { unstable, ..self } } } From d8615b392fccda75ff00252546c1f7a380b77566 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 3 Sep 2024 18:11:35 +0200 Subject: [PATCH 2/9] refactor: refactor unstable feature implementation in WASM client The 'MithrilUnstableClient' has been removed and replaced by the usage of an 'unstable' field in the client options. --- mithril-client-wasm/src/client_wasm.rs | 128 +++++++++++++++---------- 1 file changed, 77 insertions(+), 51 deletions(-) diff --git a/mithril-client-wasm/src/client_wasm.rs b/mithril-client-wasm/src/client_wasm.rs index fd8e03d29b0..7fd6546614f 100644 --- a/mithril-client-wasm/src/client_wasm.rs +++ b/mithril-client-wasm/src/client_wasm.rs @@ -58,14 +58,8 @@ impl From for MithrilEventWasm { pub struct MithrilClient { client: Client, - /// Unstable functions - pub unstable: MithrilUnstableClient, -} - -#[wasm_bindgen] -#[derive(Clone)] -pub struct MithrilUnstableClient { - client: Client, + /// Allow usage of unstable functions + unstable: bool, } #[wasm_bindgen] @@ -86,14 +80,14 @@ impl MithrilClient { .map_err(|err| format!("Failed to parse options: {err:?}")) .unwrap() }; - + let unstable = client_options.unstable; let client = ClientBuilder::aggregator(aggregator_endpoint, genesis_verification_key) .add_feedback_receiver(feedback_receiver) .with_options(client_options) .build() .map_err(|err| format!("{err:?}")) .unwrap(); - let unstable = MithrilUnstableClient::new(client.clone()); + MithrilClient { client, unstable } } @@ -227,18 +221,24 @@ impl MithrilClient { } } +// Unstable functions are only available when the unstable flag is set #[wasm_bindgen] -impl MithrilUnstableClient { - /// Constructor for unstable wasm client - fn new(inner_client: Client) -> MithrilUnstableClient { - Self { - client: inner_client, +impl MithrilClient { + fn guard_unstable(&self) -> Result<(), wasm_bindgen::JsValue> { + if !self.unstable { + return Err(JsValue::from_str("Unstable functions are not enabled. Set the 'unstable' client option field to 'true' to enable them.")); } + + Ok(()) } /// Call the client for the list of available Cardano transactions snapshots + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn list_cardano_transactions_snapshots(&self) -> WasmResult { + self.guard_unstable()?; + let result = self .client .cardano_transaction() @@ -250,8 +250,12 @@ impl MithrilUnstableClient { } /// Call the client to get a Cardano transactions snapshot from a hash + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn get_cardano_transactions_snapshot(&self, hash: &str) -> WasmResult { + self.guard_unstable()?; + let result = self .client .cardano_transaction() @@ -266,11 +270,15 @@ impl MithrilUnstableClient { } /// Call the client to get a Cardano transactions proofs + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn get_cardano_transaction_proofs( &self, ctx_hashes: Box<[JsValue]>, ) -> Result { + self.guard_unstable()?; + let hashes = ctx_hashes .iter() .map(|h| { @@ -292,12 +300,16 @@ impl MithrilUnstableClient { } /// Call the client to verify a cardano transaction proof and compute a message + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn verify_cardano_transaction_proof_then_compute_message( &self, cardano_transaction_proof: &CardanoTransactionsProofs, certificate: JsValue, ) -> WasmResult { + self.guard_unstable()?; + let certificate: MithrilCertificate = serde_wasm_bindgen::from_value(certificate).map_err(|err| format!("{err:?}"))?; let verified_proof = cardano_transaction_proof @@ -310,8 +322,12 @@ impl MithrilUnstableClient { } /// Call the client to get a cardano stake distribution from a hash + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn get_cardano_stake_distribution(&self, hash: &str) -> WasmResult { + self.guard_unstable()?; + let result = self .client .cardano_stake_distribution() @@ -327,8 +343,12 @@ impl MithrilUnstableClient { /// Call the client to get a cardano stake distribution from an epoch /// The epoch represents the epoch at the end of which the Cardano stake distribution is computed by the Cardano node + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn get_cardano_stake_distribution_by_epoch(&self, epoch: u64) -> WasmResult { + self.guard_unstable()?; + let result = self .client .cardano_stake_distribution() @@ -343,8 +363,12 @@ impl MithrilUnstableClient { } /// Call the client for the list of available cardano stake distributions + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn list_cardano_stake_distributions(&self) -> WasmResult { + self.guard_unstable()?; + let result = self .client .cardano_stake_distribution() @@ -356,12 +380,16 @@ impl MithrilUnstableClient { } /// Call the client to compute a cardano stake distribution message + /// + /// Warning: this function is unstable and may be modified in the future #[wasm_bindgen] pub async fn compute_cardano_stake_distribution_message( &self, certificate: JsValue, cardano_stake_distribution: JsValue, ) -> WasmResult { + self.guard_unstable()?; + let certificate = serde_wasm_bindgen::from_value(certificate).map_err(|err| format!("{err:?}"))?; let cardano_stake_distribution = serde_wasm_bindgen::from_value(cardano_stake_distribution) @@ -393,17 +421,27 @@ mod tests { const FAKE_AGGREGATOR_IP: &str = "127.0.0.1"; const FAKE_AGGREGATOR_PORT: &str = "8000"; - fn get_mithril_client() -> MithrilClient { + fn get_mithril_client(unstable: bool) -> MithrilClient { + let options = ClientOptions::new(None).with_unstable_features(unstable); + let options_js_value = serde_wasm_bindgen::to_value(&options).unwrap(); MithrilClient::new( &format!( "http://{}:{}/aggregator", FAKE_AGGREGATOR_IP, FAKE_AGGREGATOR_PORT ), GENESIS_VERIFICATION_KEY, - JsValue::undefined(), + options_js_value, ) } + fn get_mithril_client_stable() -> MithrilClient { + get_mithril_client(false) + } + + fn get_mithril_client_unstable() -> MithrilClient { + get_mithril_client(true) + } + wasm_bindgen_test_configure!(run_in_browser); #[wasm_bindgen_test] @@ -451,7 +489,7 @@ mod tests { #[wasm_bindgen_test] async fn list_snapshots_should_return_value_convertible_in_rust_type() { - let snapshots_list_js_value = get_mithril_client() + let snapshots_list_js_value = get_mithril_client_stable() .list_snapshots() .await .expect("list_snapshots should not fail"); @@ -468,7 +506,7 @@ mod tests { #[wasm_bindgen_test] async fn get_snapshot_should_return_value_convertible_in_rust_type() { - let snapshot_js_value = get_mithril_client() + let snapshot_js_value = get_mithril_client_stable() .get_snapshot(test_data::snapshot_digests()[0]) .await .expect("get_snapshot should not fail"); @@ -480,7 +518,7 @@ mod tests { #[wasm_bindgen_test] async fn get_snapshot_should_fail_with_unknown_digest() { - get_mithril_client() + get_mithril_client_stable() .get_snapshot("whatever") .await .expect_err("get_snapshot should fail"); @@ -488,7 +526,7 @@ mod tests { #[wasm_bindgen_test] async fn list_mithril_stake_distributions_should_return_value_convertible_in_rust_type() { - let msd_list_js_value = get_mithril_client() + let msd_list_js_value = get_mithril_client_stable() .list_mithril_stake_distributions() .await .expect("list_mithril_stake_distributions should not fail"); @@ -506,7 +544,7 @@ mod tests { #[wasm_bindgen_test] async fn get_mithril_stake_distribution_should_return_value_convertible_in_rust_type() { - let msd_js_value = get_mithril_client() + let msd_js_value = get_mithril_client_stable() .get_mithril_stake_distribution(test_data::msd_hashes()[0]) .await .expect("get_mithril_stake_distribution should not fail"); @@ -518,7 +556,7 @@ mod tests { #[wasm_bindgen_test] async fn get_mithril_stake_distribution_should_fail_with_unknown_hash() { - get_mithril_client() + get_mithril_client_stable() .get_mithril_stake_distribution("whatever") .await .expect_err("get_mithril_stake_distribution should fail"); @@ -526,7 +564,7 @@ mod tests { #[wasm_bindgen_test] async fn list_mithril_certificates_should_return_value_convertible_in_rust_type() { - let certificates_list_js_value = get_mithril_client() + let certificates_list_js_value = get_mithril_client_stable() .list_mithril_certificates() .await .expect("list_mithril_certificates should not fail"); @@ -544,7 +582,7 @@ mod tests { #[wasm_bindgen_test] async fn get_mithril_certificate_should_return_value_convertible_in_rust_type() { - let certificate_js_value = get_mithril_client() + let certificate_js_value = get_mithril_client_stable() .get_mithril_certificate(test_data::certificate_hashes()[0]) .await .expect("get_mithril_certificate should not fail"); @@ -557,7 +595,7 @@ mod tests { #[wasm_bindgen_test] async fn get_mithril_certificate_should_fail_with_unknown_hash() { - get_mithril_client() + get_mithril_client_stable() .get_mithril_certificate("whatever") .await .expect_err("get_mithril_certificate should fail"); @@ -566,7 +604,7 @@ mod tests { #[wasm_bindgen_test] async fn compute_mithril_stake_distribution_message_should_return_value_convertible_in_rust_type( ) { - let client = get_mithril_client(); + let client = get_mithril_client_stable(); let msd_js_value = client .get_mithril_stake_distribution(test_data::msd_hashes()[0]) .await @@ -582,7 +620,7 @@ mod tests { #[wasm_bindgen_test] async fn verify_certificate_chain_should_return_value_convertible_in_rust_type() { - let client = get_mithril_client(); + let client = get_mithril_client_stable(); let msd_js_value = client .get_mithril_stake_distribution(test_data::msd_hashes()[0]) .await @@ -599,7 +637,7 @@ mod tests { #[wasm_bindgen_test] async fn verify_message_match_certificate_should_return_true() { - let client = get_mithril_client(); + let client = get_mithril_client_stable(); let msd_js_value = client .get_mithril_stake_distribution(test_data::msd_hashes()[0]) .await @@ -623,8 +661,7 @@ mod tests { #[wasm_bindgen_test] async fn list_cardano_transactions_snapshots_should_return_value_convertible_in_rust_type() { - let cardano_tx_sets_js_value = get_mithril_client() - .unstable + let cardano_tx_sets_js_value = get_mithril_client_unstable() .list_cardano_transactions_snapshots() .await .expect("list_cardano_transactions_snapshots should not fail"); @@ -642,8 +679,7 @@ mod tests { #[wasm_bindgen_test] async fn get_cardano_transactions_snapshot_should_return_value_convertible_in_rust_type() { - let cardano_tx_set_js_value = get_mithril_client() - .unstable + let cardano_tx_set_js_value = get_mithril_client_unstable() .get_cardano_transactions_snapshot(test_data::ctx_snapshot_hashes()[0]) .await .expect("get_cardano_transactions_snapshot should not fail"); @@ -656,8 +692,7 @@ mod tests { #[wasm_bindgen_test] async fn get_cardano_transactions_snapshot_should_fail_with_unknown_digest() { - get_mithril_client() - .unstable + get_mithril_client_unstable() .get_cardano_transactions_snapshot("whatever") .await .expect_err("get_cardano_transactions_snapshot should fail"); @@ -667,10 +702,9 @@ mod tests { async fn get_cardano_transaction_proofs_should_return_value_convertible_in_rust_type() { let tx_hash = test_data::proof_transaction_hashes()[0]; let ctx_hashes = Box::new([JsValue::from(tx_hash)]); - let client = get_mithril_client(); + let client = get_mithril_client_unstable(); let tx_proof = client - .unstable .get_cardano_transaction_proofs(ctx_hashes) .await .expect("get_verified_cardano_transaction_proofs should not fail"); @@ -680,7 +714,6 @@ mod tests { .unwrap(); client - .unstable .verify_cardano_transaction_proof_then_compute_message(&tx_proof, certificate) .await .expect("Compute tx proof message for matching cert failed"); @@ -688,8 +721,7 @@ mod tests { #[wasm_bindgen_test] async fn list_cardano_stake_distributions_should_return_value_convertible_in_rust_type() { - let csd_list_js_value = get_mithril_client() - .unstable + let csd_list_js_value = get_mithril_client_unstable() .list_cardano_stake_distributions() .await .expect("cardano_mithril_stake_distributions should not fail"); @@ -707,8 +739,7 @@ mod tests { #[wasm_bindgen_test] async fn get_cardano_stake_distribution_should_return_value_convertible_in_rust_type() { - let csd_js_value = get_mithril_client() - .unstable + let csd_js_value = get_mithril_client_unstable() .get_cardano_stake_distribution(test_data::csd_hashes()[0]) .await .expect("get_cardano_stake_distribution should not fail"); @@ -720,8 +751,7 @@ mod tests { #[wasm_bindgen_test] async fn get_cardano_stake_distribution_should_fail_with_unknown_hash() { - get_mithril_client() - .unstable + get_mithril_client_unstable() .get_cardano_stake_distribution("whatever") .await .expect_err("get_cardano_stake_distribution should fail"); @@ -731,8 +761,7 @@ mod tests { async fn get_cardano_stake_distribution_by_epoch_should_return_value_convertible_in_rust_type() { let epoch: u64 = test_data::csd_epochs()[0].parse().unwrap(); - let csd_js_value = get_mithril_client() - .unstable + let csd_js_value = get_mithril_client_unstable() .get_cardano_stake_distribution_by_epoch(epoch) .await .expect("get_cardano_stake_distribution_by_epoch should not fail"); @@ -745,8 +774,7 @@ mod tests { #[wasm_bindgen_test] async fn get_cardano_stake_distribution_by_epoch_should_fail_with_unknown_epoch() { - get_mithril_client() - .unstable + get_mithril_client_unstable() .get_cardano_stake_distribution_by_epoch(u64::MAX) .await .expect_err("get_cardano_stake_distribution_by_epoch should fail"); @@ -755,9 +783,8 @@ mod tests { #[wasm_bindgen_test] async fn compute_cardano_stake_distribution_message_should_return_value_convertible_in_rust_type( ) { - let client = get_mithril_client(); + let client = get_mithril_client_unstable(); let csd_js_value = client - .unstable .get_cardano_stake_distribution(test_data::csd_hashes()[0]) .await .unwrap(); @@ -769,7 +796,6 @@ mod tests { .unwrap(); let message_js_value = client - .unstable .compute_cardano_stake_distribution_message(certificate_js_value, csd_js_value) .await .expect("compute_cardano_stake_distribution_message should not fail"); From ccb0b10fed89f156a692729d53b73a413604698f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 3 Sep 2024 18:12:28 +0200 Subject: [PATCH 3/9] refactor: adapt the WASM client example to work with new unstable implementation --- mithril-client-wasm/www/index.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/mithril-client-wasm/www/index.js b/mithril-client-wasm/www/index.js index 22900c13ff1..3583a75d317 100644 --- a/mithril-client-wasm/www/index.js +++ b/mithril-client-wasm/www/index.js @@ -64,21 +64,16 @@ function format_tx_list(transactions_hashes) { return "
    " + transactions_hashes.map((tx) => "
  • " + tx + "
  • ").join("") + "
"; } -function client_options_with_custom_headers() { - // The following header is set as an example. - // It's used to demonstrate how to add headers. - let http_headers_map = new Map(); - http_headers_map.set("Content-Type", "application/json"); - - return { - http_headers: http_headers_map, - }; -} - await initMithrilClient(); -let client_options = client_options_with_custom_headers(); -let client = new MithrilClient(aggregator_endpoint, genesis_verification_key, client_options); +let client = new MithrilClient(aggregator_endpoint, genesis_verification_key, { + // The following header is set as an example. + // It's used to demonstrate how to add headers. + http_headers: new Map([["Content-Type", "application/json"]]), + // The following option activates the unstable features of the client. + // Unstable features will trigger an error if this option is not set. + unstable: true, +}); displayStepInDOM(1, "Getting stake distributions list..."); let mithril_stake_distributions_list = await client.list_mithril_stake_distributions(); @@ -135,7 +130,7 @@ displayMessageInDOM("Result", "Mithril stake distribution message validated  console.log("valid_stake_distribution_message:", valid_stake_distribution_message); displayStepInDOM(7, "Getting transaction proof..."); -const proof = await client.unstable.get_cardano_transaction_proofs([ +const proof = await client.get_cardano_transaction_proofs([ "eac09f970f47ef3ab378db9232914e146773853397e79b904f1a45123a23c21f", "81fe7a5dab42867ef309b6d7210158bf99331884ac3c3b6c7188a8c9c18d5974", "320c13f4a3e51f6f4f66fcd9007e02bf658aa4ee9a88a509028d867d3b8a8e9a", @@ -157,7 +152,7 @@ displayMessageInDOM("Result", "certificate chain verified ✓"); console.log("verify_certificate_chain OK, last_certificate_from_chain:", proof_certificate); displayStepInDOM(10, "Validating Cardano transaction proof message..."); -let protocol_message = await client.unstable.verify_cardano_transaction_proof_then_compute_message( +let protocol_message = await client.verify_cardano_transaction_proof_then_compute_message( proof, proof_certificate, ); From 30e9057782de22b9f8f179c66e1625fd6d87f4a7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:02:38 +0200 Subject: [PATCH 4/9] docs: update 'Mithril client library WASM' developer doc With new unstable features implementation. --- .../nodes/mithril-client-library-wasm.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/website/root/manual/developer-docs/nodes/mithril-client-library-wasm.md b/docs/website/root/manual/developer-docs/nodes/mithril-client-library-wasm.md index e7c2573e6c0..749363eaf9f 100644 --- a/docs/website/root/manual/developer-docs/nodes/mithril-client-library-wasm.md +++ b/docs/website/root/manual/developer-docs/nodes/mithril-client-library-wasm.md @@ -94,10 +94,11 @@ broadcast_channel.onmessage = (e) => { await initMithrilClient(); -let client = await new MithrilClient( - aggregator_endpoint, - genesis_verification_key, -); +let client = new MithrilClient(aggregator_endpoint, genesis_verification_key, { + // The following option activates the unstable features of the client. + // Unstable features will trigger an error if this option is not set. + unstable: true, +}); let mithril_stake_distributions_list = await client.list_mithril_stake_distributions(); console.log("stake distributions:", mithril_stake_distributions_list); @@ -187,7 +188,7 @@ wget -q -O - https://aggregator.pre-release-preview.api.mithril.network/aggregat ::: ```js -const proof = await client.unstable.get_cardano_transaction_proofs([ +const proof = await client.get_cardano_transaction_proofs([ "CARDANO_TRANSACTION_HASH_1", "CARDANO_TRANSACTION_HASH_2", ]); @@ -203,7 +204,7 @@ console.log( ); let valid_cardano_transaction_proof = - await client.unstable.verify_cardano_transaction_proof_then_compute_message( + await client.verify_cardano_transaction_proof_then_compute_message( proof, proof_certificate, ); @@ -233,11 +234,11 @@ wget -q -O - https://aggregator.testing-preview.api.mithril.network/aggregator | ```js let cardano_stake_distributions_list = - await client.unstable.list_cardano_stake_distributions(); + await client.list_cardano_stake_distributions(); console.log("cardano stake distributions:", cardano_stake_distributions_list); let last_cardano_stake_distribution = - await client.unstable.get_cardano_stake_distribution( + await client.get_cardano_stake_distribution( cardano_stake_distributions_list[0].hash, ); console.log( @@ -259,7 +260,7 @@ console.log( ); let cardano_stake_distribution_message = - await client.unstable.compute_cardano_stake_distribution_message( + await client.compute_cardano_stake_distribution_message( certificate, last_cardano_stake_distribution, ); From b779826fdbde4cae3e2d8c806983a14ed526ee66 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:25:05 +0200 Subject: [PATCH 5/9] chore: avoid watching 'node_modules' files in client WASM test servers --- mithril-client-wasm/www-test/webpack.config.js | 3 +++ mithril-client-wasm/www/webpack.config.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/mithril-client-wasm/www-test/webpack.config.js b/mithril-client-wasm/www-test/webpack.config.js index b0ef0be8a8c..815a2c4f5c9 100644 --- a/mithril-client-wasm/www-test/webpack.config.js +++ b/mithril-client-wasm/www-test/webpack.config.js @@ -18,4 +18,7 @@ module.exports = { experiments: { asyncWebAssembly: true, }, + watchOptions: { + ignored: /node_modules/, + }, }; diff --git a/mithril-client-wasm/www/webpack.config.js b/mithril-client-wasm/www/webpack.config.js index a30cfe897b0..bc8a91ea47c 100644 --- a/mithril-client-wasm/www/webpack.config.js +++ b/mithril-client-wasm/www/webpack.config.js @@ -19,4 +19,7 @@ module.exports = { devServer: { allowedHosts: [".mithril.network"], }, + watchOptions: { + ignored: /node_modules/, + }, }; From 76e14c7f9e0e407c46e24de281ee22e95581ad7e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:27:42 +0200 Subject: [PATCH 6/9] refactor: adapt the WASM client www tests with new unstable implementation --- mithril-client-wasm/www-test/index.js | 39 +++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mithril-client-wasm/www-test/index.js b/mithril-client-wasm/www-test/index.js index 2ef1066ed94..43c2a838248 100644 --- a/mithril-client-wasm/www-test/index.js +++ b/mithril-client-wasm/www-test/index.js @@ -46,7 +46,11 @@ console.log("aggregator_endpoint: ", aggregator_endpoint); console.log("aggregator_capabilities: ", aggregator_capabilities); await run_test("constructor", test_number, async () => { - client = new MithrilClient(aggregator_endpoint, genesis_verification_key); + client = new MithrilClient(aggregator_endpoint, genesis_verification_key, { + // The following option activates the unstable features of the client. + // Unstable features will trigger an error if this option is not set. + unstable: true, + }); }); let snapshots; @@ -117,13 +121,13 @@ if (aggregator_capabilities.includes("CardanoTransactions")) { let ctx_sets; test_number++; await run_test("list_cardano_transactions_snapshots", test_number, async () => { - ctx_sets = await client.unstable.list_cardano_transactions_snapshots(); + ctx_sets = await client.list_cardano_transactions_snapshots(); console.log("cardano_transactions_sets", ctx_sets); }); test_number++; await run_test("get_cardano_transactions_snapshot", test_number, async () => { - const ctx_set = await client.unstable.get_cardano_transactions_snapshot(ctx_sets[0].hash); + const ctx_set = await client.get_cardano_transactions_snapshot(ctx_sets[0].hash); console.log("cardano_transaction_set", ctx_set); }); @@ -133,9 +137,7 @@ if (aggregator_capabilities.includes("CardanoTransactions")) { let ctx_proof; test_number++; await run_test("get_cardano_transaction_proof", test_number, async () => { - ctx_proof = await client.unstable.get_cardano_transaction_proofs( - transactions_hashes_to_certify, - ); + ctx_proof = await client.get_cardano_transaction_proofs(transactions_hashes_to_certify); console.log( "got proof for transactions: ", ctx_proof.transactions_hashes, @@ -157,11 +159,10 @@ if (aggregator_capabilities.includes("CardanoTransactions")) { "verify_cardano_transaction_proof_then_compute_message", test_number, async () => { - ctx_proof_message = - await client.unstable.verify_cardano_transaction_proof_then_compute_message( - ctx_proof, - proof_certificate, - ); + ctx_proof_message = await client.verify_cardano_transaction_proof_then_compute_message( + ctx_proof, + proof_certificate, + ); console.log("verify_cardano_transaction_proof_then_compute_message", ctx_proof_message); }, ); @@ -181,14 +182,14 @@ if (aggregator_capabilities.includes("CardanoStakeDistribution")) { let cardano_stake_distributions; test_number++; await run_test("list_cardano_stake_distributions", test_number, async () => { - cardano_stake_distributions = await client.unstable.list_cardano_stake_distributions(); + cardano_stake_distributions = await client.list_cardano_stake_distributions(); console.log("cardano_stake_distributions", cardano_stake_distributions); }); let cardano_stake_distribution; test_number++; await run_test("get_cardano_stake_distribution", test_number, async () => { - cardano_stake_distribution = await client.unstable.get_cardano_stake_distribution( + cardano_stake_distribution = await client.get_cardano_stake_distribution( cardano_stake_distributions[0].hash, ); console.log("cardano_stake_distribution", cardano_stake_distribution); @@ -198,8 +199,7 @@ if (aggregator_capabilities.includes("CardanoStakeDistribution")) { await run_test("get_cardano_stake_distribution_by_epoch", test_number, async () => { let epoch = BigInt(cardano_stake_distributions[0].epoch); - cardano_stake_distribution = - await client.unstable.get_cardano_stake_distribution_by_epoch(epoch); + cardano_stake_distribution = await client.get_cardano_stake_distribution_by_epoch(epoch); console.log("cardano_stake_distribution by epoch", cardano_stake_distribution); }); @@ -220,11 +220,10 @@ if (aggregator_capabilities.includes("CardanoStakeDistribution")) { let cardano_stake_distribution_message; test_number++; await run_test("compute_cardano_stake_distribution_message", test_number, async () => { - cardano_stake_distribution_message = - await client.unstable.compute_cardano_stake_distribution_message( - certificate, - cardano_stake_distribution, - ); + cardano_stake_distribution_message = await client.compute_cardano_stake_distribution_message( + certificate, + cardano_stake_distribution, + ); console.log("cardano_stake_distribution_message", cardano_stake_distribution_message); }); From 27016674604620fd9d9ed3cd5af946ffa2345c60 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:34:20 +0200 Subject: [PATCH 7/9] refactor: adapt explorer to new unstable implementation in WASM client --- .../CertifyCardanoTransactionsModal/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mithril-explorer/src/components/CertifyCardanoTransactionsModal/index.js b/mithril-explorer/src/components/CertifyCardanoTransactionsModal/index.js index a20e3d93d1c..be5499a4a61 100644 --- a/mithril-explorer/src/components/CertifyCardanoTransactionsModal/index.js +++ b/mithril-explorer/src/components/CertifyCardanoTransactionsModal/index.js @@ -97,13 +97,17 @@ export default function CertifyCardanoTransactionsModal({ }, [client, currentStep, transactionsProofs, certificate]); async function buildClient(aggregator, genesisKey) { - const client = new MithrilClient(aggregator, genesisKey); + const client = new MithrilClient(aggregator, genesisKey, { + // The following option activates the unstable features of the client. + // Unstable features will trigger an error if this option is not set. + unstable: true, + }); setClient(client); return client; } async function getTransactionsProofsAndCertificate(client, transactionHashes) { - const proofs = await client.unstable.get_cardano_transaction_proofs(transactionHashes); + const proofs = await client.get_cardano_transaction_proofs(transactionHashes); const certificate = await client.get_mithril_certificate(proofs.certificate_hash); setTransactionsProofs(proofs); @@ -112,11 +116,10 @@ export default function CertifyCardanoTransactionsModal({ async function verifyTransactionProofAgainstCertificate(client, transactionsProofs, certificate) { // Verify proof validity if so get its protocol message - const protocolMessage = - await client.unstable.verify_cardano_transaction_proof_then_compute_message( - transactionsProofs, - certificate, - ); + const protocolMessage = await client.verify_cardano_transaction_proof_then_compute_message( + transactionsProofs, + certificate, + ); const isProofValid = (await client.verify_message_match_certificate(protocolMessage, certificate)) === true; From 87e0edbb2eb222e3a9deeac5fe44be16f9210214 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:38:51 +0200 Subject: [PATCH 8/9] docs: update CHANGELOG --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a88b427cb..76954341c6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ As a minor extension, we have adopted a slightly different versioning convention ## Mithril Distribution [XXXX] - UNRELEASED +- **BREAKING** changes in Mithril client WASM: + + - Implementation of seamless transition from **unstable** to **stable** features. + - A new `unstable` option in the client allows the usage of unstable features. + - The previous `client.unstable` implementation is not supported anymore and must be replaced with `client`. + - Support for Mithril nodes footprint support in Prometheus monitoring in infrastructure. - Add support for custom HTTP headers in Mithril client WASM library. @@ -19,7 +25,7 @@ As a minor extension, we have adopted a slightly different versioning convention - Add feature options `num-integer-backend` and `rug-backend` for `mithril-common` and `mithril-client` crates. Allows to disable `rug-backend` and avoid `LGPL` license usage. -- Post `Chang` hard fork cleanup of the CI and the devnet. +- Post `Chang` hard fork cleanup of the CI, devnet and infrastructure. - **UNSTABLE** Cardano stake distribution certification: From b0eaa983e555d785611671ed739dc4eb799139ba Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 4 Sep 2024 11:42:39 +0200 Subject: [PATCH 9/9] chore: bump crates versions - 'mithril-client-wasm' from '0.3.10' to '0.4.0' - 'mithril-client' from '0.8.16' to '0.8.17' - 'mithril-explorer' from '0.7.5' to '0.7.6'. --- Cargo.lock | 4 ++-- mithril-client-wasm/Cargo.toml | 2 +- mithril-client-wasm/www-test/package.json | 2 +- mithril-client-wasm/www/package.json | 2 +- mithril-client/Cargo.toml | 2 +- mithril-explorer/package.json | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2dcd5ed1f2..6d24c25a41c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3629,7 +3629,7 @@ dependencies = [ [[package]] name = "mithril-client" -version = "0.8.16" +version = "0.8.17" dependencies = [ "anyhow", "async-recursion", @@ -3692,7 +3692,7 @@ dependencies = [ [[package]] name = "mithril-client-wasm" -version = "0.3.10" +version = "0.4.0" dependencies = [ "async-trait", "futures", diff --git a/mithril-client-wasm/Cargo.toml b/mithril-client-wasm/Cargo.toml index 1f635646cb8..71e24e63802 100644 --- a/mithril-client-wasm/Cargo.toml +++ b/mithril-client-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client-wasm" -version = "0.3.10" +version = "0.4.0" description = "Mithril client WASM" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-client-wasm/www-test/package.json b/mithril-client-wasm/www-test/package.json index 84e7f7d66ca..b2f000f47a8 100644 --- a/mithril-client-wasm/www-test/package.json +++ b/mithril-client-wasm/www-test/package.json @@ -1,6 +1,6 @@ { "name": "www-test", - "version": "0.1.6", + "version": "0.2.0", "private": true, "scripts": { "build": "webpack --config webpack.config.js", diff --git a/mithril-client-wasm/www/package.json b/mithril-client-wasm/www/package.json index 851bc1e6196..f2169500318 100644 --- a/mithril-client-wasm/www/package.json +++ b/mithril-client-wasm/www/package.json @@ -1,6 +1,6 @@ { "name": "www", - "version": "0.1.8", + "version": "0.2.0", "private": true, "scripts": { "build": "webpack --config webpack.config.js", diff --git a/mithril-client/Cargo.toml b/mithril-client/Cargo.toml index 52be9b32d5b..dedacd64257 100644 --- a/mithril-client/Cargo.toml +++ b/mithril-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client" -version = "0.8.16" +version = "0.8.17" description = "Mithril client library" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-explorer/package.json b/mithril-explorer/package.json index 8b019bd466e..31f62a6e57b 100644 --- a/mithril-explorer/package.json +++ b/mithril-explorer/package.json @@ -1,6 +1,6 @@ { "name": "mithril-explorer", - "version": "0.7.5", + "version": "0.7.6", "private": true, "scripts": { "dev": "next dev",