From 0ebdf71802fc1aa0b7f92f36092d87578e578814 Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Mon, 18 Dec 2023 14:03:58 +0100 Subject: [PATCH] proto: get transaction input accepts only one account, fixes #103 --- block-producer/src/server/api.rs | 5 ++--- proto/proto/requests.proto | 2 +- proto/proto/responses.proto | 2 +- proto/src/generated/requests.rs | 4 ++-- proto/src/generated/responses.rs | 4 ++-- store/src/server/api.rs | 8 ++++---- store/src/state.rs | 20 +++++++------------- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/block-producer/src/server/api.rs b/block-producer/src/server/api.rs index 9c00babd2..a955f0893 100644 --- a/block-producer/src/server/api.rs +++ b/block-producer/src/server/api.rs @@ -70,7 +70,7 @@ impl Store for DefaultStore { proven_tx: SharedProvenTx, ) -> Result { 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() @@ -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 diff --git a/proto/proto/requests.proto b/proto/proto/requests.proto index fc37c6052..634915f43 100644 --- a/proto/proto/requests.proto +++ b/proto/proto/requests.proto @@ -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; } diff --git a/proto/proto/responses.proto b/proto/proto/responses.proto index 9e8b4f982..35aafc1ed 100644 --- a/proto/proto/responses.proto +++ b/proto/proto/responses.proto @@ -97,7 +97,7 @@ message NullifierTransactionInputRecord { } message GetTransactionInputsResponse { - repeated AccountTransactionInputRecord account_states = 1; + AccountTransactionInputRecord account_state = 1; repeated NullifierTransactionInputRecord nullifiers = 2; } diff --git a/proto/src/generated/requests.rs b/proto/src/generated/requests.rs index 6a220515a..cd752a71a 100644 --- a/proto/src/generated/requests.rs +++ b/proto/src/generated/requests.rs @@ -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, + #[prost(message, optional, tag = "1")] + pub account_id: ::core::option::Option, #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, } diff --git a/proto/src/generated/responses.rs b/proto/src/generated/responses.rs index 290f2f6cc..06f2fe3a7 100644 --- a/proto/src/generated/responses.rs +++ b/proto/src/generated/responses.rs @@ -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, + #[prost(message, optional, tag = "1")] + pub account_state: ::core::option::Option, #[prost(message, repeated, tag = "2")] pub nullifiers: ::prost::alloc::vec::Vec, } diff --git a/store/src/server/api.rs b/store/src/server/api.rs index d1e16ef2d..ad4044d65 100644 --- a/store/src/server/api.rs +++ b/store/src/server/api.rs @@ -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 = 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), })) } diff --git a/store/src/state.rs b/store/src/state.rs index 43cbc69cc..3cfb673fc 100644 --- a/store/src/state.rs +++ b/store/src/state.rs @@ -404,21 +404,15 @@ impl State { pub async fn get_transaction_inputs( &self, - account_ids: &[AccountId], + account_id: AccountId, nullifiers: &[RpoDigest], - ) -> Result<(Vec, Vec), anyhow::Error> { + ) -> Result<(AccountState, Vec), 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::, MerkleError>>()?; + let account = AccountState { + account_id, + account_hash: inner.account_tree.get_leaf(account_id)?, + }; let nullifier_blocks = nullifiers .iter() @@ -434,7 +428,7 @@ impl State { }) .collect(); - Ok((accounts, nullifier_blocks)) + Ok((account, nullifier_blocks)) } }