From 416ca72c127a51f36cb6a18cf06fcd0e469b89d0 Mon Sep 17 00:00:00 2001 From: igamigo Date: Wed, 31 Jul 2024 13:28:30 -0300 Subject: [PATCH] chore: Fix build after base updates (#457) * chore: fix build and serialize procedures as bytes * chore: Point node to next * Fix node config file --- Makefile | 2 +- bin/miden-cli/src/commands/account.rs | 10 +++++----- crates/rust-client/src/mock.rs | 2 +- crates/rust-client/src/store/sqlite_store/accounts.rs | 9 ++++----- .../src/store/web_store/accounts/js_bindings.rs | 2 +- .../rust-client/src/store/web_store/accounts/mod.rs | 3 ++- .../rust-client/src/store/web_store/accounts/utils.rs | 6 +++--- crates/rust-client/src/store/web_store/js/accounts.js | 11 +++++++++-- crates/rust-client/src/tests.rs | 4 ++-- crates/rust-client/src/transactions/request.rs | 6 +++--- tests/config/miden-node.toml | 3 --- 11 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 8eb864bc3..7132b2a94 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ FEATURES_CLIENT="testing, concurrent" FEATURES_CLI="testing, concurrent" NODE_FEATURES_TESTING="testing" WARNINGS=RUSTDOCFLAGS="-D warnings" -NODE_BRANCH="main" +NODE_BRANCH="next" # --- Linting ------------------------------------------------------------------------------------- diff --git a/bin/miden-cli/src/commands/account.rs b/bin/miden-cli/src/commands/account.rs index 8b462b864..4e5928c40 100644 --- a/bin/miden-cli/src/commands/account.rs +++ b/bin/miden-cli/src/commands/account.rs @@ -125,7 +125,7 @@ pub fn show_account Vec { init_seed, account.account_type(), miden_objects::accounts::AccountStorageType::OffChain, - account.code().root(), + account.code().commitment(), account.storage().root(), ) .unwrap(); diff --git a/crates/rust-client/src/store/sqlite_store/accounts.rs b/crates/rust-client/src/store/sqlite_store/accounts.rs index fc604e36e..0630e6ad2 100644 --- a/crates/rust-client/src/store/sqlite_store/accounts.rs +++ b/crates/rust-client/src/store/sqlite_store/accounts.rs @@ -26,7 +26,7 @@ type SerializedAccountAuthParts = (i64, Vec); type SerializedAccountVaultData = (String, String); -type SerializedAccountCodeData = (String, String, Vec); +type SerializedAccountCodeData = (String, Vec, Vec); type SerializedAccountStorageData = (String, Vec); @@ -315,7 +315,7 @@ pub(super) fn parse_account( /// Serialized the provided account into database compatible types. fn serialize_account(account: &Account) -> Result { let id: u64 = account.id().into(); - let code_root = account.code().root().to_string(); + let code_root = account.code().commitment().to_string(); let storage_root = account.storage().root().to_string(); let vault_root = serde_json::to_string(&account.vault().commitment()) .map_err(StoreError::InputSerializationError)?; @@ -364,9 +364,8 @@ fn serialize_account_auth( fn serialize_account_code( account_code: &AccountCode, ) -> Result { - let root = account_code.root().to_string(); - let procedures = serde_json::to_string(account_code.procedures()) - .map_err(StoreError::InputSerializationError)?; + let root = account_code.commitment().to_string(); + let procedures = account_code.procedures().to_bytes(); let module = account_code.module().to_bytes(AstSerdeOptions { serialize_imports: true }); Ok((root, procedures, module)) diff --git a/crates/rust-client/src/store/web_store/accounts/js_bindings.rs b/crates/rust-client/src/store/web_store/accounts/js_bindings.rs index cc89a21d6..b10b216d8 100644 --- a/crates/rust-client/src/store/web_store/accounts/js_bindings.rs +++ b/crates/rust-client/src/store/web_store/accounts/js_bindings.rs @@ -44,7 +44,7 @@ extern "C" { #[wasm_bindgen(js_name = insertAccountCode)] pub fn idxdb_insert_account_code( code_root: String, - code: String, + code: Vec, module: Vec, ) -> js_sys::Promise; diff --git a/crates/rust-client/src/store/web_store/accounts/mod.rs b/crates/rust-client/src/store/web_store/accounts/mod.rs index 54a02e1a1..e6cde47c7 100644 --- a/crates/rust-client/src/store/web_store/accounts/mod.rs +++ b/crates/rust-client/src/store/web_store/accounts/mod.rs @@ -92,7 +92,8 @@ impl WebStore { ) -> Result<(Account, Option), StoreError> { let (account_stub, seed) = self.get_account_stub(account_id).await.unwrap(); let (_procedures, module_ast) = - self.get_account_code(account_stub.code_root()).await.unwrap(); + self.get_account_code(account_stub.code_commitment()).await.unwrap(); + let account_code = AccountCode::new(module_ast, &TransactionKernel::assembler()).unwrap(); let account_storage = self.get_account_storage(account_stub.storage_root()).await.unwrap(); let account_vault = self.get_vault_assets(account_stub.vault_root()).await.unwrap(); diff --git a/crates/rust-client/src/store/web_store/accounts/utils.rs b/crates/rust-client/src/store/web_store/accounts/utils.rs index bdc484bda..b5ab0fe18 100644 --- a/crates/rust-client/src/store/web_store/accounts/utils.rs +++ b/crates/rust-client/src/store/web_store/accounts/utils.rs @@ -14,8 +14,8 @@ use super::{js_bindings::*, models::*}; use crate::store::StoreError; pub async fn insert_account_code(account_code: &AccountCode) -> Result<(), ()> { - let root = account_code.root().to_string(); - let procedures = serde_json::to_string(account_code.procedures()).unwrap(); + let root = account_code.commitment().to_string(); + let procedures = account_code.procedures().to_bytes(); let module = account_code.module().to_bytes(AstSerdeOptions { serialize_imports: true }); let promise = idxdb_insert_account_code(root, procedures, module); @@ -68,7 +68,7 @@ pub async fn insert_account_record( account_seed: Option, ) -> Result<(), ()> { let account_id_str = account.id().to_string(); - let code_root = account.code().root().to_string(); + let code_root = account.code().commitment().to_string(); let storage_root = account.storage().root().to_string(); let vault_root = serde_json::to_string(&account.vault().commitment()).unwrap(); let committed = account.is_on_chain(); diff --git a/crates/rust-client/src/store/web_store/js/accounts.js b/crates/rust-client/src/store/web_store/js/accounts.js index d84af8af8..5796ab1a0 100644 --- a/crates/rust-client/src/store/web_store/js/accounts.js +++ b/crates/rust-client/src/store/web_store/js/accounts.js @@ -174,9 +174,15 @@ export async function getAccountCode( const moduleArrayBuffer = await codeRecord.module.arrayBuffer(); const moduleArray = new Uint8Array(moduleArrayBuffer); const moduleBase64 = uint8ArrayToBase64(moduleArray); + + // Convert the procedures Blob to an ArrayBuffer + const proceduresArrayBuffer = await codeRecord.procedures.arrayBuffer(); + const proceduresArray = new Uint8Array(proceduresArrayBuffer); + const proceduresBase64 = uint8ArrayToBase64(proceduresArray); + return { root: codeRecord.root, - procedures: codeRecord.procedures, + procedures: proceduresBase64, module: moduleBase64, }; } catch (error) { @@ -349,11 +355,12 @@ export async function insertAccountCode( try { // Create a Blob from the ArrayBuffer const moduleBlob = new Blob([new Uint8Array(module)]); + const codeBlob = new Blob([new Uint8Array(code)]); // Prepare the data object to insert const data = { root: codeRoot, // Using codeRoot as the key - procedures: code, + procedures: codeBlob, module: moduleBlob, // Blob created from ArrayBuffer }; diff --git a/crates/rust-client/src/tests.rs b/crates/rust-client/src/tests.rs index 469187710..4fdb92816 100644 --- a/crates/rust-client/src/tests.rs +++ b/crates/rust-client/src/tests.rs @@ -105,7 +105,7 @@ async fn insert_basic_account() { assert_eq!(account.nonce(), fetched_account.nonce()); assert_eq!(account.vault(), fetched_account.vault()); assert_eq!(account.storage().root(), fetched_account.storage().root()); - assert_eq!(account.code().root(), fetched_account.code().root()); + assert_eq!(account.code().commitment(), fetched_account.code().commitment()); // Validate seed matches assert_eq!(account_seed, fetched_account_seed.unwrap()); @@ -139,7 +139,7 @@ async fn insert_faucet_account() { assert_eq!(account.nonce(), fetched_account.nonce()); assert_eq!(account.vault(), fetched_account.vault()); assert_eq!(account.storage(), fetched_account.storage()); - assert_eq!(account.code().root(), fetched_account.code().root()); + assert_eq!(account.code().commitment(), fetched_account.code().commitment()); // Validate seed matches assert_eq!(account_seed, fetched_account_seed.unwrap()); diff --git a/crates/rust-client/src/transactions/request.rs b/crates/rust-client/src/transactions/request.rs index 82876125f..5fa43c36b 100644 --- a/crates/rust-client/src/transactions/request.rs +++ b/crates/rust-client/src/transactions/request.rs @@ -406,9 +406,9 @@ impl SwapTransactionData { // ================================================================================================ pub mod known_script_roots { - pub const P2ID: &str = "0x3df15bd183c3239332dcb535c6d0a25c668ead19a317fefe66fc2754e49ce4f1"; - pub const P2IDR: &str = "0xf6513a4c607de61288263e1d9346889e9393f3c4024bfb42efc0e2ce3c64ee72"; - pub const SWAP: &str = "0x5040bdb39e3e71d8ae4a93d65ff44d152f56192df97018a63b6b6342e87f97d5"; + pub const P2ID: &str = "0x07db8e6726c0859648a4f0ad38376440c01d98674b7d5a03d7ad729ae2a21d8f"; + pub const P2IDR: &str = "0xd43b69d65bbc22abf64dbae53ad22e3a4f6d5bfac8e47497b69c116824b46427"; + pub const SWAP: &str = "0x9270b8c89303cf7a05340351d7f9962a9722c4f35d30b7d4980929b381e5d695"; } // TESTS diff --git a/tests/config/miden-node.toml b/tests/config/miden-node.toml index 85ae4c97a..733ead18a 100644 --- a/tests/config/miden-node.toml +++ b/tests/config/miden-node.toml @@ -1,7 +1,6 @@ [block_producer] # port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-block-producer', 1)) % 2**16 endpoint = { host = "localhost", port = 48046 } -store_url = "http://localhost:28943" # enables or disables the verification of transaction proofs before they are accepted into the # transaction queue. verify_tx_proofs = true @@ -9,8 +8,6 @@ verify_tx_proofs = true [rpc] # port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-rpc', 1)) % 2**16 endpoint = { host = "0.0.0.0", port = 57291 } -block_producer_url = "http://localhost:48046" -store_url = "http://localhost:28943" [store] # port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-store', 1)) % 2**16