Skip to content

Commit

Permalink
Use sharding strategy to tell view what blocks to process
Browse files Browse the repository at this point in the history
  • Loading branch information
samdealy committed Aug 12, 2022
1 parent 7d90337 commit 8e260c5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
6 changes: 3 additions & 3 deletions fog/view/enclave/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

extern crate alloc;

use alloc::{collections::BTreeMap, vec::Vec};
use alloc::{collections::BTreeMap, string::String, vec::Vec};
use core::result::Result as StdResult;
use displaydoc::Display;
use mc_attest_core::{Quote, Report, SgxError, TargetInfo, VerificationReport};
Expand Down Expand Up @@ -235,8 +235,8 @@ pub enum Error {
EnclaveNotInitialized,
/// Cipher encryption failed: {0}
Cipher(CipherError),
/// Fog View Shard query response collation error
QueryResponseCollation,
/// Fog View Shard query response collation error: {0}
QueryResponseCollation(String),
}

impl From<SgxError> for Error {
Expand Down
46 changes: 35 additions & 11 deletions fog/view/enclave/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate alloc;
mod e_tx_out_store;
mod oblivious_utils;

use alloc::collections::BTreeMap;
use alloc::{collections::BTreeMap, string::ToString};
use e_tx_out_store::{ETxOutStore, StorageDataSize, StorageMetaSize};

use alloc::vec::Vec;
Expand Down Expand Up @@ -266,26 +266,35 @@ where
Error::ProstDecode
})?;

shard_query_response.tx_out_search_results =
self.get_collated_tx_out_search_results(client_query_request, shard_query_responses)?;
let shard_query_responses: Vec<QueryResponse> = shard_query_responses
.into_iter()
.map(|(responder_id, enclave_message)| {
let plaintext_bytes = self.ake.backend_decrypt(responder_id, enclave_message)?;
let query_response: QueryResponse = mc_util_serial::decode(&plaintext_bytes)?;

Ok(query_response)
})
.collect::<Result<Vec<QueryResponse>>>()?;

shard_query_response.tx_out_search_results = self.get_collated_tx_out_search_results(
client_query_request,
shard_query_responses.clone(),
)?;
shard_query_response.highest_processed_block_count =
self.get_minimum_highest_processed_block_count(shard_query_responses)?;

Ok(shard_query_response)
}

fn get_collated_tx_out_search_results(
&self,
client_query_request: QueryRequest,
shard_query_responses: BTreeMap<ResponderId, EnclaveMessage<ClientSession>>,
shard_query_responses: Vec<QueryResponse>,
) -> Result<Vec<TxOutSearchResult>> {
let plaintext_shard_tx_out_search_results: Vec<TxOutSearchResult> = shard_query_responses
.into_iter()
.map(|(responder_id, enclave_message)| {
let plaintext_bytes = self.ake.backend_decrypt(responder_id, enclave_message)?;
let plaintext_response: QueryResponse = mc_util_serial::decode(&plaintext_bytes)?;

Ok(plaintext_response.tx_out_search_results)
})
.collect::<Result<Vec<Vec<TxOutSearchResult>>>>()?
.map(|query_response| query_response.tx_out_search_results)
.collect::<Vec<Vec<TxOutSearchResult>>>()
.iter()
.flat_map(|array| array.iter())
.cloned()
Expand All @@ -296,4 +305,19 @@ where
plaintext_shard_tx_out_search_results,
)
}

fn get_minimum_highest_processed_block_count(
&self,
shard_query_responses: Vec<QueryResponse>,
) -> Result<u64> {
shard_query_responses
.into_iter()
.map(|query_response| query_response.highest_processed_block_count)
.min()
.ok_or_else(|| {
Error::QueryResponseCollation(
"No minimum highest processed block count found.".to_string(),
)
})
}
}

0 comments on commit 8e260c5

Please sign in to comment.