From 3c4857abc7ee1ab08a91da6f82ee9b08761e0f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 17 Aug 2023 13:16:55 +0100 Subject: [PATCH 1/4] make check-crates: check that shared can build for wasm target --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0b6345a50d..abd1f81808 100644 --- a/Makefile +++ b/Makefile @@ -72,10 +72,12 @@ check: check-mainnet: $(cargo) check --workspace --features "mainnet" -# Check that every crate can be built with default features +# Check that every crate can be built with default features and that shared crate +# can be built for wasm check-crates: $(foreach p,$(crates), echo "Checking $(p)" && cargo +$(nightly) check -Z unstable-options --tests -p $(p) && ) \ - make -C $(wasms_for_tests) check + make -C $(wasms_for_tests) check && \ + cargo check --package namada --target wasm32-unknown-unknown --no-default-features --features "abciplus,namada-sdk" clippy-wasm = $(cargo) +$(nightly) clippy --manifest-path $(wasm)/Cargo.toml --all-targets -- -D warnings From 9dd59c2aade9775df084accc3d0624412575668e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 17 Aug 2023 13:36:45 +0100 Subject: [PATCH 2/4] shared/ledger/masp: "testing" feature guard proofs load/save --- shared/src/ledger/masp.rs | 111 ++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/shared/src/ledger/masp.rs b/shared/src/ledger/masp.rs index d5322e9bf6..0448d8e6ce 100644 --- a/shared/src/ledger/masp.rs +++ b/shared/src/ledger/masp.rs @@ -116,6 +116,7 @@ pub struct ShieldedTransfer { pub epoch: Epoch, } +#[cfg(feature = "testing")] #[derive(Clone, Copy, Debug)] enum LoadOrSaveProofs { Load, @@ -1601,6 +1602,7 @@ impl ShieldedContext { } // To speed up integration tests, we can save and load proofs + #[cfg(feature = "testing")] let load_or_save = if let Ok(masp_proofs) = env::var(ENV_VAR_MASP_TEST_PROOFS) { @@ -1625,54 +1627,71 @@ impl ShieldedContext { }; let builder_clone = builder.clone().map_builder(WalletMap); + #[cfg(feature = "testing")] let builder_bytes = BorshSerialize::try_to_vec(&builder_clone).unwrap(); - let builder_hash = - namada_core::types::hash::Hash::sha256(&builder_bytes); - let saved_filepath = env::current_dir() - .unwrap() - // One up from "tests" dir to the root dir - .parent() - .unwrap() - .join(MASP_TEST_PROOFS_DIR) - .join(format!("{builder_hash}.bin")); - - if let LoadOrSaveProofs::Load = load_or_save { - let recommendation = format!( - "Re-run the tests with {ENV_VAR_MASP_TEST_PROOFS}=save to \ - re-generate proofs." - ); - let exp_str = format!( - "Read saved MASP proofs from {}. {recommendation}", - saved_filepath.to_string_lossy() - ); - let loaded_bytes = - tokio::fs::read(&saved_filepath).await.expect(&exp_str); - let exp_str = format!( - "Valid `ShieldedTransfer` bytes in {}. {recommendation}", - saved_filepath.to_string_lossy() - ); - let loaded: ShieldedTransfer = - BorshDeserialize::try_from_slice(&loaded_bytes) - .expect(&exp_str); - Ok(Some(loaded)) - } else { - // Build and return the constructed transaction - let (masp_tx, metadata) = builder.build( - &self.utils.local_tx_prover(), - &FeeRule::non_standard(tx_fee), - )?; - let built = ShieldedTransfer { - builder: builder_clone, - masp_tx, - metadata, - epoch, - }; - if let LoadOrSaveProofs::Save = load_or_save { - let built_bytes = BorshSerialize::try_to_vec(&built).unwrap(); - tokio::fs::write(&saved_filepath, built_bytes) - .await - .unwrap(); + let build_transfer = + || -> Result> { + let (masp_tx, metadata) = builder.build( + &self.utils.local_tx_prover(), + &FeeRule::non_standard(tx_fee), + )?; + Ok(ShieldedTransfer { + builder: builder_clone, + masp_tx, + metadata, + epoch, + }) + }; + + #[cfg(feature = "testing")] + { + let builder_hash = + namada_core::types::hash::Hash::sha256(&builder_bytes); + let saved_filepath = env::current_dir() + .unwrap() + // One up from "tests" dir to the root dir + .parent() + .unwrap() + .join(MASP_TEST_PROOFS_DIR) + .join(format!("{builder_hash}.bin")); + + if let LoadOrSaveProofs::Load = load_or_save { + let recommendation = format!( + "Re-run the tests with {ENV_VAR_MASP_TEST_PROOFS}=save to \ + re-generate proofs." + ); + let exp_str = format!( + "Read saved MASP proofs from {}. {recommendation}", + saved_filepath.to_string_lossy() + ); + let loaded_bytes = + tokio::fs::read(&saved_filepath).await.expect(&exp_str); + let exp_str = format!( + "Valid `ShieldedTransfer` bytes in {}. {recommendation}", + saved_filepath.to_string_lossy() + ); + let loaded: ShieldedTransfer = + BorshDeserialize::try_from_slice(&loaded_bytes) + .expect(&exp_str); + Ok(Some(loaded)) + } else { + // Build and return the constructed transaction + let built = build_transfer()?; + if let LoadOrSaveProofs::Save = load_or_save { + let built_bytes = + BorshSerialize::try_to_vec(&built).unwrap(); + tokio::fs::write(&saved_filepath, built_bytes) + .await + .unwrap(); + } + Ok(Some(built)) } + } + + #[cfg(not(feature = "testing"))] + { + // Build and return the constructed transaction + let built = build_transfer()?; Ok(Some(built)) } } From 8ba0a79702534f7b9317030cb8590231b84c8d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 17 Aug 2023 13:38:00 +0100 Subject: [PATCH 3/4] shared/types/control_flow: fix warn when no-default-features --- shared/src/types/control_flow.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/src/types/control_flow.rs b/shared/src/types/control_flow.rs index 228d725b61..6b7d07532d 100644 --- a/shared/src/types/control_flow.rs +++ b/shared/src/types/control_flow.rs @@ -7,6 +7,7 @@ use std::ops::ControlFlow; use std::pin::Pin; use std::task::{Context, Poll}; +#[cfg(any(unix, windows))] use futures::future::FutureExt; #[cfg(any(unix, windows))] use tokio::sync::oneshot; From 63e1adbce044ab2a06a61c37e7a770b04a575089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 17 Aug 2023 13:41:42 +0100 Subject: [PATCH 4/4] changelog: add #1828 --- .../improvements/1828-feature-guard-masp-proof-load.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1828-feature-guard-masp-proof-load.md diff --git a/.changelog/unreleased/improvements/1828-feature-guard-masp-proof-load.md b/.changelog/unreleased/improvements/1828-feature-guard-masp-proof-load.md new file mode 100644 index 0000000000..b72a51ef80 --- /dev/null +++ b/.changelog/unreleased/improvements/1828-feature-guard-masp-proof-load.md @@ -0,0 +1,2 @@ +- Ensure that Namada (shared) crate can be built for WASM target. + ([\#1828](https://github.com/anoma/namada/pull/1828)) \ No newline at end of file