Skip to content

Commit

Permalink
Merge pull request #108 from 0xPolygonMiden/hacka-issue-103
Browse files Browse the repository at this point in the history
proto: get transaction input accepts only one account, fixes #103
  • Loading branch information
hackaugusto authored Dec 18, 2023
2 parents f342a6e + 0ebdf71 commit 241c0ca
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
5 changes: 2 additions & 3 deletions block-producer/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Store for DefaultStore {
proven_tx: SharedProvenTx,
) -> Result<TxInputs, TxInputsError> {
let request = tonic::Request::new(GetTransactionInputsRequest {
account_ids: vec![proven_tx.account_id().into()],
account_id: Some(proven_tx.account_id().into()),
nullifiers: proven_tx
.consumed_notes()
.iter()
Expand All @@ -87,8 +87,7 @@ impl Store for DefaultStore {

let account_hash = {
let account_state = response
.account_states
.first()
.account_state
.ok_or(TxInputsError::MalformedResponse("account_states empty".to_string()))?;

let account_id_from_store: AccountId = account_state
Expand Down
2 changes: 1 addition & 1 deletion proto/proto/requests.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ message GetBlockInputsRequest {
}

message GetTransactionInputsRequest {
repeated account_id.AccountId account_ids = 1;
account_id.AccountId account_id = 1;
repeated digest.Digest nullifiers = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion proto/proto/responses.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ message NullifierTransactionInputRecord {
}

message GetTransactionInputsResponse {
repeated AccountTransactionInputRecord account_states = 1;
AccountTransactionInputRecord account_state = 1;
repeated NullifierTransactionInputRecord nullifiers = 2;
}

Expand Down
4 changes: 2 additions & 2 deletions proto/src/generated/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub struct GetBlockInputsRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetTransactionInputsRequest {
#[prost(message, repeated, tag = "1")]
pub account_ids: ::prost::alloc::vec::Vec<super::account_id::AccountId>,
#[prost(message, optional, tag = "1")]
pub account_id: ::core::option::Option<super::account_id::AccountId>,
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<super::digest::Digest>,
}
Expand Down
4 changes: 2 additions & 2 deletions proto/src/generated/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub struct NullifierTransactionInputRecord {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetTransactionInputsResponse {
#[prost(message, repeated, tag = "1")]
pub account_states: ::prost::alloc::vec::Vec<AccountTransactionInputRecord>,
#[prost(message, optional, tag = "1")]
pub account_state: ::core::option::Option<AccountTransactionInputRecord>,
#[prost(message, repeated, tag = "2")]
pub nullifiers: ::prost::alloc::vec::Vec<NullifierTransactionInputRecord>,
}
Expand Down
8 changes: 4 additions & 4 deletions store/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ impl api_server::Api for StoreApi {
let request = request.into_inner();

let nullifiers = validate_nullifiers(&request.nullifiers)?;
let account_ids: Vec<u64> = request.account_ids.iter().map(|e| e.id).collect();
let account_id = request.account_id.ok_or(invalid_argument("Account_id missing"))?.id;

let (accounts, nullifiers_blocks) = self
let (account, nullifiers_blocks) = self
.state
.get_transaction_inputs(&account_ids, &nullifiers)
.get_transaction_inputs(account_id, &nullifiers)
.await
.map_err(internal_error)?;

Ok(Response::new(GetTransactionInputsResponse {
account_states: convert(accounts),
account_state: Some(account.into()),
nullifiers: convert(nullifiers_blocks),
}))
}
Expand Down
20 changes: 7 additions & 13 deletions store/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,15 @@ impl State {

pub async fn get_transaction_inputs(
&self,
account_ids: &[AccountId],
account_id: AccountId,
nullifiers: &[RpoDigest],
) -> Result<(Vec<AccountState>, Vec<NullifierStateForTransactionInput>), anyhow::Error> {
) -> Result<(AccountState, Vec<NullifierStateForTransactionInput>), anyhow::Error> {
let inner = self.inner.read().await;

let accounts: Vec<_> = account_ids
.iter()
.cloned()
.map(|id| {
Ok(AccountState {
account_id: id,
account_hash: inner.account_tree.get_leaf(id)?,
})
})
.collect::<Result<Vec<AccountState>, MerkleError>>()?;
let account = AccountState {
account_id,
account_hash: inner.account_tree.get_leaf(account_id)?,
};

let nullifier_blocks = nullifiers
.iter()
Expand All @@ -434,7 +428,7 @@ impl State {
})
.collect();

Ok((accounts, nullifier_blocks))
Ok((account, nullifier_blocks))
}
}

Expand Down

0 comments on commit 241c0ca

Please sign in to comment.