Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0efab79
Initial re impl
sergerad Mar 5, 2026
0cd229b
Merge branch 'next' of github.com:0xMiden/miden-node into sergerad-co…
sergerad Mar 15, 2026
26dc497
ConversionError struct
sergerad Mar 16, 2026
3a07273
Add ctx ext trait
sergerad Mar 16, 2026
a2e57e2
add impl_from_for_conversion_error
sergerad Mar 16, 2026
a7266b6
more context
sergerad Mar 16, 2026
097d247
unit tests
sergerad Mar 16, 2026
eaf4c39
rm mid_conversion
sergerad Mar 16, 2026
14c3713
update comment
sergerad Mar 16, 2026
7b84c6c
fix context field details
sergerad Mar 16, 2026
132152b
fix field missing
sergerad Mar 16, 2026
4a921dc
fix nonce map_err
sergerad Mar 16, 2026
a59b281
fix more use cases
sergerad Mar 17, 2026
81838af
remove stringify
sergerad Mar 17, 2026
2d8709c
fix missing_field uses
sergerad Mar 17, 2026
6201041
use missing_field in read_account
sergerad Mar 17, 2026
050591c
try_convert_field
sergerad Mar 17, 2026
d3ce53c
TryConvertFieldExt
sergerad Mar 17, 2026
e1abb33
fix commitment field
sergerad Mar 17, 2026
74faae4
fix parsed asset convert
sergerad Mar 17, 2026
526897e
Fix more converts
sergerad Mar 17, 2026
2c77873
revert fmt
sergerad Mar 17, 2026
b45de9a
DecodeBytesExt
sergerad Mar 17, 2026
1e58ecd
GrpcDecodeExt
sergerad Mar 17, 2026
61c593f
add proc maro
sergerad Mar 18, 2026
3ba4358
update macro for more use casese
sergerad Mar 18, 2026
6c4951b
Add macro tests
sergerad Mar 18, 2026
3b1c360
Revert "Add macro tests"
sergerad Mar 24, 2026
10cc37b
Revert "update macro for more use casese"
sergerad Mar 24, 2026
c7a9427
Revert "add proc maro"
sergerad Mar 24, 2026
e672941
Merge branch 'next' of github.com:0xMiden/miden-node into sergerad-co…
sergerad Mar 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions crates/block-producer/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::num::NonZeroU32;
use itertools::Itertools;
use miden_node_proto::clients::{Builder, StoreBlockProducerClient};
use miden_node_proto::domain::batch::BatchInputs;
use miden_node_proto::errors::{ConversionError, MissingFieldHelper};
use miden_node_proto::errors::{ConversionError, ConversionResultExt, GrpcDecodeExt};
use miden_node_proto::{AccountState, generated as proto};
use miden_node_utils::formatting::format_opt;
use miden_protocol::Word;
Expand Down Expand Up @@ -70,21 +70,14 @@ impl TryFrom<proto::store::TransactionInputs> for TransactionInputs {
type Error = ConversionError;

fn try_from(response: proto::store::TransactionInputs) -> Result<Self, Self::Error> {
let AccountState { account_id, account_commitment } = response
.account_state
.ok_or(proto::store::TransactionInputs::missing_field(stringify!(account_state)))?
.try_into()?;
let decoder = response.decoder();
let AccountState { account_id, account_commitment } =
decoder.decode_field("account_state", response.account_state)?;

let mut nullifiers = HashMap::new();
for nullifier_record in response.nullifiers {
let nullifier = nullifier_record
.nullifier
.ok_or(
proto::store::transaction_inputs::NullifierTransactionInputRecord::missing_field(
stringify!(nullifier),
),
)?
.try_into()?;
let decoder = nullifier_record.decoder();
let nullifier = decoder.decode_field("nullifier", nullifier_record.nullifier)?;

// Note that this intentionally maps 0 to None as this is the definition used in
// protobuf.
Expand All @@ -95,7 +88,8 @@ impl TryFrom<proto::store::TransactionInputs> for TransactionInputs {
.found_unauthenticated_notes
.into_iter()
.map(Word::try_from)
.collect::<Result<_, ConversionError>>()?;
.collect::<Result<_, ConversionError>>()
.context("found_unauthenticated_notes")?;

let current_block_height = response.block_height.into();

Expand Down Expand Up @@ -148,11 +142,13 @@ impl StoreClient {
.await?
.into_inner()
.block_header
.ok_or(miden_node_proto::generated::blockchain::BlockHeader::missing_field(
"block_header",
))?;
.ok_or_else(|| {
StoreError::DeserializationError(ConversionError::missing_field::<
miden_node_proto::generated::blockchain::BlockHeader,
>("block_header"))
})?;

BlockHeader::try_from(response).map_err(Into::into)
BlockHeader::try_from(response).map_err(StoreError::DeserializationError)
}

#[instrument(target = COMPONENT, name = "store.client.get_tx_inputs", skip_all, err)]
Expand Down Expand Up @@ -219,7 +215,7 @@ impl StoreClient {

let store_response = self.client.clone().get_block_inputs(request).await?.into_inner();

store_response.try_into().map_err(Into::into)
store_response.try_into().map_err(StoreError::DeserializationError)
}

#[instrument(target = COMPONENT, name = "store.client.get_batch_inputs", skip_all, err)]
Expand All @@ -235,7 +231,7 @@ impl StoreClient {

let store_response = self.client.clone().get_batch_inputs(request).await?.into_inner();

store_response.try_into().map_err(Into::into)
store_response.try_into().map_err(StoreError::DeserializationError)
}

#[instrument(target = COMPONENT, name = "store.client.apply_block", skip_all, err)]
Expand Down
55 changes: 31 additions & 24 deletions crates/ntx-builder/src/clients/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Duration;

use miden_node_proto::clients::{Builder, StoreNtxBuilderClient};
use miden_node_proto::domain::account::{AccountDetails, AccountResponse, NetworkAccountId};
use miden_node_proto::errors::ConversionError;
use miden_node_proto::errors::{ConversionError, ConversionResultExt};
use miden_node_proto::generated::rpc::BlockRange;
use miden_node_proto::generated::{self as proto};
use miden_node_proto::try_convert;
Expand Down Expand Up @@ -101,7 +101,10 @@ impl StoreClient {
match response.current_block_header {
// There are new blocks compared to the builder's latest state
Some(block) => {
let peaks = try_convert(response.current_peaks).collect::<Result<_, _>>()?;
let peaks: Vec<Word> = try_convert(response.current_peaks)
.collect::<Result<_, _>>()
.context("current_peaks")
.map_err(StoreError::DeserializationError)?;
let header =
BlockHeader::try_from(block).map_err(StoreError::DeserializationError)?;

Expand Down Expand Up @@ -140,9 +143,7 @@ impl StoreClient {
// which implies details being public, so OK to error otherwise
let account = match store_response.map(|acc| acc.details) {
Some(Some(details)) => Some(Account::read_from_bytes(&details).map_err(|err| {
StoreError::DeserializationError(ConversionError::deserialization_error(
"account", err,
))
StoreError::DeserializationError(ConversionError::from(err).context("details"))
})?),
_ => None,
};
Expand Down Expand Up @@ -185,7 +186,8 @@ impl StoreClient {
let account_details = account_response
.details
.ok_or(StoreError::MissingDetails("account details".into()))?;
let partial_account = build_minimal_foreign_account(&account_details)?;
let partial_account = build_minimal_foreign_account(&account_details)
.map_err(StoreError::DeserializationError)?;

Ok(AccountInputs::new(partial_account, account_response.witness))
}
Expand Down Expand Up @@ -216,7 +218,10 @@ impl StoreClient {

all_notes.reserve(resp.notes.len());
for note in resp.notes {
all_notes.push(AccountTargetNetworkNote::try_from(note)?);
all_notes.push(
AccountTargetNetworkNote::try_from(note)
.map_err(StoreError::DeserializationError)?,
);
}

match resp.next_token {
Expand Down Expand Up @@ -317,10 +322,9 @@ impl StoreClient {
.into_iter()
.map(|account_id| {
let account_id = AccountId::read_from_bytes(&account_id.id).map_err(|err| {
StoreError::DeserializationError(ConversionError::deserialization_error(
"account_id",
err,
))
StoreError::DeserializationError(
ConversionError::from(err).context("account_id"),
)
})?;
NetworkAccountId::try_from(account_id).map_err(|_| {
StoreError::MalformedResponse(
Expand All @@ -330,12 +334,9 @@ impl StoreClient {
})
.collect::<Result<Vec<NetworkAccountId>, StoreError>>()?;

let pagination_info = response.pagination_info.ok_or(
ConversionError::MissingFieldInProtobufRepresentation {
entity: "NetworkAccountIdList",
field_name: "pagination_info",
},
)?;
let pagination_info = response.pagination_info.ok_or(ConversionError::missing_field::<
proto::store::NetworkAccountIdList,
>("pagination_info"))?;

Ok((accounts, pagination_info))
}
Expand Down Expand Up @@ -406,8 +407,10 @@ impl StoreClient {
let smt_opening = asset_witness.proof.ok_or_else(|| {
StoreError::MalformedResponse("missing proof in vault asset witness".to_string())
})?;
let proof: SmtProof =
smt_opening.try_into().map_err(StoreError::DeserializationError)?;
let proof: SmtProof = smt_opening
.try_into()
.context("proof")
.map_err(StoreError::DeserializationError)?;
let witness = AssetWitness::new(proof)
.map_err(|err| StoreError::DeserializationError(ConversionError::from(err)))?;

Expand Down Expand Up @@ -445,7 +448,10 @@ impl StoreClient {
StoreError::MalformedResponse("missing proof in storage map witness".to_string())
})?;

let proof: SmtProof = smt_opening.try_into().map_err(StoreError::DeserializationError)?;
let proof: SmtProof = smt_opening
.try_into()
.context("proof")
.map_err(StoreError::DeserializationError)?;

// Create the storage map witness using the proof and raw map key.
let witness = StorageMapWitness::new(proof, [map_key]).map_err(|_err| {
Expand Down Expand Up @@ -482,10 +488,11 @@ pub fn build_minimal_foreign_account(
account_details: &AccountDetails,
) -> Result<PartialAccount, ConversionError> {
// Derive account code.
let account_code_bytes = account_details
.account_code
.as_ref()
.ok_or(ConversionError::AccountCodeMissing)?;
let account_code_bytes = account_details.account_code.as_ref().ok_or_else(|| {
ConversionError::missing_field::<proto::rpc::account_response::AccountDetails>(
"account_code",
)
})?;
let account_code = AccountCode::from_bytes(account_code_bytes)?;

// Derive partial storage. Storage maps are not required for foreign accounts.
Expand Down
Loading
Loading