Skip to content

Commit

Permalink
fix: BlockHeader is not Copy anymore; remove unused RPC types (#765)
Browse files Browse the repository at this point in the history
* fix: BlockHeader is not Copy anymore, remove unused RPC types

* fix: WASM build
  • Loading branch information
igamigo authored Feb 26, 2025
1 parent cbcaa3a commit 46be8a3
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 159 deletions.
26 changes: 16 additions & 10 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/rust-client/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ pub fn build_wallet_id(
public_key: PublicKey,
storage_mode: AccountStorageMode,
is_mutable: bool,
anchor_block: BlockHeader,
anchor_block: &BlockHeader,
) -> Result<AccountId, ClientError> {
let account_type = if is_mutable {
AccountType::RegularAccountUpdatableCode
} else {
AccountType::RegularAccountImmutableCode
};

let accound_id_anchor = (&anchor_block).try_into().map_err(|_| {
let accound_id_anchor = anchor_block.try_into().map_err(|_| {
ClientError::AccountError(AccountError::AssumptionViolated(
"Provided block header is not an anchor block".to_string(),
))
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl NodeRpcClient for MockRpcApi {
include_mmr_proof: bool,
) -> Result<(BlockHeader, Option<MmrProof>), RpcError> {
if block_num == Some(0.into()) {
return Ok((self.blocks.first().unwrap().header(), None));
return Ok((self.blocks.first().unwrap().header().clone(), None));
}
let block = self
.blocks
Expand All @@ -248,7 +248,7 @@ impl NodeRpcClient for MockRpcApi {
None
};

Ok((block.header(), mmr_proof))
Ok((block.header().clone(), mmr_proof))
}

async fn get_notes_by_id(&mut self, note_ids: &[NoteId]) -> Result<Vec<NetworkNote>, RpcError> {
Expand Down
40 changes: 1 addition & 39 deletions crates/rust-client/src/rpc/domain/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use miden_objects::{block::BlockHeader, crypto::merkle::MerklePath};
use miden_objects::block::BlockHeader;

use super::MissingFieldHelper;
use crate::rpc::{errors::RpcConversionError, generated::block};
Expand Down Expand Up @@ -81,41 +81,3 @@ impl TryFrom<block::BlockHeader> for BlockHeader {
))
}
}

/// Data required to verify a block's inclusion proof.
#[derive(Clone, Debug)]
pub struct BlockInclusionProof {
pub block_header: BlockHeader,
pub mmr_path: MerklePath,
pub chain_length: u32,
}

impl From<BlockInclusionProof> for block::BlockInclusionProof {
fn from(value: BlockInclusionProof) -> Self {
Self {
block_header: Some(value.block_header.into()),
mmr_path: Some((&value.mmr_path).into()),
chain_length: value.chain_length,
}
}
}

impl TryFrom<block::BlockInclusionProof> for BlockInclusionProof {
type Error = RpcConversionError;

fn try_from(value: block::BlockInclusionProof) -> Result<Self, RpcConversionError> {
let result = Self {
block_header: value
.block_header
.ok_or(block::BlockInclusionProof::missing_field("block_header"))?
.try_into()?,
mmr_path: (&value
.mmr_path
.ok_or(block::BlockInclusionProof::missing_field("mmr_path"))?)
.try_into()?,
chain_length: value.chain_length,
};

Ok(result)
}
}
13 changes: 0 additions & 13 deletions crates/rust-client/src/rpc/generated/nostd/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,3 @@ pub struct BlockHeader {
#[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<BlockHeader>,
/// Merkle path associated with the inclusion proof.
#[prost(message, optional, tag = "2")]
pub mmr_path: ::core::option::Option<super::merkle::MerklePath>,
/// The chain length associated with `mmr_path`.
#[prost(fixed32, tag = "3")]
pub chain_length: u32,
}
10 changes: 0 additions & 10 deletions crates/rust-client/src/rpc/generated/nostd/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,3 @@ pub struct NoteSyncRecord {
#[prost(message, optional, tag = "4")]
pub merkle_path: ::core::option::Option<super::merkle::MerklePath>,
}
/// 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.
#[prost(message, repeated, tag = "1")]
pub note_proofs: ::prost::alloc::vec::Vec<NoteInclusionInBlockProof>,
/// Proof of each block's inclusion in the chain.
#[prost(message, repeated, tag = "2")]
pub block_proofs: ::prost::alloc::vec::Vec<super::block::BlockInclusionProof>,
}
17 changes: 14 additions & 3 deletions crates/rust-client/src/rpc/generated/nostd/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,26 @@ pub struct SyncNoteRequest {
/// 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.
/// IDs of all accounts updated in the proposed block for which to retrieve account witnesses.
#[prost(message, repeated, tag = "1")]
pub account_ids: ::prost::alloc::vec::Vec<super::account::AccountId>,
/// Set of nullifiers consumed by this transaction.
/// Nullifiers of all notes consumed by the block for which to retrieve witnesses.
///
/// Due to note erasure it will generally not be possible to know the exact set of nullifiers
/// a block will create, unless we pre-execute note erasure. So in practice, this set of
/// nullifiers will be the set of nullifiers of all proven batches in the block, which is a
/// superset of the nullifiers the block may create.
///
/// However, if it is known that a certain note will be erased, it would not be necessary to
/// provide a nullifier witness for it.
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// Array of note IDs to be checked for existence in the database.
/// Array of note IDs for which to retrieve note inclusion proofs, **if they exist in the store**.
#[prost(message, repeated, tag = "3")]
pub unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// Array of block numbers referenced by all batches in the block.
#[prost(fixed32, repeated, tag = "4")]
pub reference_blocks: ::prost::alloc::vec::Vec<u32>,
}
/// Returns the inputs for a transaction batch.
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
44 changes: 24 additions & 20 deletions crates/rust-client/src/rpc/generated/nostd/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,25 @@ pub struct SyncNoteResponse {
}
/// An account returned as a response to the `GetBlockInputs`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AccountBlockInputRecord {
pub struct AccountWitness {
/// The account ID.
#[prost(message, optional, tag = "1")]
pub account_id: ::core::option::Option<super::account::AccountId>,
/// The latest account hash, zero hash if the account doesn't exist.
/// The latest account state commitment used as the initial state of the requested block.
/// This will be the zero digest if the account doesn't exist.
#[prost(message, optional, tag = "2")]
pub account_hash: ::core::option::Option<super::digest::Digest>,
/// Merkle path to verify the account's inclusion in the MMR.
pub initial_state_commitment: ::core::option::Option<super::digest::Digest>,
/// Merkle path to verify the account's inclusion in the account tree.
#[prost(message, optional, tag = "3")]
pub proof: ::core::option::Option<super::merkle::MerklePath>,
}
/// A nullifier returned as a response to the `GetBlockInputs`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NullifierBlockInputRecord {
/// The nullifier ID.
pub struct NullifierWitness {
/// The nullifier.
#[prost(message, optional, tag = "1")]
pub nullifier: ::core::option::Option<super::digest::Digest>,
/// Merkle path to verify the nullifier's inclusion in the MMR.
/// The SMT proof to verify the nullifier's inclusion in the nullifier tree.
#[prost(message, optional, tag = "2")]
pub opening: ::core::option::Option<super::smt::SmtOpening>,
}
Expand All @@ -109,21 +110,24 @@ pub struct NullifierBlockInputRecord {
pub struct GetBlockInputsResponse {
/// The latest block header.
#[prost(message, optional, tag = "1")]
pub block_header: ::core::option::Option<super::block::BlockHeader>,
/// Peaks of the above block's mmr, The `forest` value is equal to the block number.
pub latest_block_header: ::core::option::Option<super::block::BlockHeader>,
/// Proof of each requested unauthenticated note's inclusion in a block, **if it existed in
/// the store**.
#[prost(message, repeated, tag = "2")]
pub mmr_peaks: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// The hashes of the requested accounts and their authentication paths.
#[prost(message, repeated, tag = "3")]
pub account_states: ::prost::alloc::vec::Vec<AccountBlockInputRecord>,
/// The requested nullifiers and their authentication paths.
#[prost(message, repeated, tag = "4")]
pub nullifiers: ::prost::alloc::vec::Vec<NullifierBlockInputRecord>,
/// 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,
pub unauthenticated_note_proofs: ::prost::alloc::vec::Vec<
super::note::NoteInclusionInBlockProof,
>,
/// The serialized chain MMR which includes proofs for all blocks referenced by the
/// above note inclusion proofs as well as proofs for inclusion of the requested blocks
/// referenced by the batches in the block.
#[prost(bytes = "vec", tag = "3")]
pub chain_mmr: ::prost::alloc::vec::Vec<u8>,
/// The state commitments of the requested accounts and their authentication paths.
#[prost(message, repeated, tag = "4")]
pub account_witnesses: ::prost::alloc::vec::Vec<AccountWitness>,
/// The requested nullifiers and their authentication paths.
#[prost(message, repeated, tag = "5")]
pub nullifier_witnesses: ::prost::alloc::vec::Vec<NullifierWitness>,
}
/// Represents the result of getting batch inputs.
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
13 changes: 0 additions & 13 deletions crates/rust-client/src/rpc/generated/std/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,3 @@ pub struct BlockHeader {
#[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<BlockHeader>,
/// Merkle path associated with the inclusion proof.
#[prost(message, optional, tag = "2")]
pub mmr_path: ::core::option::Option<super::merkle::MerklePath>,
/// The chain length associated with `mmr_path`.
#[prost(fixed32, tag = "3")]
pub chain_length: u32,
}
10 changes: 0 additions & 10 deletions crates/rust-client/src/rpc/generated/std/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,3 @@ pub struct NoteSyncRecord {
#[prost(message, optional, tag = "4")]
pub merkle_path: ::core::option::Option<super::merkle::MerklePath>,
}
/// 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.
#[prost(message, repeated, tag = "1")]
pub note_proofs: ::prost::alloc::vec::Vec<NoteInclusionInBlockProof>,
/// Proof of each block's inclusion in the chain.
#[prost(message, repeated, tag = "2")]
pub block_proofs: ::prost::alloc::vec::Vec<super::block::BlockInclusionProof>,
}
17 changes: 14 additions & 3 deletions crates/rust-client/src/rpc/generated/std/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,26 @@ pub struct SyncNoteRequest {
/// 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.
/// IDs of all accounts updated in the proposed block for which to retrieve account witnesses.
#[prost(message, repeated, tag = "1")]
pub account_ids: ::prost::alloc::vec::Vec<super::account::AccountId>,
/// Set of nullifiers consumed by this transaction.
/// Nullifiers of all notes consumed by the block for which to retrieve witnesses.
///
/// Due to note erasure it will generally not be possible to know the exact set of nullifiers
/// a block will create, unless we pre-execute note erasure. So in practice, this set of
/// nullifiers will be the set of nullifiers of all proven batches in the block, which is a
/// superset of the nullifiers the block may create.
///
/// However, if it is known that a certain note will be erased, it would not be necessary to
/// provide a nullifier witness for it.
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// Array of note IDs to be checked for existence in the database.
/// Array of note IDs for which to retrieve note inclusion proofs, **if they exist in the store**.
#[prost(message, repeated, tag = "3")]
pub unauthenticated_notes: ::prost::alloc::vec::Vec<super::digest::Digest>,
/// Array of block numbers referenced by all batches in the block.
#[prost(fixed32, repeated, tag = "4")]
pub reference_blocks: ::prost::alloc::vec::Vec<u32>,
}
/// Returns the inputs for a transaction batch.
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
Loading

0 comments on commit 46be8a3

Please sign in to comment.