Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 19 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,12 @@ 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 as _,
grpc_decode,
};
use miden_node_proto::{AccountState, generated as proto};
use miden_node_utils::formatting::format_opt;
use miden_protocol::Word;
Expand Down Expand Up @@ -66,25 +71,16 @@ impl Display for TransactionInputs {
}
}

#[grpc_decode]
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 AccountState { account_id, account_commitment } = response.account_state.decode()?;

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 nullifier = nullifier_record.nullifier.decode()?;

// Note that this intentionally maps 0 to None as this is the definition used in
// protobuf.
Expand All @@ -95,7 +91,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 +145,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 +218,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 +234,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
2 changes: 1 addition & 1 deletion crates/grpc-error-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ proc-macro = true

[dependencies]
quote = "1.0"
syn = { features = ["full"], version = "2.0" }
syn = { features = ["full", "visit", "visit-mut"], version = "2.0" }
Loading
Loading