diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f56b121..6270c3a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Limited the number of decimals that an asset can have (#666). * [BREAKING] Removed the `testing` feature from the CLI (#670). * Added per transaction prover support to the web client (#674). +* [BREAKING] Added `BlockNumber` structure (#677). ### Fixes diff --git a/Cargo.lock b/Cargo.lock index 6bf43c72c..5504cd3e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,9 +363,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.9" +version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" dependencies = [ "jobserver", "libc", @@ -394,9 +394,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" +checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" dependencies = [ "clap_builder", "clap_derive", @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" dependencies = [ "anstream", "anstyle", @@ -853,7 +853,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.7.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -1048,9 +1048,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -1322,7 +1322,7 @@ dependencies = [ "miden-client", "miden-client-tests", "miden-lib", - "miden-remote-provers", + "miden-proving-service-client", "predicates", "rand", "serde", @@ -1391,7 +1391,7 @@ dependencies = [ "miden-client", "miden-lib", "miden-objects", - "miden-remote-provers", + "miden-proving-service-client", "miden-tx", "rand", "serde", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "miden-lib" version = "0.7.0" -source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#0e65f4fe1d1faa43947355a40f723f0d3b01173a" +source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#a0521f17421c2db2968be404b20280457b79d195" dependencies = [ "miden-assembly", "miden-objects", @@ -1507,7 +1507,7 @@ dependencies = [ [[package]] name = "miden-objects" version = "0.7.0" -source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#0e65f4fe1d1faa43947355a40f723f0d3b01173a" +source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#a0521f17421c2db2968be404b20280457b79d195" dependencies = [ "getrandom", "miden-assembly", @@ -1517,7 +1517,7 @@ dependencies = [ "miden-verifier", "rand", "rand_xoshiro", - "semver 1.0.24", + "semver 1.0.25", "serde", "thiserror 2.0.11", "toml", @@ -1550,19 +1550,17 @@ dependencies = [ ] [[package]] -name = "miden-remote-provers" +name = "miden-proving-service-client" version = "0.1.0" -source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#0e65f4fe1d1faa43947355a40f723f0d3b01173a" +source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#a0521f17421c2db2968be404b20280457b79d195" dependencies = [ "async-trait", - "miden-lib", "miden-objects", "miden-tx", "miette", "prost", "prost-build", "protox", - "serde", "thiserror 2.0.11", "tonic", "tonic-build", @@ -1572,7 +1570,7 @@ dependencies = [ [[package]] name = "miden-rpc-proto" version = "0.6.0" -source = "git+https://github.com/0xPolygonMiden/miden-node?branch=next#c5da1e68a0db4b89afbd69aad7f5ca64e3d42d18" +source = "git+https://github.com/0xPolygonMiden/miden-node?branch=next#e8f83147ba0277a089bf07eb8443f6bd4526727b" [[package]] name = "miden-stdlib" @@ -1606,7 +1604,7 @@ dependencies = [ [[package]] name = "miden-tx" version = "0.7.0" -source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#0e65f4fe1d1faa43947355a40f723f0d3b01173a" +source = "git+https://github.com/0xPolygonMiden/miden-base?branch=next#a0521f17421c2db2968be404b20280457b79d195" dependencies = [ "async-trait", "miden-lib", @@ -1898,7 +1896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.7.0", + "indexmap 2.7.1", ] [[package]] @@ -2290,7 +2288,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.24", + "semver 1.0.25", ] [[package]] @@ -2350,9 +2348,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" dependencies = [ "serde", ] @@ -2396,9 +2394,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ "itoa", "memchr", @@ -2782,7 +2780,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.7.0", + "indexmap 2.7.1", "serde", "serde_spanned", "toml_datetime", @@ -2973,9 +2971,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "trybuild" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dcd332a5496c026f1e14b7f3d2b7bd98e509660c04239c58b0ba38a12daded4" +checksum = "9f14b5c02a137632f68194ec657ecb92304138948e8957c932127eb1b58c23be" dependencies = [ "dissimilar", "glob", @@ -3040,9 +3038,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744018581f9a3454a9e15beb8a33b017183f1e7c0cd170232a2d1453b23a51c4" +checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" dependencies = [ "getrandom", "serde", @@ -3050,9 +3048,9 @@ dependencies = [ [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vcpkg" diff --git a/Cargo.toml b/Cargo.toml index 89617c7b2..03632fc40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ async-trait = "0.1" miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false } miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false } miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["async"] } -miden-remote-provers = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", features = ["tx-prover"] } +miden-proving-service-client = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", features = ["tx-prover"] } rand = { version = "0.8" } serde = { version = "1.0", features = ["derive"] } thiserror = { version = "2.0", default-features = false } diff --git a/bin/miden-cli/Cargo.toml b/bin/miden-cli/Cargo.toml index d0b48f362..f52d64b07 100644 --- a/bin/miden-cli/Cargo.toml +++ b/bin/miden-cli/Cargo.toml @@ -37,7 +37,7 @@ comfy-table = { version = "7.1" } figment = { version = "0.10", features = ["toml", "env"] } miden-client = { version = "0.6", path = "../../crates/rust-client", features = ["sqlite", "tonic"] } miden-lib = { workspace = true } -miden-remote-provers = { workspace = true } +miden-proving-service-client = { workspace = true , features = ["std", "tx-prover"]} rand = { workspace = true } serde = { version = "1.0", features = ["derive"] } tokio = { workspace = true } diff --git a/bin/miden-cli/src/commands/new_transactions.rs b/bin/miden-cli/src/commands/new_transactions.rs index b47ef01e3..30be45795 100644 --- a/bin/miden-cli/src/commands/new_transactions.rs +++ b/bin/miden-cli/src/commands/new_transactions.rs @@ -5,14 +5,16 @@ use miden_client::{ accounts::AccountId, assets::{FungibleAsset, NonFungibleDeltaAction}, crypto::{Digest, FeltRng}, - notes::{build_swap_tag, get_input_note_with_id_prefix, NoteType as MidenNoteType}, + notes::{ + build_swap_tag, get_input_note_with_id_prefix, BlockNumber, NoteType as MidenNoteType, + }, transactions::{ PaymentTransactionData, SwapTransactionData, TransactionRequest, TransactionRequestBuilder, TransactionResult, }, Client, }; -use miden_remote_provers::RemoteTransactionProver; +use miden_proving_service_client::RemoteTransactionProver; use tracing::info; use crate::{ @@ -142,7 +144,7 @@ impl SendCmd { let transaction_request = TransactionRequestBuilder::pay_to_id( payment_transaction, - self.recall_height, + self.recall_height.map(BlockNumber::from), (&self.note_type).into(), client.rng(), ) diff --git a/bin/miden-cli/src/main.rs b/bin/miden-cli/src/main.rs index 2b68442cf..1d1d94e85 100644 --- a/bin/miden-cli/src/main.rs +++ b/bin/miden-cli/src/main.rs @@ -1,6 +1,6 @@ use miden_cli::Cli; -extern crate alloc; +extern crate std; #[tokio::main] async fn main() -> Result<(), String> { diff --git a/bin/miden-cli/src/tests.rs b/bin/miden-cli/src/tests.rs index e0edd324e..a742fb6c9 100644 --- a/bin/miden-cli/src/tests.rs +++ b/bin/miden-cli/src/tests.rs @@ -698,7 +698,7 @@ async fn debug_mode_outputs_logs() { // Export the note let note_file: NoteFile = NoteFile::NoteDetails { details: note.clone().into(), - after_block_num: 0, + after_block_num: 0.into(), tag: Some(note.metadata().tag()), }; diff --git a/crates/rust-client/src/accounts.rs b/crates/rust-client/src/accounts.rs index a88cdaa35..73e0fec0a 100644 --- a/crates/rust-client/src/accounts.rs +++ b/crates/rust-client/src/accounts.rs @@ -184,19 +184,19 @@ impl Client { pub struct AccountUpdates { /// Updated public accounts. updated_public_accounts: Vec, - /// Node account hashes that don't match the tracked information. - mismatched_offchain_accounts: Vec<(AccountId, Digest)>, + /// Node account hashes that don't match the current tracked state for private accounts. + mismatched_private_accounts: Vec<(AccountId, Digest)>, } impl AccountUpdates { /// Creates a new instance of `AccountUpdates`. pub fn new( updated_public_accounts: Vec, - mismatched_offchain_accounts: Vec<(AccountId, Digest)>, + mismatched_private_accounts: Vec<(AccountId, Digest)>, ) -> Self { Self { updated_public_accounts, - mismatched_offchain_accounts, + mismatched_private_accounts, } } @@ -205,9 +205,9 @@ impl AccountUpdates { &self.updated_public_accounts } - /// Returns the mismatched offchain accounts. - pub fn mismatched_offchain_accounts(&self) -> &[(AccountId, Digest)] { - &self.mismatched_offchain_accounts + /// Returns the mismatched private accounts. + pub fn mismatched_private_accounts(&self) -> &[(AccountId, Digest)] { + &self.mismatched_private_accounts } } diff --git a/crates/rust-client/src/lib.rs b/crates/rust-client/src/lib.rs index c34de2424..3f4f82002 100644 --- a/crates/rust-client/src/lib.rs +++ b/crates/rust-client/src/lib.rs @@ -45,8 +45,8 @@ pub mod auth { } /// Provides types for working with blocks within the Miden rollup network. -pub mod blocks { - pub use miden_objects::BlockHeader; +pub mod block { + pub use miden_objects::block::BlockHeader; } /// Provides cryptographic types and utilities used within the Miden rollup diff --git a/crates/rust-client/src/mock.rs b/crates/rust-client/src/mock.rs index 4f83f6d8d..1b1a345bc 100644 --- a/crates/rust-client/src/mock.rs +++ b/crates/rust-client/src/mock.rs @@ -10,7 +10,7 @@ use miden_lib::transaction::TransactionKernel; use miden_objects::{ accounts::{AccountCode, AccountId}, assets::{FungibleAsset, NonFungibleAsset}, - block::Block, + block::{Block, BlockHeader, BlockNumber}, crypto::{ merkle::{Mmr, MmrProof}, rand::RpoRandomCoin, @@ -21,7 +21,7 @@ use miden_objects::{ notes::NoteBuilder, }, transaction::{InputNote, ProvenTransaction}, - BlockHeader, Felt, Word, + Felt, Word, }; use miden_tx::testing::MockChain; use rand::Rng; @@ -127,17 +127,17 @@ impl MockRpcApi { } /// Returns the chain tip block number. - fn get_chain_tip_block_num(&self) -> u32 { + fn get_chain_tip_block_num(&self) -> BlockNumber { self.blocks.last().map(|b| b.header().block_num()).unwrap() } /// Retrieves a block by its block number. - fn get_block_by_num(&self, block_num: u32) -> Option<&Block> { - self.blocks.get(block_num as usize) + fn get_block_by_num(&self, block_num: BlockNumber) -> Option<&Block> { + self.blocks.get(block_num.as_usize()) } /// Generates a sync state response based on the request block number. - pub fn get_sync_state_request(&self, request_block_num: u32) -> SyncStateResponse { + pub fn get_sync_state_request(&self, request_block_num: BlockNumber) -> SyncStateResponse { // Determine the next block number to sync let next_block_num = self .notes @@ -156,7 +156,7 @@ impl MockRpcApi { // Prepare the MMR delta let mmr_delta = self .get_mmr() - .get_delta((request_block_num + 1) as usize, next_block_num as usize) + .get_delta((request_block_num.as_u32() + 1) as usize, next_block_num.as_usize()) .ok() .map(Into::into); @@ -169,12 +169,12 @@ impl MockRpcApi { .iter() .map(|n| NullifierUpdate { nullifier: Some(n.inner().into()), - block_num: next_block_num, + block_num: next_block_num.as_u32(), }) .collect(); SyncStateResponse { - chain_tip: self.get_chain_tip_block_num(), + chain_tip: self.get_chain_tip_block_num().as_u32(), block_header: Some(next_block.header().into()), mmr_delta, accounts: vec![], @@ -185,7 +185,10 @@ impl MockRpcApi { } /// Retrieves notes that are included in the specified block number. - fn get_notes_in_block(&self, block_num: u32) -> impl Iterator + '_ { + fn get_notes_in_block( + &self, + block_num: BlockNumber, + ) -> impl Iterator + '_ { self.notes.values().filter_map(move |note| { if note.location().map_or(false, |loc| loc.block_num() == block_num) { let proof = note.proof()?; @@ -206,7 +209,7 @@ use alloc::boxed::Box; impl NodeRpcClient for MockRpcApi { async fn sync_notes( &mut self, - _block_num: u32, + _block_num: BlockNumber, _note_tags: &[NoteTag], ) -> Result { let response = SyncNoteResponse { @@ -222,7 +225,7 @@ impl NodeRpcClient for MockRpcApi { /// Executes the specified sync state request and returns the response. async fn sync_state( &mut self, - block_num: u32, + block_num: BlockNumber, _account_ids: &[AccountId], _note_tags: &[NoteTag], _nullifiers_tags: &[u16], @@ -237,10 +240,10 @@ impl NodeRpcClient for MockRpcApi { /// Only used for retrieving genesis block right now so that's the only case we need to cover. async fn get_block_header_by_number( &mut self, - block_num: Option, + block_num: Option, include_mmr_proof: bool, ) -> Result<(BlockHeader, Option), RpcError> { - if block_num == Some(0) { + if block_num == Some(0.into()) { return Ok((self.blocks.first().unwrap().header(), None)); } let block = self @@ -250,7 +253,7 @@ impl NodeRpcClient for MockRpcApi { .unwrap(); let mmr_proof = if include_mmr_proof { - Some(self.get_mmr().open(block_num.unwrap() as usize).unwrap()) + Some(self.get_mmr().open(block_num.unwrap().as_usize()).unwrap()) } else { None }; diff --git a/crates/rust-client/src/notes/import.rs b/crates/rust-client/src/notes/import.rs index f38ac4f02..167983d3a 100644 --- a/crates/rust-client/src/notes/import.rs +++ b/crates/rust-client/src/notes/import.rs @@ -1,6 +1,7 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockNumber, crypto::rand::FeltRng, notes::{Note, NoteDetails, NoteFile, NoteId, NoteInclusionProof, NoteMetadata, NoteTag}, }; @@ -185,7 +186,7 @@ impl Client { &mut self, previous_note: Option, details: NoteDetails, - after_block_num: u32, + after_block_num: BlockNumber, tag: Option, ) -> Result, ClientError> { let mut note_record = previous_note.unwrap_or({ @@ -237,7 +238,7 @@ impl Client { /// proof. async fn check_expected_note( &mut self, - mut request_block_num: u32, + mut request_block_num: BlockNumber, tag: NoteTag, expected_note: &miden_objects::notes::NoteDetails, ) -> Result, ClientError> { @@ -249,7 +250,7 @@ impl Client { let sync_notes = self.rpc_api.sync_notes(request_block_num, &[tag]).await?; - if sync_notes.block_header.block_num() == sync_notes.chain_tip { + if sync_notes.block_header.block_num() == sync_notes.chain_tip.into() { return Ok(None); } diff --git a/crates/rust-client/src/notes/mod.rs b/crates/rust-client/src/notes/mod.rs index 1ec3efd23..5accc152e 100644 --- a/crates/rust-client/src/notes/mod.rs +++ b/crates/rust-client/src/notes/mod.rs @@ -24,6 +24,7 @@ pub use miden_lib::notes::{ utils::{build_p2id_recipient, build_swap_tag}, }; pub use miden_objects::{ + block::BlockNumber, notes::{ Note, NoteAssets, NoteExecutionHint, NoteExecutionMode, NoteFile, NoteId, NoteInclusionProof, NoteInputs, NoteMetadata, NoteRecipient, NoteScript, NoteTag, NoteType, diff --git a/crates/rust-client/src/notes/script_roots.rs b/crates/rust-client/src/notes/script_roots.rs index a1c5766e1..6304367ad 100644 --- a/crates/rust-client/src/notes/script_roots.rs +++ b/crates/rust-client/src/notes/script_roots.rs @@ -2,10 +2,10 @@ //! This file was generated by build.rs. /// Script root of the P2ID note script. -pub const P2ID: &str = "0xf586180b61a0fcabb7033e2bdb36ad3d00387081d19a90d32f282c8e52e31581"; +pub const P2ID: &str = "0x56ab74fa46300f5988caad8aefd0e105f7244f5784488b293be3509b251d4dfe"; /// Script root of the P2IDR note script. -pub const P2IDR: &str = "0x06819748ba07cdb67a45996091eb168ff5428e83161682dc2a63338f32a12445"; +pub const P2IDR: &str = "0xb36ea4df8d5fa29f2aa582931595b9171df0866d099c5df34868af0d6a60fad1"; /// Script root of the SWAP note script. -pub const SWAP: &str = "0xba6dc9c022ad9a988c3c8f91e40ad89f4ef736472c79f389397943a1db538bfc"; +pub const SWAP: &str = "0x1c4dd8b76fac02a3c29d8c4b41f5f1717c9c96d59a28bda3545ca5c9b6f234ea"; diff --git a/crates/rust-client/src/rpc/domain/accounts.rs b/crates/rust-client/src/rpc/domain/accounts.rs index 2f99d7ec8..cad981aab 100644 --- a/crates/rust-client/src/rpc/domain/accounts.rs +++ b/crates/rust-client/src/rpc/domain/accounts.rs @@ -7,6 +7,7 @@ use core::fmt::{self, Debug, Display, Formatter}; use miden_objects::{ accounts::{Account, AccountCode, AccountHeader, AccountId, AccountStorageHeader}, + block::BlockNumber, crypto::merkle::{MerklePath, SmtProof}, Digest, Felt, }; @@ -207,7 +208,7 @@ impl ProtoAccountStateHeader { // ================================================================================================ /// Contains a block number, and a list of account proofs at that block. -pub type AccountProofs = (u32, Vec); +pub type AccountProofs = (BlockNumber, Vec); /// Account state headers. pub struct StateHeaders { diff --git a/crates/rust-client/src/rpc/domain/blocks.rs b/crates/rust-client/src/rpc/domain/blocks.rs index 4a8c9b806..28b5c45c9 100644 --- a/crates/rust-client/src/rpc/domain/blocks.rs +++ b/crates/rust-client/src/rpc/domain/blocks.rs @@ -1,4 +1,4 @@ -use miden_objects::{crypto::merkle::MerklePath, BlockHeader}; +use miden_objects::{block::BlockHeader, crypto::merkle::MerklePath}; use super::MissingFieldHelper; use crate::rpc::{errors::RpcConversionError, generated::block}; @@ -11,7 +11,7 @@ impl From<&BlockHeader> for block::BlockHeader { Self { version: header.version(), prev_hash: Some(header.prev_hash().into()), - block_num: header.block_num(), + block_num: header.block_num().as_u32(), chain_root: Some(header.chain_root().into()), account_root: Some(header.account_root().into()), nullifier_root: Some(header.nullifier_root().into()), @@ -48,7 +48,7 @@ impl TryFrom for BlockHeader { .prev_hash .ok_or(block::BlockHeader::missing_field(stringify!(prev_hash)))? .try_into()?, - value.block_num, + value.block_num.into(), value .chain_root .ok_or(block::BlockHeader::missing_field(stringify!(chain_root)))? diff --git a/crates/rust-client/src/rpc/domain/notes.rs b/crates/rust-client/src/rpc/domain/notes.rs index 89c5c198a..c0b3459a3 100644 --- a/crates/rust-client/src/rpc/domain/notes.rs +++ b/crates/rust-client/src/rpc/domain/notes.rs @@ -1,9 +1,10 @@ use alloc::vec::Vec; use miden_objects::{ + block::BlockHeader, crypto::merkle::MerklePath, notes::{Note, NoteExecutionHint, NoteId, NoteInclusionProof, NoteMetadata, NoteTag, NoteType}, - BlockHeader, Digest, Felt, + Digest, Felt, }; use super::{MissingFieldHelper, RpcConversionError}; diff --git a/crates/rust-client/src/rpc/domain/sync.rs b/crates/rust-client/src/rpc/domain/sync.rs index 7c5892cee..be26ec73b 100644 --- a/crates/rust-client/src/rpc/domain/sync.rs +++ b/crates/rust-client/src/rpc/domain/sync.rs @@ -1,8 +1,12 @@ use alloc::vec::Vec; use miden_objects::{ - accounts::AccountId, crypto::merkle::MmrDelta, notes::NoteId, transaction::TransactionId, - BlockHeader, Digest, + accounts::AccountId, + block::{BlockHeader, BlockNumber}, + crypto::merkle::MmrDelta, + notes::NoteId, + transaction::TransactionId, + Digest, }; use super::{notes::CommittedNote, nullifiers::NullifierUpdate, transactions::TransactionUpdate}; @@ -14,7 +18,7 @@ use crate::rpc::{generated::responses::SyncStateResponse, RpcError}; /// Represents a `SyncStateResponse` with fields converted into domain types. pub struct StateSyncInfo { /// The block number of the chain tip at the moment of the response. - pub chain_tip: u32, + pub chain_tip: BlockNumber, /// The returned block header. pub block_header: BlockHeader, /// MMR delta that contains data for (current_block.num, incoming_block_header.num-1). @@ -141,7 +145,7 @@ impl TryFrom for StateSyncInfo { .collect::, RpcError>>()?; Ok(Self { - chain_tip, + chain_tip: chain_tip.into(), block_header, mmr_delta, account_hash_updates, diff --git a/crates/rust-client/src/rpc/generated/nostd/account.rs b/crates/rust-client/src/rpc/generated/nostd/account.rs index 85760632c..a2683eb0d 100644 --- a/crates/rust-client/src/rpc/generated/nostd/account.rs +++ b/crates/rust-client/src/rpc/generated/nostd/account.rs @@ -1,28 +1,41 @@ // This file is @generated by prost-build. +/// Uniquely identifies a specific account. +/// +/// A Miden account ID is a 120-bit value derived from the commitments to account code and storage, +/// and a random user-provided seed. #[derive(Clone, PartialEq, ::prost::Message)] #[prost(skip_debug)] pub struct AccountId { - /// A Miden account ID is a 120-bit value derived from the commitments to account code and - /// storage, and a random user-provided seed. + /// 15 bytes (120 bits) encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::accounts::account_id::AccountId\]. #[prost(bytes = "vec", tag = "1")] pub id: ::prost::alloc::vec::Vec, } +/// The state of an account at a specific block height. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountSummary { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// The current account hash or zero if the account does not exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, + /// Block number at which the summary was made. #[prost(uint32, tag = "3")] pub block_num: u32, } +/// An account info. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountInfo { + /// Account summary. #[prost(message, optional, tag = "1")] pub summary: ::core::option::Option, + /// Account details encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::accounts::Account\]. #[prost(bytes = "vec", optional, tag = "2")] pub details: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// An account header. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct AccountHeader { /// Vault root hash. diff --git a/crates/rust-client/src/rpc/generated/nostd/block.rs b/crates/rust-client/src/rpc/generated/nostd/block.rs index 2c0898b1f..915dce7ec 100644 --- a/crates/rust-client/src/rpc/generated/nostd/block.rs +++ b/crates/rust-client/src/rpc/generated/nostd/block.rs @@ -1,44 +1,48 @@ // This file is @generated by prost-build. +/// Represents a block header. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct BlockHeader { - /// specifies the version of the protocol. + /// Specifies the version of the protocol. #[prost(uint32, tag = "1")] pub version: u32, - /// the hash of the previous blocks header. + /// The hash of the previous blocks header. #[prost(message, optional, tag = "2")] pub prev_hash: ::core::option::Option, - /// a unique sequential number of the current block. + /// A unique sequential number of the current block. #[prost(fixed32, tag = "3")] pub block_num: u32, - /// a commitment to an MMR of the entire chain where each block is a leaf. + /// A commitment to an MMR of the entire chain where each block is a leaf. #[prost(message, optional, tag = "4")] pub chain_root: ::core::option::Option, - /// a commitment to account database. + /// A commitment to account database. #[prost(message, optional, tag = "5")] pub account_root: ::core::option::Option, - /// a commitment to the nullifier database. + /// A commitment to the nullifier database. #[prost(message, optional, tag = "6")] pub nullifier_root: ::core::option::Option, - /// a commitment to all notes created in the current block. + /// A commitment to all notes created in the current block. #[prost(message, optional, tag = "7")] pub note_root: ::core::option::Option, - /// a commitment to a set of IDs of transactions which affected accounts in this block. + /// A commitment to a set of IDs of transactions which affected accounts in this block. #[prost(message, optional, tag = "8")] pub tx_hash: ::core::option::Option, - /// a hash of a STARK proof attesting to the correct state transition. + /// A hash of a STARK proof attesting to the correct state transition. #[prost(message, optional, tag = "9")] pub proof_hash: ::core::option::Option, - /// a commitment to all transaction kernels supported by this block. + /// A commitment to all transaction kernels supported by this block. #[prost(message, optional, tag = "10")] pub kernel_root: ::core::option::Option, - /// the time when the block was created. + /// The time when the block was created. #[prost(fixed32, tag = "11")] pub timestamp: u32, } +/// Represents a block inclusion proof. #[derive(Clone, PartialEq, ::prost::Message)] pub struct BlockInclusionProof { + /// Block header associated with the inclusion proof. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, + /// Merkle path associated with the inclusion proof. #[prost(message, optional, tag = "2")] pub mmr_path: ::core::option::Option, /// The chain length associated with `mmr_path`. diff --git a/crates/rust-client/src/rpc/generated/nostd/merkle.rs b/crates/rust-client/src/rpc/generated/nostd/merkle.rs index 0aed4fbdc..e5c4a657a 100644 --- a/crates/rust-client/src/rpc/generated/nostd/merkle.rs +++ b/crates/rust-client/src/rpc/generated/nostd/merkle.rs @@ -1,6 +1,8 @@ // This file is @generated by prost-build. +/// Represents a Merkle path. #[derive(Clone, PartialEq, ::prost::Message)] pub struct MerklePath { + /// List of sibling node hashes, in order from the root to the leaf. #[prost(message, repeated, tag = "1")] pub siblings: ::prost::alloc::vec::Vec, } diff --git a/crates/rust-client/src/rpc/generated/nostd/mmr.rs b/crates/rust-client/src/rpc/generated/nostd/mmr.rs index f53ebe2d3..ca5591f71 100644 --- a/crates/rust-client/src/rpc/generated/nostd/mmr.rs +++ b/crates/rust-client/src/rpc/generated/nostd/mmr.rs @@ -1,8 +1,11 @@ // This file is @generated by prost-build. +/// Represents an MMR delta. #[derive(Clone, PartialEq, ::prost::Message)] pub struct MmrDelta { + /// The number of leaf nodes in the MMR. #[prost(uint64, tag = "1")] pub forest: u64, + /// New and changed MMR peaks. #[prost(message, repeated, tag = "2")] pub data: ::prost::alloc::vec::Vec, } diff --git a/crates/rust-client/src/rpc/generated/nostd/note.rs b/crates/rust-client/src/rpc/generated/nostd/note.rs index 3768961d0..b64565915 100644 --- a/crates/rust-client/src/rpc/generated/nostd/note.rs +++ b/crates/rust-client/src/rpc/generated/nostd/note.rs @@ -1,56 +1,84 @@ // This file is @generated by prost-build. +/// Represents a note's metadata. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteMetadata { + /// The account which sent the note. #[prost(message, optional, tag = "1")] pub sender: ::core::option::Option, + /// The type of the note (0b01 = public, 0b10 = private, 0b11 = encrypted). #[prost(uint32, tag = "2")] pub note_type: u32, + /// A value which can be used by the recipient(s) to identify notes intended for them. + /// + /// See `miden_objects::notes::note_tag` for more info. #[prost(fixed32, tag = "3")] pub tag: u32, + /// Specifies when a note is ready to be consumed. + /// + /// See `miden_objects::notes::execution_hint` for more info. #[prost(fixed64, tag = "4")] pub execution_hint: u64, + /// An arbitrary user-defined value. #[prost(fixed64, tag = "5")] pub aux: u64, } +/// Represents a note. #[derive(Clone, PartialEq, ::prost::Message)] pub struct Note { + /// The block number in which the note was created. #[prost(fixed32, tag = "1")] pub block_num: u32, + /// The index of the note in the block. #[prost(uint32, tag = "2")] pub note_index: u32, + /// The ID of the note. #[prost(message, optional, tag = "3")] pub note_id: ::core::option::Option, + /// The note's metadata. #[prost(message, optional, tag = "4")] pub metadata: ::core::option::Option, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "5")] pub merkle_path: ::core::option::Option, - /// This field will be present when the note is public. - /// details contain the `Note` in a serialized format. + /// Serialized details of the public note (empty for private notes). #[prost(bytes = "vec", optional, tag = "6")] pub details: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents a proof of note's inclusion in a block. +/// +/// Does not include proof of the block's inclusion in the chain. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteInclusionInBlockProof { + /// A unique identifier of the note which is a 32-byte commitment to the underlying note data. #[prost(message, optional, tag = "1")] pub note_id: ::core::option::Option, + /// The block number in which the note was created. #[prost(fixed32, tag = "2")] pub block_num: u32, + /// The index of the note in the block. #[prost(uint32, tag = "3")] pub note_index_in_block: u32, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "4")] pub merkle_path: ::core::option::Option, } +/// Represents proof of a note inclusion in the block. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteSyncRecord { + /// The index of the note. #[prost(uint32, tag = "1")] pub note_index: u32, + /// A unique identifier of the note which is a 32-byte commitment to the underlying note data. #[prost(message, optional, tag = "2")] pub note_id: ::core::option::Option, + /// The note's metadata. #[prost(message, optional, tag = "3")] pub metadata: ::core::option::Option, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "4")] pub merkle_path: ::core::option::Option, } +/// Represents proof of notes inclusion in the block(s) and block(s) inclusion in the chain. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteAuthenticationInfo { /// Proof of each note's inclusion in a block. diff --git a/crates/rust-client/src/rpc/generated/nostd/requests.rs b/crates/rust-client/src/rpc/generated/nostd/requests.rs index b28e0e3cf..6cdccab33 100644 --- a/crates/rust-client/src/rpc/generated/nostd/requests.rs +++ b/crates/rust-client/src/rpc/generated/nostd/requests.rs @@ -1,6 +1,9 @@ // This file is @generated by prost-build. +/// Applies changes of a new block to the DB and in-memory data structures. #[derive(Clone, PartialEq, ::prost::Message)] pub struct ApplyBlockRequest { + /// Block data encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::block::Block\]. #[prost(bytes = "vec", tag = "1")] pub block: ::prost::alloc::vec::Vec, } @@ -11,12 +14,14 @@ pub struct CheckNullifiersByPrefixRequest { #[prost(uint32, tag = "1")] pub prefix_len: u32, /// List of nullifiers to check. Each nullifier is specified by its prefix with length equal - /// to prefix_len + /// to `prefix_len`. #[prost(uint32, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Get a list of proofs for given nullifier hashes, each proof as a sparse Merkle Tree. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersRequest { + /// List of nullifiers to return proofs for. #[prost(message, repeated, tag = "1")] pub nullifiers: ::prost::alloc::vec::Vec, } @@ -26,9 +31,7 @@ pub struct CheckNullifiersRequest { /// The Merkle path is an MMR proof for the block's leaf, based on the current chain length. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct GetBlockHeaderByNumberRequest { - /// The block number of the target block. - /// - /// If not provided, means latest known block. + /// The target block height, defaults to latest if not provided. #[prost(uint32, optional, tag = "1")] pub block_num: ::core::option::Option, /// Whether or not to return authentication data for the block header. @@ -76,42 +79,54 @@ pub struct SyncNoteRequest { #[prost(fixed32, repeated, tag = "2")] pub note_tags: ::prost::alloc::vec::Vec, } +/// Returns data required to prove the next block. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockInputsRequest { /// ID of the account against which a transaction is executed. #[prost(message, repeated, tag = "1")] pub account_ids: ::prost::alloc::vec::Vec, - /// Array of nullifiers for all notes consumed by a transaction. + /// Set of nullifiers consumed by this transaction. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, /// Array of note IDs to be checked for existence in the database. #[prost(message, repeated, tag = "3")] pub unauthenticated_notes: ::prost::alloc::vec::Vec, } +/// Returns data required to validate a new transaction. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTransactionInputsRequest { + /// ID of the account against which a transaction is executed. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// Set of nullifiers consumed by this transaction. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, + /// Set of unauthenticated notes to check for existence on-chain. + /// + /// These are notes which were not on-chain at the state the transaction was proven, + /// but could by now be present. #[prost(message, repeated, tag = "3")] pub unauthenticated_notes: ::prost::alloc::vec::Vec, } +/// Submits proven transaction to the Miden network. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubmitProvenTransactionRequest { - /// Transaction encoded using miden's native format + /// Transaction encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::transaction::proven_tx::ProvenTransaction\]. #[prost(bytes = "vec", tag = "1")] pub transaction: ::prost::alloc::vec::Vec, } +/// Returns a list of notes matching the provided note IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNotesByIdRequest { - /// List of NoteId's to be queried from the database + /// List of notes to be queried from the database. #[prost(message, repeated, tag = "1")] pub note_ids: ::prost::alloc::vec::Vec, } +/// Returns a list of Note inclusion proofs for the specified Note IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNoteAuthenticationInfoRequest { - /// List of NoteId's to be queried from the database + /// List of notes to be queried from the database. #[prost(message, repeated, tag = "1")] pub note_ids: ::prost::alloc::vec::Vec, } @@ -122,6 +137,7 @@ pub struct GetAccountDetailsRequest { #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, } +/// Retrieves block data by given block number. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct GetBlockByNumberRequest { /// The block number of the target block. @@ -142,7 +158,7 @@ pub struct GetAccountStateDeltaRequest { #[prost(fixed32, tag = "3")] pub to_block_num: u32, } -/// Request message to get account proofs. +/// Returns the latest state proofs of the specified accounts. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountProofsRequest { /// A list of account requests, including map keys + values. diff --git a/crates/rust-client/src/rpc/generated/nostd/responses.rs b/crates/rust-client/src/rpc/generated/nostd/responses.rs index 46ce0cd3d..ee222ce8e 100644 --- a/crates/rust-client/src/rpc/generated/nostd/responses.rs +++ b/crates/rust-client/src/rpc/generated/nostd/responses.rs @@ -1,68 +1,77 @@ // This file is @generated by prost-build. +/// Represents the result of applying a block. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct ApplyBlockResponse {} +/// Represents the result of checking nullifiers. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersResponse { /// Each requested nullifier has its corresponding nullifier proof at the same position. #[prost(message, repeated, tag = "1")] pub proofs: ::prost::alloc::vec::Vec, } +/// Represents the result of checking nullifiers by prefix. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersByPrefixResponse { /// List of nullifiers matching the prefixes specified in the request. #[prost(message, repeated, tag = "1")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Represents the result of getting a block header by block number. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockHeaderByNumberResponse { - /// The requested block header + /// The requested block header. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, - /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_length` + /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_length`. #[prost(message, optional, tag = "2")] pub mmr_path: ::core::option::Option, - /// Current chain length + /// Current chain length. #[prost(fixed32, optional, tag = "3")] pub chain_length: ::core::option::Option, } +/// Represents a single nullifier update. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct NullifierUpdate { + /// Nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, + /// Block number. #[prost(fixed32, tag = "2")] pub block_num: u32, } +/// Represents the result of syncing state request. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SyncStateResponse { - /// Number of the latest block in the chain + /// Number of the latest block in the chain. #[prost(fixed32, tag = "1")] pub chain_tip: u32, - /// Block header of the block with the first note matching the specified criteria + /// Block header of the block with the first note matching the specified criteria. #[prost(message, optional, tag = "2")] pub block_header: ::core::option::Option, - /// Data needed to update the partial MMR from `request.block_num + 1` to `response.block_header.block_num` + /// Data needed to update the partial MMR from `request.block_num + 1` to `response.block_header.block_num`. #[prost(message, optional, tag = "3")] pub mmr_delta: ::core::option::Option, - /// List of account hashes updated after `request.block_num + 1` but not after `response.block_header.block_num` + /// List of account hashes updated after `request.block_num + 1` but not after `response.block_header.block_num`. #[prost(message, repeated, tag = "5")] pub accounts: ::prost::alloc::vec::Vec, /// List of transactions executed against requested accounts between `request.block_num + 1` and - /// `response.block_header.block_num` + /// `response.block_header.block_num`. #[prost(message, repeated, tag = "6")] pub transactions: ::prost::alloc::vec::Vec, - /// List of all notes together with the Merkle paths from `response.block_header.note_root` + /// List of all notes together with the Merkle paths from `response.block_header.note_root`. #[prost(message, repeated, tag = "7")] pub notes: ::prost::alloc::vec::Vec, - /// List of nullifiers created between `request.block_num + 1` and `response.block_header.block_num` + /// List of nullifiers created between `request.block_num + 1` and `response.block_header.block_num`. #[prost(message, repeated, tag = "8")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Represents the result of syncing notes request. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SyncNoteResponse { - /// Number of the latest block in the chain + /// Number of the latest block in the chain. #[prost(fixed32, tag = "1")] pub chain_tip: u32, - /// Block header of the block with the first note matching the specified criteria + /// Block header of the block with the first note matching the specified criteria. #[prost(message, optional, tag = "2")] pub block_header: ::core::option::Option, /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_tip`. @@ -71,112 +80,135 @@ pub struct SyncNoteResponse { /// an MMR of forest `chain_tip` with this path. #[prost(message, optional, tag = "3")] pub mmr_path: ::core::option::Option, - /// List of all notes together with the Merkle paths from `response.block_header.note_root` + /// List of all notes together with the Merkle paths from `response.block_header.note_root`. #[prost(message, repeated, tag = "4")] pub notes: ::prost::alloc::vec::Vec, } -/// An account returned as a response to the GetBlockInputs +/// An account returned as a response to the `GetBlockInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountBlockInputRecord { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// The latest account hash, zero hash if the account doesn't exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, + /// Merkle path to verify the account's inclusion in the MMR. #[prost(message, optional, tag = "3")] pub proof: ::core::option::Option, } -/// A nullifier returned as a response to the GetBlockInputs +/// A nullifier returned as a response to the `GetBlockInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NullifierBlockInputRecord { + /// The nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, + /// Merkle path to verify the nullifier's inclusion in the MMR. #[prost(message, optional, tag = "2")] pub opening: ::core::option::Option, } +/// Represents the result of getting block inputs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockInputsResponse { - /// The latest block header + /// The latest block header. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, - /// Peaks of the above block's mmr, The `forest` value is equal to the block number + /// Peaks of the above block's mmr, The `forest` value is equal to the block number. #[prost(message, repeated, tag = "2")] pub mmr_peaks: ::prost::alloc::vec::Vec, - /// The hashes of the requested accounts and their authentication paths + /// The hashes of the requested accounts and their authentication paths. #[prost(message, repeated, tag = "3")] pub account_states: ::prost::alloc::vec::Vec, - /// The requested nullifiers and their authentication paths + /// The requested nullifiers and their authentication paths. #[prost(message, repeated, tag = "4")] pub nullifiers: ::prost::alloc::vec::Vec, - /// The list of requested notes which were found in the database + /// The list of requested notes which were found in the database. #[prost(message, optional, tag = "5")] pub found_unauthenticated_notes: ::core::option::Option< super::note::NoteAuthenticationInfo, >, } -/// An account returned as a response to the GetTransactionInputs +/// An account returned as a response to the `GetTransactionInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountTransactionInputRecord { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, /// The latest account hash, zero hash if the account doesn't exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, } -/// A nullifier returned as a response to the GetTransactionInputs +/// A nullifier returned as a response to the `GetTransactionInputs`. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct NullifierTransactionInputRecord { + /// The nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, /// The block at which the nullifier has been consumed, zero if not consumed. #[prost(fixed32, tag = "2")] pub block_num: u32, } +/// Represents the result of getting transaction inputs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTransactionInputsResponse { + /// Account state proof. #[prost(message, optional, tag = "1")] pub account_state: ::core::option::Option, + /// List of nullifiers that have been consumed. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, + /// List of unauthenticated notes that were not found in the database. #[prost(message, repeated, tag = "3")] pub found_unauthenticated_notes: ::prost::alloc::vec::Vec, + /// The node's current block height. #[prost(fixed32, tag = "4")] pub block_height: u32, } +/// Represents the result of submitting proven transaction. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct SubmitProvenTransactionResponse { - /// The node's current block height + /// The node's current block height. #[prost(fixed32, tag = "1")] pub block_height: u32, } +/// Represents the result of getting notes by IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNotesByIdResponse { - /// Lists Note's returned by the database + /// Lists Note's returned by the database. #[prost(message, repeated, tag = "1")] pub notes: ::prost::alloc::vec::Vec, } +/// Represents the result of getting note authentication info. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNoteAuthenticationInfoResponse { + /// Proofs of note inclusions in blocks and block inclusions in chain. #[prost(message, optional, tag = "1")] pub proofs: ::core::option::Option, } +/// Represents the result of getting account details. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountDetailsResponse { - /// Account info (with details for public accounts) + /// Account info (with details for public accounts). #[prost(message, optional, tag = "1")] pub details: ::core::option::Option, } +/// Represents the result of getting block by number. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockByNumberResponse { - /// The requested `Block` data encoded using miden native format + /// The requested block data encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::block::Block\]. #[prost(bytes = "vec", optional, tag = "1")] pub block: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents the result of getting account state delta. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountStateDeltaResponse { - /// The calculated `AccountStateDelta` encoded using miden native format + /// The calculated account delta encoded using \[winter_utils::Serializable\] implementation + /// for \[miden_objects::accounts::delta::AccountDelta\]. #[prost(bytes = "vec", optional, tag = "1")] pub delta: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents the result of getting account proofs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountProofsResponse { /// Block number at which the state of the account was returned. @@ -186,6 +218,7 @@ pub struct GetAccountProofsResponse { #[prost(message, repeated, tag = "2")] pub account_proofs: ::prost::alloc::vec::Vec, } +/// A single account proof returned as a response to the `GetAccountProofs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountProofsResponse { /// Account ID. @@ -201,6 +234,7 @@ pub struct AccountProofsResponse { #[prost(message, optional, tag = "4")] pub state_header: ::core::option::Option, } +/// State header for public accounts. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountStateHeader { /// Account header. diff --git a/crates/rust-client/src/rpc/generated/nostd/rpc.rs b/crates/rust-client/src/rpc/generated/nostd/rpc.rs index 21b35825f..ef7d29203 100644 --- a/crates/rust-client/src/rpc/generated/nostd/rpc.rs +++ b/crates/rust-client/src/rpc/generated/nostd/rpc.rs @@ -79,6 +79,7 @@ pub mod api_client { self.inner = self.inner.max_encoding_message_size(limit); self } + /// Gets a list of proofs for given nullifier hashes, each proof as a sparse Merkle Tree. pub async fn check_nullifiers( &mut self, request: impl tonic::IntoRequest< @@ -102,6 +103,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "CheckNullifiers")); self.inner.unary(req, path, codec).await } + /// Returns a list of nullifiers that match the specified prefixes and are recorded in the node. pub async fn check_nullifiers_by_prefix( &mut self, request: impl tonic::IntoRequest< @@ -128,6 +130,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "CheckNullifiersByPrefix")); self.inner.unary(req, path, codec).await } + /// Returns the latest state of an account with the specified ID. pub async fn get_account_details( &mut self, request: impl tonic::IntoRequest< @@ -153,6 +156,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetAccountDetails")); self.inner.unary(req, path, codec).await } + /// Returns the latest state proofs of the specified accounts. pub async fn get_account_proofs( &mut self, request: impl tonic::IntoRequest< @@ -176,6 +180,8 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetAccountProofs")); self.inner.unary(req, path, codec).await } + /// Returns delta of the account states in the range from `from_block_num` (exclusive) to + /// `to_block_num` (inclusive). pub async fn get_account_state_delta( &mut self, request: impl tonic::IntoRequest< @@ -202,6 +208,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "GetAccountStateDelta")); self.inner.unary(req, path, codec).await } + /// Retrieves block data by given block number. pub async fn get_block_by_number( &mut self, request: impl tonic::IntoRequest< @@ -225,6 +232,8 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetBlockByNumber")); self.inner.unary(req, path, codec).await } + /// Retrieves block header by given block number. Optionally, it also returns the MMR path + /// and current chain length to authenticate the block's inclusion. pub async fn get_block_header_by_number( &mut self, request: impl tonic::IntoRequest< @@ -251,6 +260,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "GetBlockHeaderByNumber")); self.inner.unary(req, path, codec).await } + /// Returns a list of notes matching the provided note IDs. pub async fn get_notes_by_id( &mut self, request: impl tonic::IntoRequest, @@ -272,6 +282,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetNotesById")); self.inner.unary(req, path, codec).await } + /// Submits proven transaction to the Miden network. pub async fn submit_proven_transaction( &mut self, request: impl tonic::IntoRequest< @@ -298,6 +309,10 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "SubmitProvenTransaction")); self.inner.unary(req, path, codec).await } + /// Note synchronization request. + /// + /// Specifies note tags that client is interested in. The server will return the first block which + /// contains a note matching `note_tags` or the chain tip. pub async fn sync_notes( &mut self, request: impl tonic::IntoRequest, @@ -319,6 +334,21 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "SyncNotes")); self.inner.unary(req, path, codec).await } + /// Returns info which can be used by the client to sync up to the latest state of the chain + /// for the objects (accounts, notes, nullifiers) the client is interested in. + /// + /// This request returns the next block containing requested data. It also returns `chain_tip` + /// which is the latest block number in the chain. Client is expected to repeat these requests + /// in a loop until `response.block_header.block_num == response.chain_tip`, at which point + /// the client is fully synchronized with the chain. + /// + /// Each request also returns info about new notes, nullifiers etc. created. It also returns + /// Chain MMR delta that can be used to update the state of Chain MMR. This includes both chain + /// MMR peaks and chain MMR nodes. + /// + /// For preserving some degree of privacy, note tags and nullifiers filters contain only high + /// part of hashes. Thus, returned data contains excessive notes and nullifiers, client can make + /// additional filtering of that data on its side. pub async fn sync_state( &mut self, request: impl tonic::IntoRequest, diff --git a/crates/rust-client/src/rpc/generated/nostd/smt.rs b/crates/rust-client/src/rpc/generated/nostd/smt.rs index c4aaf2d77..90e9394d3 100644 --- a/crates/rust-client/src/rpc/generated/nostd/smt.rs +++ b/crates/rust-client/src/rpc/generated/nostd/smt.rs @@ -1,14 +1,18 @@ // This file is @generated by prost-build. -/// An entry in a leaf. +/// Represents a single SMT leaf entry. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct SmtLeafEntry { + /// The key of the entry. #[prost(message, optional, tag = "1")] pub key: ::core::option::Option, + /// The value of the entry. #[prost(message, optional, tag = "2")] pub value: ::core::option::Option, } +/// Represents multiple leaf entries in an SMT. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SmtLeafEntries { + /// The entries list. #[prost(message, repeated, tag = "1")] pub entries: ::prost::alloc::vec::Vec, } @@ -22,10 +26,13 @@ pub struct SmtLeaf { pub mod smt_leaf { #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum Leaf { + /// An empty leaf. #[prost(uint64, tag = "1")] Empty(u64), + /// A single leaf entry. #[prost(message, tag = "2")] Single(super::SmtLeafEntry), + /// Multiple leaf entries. #[prost(message, tag = "3")] Multiple(super::SmtLeafEntries), } @@ -33,8 +40,10 @@ pub mod smt_leaf { /// The opening of a leaf in an SMT. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SmtOpening { + /// The merkle path to the leaf. #[prost(message, optional, tag = "1")] pub path: ::core::option::Option, + /// The leaf itself. #[prost(message, optional, tag = "2")] pub leaf: ::core::option::Option, } diff --git a/crates/rust-client/src/rpc/generated/nostd/transaction.rs b/crates/rust-client/src/rpc/generated/nostd/transaction.rs index 7dca33a33..3439e78ea 100644 --- a/crates/rust-client/src/rpc/generated/nostd/transaction.rs +++ b/crates/rust-client/src/rpc/generated/nostd/transaction.rs @@ -1,15 +1,21 @@ // This file is @generated by prost-build. +/// Represents a transaction ID. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct TransactionId { + /// The transaction ID. #[prost(message, optional, tag = "1")] pub id: ::core::option::Option, } +/// Represents a transaction summary. #[derive(Clone, PartialEq, ::prost::Message)] pub struct TransactionSummary { + /// A unique 32-byte identifier of a transaction. #[prost(message, optional, tag = "1")] pub transaction_id: ::core::option::Option, + /// The block number in which the transaction was executed. #[prost(fixed32, tag = "2")] pub block_num: u32, + /// The ID of the account affected by the transaction. #[prost(message, optional, tag = "3")] pub account_id: ::core::option::Option, } diff --git a/crates/rust-client/src/rpc/generated/std/account.rs b/crates/rust-client/src/rpc/generated/std/account.rs index 85760632c..a2683eb0d 100644 --- a/crates/rust-client/src/rpc/generated/std/account.rs +++ b/crates/rust-client/src/rpc/generated/std/account.rs @@ -1,28 +1,41 @@ // This file is @generated by prost-build. +/// Uniquely identifies a specific account. +/// +/// A Miden account ID is a 120-bit value derived from the commitments to account code and storage, +/// and a random user-provided seed. #[derive(Clone, PartialEq, ::prost::Message)] #[prost(skip_debug)] pub struct AccountId { - /// A Miden account ID is a 120-bit value derived from the commitments to account code and - /// storage, and a random user-provided seed. + /// 15 bytes (120 bits) encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::accounts::account_id::AccountId\]. #[prost(bytes = "vec", tag = "1")] pub id: ::prost::alloc::vec::Vec, } +/// The state of an account at a specific block height. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountSummary { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// The current account hash or zero if the account does not exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, + /// Block number at which the summary was made. #[prost(uint32, tag = "3")] pub block_num: u32, } +/// An account info. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountInfo { + /// Account summary. #[prost(message, optional, tag = "1")] pub summary: ::core::option::Option, + /// Account details encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::accounts::Account\]. #[prost(bytes = "vec", optional, tag = "2")] pub details: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// An account header. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct AccountHeader { /// Vault root hash. diff --git a/crates/rust-client/src/rpc/generated/std/block.rs b/crates/rust-client/src/rpc/generated/std/block.rs index 2c0898b1f..915dce7ec 100644 --- a/crates/rust-client/src/rpc/generated/std/block.rs +++ b/crates/rust-client/src/rpc/generated/std/block.rs @@ -1,44 +1,48 @@ // This file is @generated by prost-build. +/// Represents a block header. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct BlockHeader { - /// specifies the version of the protocol. + /// Specifies the version of the protocol. #[prost(uint32, tag = "1")] pub version: u32, - /// the hash of the previous blocks header. + /// The hash of the previous blocks header. #[prost(message, optional, tag = "2")] pub prev_hash: ::core::option::Option, - /// a unique sequential number of the current block. + /// A unique sequential number of the current block. #[prost(fixed32, tag = "3")] pub block_num: u32, - /// a commitment to an MMR of the entire chain where each block is a leaf. + /// A commitment to an MMR of the entire chain where each block is a leaf. #[prost(message, optional, tag = "4")] pub chain_root: ::core::option::Option, - /// a commitment to account database. + /// A commitment to account database. #[prost(message, optional, tag = "5")] pub account_root: ::core::option::Option, - /// a commitment to the nullifier database. + /// A commitment to the nullifier database. #[prost(message, optional, tag = "6")] pub nullifier_root: ::core::option::Option, - /// a commitment to all notes created in the current block. + /// A commitment to all notes created in the current block. #[prost(message, optional, tag = "7")] pub note_root: ::core::option::Option, - /// a commitment to a set of IDs of transactions which affected accounts in this block. + /// A commitment to a set of IDs of transactions which affected accounts in this block. #[prost(message, optional, tag = "8")] pub tx_hash: ::core::option::Option, - /// a hash of a STARK proof attesting to the correct state transition. + /// A hash of a STARK proof attesting to the correct state transition. #[prost(message, optional, tag = "9")] pub proof_hash: ::core::option::Option, - /// a commitment to all transaction kernels supported by this block. + /// A commitment to all transaction kernels supported by this block. #[prost(message, optional, tag = "10")] pub kernel_root: ::core::option::Option, - /// the time when the block was created. + /// The time when the block was created. #[prost(fixed32, tag = "11")] pub timestamp: u32, } +/// Represents a block inclusion proof. #[derive(Clone, PartialEq, ::prost::Message)] pub struct BlockInclusionProof { + /// Block header associated with the inclusion proof. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, + /// Merkle path associated with the inclusion proof. #[prost(message, optional, tag = "2")] pub mmr_path: ::core::option::Option, /// The chain length associated with `mmr_path`. diff --git a/crates/rust-client/src/rpc/generated/std/merkle.rs b/crates/rust-client/src/rpc/generated/std/merkle.rs index 0aed4fbdc..e5c4a657a 100644 --- a/crates/rust-client/src/rpc/generated/std/merkle.rs +++ b/crates/rust-client/src/rpc/generated/std/merkle.rs @@ -1,6 +1,8 @@ // This file is @generated by prost-build. +/// Represents a Merkle path. #[derive(Clone, PartialEq, ::prost::Message)] pub struct MerklePath { + /// List of sibling node hashes, in order from the root to the leaf. #[prost(message, repeated, tag = "1")] pub siblings: ::prost::alloc::vec::Vec, } diff --git a/crates/rust-client/src/rpc/generated/std/mmr.rs b/crates/rust-client/src/rpc/generated/std/mmr.rs index f53ebe2d3..ca5591f71 100644 --- a/crates/rust-client/src/rpc/generated/std/mmr.rs +++ b/crates/rust-client/src/rpc/generated/std/mmr.rs @@ -1,8 +1,11 @@ // This file is @generated by prost-build. +/// Represents an MMR delta. #[derive(Clone, PartialEq, ::prost::Message)] pub struct MmrDelta { + /// The number of leaf nodes in the MMR. #[prost(uint64, tag = "1")] pub forest: u64, + /// New and changed MMR peaks. #[prost(message, repeated, tag = "2")] pub data: ::prost::alloc::vec::Vec, } diff --git a/crates/rust-client/src/rpc/generated/std/note.rs b/crates/rust-client/src/rpc/generated/std/note.rs index 3768961d0..b64565915 100644 --- a/crates/rust-client/src/rpc/generated/std/note.rs +++ b/crates/rust-client/src/rpc/generated/std/note.rs @@ -1,56 +1,84 @@ // This file is @generated by prost-build. +/// Represents a note's metadata. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteMetadata { + /// The account which sent the note. #[prost(message, optional, tag = "1")] pub sender: ::core::option::Option, + /// The type of the note (0b01 = public, 0b10 = private, 0b11 = encrypted). #[prost(uint32, tag = "2")] pub note_type: u32, + /// A value which can be used by the recipient(s) to identify notes intended for them. + /// + /// See `miden_objects::notes::note_tag` for more info. #[prost(fixed32, tag = "3")] pub tag: u32, + /// Specifies when a note is ready to be consumed. + /// + /// See `miden_objects::notes::execution_hint` for more info. #[prost(fixed64, tag = "4")] pub execution_hint: u64, + /// An arbitrary user-defined value. #[prost(fixed64, tag = "5")] pub aux: u64, } +/// Represents a note. #[derive(Clone, PartialEq, ::prost::Message)] pub struct Note { + /// The block number in which the note was created. #[prost(fixed32, tag = "1")] pub block_num: u32, + /// The index of the note in the block. #[prost(uint32, tag = "2")] pub note_index: u32, + /// The ID of the note. #[prost(message, optional, tag = "3")] pub note_id: ::core::option::Option, + /// The note's metadata. #[prost(message, optional, tag = "4")] pub metadata: ::core::option::Option, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "5")] pub merkle_path: ::core::option::Option, - /// This field will be present when the note is public. - /// details contain the `Note` in a serialized format. + /// Serialized details of the public note (empty for private notes). #[prost(bytes = "vec", optional, tag = "6")] pub details: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents a proof of note's inclusion in a block. +/// +/// Does not include proof of the block's inclusion in the chain. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteInclusionInBlockProof { + /// A unique identifier of the note which is a 32-byte commitment to the underlying note data. #[prost(message, optional, tag = "1")] pub note_id: ::core::option::Option, + /// The block number in which the note was created. #[prost(fixed32, tag = "2")] pub block_num: u32, + /// The index of the note in the block. #[prost(uint32, tag = "3")] pub note_index_in_block: u32, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "4")] pub merkle_path: ::core::option::Option, } +/// Represents proof of a note inclusion in the block. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteSyncRecord { + /// The index of the note. #[prost(uint32, tag = "1")] pub note_index: u32, + /// A unique identifier of the note which is a 32-byte commitment to the underlying note data. #[prost(message, optional, tag = "2")] pub note_id: ::core::option::Option, + /// The note's metadata. #[prost(message, optional, tag = "3")] pub metadata: ::core::option::Option, + /// The note's inclusion proof in the block. #[prost(message, optional, tag = "4")] pub merkle_path: ::core::option::Option, } +/// Represents proof of notes inclusion in the block(s) and block(s) inclusion in the chain. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NoteAuthenticationInfo { /// Proof of each note's inclusion in a block. diff --git a/crates/rust-client/src/rpc/generated/std/requests.rs b/crates/rust-client/src/rpc/generated/std/requests.rs index b28e0e3cf..6cdccab33 100644 --- a/crates/rust-client/src/rpc/generated/std/requests.rs +++ b/crates/rust-client/src/rpc/generated/std/requests.rs @@ -1,6 +1,9 @@ // This file is @generated by prost-build. +/// Applies changes of a new block to the DB and in-memory data structures. #[derive(Clone, PartialEq, ::prost::Message)] pub struct ApplyBlockRequest { + /// Block data encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::block::Block\]. #[prost(bytes = "vec", tag = "1")] pub block: ::prost::alloc::vec::Vec, } @@ -11,12 +14,14 @@ pub struct CheckNullifiersByPrefixRequest { #[prost(uint32, tag = "1")] pub prefix_len: u32, /// List of nullifiers to check. Each nullifier is specified by its prefix with length equal - /// to prefix_len + /// to `prefix_len`. #[prost(uint32, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Get a list of proofs for given nullifier hashes, each proof as a sparse Merkle Tree. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersRequest { + /// List of nullifiers to return proofs for. #[prost(message, repeated, tag = "1")] pub nullifiers: ::prost::alloc::vec::Vec, } @@ -26,9 +31,7 @@ pub struct CheckNullifiersRequest { /// The Merkle path is an MMR proof for the block's leaf, based on the current chain length. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct GetBlockHeaderByNumberRequest { - /// The block number of the target block. - /// - /// If not provided, means latest known block. + /// The target block height, defaults to latest if not provided. #[prost(uint32, optional, tag = "1")] pub block_num: ::core::option::Option, /// Whether or not to return authentication data for the block header. @@ -76,42 +79,54 @@ pub struct SyncNoteRequest { #[prost(fixed32, repeated, tag = "2")] pub note_tags: ::prost::alloc::vec::Vec, } +/// Returns data required to prove the next block. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockInputsRequest { /// ID of the account against which a transaction is executed. #[prost(message, repeated, tag = "1")] pub account_ids: ::prost::alloc::vec::Vec, - /// Array of nullifiers for all notes consumed by a transaction. + /// Set of nullifiers consumed by this transaction. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, /// Array of note IDs to be checked for existence in the database. #[prost(message, repeated, tag = "3")] pub unauthenticated_notes: ::prost::alloc::vec::Vec, } +/// Returns data required to validate a new transaction. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTransactionInputsRequest { + /// ID of the account against which a transaction is executed. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// Set of nullifiers consumed by this transaction. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, + /// Set of unauthenticated notes to check for existence on-chain. + /// + /// These are notes which were not on-chain at the state the transaction was proven, + /// but could by now be present. #[prost(message, repeated, tag = "3")] pub unauthenticated_notes: ::prost::alloc::vec::Vec, } +/// Submits proven transaction to the Miden network. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubmitProvenTransactionRequest { - /// Transaction encoded using miden's native format + /// Transaction encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::transaction::proven_tx::ProvenTransaction\]. #[prost(bytes = "vec", tag = "1")] pub transaction: ::prost::alloc::vec::Vec, } +/// Returns a list of notes matching the provided note IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNotesByIdRequest { - /// List of NoteId's to be queried from the database + /// List of notes to be queried from the database. #[prost(message, repeated, tag = "1")] pub note_ids: ::prost::alloc::vec::Vec, } +/// Returns a list of Note inclusion proofs for the specified Note IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNoteAuthenticationInfoRequest { - /// List of NoteId's to be queried from the database + /// List of notes to be queried from the database. #[prost(message, repeated, tag = "1")] pub note_ids: ::prost::alloc::vec::Vec, } @@ -122,6 +137,7 @@ pub struct GetAccountDetailsRequest { #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, } +/// Retrieves block data by given block number. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct GetBlockByNumberRequest { /// The block number of the target block. @@ -142,7 +158,7 @@ pub struct GetAccountStateDeltaRequest { #[prost(fixed32, tag = "3")] pub to_block_num: u32, } -/// Request message to get account proofs. +/// Returns the latest state proofs of the specified accounts. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountProofsRequest { /// A list of account requests, including map keys + values. diff --git a/crates/rust-client/src/rpc/generated/std/responses.rs b/crates/rust-client/src/rpc/generated/std/responses.rs index 46ce0cd3d..ee222ce8e 100644 --- a/crates/rust-client/src/rpc/generated/std/responses.rs +++ b/crates/rust-client/src/rpc/generated/std/responses.rs @@ -1,68 +1,77 @@ // This file is @generated by prost-build. +/// Represents the result of applying a block. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct ApplyBlockResponse {} +/// Represents the result of checking nullifiers. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersResponse { /// Each requested nullifier has its corresponding nullifier proof at the same position. #[prost(message, repeated, tag = "1")] pub proofs: ::prost::alloc::vec::Vec, } +/// Represents the result of checking nullifiers by prefix. #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersByPrefixResponse { /// List of nullifiers matching the prefixes specified in the request. #[prost(message, repeated, tag = "1")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Represents the result of getting a block header by block number. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockHeaderByNumberResponse { - /// The requested block header + /// The requested block header. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, - /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_length` + /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_length`. #[prost(message, optional, tag = "2")] pub mmr_path: ::core::option::Option, - /// Current chain length + /// Current chain length. #[prost(fixed32, optional, tag = "3")] pub chain_length: ::core::option::Option, } +/// Represents a single nullifier update. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct NullifierUpdate { + /// Nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, + /// Block number. #[prost(fixed32, tag = "2")] pub block_num: u32, } +/// Represents the result of syncing state request. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SyncStateResponse { - /// Number of the latest block in the chain + /// Number of the latest block in the chain. #[prost(fixed32, tag = "1")] pub chain_tip: u32, - /// Block header of the block with the first note matching the specified criteria + /// Block header of the block with the first note matching the specified criteria. #[prost(message, optional, tag = "2")] pub block_header: ::core::option::Option, - /// Data needed to update the partial MMR from `request.block_num + 1` to `response.block_header.block_num` + /// Data needed to update the partial MMR from `request.block_num + 1` to `response.block_header.block_num`. #[prost(message, optional, tag = "3")] pub mmr_delta: ::core::option::Option, - /// List of account hashes updated after `request.block_num + 1` but not after `response.block_header.block_num` + /// List of account hashes updated after `request.block_num + 1` but not after `response.block_header.block_num`. #[prost(message, repeated, tag = "5")] pub accounts: ::prost::alloc::vec::Vec, /// List of transactions executed against requested accounts between `request.block_num + 1` and - /// `response.block_header.block_num` + /// `response.block_header.block_num`. #[prost(message, repeated, tag = "6")] pub transactions: ::prost::alloc::vec::Vec, - /// List of all notes together with the Merkle paths from `response.block_header.note_root` + /// List of all notes together with the Merkle paths from `response.block_header.note_root`. #[prost(message, repeated, tag = "7")] pub notes: ::prost::alloc::vec::Vec, - /// List of nullifiers created between `request.block_num + 1` and `response.block_header.block_num` + /// List of nullifiers created between `request.block_num + 1` and `response.block_header.block_num`. #[prost(message, repeated, tag = "8")] pub nullifiers: ::prost::alloc::vec::Vec, } +/// Represents the result of syncing notes request. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SyncNoteResponse { - /// Number of the latest block in the chain + /// Number of the latest block in the chain. #[prost(fixed32, tag = "1")] pub chain_tip: u32, - /// Block header of the block with the first note matching the specified criteria + /// Block header of the block with the first note matching the specified criteria. #[prost(message, optional, tag = "2")] pub block_header: ::core::option::Option, /// Merkle path to verify the block's inclusion in the MMR at the returned `chain_tip`. @@ -71,112 +80,135 @@ pub struct SyncNoteResponse { /// an MMR of forest `chain_tip` with this path. #[prost(message, optional, tag = "3")] pub mmr_path: ::core::option::Option, - /// List of all notes together with the Merkle paths from `response.block_header.note_root` + /// List of all notes together with the Merkle paths from `response.block_header.note_root`. #[prost(message, repeated, tag = "4")] pub notes: ::prost::alloc::vec::Vec, } -/// An account returned as a response to the GetBlockInputs +/// An account returned as a response to the `GetBlockInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountBlockInputRecord { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, + /// The latest account hash, zero hash if the account doesn't exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, + /// Merkle path to verify the account's inclusion in the MMR. #[prost(message, optional, tag = "3")] pub proof: ::core::option::Option, } -/// A nullifier returned as a response to the GetBlockInputs +/// A nullifier returned as a response to the `GetBlockInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct NullifierBlockInputRecord { + /// The nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, + /// Merkle path to verify the nullifier's inclusion in the MMR. #[prost(message, optional, tag = "2")] pub opening: ::core::option::Option, } +/// Represents the result of getting block inputs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockInputsResponse { - /// The latest block header + /// The latest block header. #[prost(message, optional, tag = "1")] pub block_header: ::core::option::Option, - /// Peaks of the above block's mmr, The `forest` value is equal to the block number + /// Peaks of the above block's mmr, The `forest` value is equal to the block number. #[prost(message, repeated, tag = "2")] pub mmr_peaks: ::prost::alloc::vec::Vec, - /// The hashes of the requested accounts and their authentication paths + /// The hashes of the requested accounts and their authentication paths. #[prost(message, repeated, tag = "3")] pub account_states: ::prost::alloc::vec::Vec, - /// The requested nullifiers and their authentication paths + /// The requested nullifiers and their authentication paths. #[prost(message, repeated, tag = "4")] pub nullifiers: ::prost::alloc::vec::Vec, - /// The list of requested notes which were found in the database + /// The list of requested notes which were found in the database. #[prost(message, optional, tag = "5")] pub found_unauthenticated_notes: ::core::option::Option< super::note::NoteAuthenticationInfo, >, } -/// An account returned as a response to the GetTransactionInputs +/// An account returned as a response to the `GetTransactionInputs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountTransactionInputRecord { + /// The account ID. #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, /// The latest account hash, zero hash if the account doesn't exist. #[prost(message, optional, tag = "2")] pub account_hash: ::core::option::Option, } -/// A nullifier returned as a response to the GetTransactionInputs +/// A nullifier returned as a response to the `GetTransactionInputs`. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct NullifierTransactionInputRecord { + /// The nullifier ID. #[prost(message, optional, tag = "1")] pub nullifier: ::core::option::Option, /// The block at which the nullifier has been consumed, zero if not consumed. #[prost(fixed32, tag = "2")] pub block_num: u32, } +/// Represents the result of getting transaction inputs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTransactionInputsResponse { + /// Account state proof. #[prost(message, optional, tag = "1")] pub account_state: ::core::option::Option, + /// List of nullifiers that have been consumed. #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, + /// List of unauthenticated notes that were not found in the database. #[prost(message, repeated, tag = "3")] pub found_unauthenticated_notes: ::prost::alloc::vec::Vec, + /// The node's current block height. #[prost(fixed32, tag = "4")] pub block_height: u32, } +/// Represents the result of submitting proven transaction. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct SubmitProvenTransactionResponse { - /// The node's current block height + /// The node's current block height. #[prost(fixed32, tag = "1")] pub block_height: u32, } +/// Represents the result of getting notes by IDs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNotesByIdResponse { - /// Lists Note's returned by the database + /// Lists Note's returned by the database. #[prost(message, repeated, tag = "1")] pub notes: ::prost::alloc::vec::Vec, } +/// Represents the result of getting note authentication info. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetNoteAuthenticationInfoResponse { + /// Proofs of note inclusions in blocks and block inclusions in chain. #[prost(message, optional, tag = "1")] pub proofs: ::core::option::Option, } +/// Represents the result of getting account details. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountDetailsResponse { - /// Account info (with details for public accounts) + /// Account info (with details for public accounts). #[prost(message, optional, tag = "1")] pub details: ::core::option::Option, } +/// Represents the result of getting block by number. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetBlockByNumberResponse { - /// The requested `Block` data encoded using miden native format + /// The requested block data encoded using \[winter_utils::Serializable\] implementation for + /// \[miden_objects::block::Block\]. #[prost(bytes = "vec", optional, tag = "1")] pub block: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents the result of getting account state delta. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountStateDeltaResponse { - /// The calculated `AccountStateDelta` encoded using miden native format + /// The calculated account delta encoded using \[winter_utils::Serializable\] implementation + /// for \[miden_objects::accounts::delta::AccountDelta\]. #[prost(bytes = "vec", optional, tag = "1")] pub delta: ::core::option::Option<::prost::alloc::vec::Vec>, } +/// Represents the result of getting account proofs. #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetAccountProofsResponse { /// Block number at which the state of the account was returned. @@ -186,6 +218,7 @@ pub struct GetAccountProofsResponse { #[prost(message, repeated, tag = "2")] pub account_proofs: ::prost::alloc::vec::Vec, } +/// A single account proof returned as a response to the `GetAccountProofs`. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountProofsResponse { /// Account ID. @@ -201,6 +234,7 @@ pub struct AccountProofsResponse { #[prost(message, optional, tag = "4")] pub state_header: ::core::option::Option, } +/// State header for public accounts. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AccountStateHeader { /// Account header. diff --git a/crates/rust-client/src/rpc/generated/std/rpc.rs b/crates/rust-client/src/rpc/generated/std/rpc.rs index f17733198..5067a8cb8 100644 --- a/crates/rust-client/src/rpc/generated/std/rpc.rs +++ b/crates/rust-client/src/rpc/generated/std/rpc.rs @@ -90,6 +90,7 @@ pub mod api_client { self.inner = self.inner.max_encoding_message_size(limit); self } + /// Gets a list of proofs for given nullifier hashes, each proof as a sparse Merkle Tree. pub async fn check_nullifiers( &mut self, request: impl tonic::IntoRequest< @@ -113,6 +114,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "CheckNullifiers")); self.inner.unary(req, path, codec).await } + /// Returns a list of nullifiers that match the specified prefixes and are recorded in the node. pub async fn check_nullifiers_by_prefix( &mut self, request: impl tonic::IntoRequest< @@ -139,6 +141,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "CheckNullifiersByPrefix")); self.inner.unary(req, path, codec).await } + /// Returns the latest state of an account with the specified ID. pub async fn get_account_details( &mut self, request: impl tonic::IntoRequest< @@ -164,6 +167,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetAccountDetails")); self.inner.unary(req, path, codec).await } + /// Returns the latest state proofs of the specified accounts. pub async fn get_account_proofs( &mut self, request: impl tonic::IntoRequest< @@ -187,6 +191,8 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetAccountProofs")); self.inner.unary(req, path, codec).await } + /// Returns delta of the account states in the range from `from_block_num` (exclusive) to + /// `to_block_num` (inclusive). pub async fn get_account_state_delta( &mut self, request: impl tonic::IntoRequest< @@ -213,6 +219,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "GetAccountStateDelta")); self.inner.unary(req, path, codec).await } + /// Retrieves block data by given block number. pub async fn get_block_by_number( &mut self, request: impl tonic::IntoRequest< @@ -236,6 +243,8 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetBlockByNumber")); self.inner.unary(req, path, codec).await } + /// Retrieves block header by given block number. Optionally, it also returns the MMR path + /// and current chain length to authenticate the block's inclusion. pub async fn get_block_header_by_number( &mut self, request: impl tonic::IntoRequest< @@ -262,6 +271,7 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "GetBlockHeaderByNumber")); self.inner.unary(req, path, codec).await } + /// Returns a list of notes matching the provided note IDs. pub async fn get_notes_by_id( &mut self, request: impl tonic::IntoRequest, @@ -283,6 +293,7 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "GetNotesById")); self.inner.unary(req, path, codec).await } + /// Submits proven transaction to the Miden network. pub async fn submit_proven_transaction( &mut self, request: impl tonic::IntoRequest< @@ -309,6 +320,10 @@ pub mod api_client { .insert(GrpcMethod::new("rpc.Api", "SubmitProvenTransaction")); self.inner.unary(req, path, codec).await } + /// Note synchronization request. + /// + /// Specifies note tags that client is interested in. The server will return the first block which + /// contains a note matching `note_tags` or the chain tip. pub async fn sync_notes( &mut self, request: impl tonic::IntoRequest, @@ -330,6 +345,21 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "SyncNotes")); self.inner.unary(req, path, codec).await } + /// Returns info which can be used by the client to sync up to the latest state of the chain + /// for the objects (accounts, notes, nullifiers) the client is interested in. + /// + /// This request returns the next block containing requested data. It also returns `chain_tip` + /// which is the latest block number in the chain. Client is expected to repeat these requests + /// in a loop until `response.block_header.block_num == response.chain_tip`, at which point + /// the client is fully synchronized with the chain. + /// + /// Each request also returns info about new notes, nullifiers etc. created. It also returns + /// Chain MMR delta that can be used to update the state of Chain MMR. This includes both chain + /// MMR peaks and chain MMR nodes. + /// + /// For preserving some degree of privacy, note tags and nullifiers filters contain only high + /// part of hashes. Thus, returned data contains excessive notes and nullifiers, client can make + /// additional filtering of that data on its side. pub async fn sync_state( &mut self, request: impl tonic::IntoRequest, diff --git a/crates/rust-client/src/rpc/generated/std/smt.rs b/crates/rust-client/src/rpc/generated/std/smt.rs index c4aaf2d77..90e9394d3 100644 --- a/crates/rust-client/src/rpc/generated/std/smt.rs +++ b/crates/rust-client/src/rpc/generated/std/smt.rs @@ -1,14 +1,18 @@ // This file is @generated by prost-build. -/// An entry in a leaf. +/// Represents a single SMT leaf entry. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct SmtLeafEntry { + /// The key of the entry. #[prost(message, optional, tag = "1")] pub key: ::core::option::Option, + /// The value of the entry. #[prost(message, optional, tag = "2")] pub value: ::core::option::Option, } +/// Represents multiple leaf entries in an SMT. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SmtLeafEntries { + /// The entries list. #[prost(message, repeated, tag = "1")] pub entries: ::prost::alloc::vec::Vec, } @@ -22,10 +26,13 @@ pub struct SmtLeaf { pub mod smt_leaf { #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum Leaf { + /// An empty leaf. #[prost(uint64, tag = "1")] Empty(u64), + /// A single leaf entry. #[prost(message, tag = "2")] Single(super::SmtLeafEntry), + /// Multiple leaf entries. #[prost(message, tag = "3")] Multiple(super::SmtLeafEntries), } @@ -33,8 +40,10 @@ pub mod smt_leaf { /// The opening of a leaf in an SMT. #[derive(Clone, PartialEq, ::prost::Message)] pub struct SmtOpening { + /// The merkle path to the leaf. #[prost(message, optional, tag = "1")] pub path: ::core::option::Option, + /// The leaf itself. #[prost(message, optional, tag = "2")] pub leaf: ::core::option::Option, } diff --git a/crates/rust-client/src/rpc/generated/std/transaction.rs b/crates/rust-client/src/rpc/generated/std/transaction.rs index 7dca33a33..3439e78ea 100644 --- a/crates/rust-client/src/rpc/generated/std/transaction.rs +++ b/crates/rust-client/src/rpc/generated/std/transaction.rs @@ -1,15 +1,21 @@ // This file is @generated by prost-build. +/// Represents a transaction ID. #[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct TransactionId { + /// The transaction ID. #[prost(message, optional, tag = "1")] pub id: ::core::option::Option, } +/// Represents a transaction summary. #[derive(Clone, PartialEq, ::prost::Message)] pub struct TransactionSummary { + /// A unique 32-byte identifier of a transaction. #[prost(message, optional, tag = "1")] pub transaction_id: ::core::option::Option, + /// The block number in which the transaction was executed. #[prost(fixed32, tag = "2")] pub block_num: u32, + /// The ID of the account affected by the transaction. #[prost(message, optional, tag = "3")] pub account_id: ::core::option::Option, } diff --git a/crates/rust-client/src/rpc/mod.rs b/crates/rust-client/src/rpc/mod.rs index b5f5987dc..e24f96f85 100644 --- a/crates/rust-client/src/rpc/mod.rs +++ b/crates/rust-client/src/rpc/mod.rs @@ -13,10 +13,10 @@ use domain::{ }; use miden_objects::{ accounts::{Account, AccountCode, AccountHeader, AccountId}, + block::{BlockHeader, BlockNumber}, crypto::merkle::MmrProof, notes::{NoteId, NoteTag, Nullifier}, transaction::ProvenTransaction, - BlockHeader, }; pub mod domain; @@ -73,7 +73,7 @@ pub trait NodeRpcClient { /// When `None` is provided, returns info regarding the latest block. async fn get_block_header_by_number( &mut self, - block_num: Option, + block_num: Option, include_mmr_proof: bool, ) -> Result<(BlockHeader, Option), RpcError>; @@ -98,7 +98,7 @@ pub trait NodeRpcClient { /// corresponding to some notes the client is interested in. async fn sync_state( &mut self, - block_num: u32, + block_num: BlockNumber, account_ids: &[AccountId], note_tags: &[NoteTag], nullifiers_tags: &[u16], @@ -115,7 +115,7 @@ pub trait NodeRpcClient { async fn sync_notes( &mut self, - block_num: u32, + block_num: BlockNumber, note_tags: &[NoteTag], ) -> Result; @@ -214,7 +214,7 @@ pub trait NodeRpcClient { /// The default implementation of this method uses [NodeRpcClient::get_block_header_by_number]. async fn get_block_header_with_proof( &mut self, - block_num: u32, + block_num: BlockNumber, ) -> Result<(BlockHeader, MmrProof), RpcError> { let (header, proof) = self.get_block_header_by_number(Some(block_num), true).await?; Ok((header, proof.ok_or(RpcError::ExpectedDataMissing(String::from("MmrProof")))?)) diff --git a/crates/rust-client/src/rpc/tonic_client/mod.rs b/crates/rust-client/src/rpc/tonic_client/mod.rs index 2fb3c8c38..deef5181a 100644 --- a/crates/rust-client/src/rpc/tonic_client/mod.rs +++ b/crates/rust-client/src/rpc/tonic_client/mod.rs @@ -9,11 +9,12 @@ use std::{collections::BTreeMap, time::Duration}; use async_trait::async_trait; use miden_objects::{ accounts::{Account, AccountCode, AccountId}, + block::{BlockHeader, BlockNumber}, crypto::merkle::{MerklePath, MmrProof}, notes::{Note, NoteId, NoteInclusionProof, NoteTag, Nullifier}, transaction::ProvenTransaction, utils::Deserializable, - BlockHeader, Digest, + Digest, }; use miden_tx::utils::Serializable; use tonic::transport::Channel; @@ -101,11 +102,11 @@ impl NodeRpcClient for TonicRpcClient { async fn get_block_header_by_number( &mut self, - block_num: Option, + block_num: Option, include_mmr_proof: bool, ) -> Result<(BlockHeader, Option), RpcError> { let request = GetBlockHeaderByNumberRequest { - block_num, + block_num: block_num.as_ref().map(BlockNumber::as_u32), include_mmr_proof: Some(include_mmr_proof), }; @@ -137,7 +138,7 @@ impl NodeRpcClient for TonicRpcClient { Some(MmrProof { forest: forest as usize, - position: block_header.block_num() as usize, + position: block_header.block_num().as_usize(), merkle_path, }) } else { @@ -168,7 +169,7 @@ impl NodeRpcClient for TonicRpcClient { .ok_or(RpcError::ExpectedDataMissing("Notes.MerklePath".into()))? .try_into()?; - NoteInclusionProof::new(note.block_num, note.note_index as u16, merkle_path)? + NoteInclusionProof::new(note.block_num.into(), note.note_index as u16, merkle_path)? }; let note = match note.details { @@ -202,7 +203,7 @@ impl NodeRpcClient for TonicRpcClient { /// into a [StateSyncInfo] struct. async fn sync_state( &mut self, - block_num: u32, + block_num: BlockNumber, account_ids: &[AccountId], note_tags: &[NoteTag], nullifiers_tags: &[u16], @@ -214,7 +215,7 @@ impl NodeRpcClient for TonicRpcClient { let note_tags = note_tags.iter().map(|¬e_tag| note_tag.into()).collect(); let request = SyncStateRequest { - block_num, + block_num: block_num.as_u32(), account_ids, note_tags, nullifiers, @@ -330,7 +331,7 @@ impl NodeRpcClient for TonicRpcClient { .into_inner(); let mut account_proofs = Vec::with_capacity(response.account_proofs.len()); - let block_num = response.block_num; + let block_num = response.block_num.into(); // sanity check response if requested_accounts != response.account_proofs.len() { @@ -378,12 +379,12 @@ impl NodeRpcClient for TonicRpcClient { async fn sync_notes( &mut self, - block_num: u32, + block_num: BlockNumber, note_tags: &[NoteTag], ) -> Result { let note_tags = note_tags.iter().map(|¬e_tag| note_tag.into()).collect(); - let request = SyncNoteRequest { block_num, note_tags }; + let request = SyncNoteRequest { block_num: block_num.as_u32(), note_tags }; let rpc_api = self.rpc_api().await?; diff --git a/crates/rust-client/src/rpc/web_tonic_client/mod.rs b/crates/rust-client/src/rpc/web_tonic_client/mod.rs index a05a5bf1b..51425aa51 100644 --- a/crates/rust-client/src/rpc/web_tonic_client/mod.rs +++ b/crates/rust-client/src/rpc/web_tonic_client/mod.rs @@ -8,11 +8,12 @@ use alloc::{ use async_trait::async_trait; use miden_objects::{ accounts::{Account, AccountCode, AccountId}, + block::{BlockHeader, BlockNumber}, crypto::merkle::{MerklePath, MmrProof}, notes::{Note, NoteId, NoteInclusionProof, NoteTag, Nullifier}, transaction::ProvenTransaction, utils::Deserializable, - BlockHeader, Digest, + Digest, }; use miden_tx::utils::Serializable; use tonic_web_wasm_client::Client; @@ -74,13 +75,13 @@ impl NodeRpcClient for WebTonicRpcClient { async fn get_block_header_by_number( &mut self, - block_num: Option, + block_num: Option, include_mmr_proof: bool, ) -> Result<(BlockHeader, Option), RpcError> { let mut query_client = self.build_api_client(); let request = GetBlockHeaderByNumberRequest { - block_num, + block_num: block_num.as_ref().map(BlockNumber::as_u32), include_mmr_proof: Some(include_mmr_proof), }; @@ -112,7 +113,7 @@ impl NodeRpcClient for WebTonicRpcClient { Some(MmrProof { forest: forest as usize, - position: block_header.block_num() as usize, + position: block_header.block_num().as_usize(), merkle_path, }) } else { @@ -145,7 +146,7 @@ impl NodeRpcClient for WebTonicRpcClient { .ok_or(RpcError::ExpectedDataMissing("Notes.MerklePath".into()))? .try_into()?; - NoteInclusionProof::new(note.block_num, note.note_index as u16, merkle_path)? + NoteInclusionProof::new(note.block_num.into(), note.note_index as u16, merkle_path)? }; let note = match note.details { @@ -178,7 +179,7 @@ impl NodeRpcClient for WebTonicRpcClient { /// into a [StateSyncInfo] struct. async fn sync_state( &mut self, - block_num: u32, + block_num: BlockNumber, account_ids: &[AccountId], note_tags: &[NoteTag], nullifiers_tags: &[u16], @@ -190,7 +191,7 @@ impl NodeRpcClient for WebTonicRpcClient { let note_tags = note_tags.iter().map(|¬e_tag| note_tag.into()).collect(); let request = SyncStateRequest { - block_num, + block_num: block_num.as_u32(), account_ids, note_tags, nullifiers, @@ -204,14 +205,14 @@ impl NodeRpcClient for WebTonicRpcClient { async fn sync_notes( &mut self, - block_num: u32, + block_num: BlockNumber, note_tags: &[NoteTag], ) -> Result { let mut query_client = self.build_api_client(); let note_tags = note_tags.iter().map(|¬e_tag| note_tag.into()).collect(); - let request = SyncNoteRequest { block_num, note_tags }; + let request = SyncNoteRequest { block_num: block_num.as_u32(), note_tags }; let response = query_client.sync_notes(request).await.map_err(|err| { RpcError::RequestError(NodeRpcClientEndpoint::SyncState.to_string(), err.to_string()) @@ -268,7 +269,7 @@ impl NodeRpcClient for WebTonicRpcClient { .into_inner(); let mut account_proofs = Vec::with_capacity(response.account_proofs.len()); - let block_num = response.block_num; + let block_num = response.block_num.into(); // sanity check response if requested_accounts != response.account_proofs.len() { @@ -320,8 +321,8 @@ impl NodeRpcClient for WebTonicRpcClient { /// /// This function will return an error if: /// - /// - The provided account isn't on-chain: this is due to the fact that for offchain accounts - /// the client is responsible. + /// - The provided account isn't on-chain: this is due to the fact that for private accounts the + /// client is responsible. /// - There was an error sending the request to the node. /// - The answer had a `None` for its account, or the account had a `None` at the `details` /// field. diff --git a/crates/rust-client/src/store/data_store.rs b/crates/rust-client/src/store/data_store.rs index 4f67ec484..08d389b46 100644 --- a/crates/rust-client/src/store/data_store.rs +++ b/crates/rust-client/src/store/data_store.rs @@ -6,11 +6,10 @@ use alloc::{ use miden_objects::{ accounts::{Account, AccountId}, - block::block_num_from_epoch, + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MerklePath, PartialMmr}, notes::NoteId, transaction::{ChainMmr, InputNote, InputNotes}, - BlockHeader, }; use miden_tx::{DataStore, DataStoreError, TransactionInputs}; @@ -36,7 +35,7 @@ impl DataStore for ClientDataStore { async fn get_transaction_inputs( &self, account_id: AccountId, - block_num: u32, + block_num: BlockNumber, notes: &[NoteId], ) -> Result { let input_note_records: BTreeMap = self @@ -75,11 +74,11 @@ impl DataStore for ClientDataStore { .ok_or(DataStoreError::BlockNotFound(block_num))?; let mut list_of_notes = vec![]; - let mut block_nums: Vec = vec![]; + let mut block_nums: Vec = vec![]; // If the account is new, add its anchor block to partial MMR if seed.is_some() { - let anchor_block = block_num_from_epoch(account_id.anchor_epoch()); + let anchor_block = BlockNumber::from_epoch(account_id.anchor_epoch()); if anchor_block != block_num { block_nums.push(anchor_block); } @@ -115,7 +114,7 @@ impl DataStore for ClientDataStore { .collect(); let partial_mmr = - build_partial_mmr_with_paths(&self.store, block_num, &block_headers).await?; + build_partial_mmr_with_paths(&self.store, block_num.as_u32(), &block_headers).await?; let chain_mmr = ChainMmr::new(partial_mmr, block_headers).map_err(|err| { DataStoreError::other_with_source("error creating ChainMmr from internal data", err) })?; @@ -139,19 +138,20 @@ async fn build_partial_mmr_with_paths( authenticated_blocks: &[BlockHeader], ) -> Result { let mut partial_mmr: PartialMmr = { - let current_peaks = store.get_chain_mmr_peaks_by_block_num(forest).await?; + let current_peaks = + store.get_chain_mmr_peaks_by_block_num(BlockNumber::from(forest)).await?; PartialMmr::from_peaks(current_peaks) }; - let block_nums: Vec = authenticated_blocks.iter().map(|b| b.block_num()).collect(); + let block_nums: Vec = authenticated_blocks.iter().map(|b| b.block_num()).collect(); let authentication_paths = get_authentication_path_for_blocks(store, &block_nums, partial_mmr.forest()).await?; for (header, path) in authenticated_blocks.iter().zip(authentication_paths.iter()) { partial_mmr - .track(header.block_num() as usize, header.hash(), path) + .track(header.block_num().as_usize(), header.hash(), path) .map_err(|err| DataStoreError::other(format!("error constructing MMR: {}", err)))?; } @@ -165,16 +165,16 @@ async fn build_partial_mmr_with_paths( /// If there are any such values, the function will panic when calling `mmr_merkle_path_len()`. async fn get_authentication_path_for_blocks( store: &alloc::sync::Arc, - block_nums: &[u32], + block_nums: &[BlockNumber], forest: usize, ) -> Result, StoreError> { let mut node_indices = BTreeSet::new(); // Calculate all needed nodes indices for generating the paths for block_num in block_nums { - let path_depth = mmr_merkle_path_len(*block_num as usize, forest); + let path_depth = mmr_merkle_path_len(block_num.as_usize(), forest); - let mut idx = InOrderIndex::from_leaf_pos(*block_num as usize); + let mut idx = InOrderIndex::from_leaf_pos(block_num.as_usize()); for _ in 0..path_depth { node_indices.insert(idx.sibling()); @@ -192,7 +192,7 @@ async fn get_authentication_path_for_blocks( let mut authentication_paths = vec![]; for block_num in block_nums { let mut merkle_nodes = vec![]; - let mut idx = InOrderIndex::from_leaf_pos(*block_num as usize); + let mut idx = InOrderIndex::from_leaf_pos(block_num.as_usize()); while let Some(node) = mmr_nodes.get(&idx.sibling()) { merkle_nodes.push(*node); diff --git a/crates/rust-client/src/store/mod.rs b/crates/rust-client/src/store/mod.rs index 70e26d571..b10144ad4 100644 --- a/crates/rust-client/src/store/mod.rs +++ b/crates/rust-client/src/store/mod.rs @@ -10,9 +10,10 @@ use core::fmt::Debug; use async_trait::async_trait; use miden_objects::{ accounts::{Account, AccountCode, AccountHeader, AccountId, AuthSecretKey}, + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MmrPeaks}, notes::{NoteId, NoteTag, Nullifier}, - BlockHeader, Digest, Word, + Digest, Word, }; use crate::{ @@ -138,7 +139,7 @@ pub trait Store: Send + Sync { /// contains notes relevant to the client. async fn get_block_headers( &self, - block_numbers: &[u32], + block_numbers: &[BlockNumber], ) -> Result, StoreError>; /// Retrieves a [BlockHeader] corresponding to the provided block number and a boolean value @@ -148,7 +149,7 @@ pub trait Store: Send + Sync { /// The default implementation of this method uses [Store::get_block_headers]. async fn get_block_header_by_num( &self, - block_number: u32, + block_number: BlockNumber, ) -> Result, StoreError> { self.get_block_headers(&[block_number]) .await @@ -177,7 +178,7 @@ pub trait Store: Send + Sync { /// If there is no chain MMR info stored for the provided block returns an empty [MmrPeaks]. async fn get_chain_mmr_peaks_by_block_num( &self, - block_num: u32, + block_num: BlockNumber, ) -> Result; /// Inserts a block header into the store, alongside peaks information at the block's height. @@ -294,7 +295,7 @@ pub trait Store: Send + Sync { async fn remove_note_tag(&self, tag: NoteTagRecord) -> Result; /// Returns the block number of the last state sync block. - async fn get_sync_height(&self) -> Result; + async fn get_sync_height(&self) -> Result; /// Applies the state sync update to the store. An update involves: /// diff --git a/crates/rust-client/src/store/note_record/input_note_record/mod.rs b/crates/rust-client/src/store/note_record/input_note_record/mod.rs index 9acfe22c3..779a58bc4 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/mod.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/mod.rs @@ -2,10 +2,11 @@ use alloc::string::ToString; use miden_objects::{ accounts::AccountId, + block::{BlockHeader, BlockNumber}, notes::{Note, NoteAssets, NoteDetails, NoteId, NoteInclusionProof, NoteMetadata, Nullifier}, transaction::{InputNote, TransactionId}, utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}, - BlockHeader, Digest, + Digest, }; use super::NoteRecordError; @@ -258,7 +259,7 @@ impl From for InputNoteRecord { created_at: None, state: ExpectedNoteState { metadata: Some(metadata), - after_block_num: 0, + after_block_num: BlockNumber::from(0), tag: Some(metadata.tag()), } .into(), diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/committed.rs b/crates/rust-client/src/store/note_record/input_note_record/states/committed.rs index 1d86ff40c..4979ff174 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/committed.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/committed.rs @@ -1,9 +1,10 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, Digest, + Digest, }; use super::{ diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_authenticated_local.rs b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_authenticated_local.rs index 908d1b6d5..b11512a98 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_authenticated_local.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_authenticated_local.rs @@ -1,9 +1,10 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, Digest, + Digest, }; use super::{InputNoteState, NoteStateHandler, NoteSubmissionData}; diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_external.rs b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_external.rs index e0dfae014..067c79ac5 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_external.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_external.rs @@ -1,9 +1,9 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, }; use super::{InputNoteState, NoteStateHandler}; diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_unauthenticated_local.rs b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_unauthenticated_local.rs index d3688e269..9aefae8c1 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/consumed_unauthenticated_local.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/consumed_unauthenticated_local.rs @@ -1,9 +1,9 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, }; use super::{InputNoteState, NoteStateHandler, NoteSubmissionData}; diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/expected.rs b/crates/rust-client/src/store/note_record/input_note_record/states/expected.rs index 8a2a189d4..d46a954be 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/expected.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/expected.rs @@ -2,9 +2,9 @@ use alloc::string::ToString; use miden_objects::{ accounts::AccountId, + block::{BlockHeader, BlockNumber}, notes::{NoteId, NoteInclusionProof, NoteMetadata, NoteTag}, transaction::TransactionId, - BlockHeader, }; use super::{ @@ -20,7 +20,7 @@ pub struct ExpectedNoteState { /// retrieving it from the node. Imported or future notes may not have metadata. pub metadata: Option, /// Block height after which the note is expected to be committed. - pub after_block_num: u32, + pub after_block_num: BlockNumber, /// A tag used to identify the note. The tag may not be known if the note was imported without /// it or if it's a future note. pub tag: Option, @@ -117,7 +117,7 @@ impl miden_tx::utils::Deserializable for ExpectedNoteState { source: &mut R, ) -> Result { let metadata = Option::::read_from(source)?; - let after_block_num = u32::read_from(source)?; + let after_block_num = BlockNumber::read_from(source)?; let tag = Option::::read_from(source)?; Ok(ExpectedNoteState { metadata, after_block_num, tag }) } diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/invalid.rs b/crates/rust-client/src/store/note_record/input_note_record/states/invalid.rs index 3acf73bf2..1d5b861a1 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/invalid.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/invalid.rs @@ -1,9 +1,10 @@ use alloc::string::ToString; use miden_objects::{ + block::BlockHeader, notes::{compute_note_hash, NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, Digest, + Digest, }; use super::{ diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/mod.rs b/crates/rust-client/src/store/note_record/input_note_record/states/mod.rs index fc3971932..ae5db78b9 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/mod.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/mod.rs @@ -4,9 +4,9 @@ use core::fmt::{self, Display}; use chrono::{Local, TimeZone}; use miden_objects::{ accounts::AccountId, + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, }; pub use miden_tx::utils::{ ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/processing_authenticated.rs b/crates/rust-client/src/store/note_record/input_note_record/states/processing_authenticated.rs index 1c59dacce..6611e445a 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/processing_authenticated.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/processing_authenticated.rs @@ -2,9 +2,10 @@ use alloc::string::ToString; use miden_objects::{ accounts::AccountId, + block::BlockHeader, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, Digest, + Digest, }; use super::{ diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/processing_unauthenticated.rs b/crates/rust-client/src/store/note_record/input_note_record/states/processing_unauthenticated.rs index 2309f5410..22ded7ca3 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/processing_unauthenticated.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/processing_unauthenticated.rs @@ -1,9 +1,9 @@ use alloc::string::ToString; use miden_objects::{ + block::{BlockHeader, BlockNumber}, notes::{NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, }; use super::{ @@ -18,7 +18,7 @@ pub struct ProcessingUnauthenticatedNoteState { /// information. pub metadata: NoteMetadata, /// Block height after which the note is expected to be committed. - pub after_block_num: u32, + pub after_block_num: BlockNumber, /// Information about the submission of the note. pub submission_data: NoteSubmissionData, } @@ -103,7 +103,7 @@ impl miden_tx::utils::Deserializable for ProcessingUnauthenticatedNoteState { source: &mut R, ) -> Result { let metadata = NoteMetadata::read_from(source)?; - let after_block_num = u32::read_from(source)?; + let after_block_num = BlockNumber::read_from(source)?; let submission_data = NoteSubmissionData::read_from(source)?; Ok(ProcessingUnauthenticatedNoteState { metadata, diff --git a/crates/rust-client/src/store/note_record/input_note_record/states/unverified.rs b/crates/rust-client/src/store/note_record/input_note_record/states/unverified.rs index 30f5ca62f..543a2a614 100644 --- a/crates/rust-client/src/store/note_record/input_note_record/states/unverified.rs +++ b/crates/rust-client/src/store/note_record/input_note_record/states/unverified.rs @@ -1,9 +1,9 @@ use alloc::string::ToString; use miden_objects::{ + block::{BlockHeader, BlockNumber}, notes::{compute_note_hash, NoteId, NoteInclusionProof, NoteMetadata}, transaction::TransactionId, - BlockHeader, }; use super::{ @@ -84,10 +84,12 @@ impl NoteStateHandler for UnverifiedNoteState { consumer_transaction, }; + let after_block_num = + self.inclusion_proof.location().block_num().as_u32().saturating_sub(1); Ok(Some( ProcessingUnauthenticatedNoteState { metadata: self.metadata, - after_block_num: self.inclusion_proof.location().block_num() - 1, + after_block_num: BlockNumber::from(after_block_num), submission_data, } .into(), diff --git a/crates/rust-client/src/store/note_record/output_note_record/mod.rs b/crates/rust-client/src/store/note_record/output_note_record/mod.rs index 1b8ef2bcb..2e5a1b162 100644 --- a/crates/rust-client/src/store/note_record/output_note_record/mod.rs +++ b/crates/rust-client/src/store/note_record/output_note_record/mod.rs @@ -2,6 +2,7 @@ use alloc::string::ToString; use core::fmt::{self, Display}; use miden_objects::{ + block::BlockNumber, notes::{ Note, NoteAssets, NoteDetails, NoteFile, NoteId, NoteInclusionProof, NoteMetadata, NoteRecipient, Nullifier, PartialNote, @@ -36,7 +37,7 @@ pub struct OutputNoteRecord { /// The state of the note, with specific fields for each one. state: OutputNoteState, /// The expected block height at which the note should be included in the chain. - expected_height: u32, + expected_height: BlockNumber, } impl OutputNoteRecord { @@ -45,7 +46,7 @@ impl OutputNoteRecord { assets: NoteAssets, metadata: NoteMetadata, state: OutputNoteState, - expected_height: u32, + expected_height: BlockNumber, ) -> OutputNoteRecord { OutputNoteRecord { recipient_digest, @@ -94,7 +95,7 @@ impl OutputNoteRecord { )) } - pub fn expected_height(&self) -> u32 { + pub fn expected_height(&self) -> BlockNumber { self.expected_height } @@ -156,7 +157,7 @@ impl OutputNoteRecord { // TODO: Improve conversions by implementing into_parts() impl OutputNoteRecord { - pub fn from_full_note(note: Note, expected_height: u32) -> Self { + pub fn from_full_note(note: Note, expected_height: BlockNumber) -> Self { let header = *note.header(); let (assets, recipient) = NoteDetails::from(note).into_parts(); OutputNoteRecord { @@ -168,7 +169,7 @@ impl OutputNoteRecord { } } - pub fn from_partial_note(partial_note: PartialNote, expected_height: u32) -> Self { + pub fn from_partial_note(partial_note: PartialNote, expected_height: BlockNumber) -> Self { OutputNoteRecord { recipient_digest: partial_note.recipient_digest(), assets: partial_note.assets().clone(), @@ -184,7 +185,7 @@ impl OutputNoteRecord { /// to filter the full and partial output notes. pub fn try_from_output_note( output_note: OutputNote, - expected_height: u32, + expected_height: BlockNumber, ) -> Result { match output_note { OutputNote::Full(note) => Ok(Self::from_full_note(note, expected_height)), diff --git a/crates/rust-client/src/store/sqlite_store/chain_data.rs b/crates/rust-client/src/store/sqlite_store/chain_data.rs index 1274b4c90..990698625 100644 --- a/crates/rust-client/src/store/sqlite_store/chain_data.rs +++ b/crates/rust-client/src/store/sqlite_store/chain_data.rs @@ -2,8 +2,9 @@ use alloc::{collections::BTreeMap, rc::Rc, string::String, vec::Vec}; use std::num::NonZeroUsize; use miden_objects::{ + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MmrPeaks}, - BlockHeader, Digest, + Digest, }; use miden_tx::utils::{Deserializable, Serializable}; use rusqlite::{ @@ -13,7 +14,7 @@ use rusqlite::{ use super::SqliteStore; use crate::store::{ChainMmrNodeFilter, StoreError}; -type SerializedBlockHeaderData = (i64, Vec, Vec, bool); +type SerializedBlockHeaderData = (u32, Vec, Vec, bool); type SerializedBlockHeaderParts = (u64, Vec, Vec, bool); type SerializedChainMmrNodeData = (i64, String); @@ -51,11 +52,11 @@ impl SqliteStore { pub(crate) fn get_block_headers( conn: &mut Connection, - block_numbers: &[u32], + block_numbers: &[BlockNumber], ) -> Result, StoreError> { let block_number_list = block_numbers .iter() - .map(|block_number| Value::Integer(*block_number as i64)) + .map(|block_number| Value::Integer(block_number.as_u32() as i64)) .collect::>(); const QUERY : &str = "SELECT block_num, header, chain_mmr_peaks, has_client_notes FROM block_headers WHERE block_num IN rarray(?)"; @@ -98,20 +99,20 @@ impl SqliteStore { pub(crate) fn get_chain_mmr_peaks_by_block_num( conn: &mut Connection, - block_num: u32, + block_num: BlockNumber, ) -> Result { const QUERY: &str = "SELECT chain_mmr_peaks FROM block_headers WHERE block_num = ?"; let mmr_peaks = conn .prepare(QUERY)? - .query_row(params![block_num], |row| { + .query_row(params![block_num.as_u32()], |row| { let peaks: Vec = row.get(0)?; Ok(peaks) }) .optional()?; if let Some(mmr_peaks) = mmr_peaks { - return parse_mmr_peaks(block_num, mmr_peaks); + return parse_mmr_peaks(block_num.as_u32(), mmr_peaks); } Ok(MmrPeaks::new(0, vec![])?) @@ -193,13 +194,13 @@ fn serialize_block_header( let header = block_header.to_bytes(); let chain_mmr_peaks = chain_mmr_peaks.to_bytes(); - Ok((block_num as i64, header, chain_mmr_peaks, has_client_notes)) + Ok((block_num.as_u32(), header, chain_mmr_peaks, has_client_notes)) } fn parse_block_headers_columns( row: &rusqlite::Row<'_>, ) -> Result { - let block_num: i64 = row.get(0)?; + let block_num: u32 = row.get(0)?; let header: Vec = row.get(1)?; let chain_mmr: Vec = row.get(2)?; let has_client_notes: bool = row.get(3)?; @@ -261,7 +262,7 @@ mod test { use alloc::vec::Vec; use miden_lib::transaction::TransactionKernel; - use miden_objects::{crypto::merkle::MmrPeaks, BlockHeader}; + use miden_objects::{block::BlockHeader, crypto::merkle::MmrPeaks}; use crate::store::{ sqlite_store::{tests::create_test_store, SqliteStore}, @@ -303,7 +304,7 @@ mod test { let mut store = create_test_store().await; let block_headers = insert_dummy_block_headers(&mut store).await; - let block_header = Store::get_block_header_by_num(&store, 3).await.unwrap().unwrap(); + let block_header = Store::get_block_header_by_num(&store, 3.into()).await.unwrap().unwrap(); assert_eq!(block_headers[3], block_header.0); } @@ -312,12 +313,13 @@ mod test { let mut store = create_test_store().await; let mock_block_headers = insert_dummy_block_headers(&mut store).await; - let block_headers: Vec = Store::get_block_headers(&store, &[1, 3]) - .await - .unwrap() - .into_iter() - .map(|(block_header, _has_notes)| block_header) - .collect(); + let block_headers: Vec = + Store::get_block_headers(&store, &[1.into(), 3.into()]) + .await + .unwrap() + .into_iter() + .map(|(block_header, _has_notes)| block_header) + .collect(); assert_eq!(&[mock_block_headers[1], mock_block_headers[3]], &block_headers[..]); } } diff --git a/crates/rust-client/src/store/sqlite_store/mod.rs b/crates/rust-client/src/store/sqlite_store/mod.rs index a913d7237..ce1708b55 100644 --- a/crates/rust-client/src/store/sqlite_store/mod.rs +++ b/crates/rust-client/src/store/sqlite_store/mod.rs @@ -8,9 +8,10 @@ use std::{path::PathBuf, string::ToString}; use deadpool_sqlite::{Config, Hook, HookError, Pool, Runtime}; use miden_objects::{ accounts::{Account, AccountCode, AccountHeader, AccountId, AuthSecretKey}, + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MmrPeaks}, notes::{NoteTag, Nullifier}, - BlockHeader, Digest, Word, + Digest, Word, }; use rusqlite::{vtab::array, Connection}; use tonic::async_trait; @@ -133,7 +134,7 @@ impl Store for SqliteStore { .await } - async fn get_sync_height(&self) -> Result { + async fn get_sync_height(&self) -> Result { self.interact_with_connection(SqliteStore::get_sync_height).await } @@ -195,7 +196,7 @@ impl Store for SqliteStore { async fn get_block_headers( &self, - block_numbers: &[u32], + block_numbers: &[BlockNumber], ) -> Result, StoreError> { let block_numbers = block_numbers.to_vec(); self.interact_with_connection(move |conn| { @@ -227,7 +228,7 @@ impl Store for SqliteStore { async fn get_chain_mmr_peaks_by_block_num( &self, - block_num: u32, + block_num: BlockNumber, ) -> Result { self.interact_with_connection(move |conn| { SqliteStore::get_chain_mmr_peaks_by_block_num(conn, block_num) diff --git a/crates/rust-client/src/store/sqlite_store/notes.rs b/crates/rust-client/src/store/sqlite_store/notes.rs index 067bba273..095dc709f 100644 --- a/crates/rust-client/src/store/sqlite_store/notes.rs +++ b/crates/rust-client/src/store/sqlite_store/notes.rs @@ -5,6 +5,7 @@ use alloc::{ }; use miden_objects::{ + block::BlockNumber, crypto::utils::{Deserializable, Serializable}, notes::{ NoteAssets, NoteDetails, NoteInputs, NoteMetadata, NoteRecipient, NoteScript, Nullifier, @@ -554,7 +555,7 @@ fn parse_output_note( assets, metadata, state, - expected_height, + BlockNumber::from(expected_height), )) } @@ -576,7 +577,7 @@ fn serialize_output_note(note: &OutputNoteRecord) -> Result Result { + pub(super) fn get_sync_height(conn: &mut Connection) -> Result { const QUERY: &str = "SELECT block_num FROM state_sync"; conn.prepare(QUERY)? .query_map([], |row| row.get(0)) .expect("no binding parameters used in query") - .map(|result| Ok(result?).map(|v: i64| v as u32)) + .map(|result| Ok(result?).map(|v: i64| BlockNumber::from(v as u32))) .next() .expect("state sync block number exists") } @@ -111,7 +111,7 @@ impl SqliteStore { // Update state sync block number const BLOCK_NUMBER_QUERY: &str = "UPDATE state_sync SET block_num = ?"; - tx.execute(BLOCK_NUMBER_QUERY, params![block_header.block_num()])?; + tx.execute(BLOCK_NUMBER_QUERY, params![block_header.block_num().as_u32() as i64])?; Self::insert_block_header_tx(&tx, block_header, new_mmr_peaks, block_has_relevant_notes)?; @@ -137,7 +137,7 @@ impl SqliteStore { update_account(&tx, account)?; } - for (account_id, _) in updated_accounts.mismatched_offchain_accounts() { + for (account_id, _) in updated_accounts.mismatched_private_accounts() { lock_account(&tx, *account_id)?; } diff --git a/crates/rust-client/src/store/sqlite_store/transactions.rs b/crates/rust-client/src/store/sqlite_store/transactions.rs index f37663257..2d88f4f09 100644 --- a/crates/rust-client/src/store/sqlite_store/transactions.rs +++ b/crates/rust-client/src/store/sqlite_store/transactions.rs @@ -6,6 +6,7 @@ use alloc::{ use miden_objects::{ accounts::AccountId, + block::BlockNumber, crypto::utils::{Deserializable, Serializable}, transaction::{ ExecutedTransaction, OutputNotes, ToInputNoteCommitments, TransactionId, TransactionScript, @@ -228,7 +229,7 @@ pub(super) fn serialize_transaction_data( output_notes.to_bytes(), script_hash, tx_script, - executed_transaction.block_header().block_num(), + executed_transaction.block_header().block_num().as_u32(), None, false, )) @@ -284,7 +285,6 @@ fn parse_transaction( let account_id = AccountId::from_hex(&account_id)?; let id: Digest = id.try_into()?; let init_account_state: Digest = init_account_state.try_into()?; - let final_account_state: Digest = final_account_state.try_into()?; let input_note_nullifiers: Vec = Vec::::read_from_bytes(&input_notes) @@ -299,6 +299,7 @@ fn parse_transaction( let transaction_status = if discarded { TransactionStatus::Discarded } else { + let commit_height = commit_height.map(BlockNumber::from); commit_height.map_or(TransactionStatus::Pending, TransactionStatus::Committed) }; @@ -310,7 +311,7 @@ fn parse_transaction( input_note_nullifiers, output_notes, transaction_script, - block_num, + block_num: block_num.into(), transaction_status, }) } diff --git a/crates/rust-client/src/store/web_store/chain_data/mod.rs b/crates/rust-client/src/store/web_store/chain_data/mod.rs index 703c65566..9492fd22f 100644 --- a/crates/rust-client/src/store/web_store/chain_data/mod.rs +++ b/crates/rust-client/src/store/web_store/chain_data/mod.rs @@ -5,8 +5,9 @@ use alloc::{ }; use miden_objects::{ + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MmrPeaks}, - BlockHeader, Digest, + Digest, }; use miden_tx::utils::Deserializable; use serde_wasm_bindgen::from_value; @@ -48,11 +49,11 @@ impl WebStore { pub(crate) async fn get_block_headers( &self, - block_numbers: &[u32], + block_numbers: &[BlockNumber], ) -> Result, StoreError> { let formatted_block_numbers_list: Vec = block_numbers .iter() - .map(|block_number| (*block_number as i64).to_string()) + .map(|block_number| (block_number.as_u32() as i64).to_string()) .collect(); let promise = idxdb_get_block_headers(formatted_block_numbers_list); @@ -116,7 +117,7 @@ impl WebStore { pub(crate) async fn get_chain_mmr_peaks_by_block_num( &self, - block_num: u32, + block_num: BlockNumber, ) -> Result { let block_num_as_str = block_num.to_string(); @@ -127,7 +128,7 @@ impl WebStore { if let Some(peaks) = mmr_peaks_idxdb.peaks { let mmr_peaks_nodes: Vec = Vec::::read_from_bytes(&peaks)?; - return MmrPeaks::new(block_num as usize, mmr_peaks_nodes) + return MmrPeaks::new(block_num.as_usize(), mmr_peaks_nodes) .map_err(StoreError::MmrError); } diff --git a/crates/rust-client/src/store/web_store/chain_data/utils.rs b/crates/rust-client/src/store/web_store/chain_data/utils.rs index 6e5485ec0..4c336a695 100644 --- a/crates/rust-client/src/store/web_store/chain_data/utils.rs +++ b/crates/rust-client/src/store/web_store/chain_data/utils.rs @@ -5,7 +5,7 @@ use alloc::{ }; use core::num::NonZeroUsize; -use miden_objects::{crypto::merkle::InOrderIndex, BlockHeader, Digest}; +use miden_objects::{block::BlockHeader, crypto::merkle::InOrderIndex, Digest}; use miden_tx::utils::Serializable; use serde_wasm_bindgen::from_value; use wasm_bindgen::JsValue; diff --git a/crates/rust-client/src/store/web_store/mod.rs b/crates/rust-client/src/store/web_store/mod.rs index b8775c6af..13a5578c7 100644 --- a/crates/rust-client/src/store/web_store/mod.rs +++ b/crates/rust-client/src/store/web_store/mod.rs @@ -2,9 +2,10 @@ use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; use miden_objects::{ accounts::{Account, AccountCode, AccountHeader, AccountId, AuthSecretKey}, + block::{BlockHeader, BlockNumber}, crypto::merkle::{InOrderIndex, MmrPeaks}, notes::Nullifier, - BlockHeader, Digest, Word, + Digest, Word, }; use tonic::async_trait; use wasm_bindgen::prelude::*; @@ -40,6 +41,7 @@ impl WebStore { Ok(WebStore {}) } } + #[async_trait(?Send)] impl Store for WebStore { fn get_current_timestamp(&self) -> Option { @@ -61,7 +63,7 @@ impl Store for WebStore { self.remove_note_tag(tag).await } - async fn get_sync_height(&self) -> Result { + async fn get_sync_height(&self) -> Result { self.get_sync_height().await } @@ -117,7 +119,7 @@ impl Store for WebStore { async fn get_block_headers( &self, - block_numbers: &[u32], + block_numbers: &[BlockNumber], ) -> Result, StoreError> { self.get_block_headers(block_numbers).await } @@ -142,7 +144,7 @@ impl Store for WebStore { async fn get_chain_mmr_peaks_by_block_num( &self, - block_num: u32, + block_num: BlockNumber, ) -> Result { self.get_chain_mmr_peaks_by_block_num(block_num).await } diff --git a/crates/rust-client/src/store/web_store/notes/utils.rs b/crates/rust-client/src/store/web_store/notes/utils.rs index 7f27e8307..39d1141a7 100644 --- a/crates/rust-client/src/store/web_store/notes/utils.rs +++ b/crates/rust-client/src/store/web_store/notes/utils.rs @@ -121,7 +121,7 @@ pub(crate) fn serialize_output_note( nullifier, state_discriminant, state, - expected_height: note.expected_height(), + expected_height: note.expected_height().as_u32(), }) } @@ -188,7 +188,7 @@ pub fn parse_output_note_idxdb_object( note_assets, note_metadata, state, - note_idxdb.expected_height, + note_idxdb.expected_height.into(), )) } diff --git a/crates/rust-client/src/store/web_store/sync/mod.rs b/crates/rust-client/src/store/web_store/sync/mod.rs index 0f4643ced..ebd148c29 100644 --- a/crates/rust-client/src/store/web_store/sync/mod.rs +++ b/crates/rust-client/src/store/web_store/sync/mod.rs @@ -5,6 +5,7 @@ use alloc::{ use miden_objects::{ accounts::AccountId, + block::BlockNumber, notes::{NoteId, NoteTag}, }; use miden_tx::utils::{Deserializable, Serializable}; @@ -58,13 +59,13 @@ impl WebStore { Ok(tags) } - pub(super) async fn get_sync_height(&self) -> Result { + pub(super) async fn get_sync_height(&self) -> Result { let promise = idxdb_get_sync_height(); let js_value = JsFuture::from(promise).await.unwrap(); let block_num_idxdb: SyncHeightIdxdbObject = from_value(js_value).unwrap(); let block_num_as_u32: u32 = block_num_idxdb.block_num.parse::().unwrap(); - Ok(block_num_as_u32) + Ok(block_num_as_u32.into()) } pub(super) async fn add_note_tag(&self, tag: NoteTagRecord) -> Result { @@ -162,7 +163,7 @@ impl WebStore { update_account(&account.clone()).await.unwrap(); } - for (account_id, _) in updated_accounts.mismatched_offchain_accounts() { + for (account_id, _) in updated_accounts.mismatched_private_accounts() { lock_account(account_id).await.unwrap(); } diff --git a/crates/rust-client/src/store/web_store/transactions/mod.rs b/crates/rust-client/src/store/web_store/transactions/mod.rs index 9a818309b..caa6cc248 100644 --- a/crates/rust-client/src/store/web_store/transactions/mod.rs +++ b/crates/rust-client/src/store/web_store/transactions/mod.rs @@ -2,6 +2,7 @@ use alloc::{string::ToString, vec::Vec}; use miden_objects::{ accounts::AccountId, + block::BlockNumber, transaction::{OutputNotes, TransactionScript}, Digest, }; @@ -42,9 +43,9 @@ impl WebStore { .into_iter() .map(|tx_idxdb| { let native_account_id = AccountId::from_hex(&tx_idxdb.account_id).unwrap(); - let block_num_as_u32: u32 = tx_idxdb.block_num.parse::().unwrap(); - let commit_height_as_u32: Option = - tx_idxdb.commit_height.map(|height| height.parse::().unwrap()); + let block_num: BlockNumber = tx_idxdb.block_num.parse::().unwrap().into(); + let commit_height: Option = + tx_idxdb.commit_height.map(|height| height.parse::().unwrap().into()); let id: Digest = tx_idxdb.id.try_into()?; let init_account_state: Digest = tx_idxdb.init_account_state.try_into()?; @@ -69,8 +70,8 @@ impl WebStore { None }; - let transaction_status = commit_height_as_u32 - .map_or(TransactionStatus::Pending, TransactionStatus::Committed); + let transaction_status = + commit_height.map_or(TransactionStatus::Pending, TransactionStatus::Committed); Ok(TransactionRecord { id: id.into(), @@ -80,7 +81,7 @@ impl WebStore { input_note_nullifiers, output_notes, transaction_script, - block_num: block_num_as_u32, + block_num, transaction_status, }) }) diff --git a/crates/rust-client/src/sync/block_headers.rs b/crates/rust-client/src/sync/block_headers.rs index 92696ab1f..092635392 100644 --- a/crates/rust-client/src/sync/block_headers.rs +++ b/crates/rust-client/src/sync/block_headers.rs @@ -2,9 +2,9 @@ use alloc::vec::Vec; use crypto::merkle::{InOrderIndex, MmrDelta, MmrPeaks, PartialMmr}; use miden_objects::{ - block::{block_epoch_from_number, block_num_from_epoch}, + block::{BlockHeader, BlockNumber}, crypto::{self, merkle::MerklePath, rand::FeltRng}, - BlockHeader, Digest, + Digest, }; use tracing::warn; @@ -46,7 +46,7 @@ impl Client { /// Attempts to retrieve the genesis block from the store. If not found, /// it requests it from the node and store it. pub(crate) async fn ensure_genesis_in_place(&mut self) -> Result { - let genesis = self.store.get_block_header_by_num(0).await?; + let genesis = self.store.get_block_header_by_num(0.into()).await?; match genesis { Some((block, _)) => Ok(block), @@ -57,7 +57,10 @@ impl Client { /// Calls `get_block_header_by_number` requesting the genesis block and storing it /// in the local database. async fn retrieve_and_store_genesis(&mut self) -> Result { - let (genesis_block, _) = self.rpc_api.get_block_header_by_number(Some(0), false).await?; + let (genesis_block, _) = self + .rpc_api + .get_block_header_by_number(Some(BlockNumber::GENESIS), false) + .await?; let blank_mmr_peaks = MmrPeaks::new(0, vec![]).expect("Blank MmrPeaks should not fail to instantiate"); @@ -114,8 +117,12 @@ impl Client { let tracked_nodes = self.store.get_chain_mmr_nodes(ChainMmrNodeFilter::All).await?; let current_peaks = self.store.get_chain_mmr_peaks_by_block_num(current_block_num).await?; - let track_latest = if current_block_num != 0 { - match self.store.get_block_header_by_num(current_block_num - 1).await? { + let track_latest = if current_block_num.as_u32() != 0 { + match self + .store + .get_block_header_by_num(BlockNumber::from(current_block_num.as_u32() - 1)) + .await? + { Some((_, previous_block_had_notes)) => previous_block_had_notes, None => false, } @@ -145,10 +152,10 @@ impl Client { /// done and the stored block header is returned. pub(crate) async fn get_and_store_authenticated_block( &mut self, - block_num: u32, + block_num: BlockNumber, current_partial_mmr: &mut PartialMmr, ) -> Result { - if current_partial_mmr.is_tracked(block_num as usize) { + if current_partial_mmr.is_tracked(block_num.as_usize()) { warn!("Current partial MMR already contains the requested data"); let (block_header, _) = self .store @@ -163,14 +170,14 @@ impl Client { // might be of a forest arbitrarily higher let path_nodes = adjust_merkle_path_for_forest( &mmr_proof.merkle_path, - block_num as usize, + block_num, current_partial_mmr.forest(), ); let merkle_path = MerklePath::new(path_nodes.iter().map(|(_, n)| *n).collect()); current_partial_mmr - .track(block_num as usize, block_header.hash(), &merkle_path) + .track(block_num.as_usize(), block_header.hash(), &merkle_path) .map_err(StoreError::MmrError)?; // Insert header and MMR nodes @@ -185,9 +192,12 @@ impl Client { /// Returns the epoch block for the specified block number. /// /// If the epoch block header is not stored, it will be retrieved and stored. - pub async fn get_epoch_block(&mut self, block_num: u32) -> Result { - let epoch = block_epoch_from_number(block_num); - let epoch_block_number = block_num_from_epoch(epoch); + pub async fn get_epoch_block( + &mut self, + block_num: BlockNumber, + ) -> Result { + let epoch = block_num.block_epoch(); + let epoch_block_number = BlockNumber::from_epoch(epoch); if let Some((epoch_block, _)) = self.store.get_block_header_by_num(epoch_block_number).await? @@ -195,7 +205,7 @@ impl Client { return Ok(epoch_block); } - if epoch_block_number == 0 { + if epoch_block_number == 0.into() { return self.ensure_genesis_in_place().await; } @@ -229,16 +239,16 @@ impl Client { /// - `forest`: The target size of the forest. fn adjust_merkle_path_for_forest( merkle_path: &MerklePath, - block_num: usize, + block_num: BlockNumber, forest: usize, ) -> Vec<(InOrderIndex, Digest)> { - if forest - 1 < block_num { + if forest - 1 < block_num.as_usize() { panic!("Can't adjust merkle path for a forest that does not include the block number"); } let rightmost_index = InOrderIndex::from_leaf_pos(forest - 1); - let mut idx = InOrderIndex::from_leaf_pos(block_num); + let mut idx = InOrderIndex::from_leaf_pos(block_num.as_usize()); let mut path_nodes = vec![]; for node in merkle_path.iter() { idx = idx.sibling(); diff --git a/crates/rust-client/src/sync/mod.rs b/crates/rust-client/src/sync/mod.rs index 0ebbef0e1..3a126353e 100644 --- a/crates/rust-client/src/sync/mod.rs +++ b/crates/rust-client/src/sync/mod.rs @@ -7,10 +7,11 @@ use core::cmp::max; use crypto::merkle::{InOrderIndex, MmrPeaks}; use miden_objects::{ accounts::{Account, AccountHeader, AccountId}, + block::{BlockHeader, BlockNumber}, crypto::{self, rand::FeltRng}, notes::{NoteId, NoteInclusionProof, NoteTag, Nullifier}, transaction::TransactionId, - BlockHeader, Digest, + Digest, }; use tracing::info; @@ -33,7 +34,7 @@ pub use tags::{NoteTagRecord, NoteTagSource}; /// Contains stats about the sync operation. pub struct SyncSummary { /// Block number up to which the client has been synced. - pub block_num: u32, + pub block_num: BlockNumber, /// IDs of new notes received. pub received_notes: Vec, /// IDs of tracked notes that received inclusion proofs. @@ -50,7 +51,7 @@ pub struct SyncSummary { impl SyncSummary { pub fn new( - block_num: u32, + block_num: BlockNumber, received_notes: Vec, committed_notes: Vec, consumed_notes: Vec, @@ -69,7 +70,7 @@ impl SyncSummary { } } - pub fn new_empty(block_num: u32) -> Self { + pub fn new_empty(block_num: BlockNumber) -> Self { Self { block_num, received_notes: vec![], @@ -150,7 +151,7 @@ impl Client { // -------------------------------------------------------------------------------------------- /// Returns the block number of the last state sync block. - pub async fn get_sync_height(&self) -> Result { + pub async fn get_sync_height(&self) -> Result { self.store.get_sync_height().await.map_err(|err| err.into()) } @@ -175,7 +176,7 @@ impl Client { /// 8. All updates are applied to the store to be persisted. pub async fn sync_state(&mut self) -> Result { _ = self.ensure_genesis_in_place().await?; - let mut total_sync_summary = SyncSummary::new_empty(0); + let mut total_sync_summary = SyncSummary::new_empty(0.into()); loop { let response = self.sync_state_once().await?; let is_last_block = matches!(response, SyncStatus::SyncedToLastBlock(_)); @@ -242,15 +243,15 @@ impl Client { let note_updates = committed_note_updates.combine_with(consumed_note_updates); - let (public_accounts, offchain_accounts): (Vec<_>, Vec<_>) = + let (public_accounts, private_accounts): (Vec<_>, Vec<_>) = accounts.into_iter().partition(|account_header| account_header.id().is_public()); let updated_public_accounts = self .get_updated_public_accounts(&response.account_hash_updates, &public_accounts) .await?; - let mismatched_offchain_accounts = self - .validate_local_account_hashes(&response.account_hash_updates, &offchain_accounts) + let mismatched_private_accounts = self + .validate_local_account_hashes(&response.account_hash_updates, &private_accounts) .await?; // Build PartialMmr with current data and apply updates @@ -278,7 +279,7 @@ impl Client { note_updates.committed_note_ids().into_iter().collect(), note_updates.consumed_note_ids().into_iter().collect(), updated_public_accounts.iter().map(|acc| acc.id()).collect(), - mismatched_offchain_accounts.iter().map(|(acc_id, _)| *acc_id).collect(), + mismatched_private_accounts.iter().map(|(acc_id, _)| *acc_id).collect(), transactions_to_commit.iter().map(|tx| tx.transaction_id).collect(), ); @@ -290,7 +291,7 @@ impl Client { new_authentication_nodes, updated_accounts: AccountUpdates::new( updated_public_accounts, - mismatched_offchain_accounts, + mismatched_private_accounts, ), block_has_relevant_notes: incoming_block_has_relevant_notes, transactions_to_discard, @@ -573,10 +574,10 @@ impl Client { .map_err(ClientError::RpcError) } - /// Validates account hash updates and returns a vector with all the offchain account + /// Validates account hash updates and returns a vector with all the private account /// mismatches. /// - /// Offchain account mismatches happen when the hash account of the local tracked account + /// Private account mismatches happen when the hash account of the local tracked account /// doesn't match the hash account of the account in the node. This would be an anomaly and may /// happen for two main reasons: /// - A different client made a transaction with the account, changing its state. @@ -585,13 +586,13 @@ impl Client { async fn validate_local_account_hashes( &mut self, account_updates: &[(AccountId, Digest)], - current_offchain_accounts: &[AccountHeader], + current_private_accounts: &[AccountHeader], ) -> Result, ClientError> { let mut mismatched_accounts = vec![]; for (remote_account_id, remote_account_hash) in account_updates { // ensure that if we track that account, it has the same hash - let mismatched_account = current_offchain_accounts + let mismatched_account = current_private_accounts .iter() .find(|acc| *remote_account_id == acc.id() && *remote_account_hash != acc.hash()); diff --git a/crates/rust-client/src/tests.rs b/crates/rust-client/src/tests.rs index b535b5174..e248e32a5 100644 --- a/crates/rust-client/src/tests.rs +++ b/crates/rust-client/src/tests.rs @@ -143,7 +143,7 @@ async fn test_get_input_note() { .import_note(NoteFile::NoteDetails { details: note.into(), tag: None, - after_block_num: 0, + after_block_num: 0.into(), }) .await .unwrap(); @@ -385,11 +385,11 @@ async fn test_sync_state_mmr() { // Ensure the proofs are valid let mmr_proof = partial_mmr.open(1).unwrap().unwrap(); - let (block_1, _) = rpc_api.get_block_header_by_number(Some(1), false).await.unwrap(); + let (block_1, _) = rpc_api.get_block_header_by_number(Some(1.into()), false).await.unwrap(); partial_mmr.peaks().verify(block_1.hash(), mmr_proof).unwrap(); let mmr_proof = partial_mmr.open(4).unwrap().unwrap(); - let (block_4, _) = rpc_api.get_block_header_by_number(Some(4), false).await.unwrap(); + let (block_4, _) = rpc_api.get_block_header_by_number(Some(4.into()), false).await.unwrap(); partial_mmr.peaks().verify(block_4.hash(), mmr_proof).unwrap(); } @@ -501,7 +501,7 @@ async fn test_import_note_validation() { client .import_note(NoteFile::NoteDetails { details: committed_note.clone().into(), - after_block_num: 0, + after_block_num: 0.into(), tag: None, }) .await @@ -510,7 +510,7 @@ async fn test_import_note_validation() { client .import_note(NoteFile::NoteDetails { details: expected_note.clone().into(), - after_block_num: 0, + after_block_num: 0.into(), tag: None, }) .await diff --git a/crates/rust-client/src/transactions/mod.rs b/crates/rust-client/src/transactions/mod.rs index edc74c92c..0362f964a 100644 --- a/crates/rust-client/src/transactions/mod.rs +++ b/crates/rust-client/src/transactions/mod.rs @@ -13,6 +13,7 @@ pub use miden_lib::transaction::TransactionKernel; use miden_objects::{ accounts::{Account, AccountCode, AccountDelta, AccountId, AccountType}, assets::{Asset, NonFungibleAsset}, + block::BlockNumber, crypto::merkle::MerklePath, notes::{Note, NoteDetails, NoteId, NoteTag}, transaction::{InputNotes, TransactionArgs}, @@ -74,7 +75,7 @@ impl TransactionResult { transaction: ExecutedTransaction, note_screener: NoteScreener, partial_notes: Vec<(NoteDetails, NoteTag)>, - current_block_num: u32, + current_block_num: BlockNumber, current_timestamp: Option, ) -> Result { let mut relevant_notes = vec![]; @@ -132,7 +133,7 @@ impl TransactionResult { } /// Returns the block against which the transaction was executed. - pub fn block_num(&self) -> u32 { + pub fn block_num(&self) -> BlockNumber { self.transaction.block_header().block_num() } @@ -174,7 +175,7 @@ pub struct TransactionRecord { pub input_note_nullifiers: Vec, pub output_notes: OutputNotes, pub transaction_script: Option, - pub block_num: u32, + pub block_num: BlockNumber, pub transaction_status: TransactionStatus, } @@ -188,7 +189,7 @@ impl TransactionRecord { input_note_nullifiers: Vec, output_notes: OutputNotes, transaction_script: Option, - block_num: u32, + block_num: BlockNumber, transaction_status: TransactionStatus, ) -> TransactionRecord { TransactionRecord { @@ -211,7 +212,7 @@ pub enum TransactionStatus { /// Transaction has been submitted but not yet committed. Pending, /// Transaction has been committed and included at the specified block number. - Committed(u32), + Committed(BlockNumber), /// Transaction has been discarded and isn't included in the node. Discarded, } @@ -743,7 +744,7 @@ impl Client { &mut self, foreign_accounts: BTreeSet, tx_args: &mut TransactionArgs, - ) -> Result, ClientError> { + ) -> Result, ClientError> { if foreign_accounts.is_empty() { return Ok(None); } diff --git a/crates/rust-client/src/transactions/request/builder.rs b/crates/rust-client/src/transactions/request/builder.rs index b46b45483..2f3704abc 100644 --- a/crates/rust-client/src/transactions/request/builder.rs +++ b/crates/rust-client/src/transactions/request/builder.rs @@ -5,6 +5,7 @@ use miden_lib::notes::{create_p2id_note, create_p2idr_note, create_swap_note}; use miden_objects::{ accounts::AccountId, assets::{Asset, FungibleAsset}, + block::BlockNumber, crypto::{ merkle::{InnerNodeInfo, MerkleStore}, rand::FeltRng, @@ -280,7 +281,7 @@ impl TransactionRequestBuilder { /// note. pub fn pay_to_id( payment_data: PaymentTransactionData, - recall_height: Option, + recall_height: Option, note_type: NoteType, rng: &mut impl FeltRng, ) -> Result { diff --git a/crates/web-client/Cargo.toml b/crates/web-client/Cargo.toml index 1f4460b26..cca2ae114 100644 --- a/crates/web-client/Cargo.toml +++ b/crates/web-client/Cargo.toml @@ -22,7 +22,7 @@ testing = ["miden-client/testing"] miden-client = { version = "0.6", path = "../rust-client", default-features = false, features = ["idxdb", "web-tonic"] } miden-lib = { workspace = true } miden-objects = { workspace = true } -miden-remote-provers = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["tx-prover"] } +miden-proving-service-client = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["tx-prover"] } miden-tx = { workspace = true } rand = { workspace = true } serde = { workspace = true } diff --git a/crates/web-client/package-lock.json b/crates/web-client/package-lock.json index c314bf4ec..9c504c5b3 100644 --- a/crates/web-client/package-lock.json +++ b/crates/web-client/package-lock.json @@ -1,12 +1,12 @@ { "name": "@demox-labs/miden-sdk", - "version": "0.0.19", + "version": "0.6.1-next.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@demox-labs/miden-sdk", - "version": "0.0.19", + "version": "0.6.1-next.3", "dependencies": { "chai-as-promised": "^8.0.0", "dexie": "^4.0.1", diff --git a/crates/web-client/src/lib.rs b/crates/web-client/src/lib.rs index 1c37f3d9f..e060b3c15 100644 --- a/crates/web-client/src/lib.rs +++ b/crates/web-client/src/lib.rs @@ -8,7 +8,7 @@ use miden_client::{ Client, }; use miden_objects::{crypto::rand::RpoRandomCoin, Felt}; -use miden_remote_provers::RemoteTransactionProver; +use miden_proving_service_client::RemoteTransactionProver; use rand::{rngs::StdRng, Rng, SeedableRng}; use wasm_bindgen::prelude::*; diff --git a/crates/web-client/src/models/block_header.rs b/crates/web-client/src/models/block_header.rs index 5cc8288dc..6e2cc90e8 100644 --- a/crates/web-client/src/models/block_header.rs +++ b/crates/web-client/src/models/block_header.rs @@ -26,7 +26,7 @@ impl BlockHeader { } pub fn block_num(&self) -> u32 { - self.0.block_num() + self.0.block_num().as_u32() } pub fn chain_root(&self) -> RpoDigest { diff --git a/crates/web-client/src/models/note_execution_hint.rs b/crates/web-client/src/models/note_execution_hint.rs index 1e43b54cf..4265afa49 100644 --- a/crates/web-client/src/models/note_execution_hint.rs +++ b/crates/web-client/src/models/note_execution_hint.rs @@ -16,7 +16,7 @@ impl NoteExecutionHint { } pub fn after_block(block_num: u32) -> NoteExecutionHint { - NoteExecutionHint(NativeNoteExecutionHint::after_block(block_num).unwrap()) + NoteExecutionHint(NativeNoteExecutionHint::after_block(block_num.into()).unwrap()) } pub fn on_block_slot(epoch_len: u8, slot_len: u8, slot_offset: u8) -> NoteExecutionHint { @@ -28,7 +28,7 @@ impl NoteExecutionHint { } pub fn can_be_consumed(&self, block_num: u32) -> bool { - self.0.can_be_consumed(block_num).unwrap() + self.0.can_be_consumed(block_num.into()).unwrap() } } diff --git a/crates/web-client/src/models/note_location.rs b/crates/web-client/src/models/note_location.rs index fd8a0729f..8d008cc48 100644 --- a/crates/web-client/src/models/note_location.rs +++ b/crates/web-client/src/models/note_location.rs @@ -8,7 +8,7 @@ pub struct NoteLocation(NativeNoteLocation); #[wasm_bindgen] impl NoteLocation { pub fn block_num(&self) -> u32 { - self.0.block_num() + self.0.block_num().as_u32() } pub fn node_index_in_block(&self) -> u16 { diff --git a/crates/web-client/src/models/provers.rs b/crates/web-client/src/models/provers.rs index 63ebf5d57..26bed1a7e 100644 --- a/crates/web-client/src/models/provers.rs +++ b/crates/web-client/src/models/provers.rs @@ -1,6 +1,6 @@ use alloc::sync::Arc; -use miden_remote_provers::RemoteTransactionProver; +use miden_proving_service_client::RemoteTransactionProver; use miden_tx::{LocalTransactionProver, TransactionProver as TransactionProverTrait}; use wasm_bindgen::prelude::*; diff --git a/crates/web-client/src/models/sync_summary.rs b/crates/web-client/src/models/sync_summary.rs index d927df097..34d1bf4e1 100644 --- a/crates/web-client/src/models/sync_summary.rs +++ b/crates/web-client/src/models/sync_summary.rs @@ -9,7 +9,7 @@ pub struct SyncSummary(NativeSyncSummary); #[wasm_bindgen] impl SyncSummary { pub fn block_num(&self) -> u32 { - self.0.block_num + self.0.block_num.as_u32() } pub fn received_notes(&self) -> Vec { diff --git a/crates/web-client/src/models/transaction_record.rs b/crates/web-client/src/models/transaction_record.rs index 0c5e06b40..627a6ab4f 100644 --- a/crates/web-client/src/models/transaction_record.rs +++ b/crates/web-client/src/models/transaction_record.rs @@ -45,7 +45,7 @@ impl TransactionRecord { // } pub fn block_num(&self) -> u32 { - self.0.block_num + self.0.block_num.as_u32() } pub fn transaction_status(&self) -> TransactionStatus { diff --git a/crates/web-client/src/models/transaction_result.rs b/crates/web-client/src/models/transaction_result.rs index cd7e914be..b43db9d99 100644 --- a/crates/web-client/src/models/transaction_result.rs +++ b/crates/web-client/src/models/transaction_result.rs @@ -22,7 +22,7 @@ impl TransactionResult { // TODO: relevant_notes pub fn block_num(&self) -> u32 { - self.0.block_num() + self.0.block_num().as_u32() } pub fn transaction_arguments(&self) -> TransactionArgs { diff --git a/crates/web-client/src/models/transaction_status.rs b/crates/web-client/src/models/transaction_status.rs index 029ce86e1..250f46f7c 100644 --- a/crates/web-client/src/models/transaction_status.rs +++ b/crates/web-client/src/models/transaction_status.rs @@ -12,7 +12,7 @@ impl TransactionStatus { } pub fn committed(block_num: u32) -> TransactionStatus { - TransactionStatus(NativeTransactionStatus::Committed(block_num)) + TransactionStatus(NativeTransactionStatus::Committed(block_num.into())) } pub fn is_pending(&self) -> bool { @@ -25,7 +25,7 @@ impl TransactionStatus { pub fn get_block_num(&self) -> Option { match self.0 { - NativeTransactionStatus::Committed(block_num) => Some(block_num), + NativeTransactionStatus::Committed(block_num) => Some(block_num.as_u32()), _ => None, } } diff --git a/crates/web-client/src/new_transactions.rs b/crates/web-client/src/new_transactions.rs index 42e55a750..e745691be 100644 --- a/crates/web-client/src/new_transactions.rs +++ b/crates/web-client/src/new_transactions.rs @@ -1,5 +1,5 @@ use miden_client::{ - notes::get_input_note_with_id_prefix, + notes::{get_input_note_with_id_prefix, BlockNumber}, transactions::{ PaymentTransactionData, SwapTransactionData, TransactionRequestBuilder as NativeTransactionRequestBuilder, @@ -160,7 +160,7 @@ impl WebClient { let send_transaction_request = if let Some(recall_height) = recall_height { NativeTransactionRequestBuilder::pay_to_id( payment_transaction, - Some(recall_height), + Some(BlockNumber::from(recall_height)), note_type.into(), client.rng(), ) diff --git a/crates/web-client/test/mocha.global.setup.mjs b/crates/web-client/test/mocha.global.setup.mjs index 7ba8cc66a..1de5b51a8 100644 --- a/crates/web-client/test/mocha.global.setup.mjs +++ b/crates/web-client/test/mocha.global.setup.mjs @@ -45,9 +45,7 @@ before(async () => { throw error; } - if (env.DEBUG_MODE) { - testingPage.on("console", (msg) => console.log("PAGE LOG:", msg.text())); - } + testingPage.on("console", (msg) => console.log("PAGE LOG:", msg.text())); // Creates the client in the test context and attach to window object await testingPage.evaluate( diff --git a/crates/web-client/test/new_transactions.test.ts b/crates/web-client/test/new_transactions.test.ts index 92e34c48e..8e8305bd6 100644 --- a/crates/web-client/test/new_transactions.test.ts +++ b/crates/web-client/test/new_transactions.test.ts @@ -491,116 +491,115 @@ const customTxWithMultipleNotes = async ( ); const p2id_script = ` - use.miden::account - use.miden::note - use.miden::contracts::wallets::basic->wallet - - # ERRORS - # ================================================================================================= - - # P2ID script expects exactly 2 note inputs - const.ERR_P2ID_WRONG_NUMBER_OF_INPUTS=0x00020050 - - # P2ID's target account address and transaction address do not match - const.ERR_P2ID_TARGET_ACCT_MISMATCH=0x00020051 - - #! Helper procedure to add all assets of a note to an account. - #! - #! Inputs: [] - #! Outputs: [] - proc.add_note_assets_to_account - push.0 exec.note::get_assets - # => [num_of_assets, 0 = ptr, ...] - - # compute the pointer at which we should stop iterating - dup.1 add - # => [end_ptr, ptr, ...] - - # pad the stack and move the pointer to the top - padw movup.5 - # => [ptr, 0, 0, 0, 0, end_ptr, ...] - - # compute the loop latch - dup dup.6 neq - # => [latch, ptr, 0, 0, 0, 0, end_ptr, ...] - - while.true - # => [ptr, 0, 0, 0, 0, end_ptr, ...] - - # save the pointer so that we can use it later - dup movdn.5 - # => [ptr, 0, 0, 0, 0, ptr, end_ptr, ...] - - # load the asset - mem_loadw - # => [ASSET, ptr, end_ptr, ...] - - # pad the stack before call - padw swapw padw padw swapdw - # => [ASSET, pad(12), ptr, end_ptr, ...] - - # add asset to the account - call.wallet::receive_asset - # => [pad(16), ptr, end_ptr, ...] - - # clean the stack after call - dropw dropw dropw - # => [0, 0, 0, 0, ptr, end_ptr, ...] - - # increment the pointer and compare it to the end_ptr - movup.4 add.1 dup dup.6 neq - # => [latch, ptr+1, ASSET, end_ptr, ...] - end - - # clear the stack - drop dropw drop - end - - #! Pay-to-ID script: adds all assets from the note to the account, assuming ID of the account - #! matches target account ID specified by the note inputs. - #! - #! Requires that the account exposes: - #! - miden::contracts::wallets::basic::receive_asset procedure. - #! - #! Inputs: [] - #! Outputs: [] - #! - #! Note inputs are assumed to be as follows: - #! - target_account_id is the ID of the account for which the note is intended. - #! - #! Panics if: - #! - Account does not expose miden::contracts::wallets::basic::receive_asset procedure. - #! - Account ID of executing account is not equal to the Account ID specified via note inputs. - #! - The same non-fungible asset already exists in the account. - #! - Adding a fungible asset would result in amount overflow, i.e., the total amount would be - #! greater than 2^63. - begin - # store the note inputs to memory starting at address 0 - push.0 exec.note::get_inputs - # => [num_inputs, inputs_ptr] - - # make sure the number of inputs is 2 - eq.2 assert.err=ERR_P2ID_WRONG_NUMBER_OF_INPUTS - # => [inputs_ptr] - - # read the target account ID from the note inputs - padw movup.4 mem_loadw drop drop - # => [target_account_id_prefix, target_account_id_suffix] - - exec.account::get_id - # => [account_id_prefix, account_id_suffix, target_account_id_prefix, target_account_id_suffix, ...] - - # ensure account_id = target_account_id, fails otherwise - exec.account::is_id_eq assert.err=ERR_P2ID_TARGET_ACCT_MISMATCH - # => [] - - exec.add_note_assets_to_account - # => [] - end + use.miden::account + use.miden::note + use.miden::contracts::wallets::basic->wallet + + # ERRORS + # ================================================================================================= + + # P2ID script expects exactly 2 note inputs + const.ERR_P2ID_WRONG_NUMBER_OF_INPUTS=0x00020050 + + # P2ID's target account address and transaction address do not match + const.ERR_P2ID_TARGET_ACCT_MISMATCH=0x00020051 + + #! Helper procedure to add all assets of a note to an account. + #! + #! Inputs: [] + #! Outputs: [] + proc.add_note_assets_to_account + push.0 exec.note::get_assets + # => [num_of_assets, 0 = ptr, ...] + + # compute the pointer at which we should stop iterating + dup.1 add + # => [end_ptr, ptr, ...] + + # pad the stack and move the pointer to the top + padw movup.5 + # => [ptr, 0, 0, 0, 0, end_ptr, ...] + + # compute the loop latch + dup dup.6 neq + # => [latch, ptr, 0, 0, 0, 0, end_ptr, ...] + + while.true + # => [ptr, 0, 0, 0, 0, end_ptr, ...] + + # save the pointer so that we can use it later + dup movdn.5 + # => [ptr, 0, 0, 0, 0, ptr, end_ptr, ...] + + # load the asset + mem_loadw + # => [ASSET, ptr, end_ptr, ...] + + # pad the stack before call + padw swapw padw padw swapdw + # => [ASSET, pad(12), ptr, end_ptr, ...] + + # add asset to the account + call.wallet::receive_asset + # => [pad(16), ptr, end_ptr, ...] + + # clean the stack after call + dropw dropw dropw + # => [0, 0, 0, 0, ptr, end_ptr, ...] + + # increment the pointer and compare it to the end_ptr + movup.4 add.1 dup dup.6 neq + # => [latch, ptr+1, ASSET, end_ptr, ...] + end + + # clear the stack + drop dropw drop + end + + #! Pay-to-ID script: adds all assets from the note to the account, assuming ID of the account + #! matches target account ID specified by the note inputs. + #! + #! Requires that the account exposes: + #! - miden::contracts::wallets::basic::receive_asset procedure. + #! + #! Inputs: [] + #! Outputs: [] + #! + #! Note inputs are assumed to be as follows: + #! - target_account_id is the ID of the account for which the note is intended. + #! + #! Panics if: + #! - Account does not expose miden::contracts::wallets::basic::receive_asset procedure. + #! - Account ID of executing account is not equal to the Account ID specified via note inputs. + #! - The same non-fungible asset already exists in the account. + #! - Adding a fungible asset would result in amount overflow, i.e., the total amount would be + #! greater than 2^63. + begin + # store the note inputs to memory starting at address 0 + push.0 exec.note::get_inputs + # => [num_inputs, inputs_ptr] + + # make sure the number of inputs is 2 + eq.2 assert.err=ERR_P2ID_WRONG_NUMBER_OF_INPUTS + # => [inputs_ptr] + + # read the target account ID from the note inputs + padw movup.4 mem_loadw drop drop + # => [target_account_id_prefix, target_account_id_suffix] + + exec.account::get_id + # => [account_id_prefix, account_id_suffix, target_account_id_prefix, target_account_id_suffix, ...] + + # ensure account_id = target_account_id, fails otherwise + exec.account::is_id_equal assert.err=ERR_P2ID_TARGET_ACCT_MISMATCH + # => [] + + exec.add_note_assets_to_account + # => [] + end `; let compiledNoteScript = await client.compile_note_script(p2id_script); - let noteInputs = new window.NoteInputs( new window.FeltArray([ targetAccount.id().suffix(), diff --git a/crates/web-client/yarn.lock b/crates/web-client/yarn.lock index 3b8ad8b97..4d4615f93 100644 --- a/crates/web-client/yarn.lock +++ b/crates/web-client/yarn.lock @@ -432,7 +432,7 @@ chai-as-promised@^8.0.0: dependencies: check-error "^2.0.0" -chai@^5.1.1: +chai@^5.1.1, "chai@>= 2.1.2 < 6": version "5.1.1" resolved "https://registry.npmjs.org/chai/-/chai-5.1.1.tgz" integrity sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA== @@ -526,16 +526,16 @@ color-convert@^2.0.1: dependencies: color-name "~1.1.4" -color-name@1.1.3: - version "1.1.3" - resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz" - integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw== - color-name@~1.1.4: version "1.1.4" resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +color-name@1.1.3: + version "1.1.3" + resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz" + integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw== + commondir@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz" @@ -597,13 +597,6 @@ data-uri-to-buffer@^6.0.2: resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz" integrity sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw== -debug@4, debug@^4.1.1, debug@^4.3.4, debug@^4.3.5, debug@^4.3.6: - version "4.3.6" - resolved "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz" - integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== - dependencies: - ms "2.1.2" - debug@^3.2.7: version "3.2.7" resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz" @@ -611,6 +604,13 @@ debug@^3.2.7: dependencies: ms "^2.1.1" +debug@^4.1.1, debug@^4.3.4, debug@^4.3.5, debug@^4.3.6, debug@4: + version "4.3.6" + resolved "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz" + integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== + dependencies: + ms "2.1.2" + decamelize@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz" @@ -644,7 +644,7 @@ degenerator@^5.0.0: escodegen "^2.1.0" esprima "^4.0.1" -devtools-protocol@0.0.1330662: +devtools-protocol@*, devtools-protocol@0.0.1330662: version "0.0.1330662" resolved "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1330662.tgz" integrity sha512-pzh6YQ8zZfz3iKlCvgzVCu22NdpZ8hNmwU6WnQjNVquh0A9iVosPtNLWDwaWVGyrntQlltPFztTMK5Cg6lfCuw== @@ -934,7 +934,18 @@ glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^8.0.3, glob@^8.1.0: +glob@^8.0.3: + version "8.1.0" + resolved "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + +glob@^8.1.0: version "8.1.0" resolved "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz" integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== @@ -1316,16 +1327,16 @@ minipass@^3.0.0: dependencies: yallist "^4.0.0" -minipass@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz" - integrity sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ== - "minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.1.2: version "7.1.2" resolved "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz" integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== +minipass@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz" + integrity sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ== + minizlib@^2.1.1: version "2.1.2" resolved "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz" @@ -1377,16 +1388,16 @@ mocha@^10.7.3: yargs-parser "^20.2.9" yargs-unparser "^2.0.0" -ms@2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== - ms@^2.1.1, ms@^2.1.3: version "2.1.3" resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +ms@2.1.2: + version "2.1.2" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + netmask@^2.0.2: version "2.0.2" resolved "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz" @@ -1672,14 +1683,14 @@ rimraf@^6.0.1: glob "^11.0.0" package-json-from-dist "^1.0.0" -rollup@^3.27.2: +rollup@^1.20.0||^2.0.0||^3.0.0||^4.0.0, rollup@^2.68.0||^3.0.0||^4.0.0, rollup@^2.78.0||^3.0.0||^4.0.0, rollup@^3.27.2: version "3.29.4" resolved "https://registry.npmjs.org/rollup/-/rollup-3.29.4.tgz" integrity sha512-oWzmBZwvYrU0iJHtDmhsm662rC15FRXmcjCk1xD771dFDx5jJ02ufAQQTn0etB2emNk4J9EZg/yWKpsn9BWGRw== optionalDependencies: fsevents "~2.3.2" -safe-buffer@5.1.2, safe-buffer@^5.1.0: +safe-buffer@^5.1.0, safe-buffer@5.1.2: version "5.1.2" resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== @@ -1952,7 +1963,7 @@ typed-query-selector@^2.12.0: resolved "https://registry.npmjs.org/typed-query-selector/-/typed-query-selector-2.12.0.tgz" integrity sha512-SbklCd1F0EiZOyPiW192rrHZzZ5sBijB6xM+cpmrwDqObvdtunOHHIk9fCGsoK5JVIYXoyEp4iEdE3upFH3PAg== -typescript@^5.5.4: +typescript@^5.5.4, typescript@>=2.7, typescript@>=4.9.5: version "5.5.4" resolved "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz" integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== diff --git a/tests/integration/fpi_tests.rs b/tests/integration/fpi_tests.rs index 1fcf4c870..a03a07c35 100644 --- a/tests/integration/fpi_tests.rs +++ b/tests/integration/fpi_tests.rs @@ -1,5 +1,6 @@ use miden_client::{ accounts::{Account, StorageSlot}, + block::BlockHeader, rpc::domain::accounts::{AccountStorageRequirements, StorageMapKey}, testing::prepare_word, transactions::{ @@ -12,7 +13,7 @@ use miden_objects::{ accounts::{AccountBuilder, AccountComponent, AccountStorageMode, AuthSecretKey, StorageMap}, crypto::dsa::rpo_falcon512::SecretKey, transaction::TransactionScript, - BlockHeader, Digest, + Digest, }; use super::common::*; diff --git a/tests/integration/main.rs b/tests/integration/main.rs index 3af29f296..201fcbd5f 100644 --- a/tests/integration/main.rs +++ b/tests/integration/main.rs @@ -515,7 +515,7 @@ async fn test_get_consumable_notes() { println!("Running P2IDR tx..."); let tx_request = TransactionRequestBuilder::pay_to_id( PaymentTransactionData::new(vec![Asset::Fungible(asset)], from_account_id, to_account_id), - Some(100), + Some(100.into()), NoteType::Private, client.rng(), ) @@ -713,7 +713,7 @@ async fn test_import_expected_note_uncommitted() { let imported_note_id = client_2 .import_note(NoteFile::NoteDetails { details: note.into(), - after_block_num: 0, + after_block_num: 0.into(), tag: None, }) .await diff --git a/tests/integration/onchain_tests.rs b/tests/integration/onchain_tests.rs index df2d840b7..af1951539 100644 --- a/tests/integration/onchain_tests.rs +++ b/tests/integration/onchain_tests.rs @@ -13,9 +13,9 @@ use super::common::*; #[tokio::test] async fn test_onchain_notes_flow() { - // Client 1 is an offchain faucet which will mint an onchain note for client 2 + // Client 1 is an private faucet which will mint an onchain note for client 2 let mut client_1 = create_test_client().await; - // Client 2 is an offchain account which will consume the note that it will sync from the node + // Client 2 is an private account which will consume the note that it will sync from the node let mut client_2 = create_test_client().await; // Client 3 will be transferred part of the assets by client 2's account let mut client_3 = create_test_client().await; @@ -278,7 +278,7 @@ async fn test_onchain_accounts() { #[tokio::test] async fn test_onchain_notes_sync_with_tag() { - // Client 1 has an offchain faucet which will mint an onchain note for client 2 + // Client 1 has an private faucet which will mint an onchain note for client 2 let mut client_1 = create_test_client().await; // Client 2 will be used to sync and check that by adding the tag we can still fetch notes // whose tag doesn't necessarily match any of its accounts diff --git a/tests/integration/swap_transactions_tests.rs b/tests/integration/swap_transactions_tests.rs index 99fcbae6e..8eb6ee643 100644 --- a/tests/integration/swap_transactions_tests.rs +++ b/tests/integration/swap_transactions_tests.rs @@ -217,7 +217,7 @@ async fn test_swap_fully_onchain() { } #[tokio::test] -async fn test_swap_offchain() { +async fn test_swap_private() { const OFFERED_ASSET_AMOUNT: u64 = 1; const REQUESTED_ASSET_AMOUNT: u64 = 25; const BTC_MINT_AMOUNT: u64 = 1000;