-
Notifications
You must be signed in to change notification settings - Fork 154
Key Image Router Service #2898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
awygle
merged 11 commits into
feature/fog-ledger-router
from
awygle/key-image-router-service
Jan 3, 2023
Merged
Key Image Router Service #2898
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd880fe
Key Image Router Service
awygle 66d011e
Remove unneeded dead_code annotation
awygle e55b8dc
Update fog/ledger/server/src/error.rs
NotGyro 62a2d4e
Update fog/ledger/server/src/key_image_router_service.rs
NotGyro 7ed4a84
Clean up commented-out code
NotGyro aab7d3c
Fix misnamed type in a comment
NotGyro ca10651
Address PR feedback around logging and comments.
awygle 7b1ebdd
Address error in loop termination logic.
awygle caaff3e
Parameterize allowed number of retries for query loop
awygle 1d42c76
Update based on changes from previous PRs
awygle e918a66
Don't create 'groups' in `mod` or `use` declarations.
awygle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2018-2022 The MobileCoin Foundation | ||
|
||
use displaydoc::Display; | ||
use grpcio::RpcStatus; | ||
use mc_common::logger::Logger; | ||
use mc_fog_ledger_enclave_api::Error as LedgerEnclaveError; | ||
use mc_sgx_report_cache_untrusted::Error as ReportCacheError; | ||
use mc_util_grpc::{rpc_internal_error, rpc_permissions_error}; | ||
|
||
#[derive(Debug, Display)] | ||
pub enum RouterServerError { | ||
/// Error related to contacting Fog Ledger Store: {0} | ||
LedgerStoreError(String), | ||
/// Ledger Enclave error: {0} | ||
Enclave(LedgerEnclaveError), | ||
} | ||
|
||
impl From<grpcio::Error> for RouterServerError { | ||
fn from(src: grpcio::Error) -> Self { | ||
RouterServerError::LedgerStoreError(format!("{}", src)) | ||
} | ||
} | ||
|
||
impl From<mc_common::ResponderIdParseError> for RouterServerError { | ||
fn from(src: mc_common::ResponderIdParseError) -> Self { | ||
RouterServerError::LedgerStoreError(format!("{}", src)) | ||
} | ||
} | ||
|
||
impl From<mc_util_uri::UriParseError> for RouterServerError { | ||
fn from(src: mc_util_uri::UriParseError) -> Self { | ||
RouterServerError::LedgerStoreError(format!("{}", src)) | ||
} | ||
} | ||
|
||
impl From<mc_util_uri::UriConversionError> for RouterServerError { | ||
fn from(src: mc_util_uri::UriConversionError) -> Self { | ||
RouterServerError::LedgerStoreError(format!("{}", src)) | ||
} | ||
} | ||
|
||
pub fn router_server_err_to_rpc_status( | ||
context: &str, | ||
src: RouterServerError, | ||
logger: Logger, | ||
) -> RpcStatus { | ||
match src { | ||
RouterServerError::LedgerStoreError(_) => { | ||
rpc_internal_error(context, format!("{}", src), &logger) | ||
} | ||
RouterServerError::Enclave(_) => { | ||
rpc_permissions_error(context, format!("{}", src), &logger) | ||
} | ||
} | ||
} | ||
|
||
impl From<LedgerEnclaveError> for RouterServerError { | ||
fn from(src: LedgerEnclaveError) -> Self { | ||
RouterServerError::Enclave(src) | ||
} | ||
} | ||
|
||
#[derive(Display)] | ||
pub enum LedgerServerError { | ||
/// Ledger Enclave error: {0} | ||
Enclave(LedgerEnclaveError), | ||
/// Report cache error: {0} | ||
ReportCache(ReportCacheError), | ||
} | ||
|
||
impl From<LedgerEnclaveError> for LedgerServerError { | ||
fn from(src: LedgerEnclaveError) -> Self { | ||
LedgerServerError::Enclave(src) | ||
} | ||
} | ||
|
||
impl From<ReportCacheError> for LedgerServerError { | ||
fn from(src: ReportCacheError) -> Self { | ||
Self::ReportCache(src) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2018-2022 The MobileCoin Foundation | ||
|
||
use crate::router_handlers; | ||
use futures::{FutureExt, TryFutureExt}; | ||
use grpcio::{DuplexSink, RequestStream, RpcContext}; | ||
use mc_common::logger::{log, Logger}; | ||
use mc_fog_api::{ | ||
ledger::{LedgerRequest, LedgerResponse}, | ||
ledger_grpc::{self, LedgerApi}, | ||
}; | ||
use mc_fog_ledger_enclave::LedgerEnclaveProxy; | ||
use mc_fog_uri::KeyImageStoreUri; | ||
use mc_util_grpc::rpc_logger; | ||
use mc_util_metrics::SVC_COUNTERS; | ||
use std::{ | ||
collections::HashMap, | ||
sync::{Arc, RwLock}, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct KeyImageRouterService<E> | ||
where | ||
E: LedgerEnclaveProxy, | ||
{ | ||
enclave: E, | ||
shards: Arc<RwLock<HashMap<KeyImageStoreUri, Arc<ledger_grpc::KeyImageStoreApiClient>>>>, | ||
query_retries: usize, | ||
logger: Logger, | ||
} | ||
|
||
impl<E: LedgerEnclaveProxy> KeyImageRouterService<E> { | ||
/// Creates a new LedgerRouterService that can be used by a gRPC server to | ||
/// fulfill gRPC requests. | ||
#[allow(dead_code)] // FIXME | ||
awygle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn new( | ||
enclave: E, | ||
shards: Arc<RwLock<HashMap<KeyImageStoreUri, Arc<ledger_grpc::KeyImageStoreApiClient>>>>, | ||
query_retries: usize, | ||
logger: Logger, | ||
) -> Self { | ||
Self { | ||
enclave, | ||
shards, | ||
query_retries, | ||
logger, | ||
} | ||
} | ||
} | ||
|
||
impl<E> LedgerApi for KeyImageRouterService<E> | ||
where | ||
E: LedgerEnclaveProxy, | ||
{ | ||
fn request( | ||
&mut self, | ||
ctx: RpcContext, | ||
requests: RequestStream<LedgerRequest>, | ||
responses: DuplexSink<LedgerResponse>, | ||
) { | ||
let _timer = SVC_COUNTERS.req(&ctx); | ||
mc_common::logger::scoped_global_logger(&rpc_logger(&ctx, &self.logger), |logger| { | ||
log::warn!( | ||
self.logger, | ||
"Streaming GRPC Ledger API only partially implemented." | ||
); | ||
let logger = logger.clone(); | ||
|
||
let shards = self.shards.read().expect("RwLock poisoned"); | ||
let future = router_handlers::handle_requests( | ||
shards.values().cloned().collect(), | ||
self.enclave.clone(), | ||
requests, | ||
responses, | ||
self.query_retries, | ||
logger.clone(), | ||
) | ||
.map_err(move |err| log::error!(&logger, "failed to reply: {}", err)) | ||
// TODO: Do more with the error than just push it to the log. | ||
awygle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.map(|_| ()); | ||
|
||
ctx.spawn(future) | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.