Skip to content
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

Implement query / dynamic shard component discovery in Fog View Router #2189

Merged
merged 10 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fog/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protobuf = "2.27.1"
mc-api = { path = "../../api" }
mc-attest-api = { path = "../../attest/api" }
mc-attest-core = { path = "../../attest/core" }
mc-attest-enclave-api = { path = "../../attest/enclave-api" }
mc-consensus-api = { path = "../../consensus/api" }
mc-crypto-keys = { path = "../../crypto/keys" }
mc-fog-enclave-connection = { path = "../enclave_connection" }
Expand Down
24 changes: 23 additions & 1 deletion fog/api/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@
//
// Contains helper methods that enable conversions for Fog Api types.

use crate::{fog_common, ingest_common};
use crate::{fog_common, ingest_common, view::MultiViewStoreQueryRequest};
use mc_api::ConversionError;
use mc_attest_api::attest;
use mc_attest_enclave_api::{ClientSession, EnclaveMessage};
use mc_crypto_keys::CompressedRistrettoPublic;
use mc_fog_types::common;

impl From<Vec<mc_attest_enclave_api::EnclaveMessage<mc_attest_enclave_api::ClientSession>>>
for MultiViewStoreQueryRequest
{
fn from(enclave_messages: Vec<EnclaveMessage<ClientSession>>) -> MultiViewStoreQueryRequest {
enclave_messages
.into_iter()
.map(|enclave_message| enclave_message.into())
.collect::<Vec<attest::Message>>().into()
}
}

impl From<Vec<attest::Message>> for MultiViewStoreQueryRequest {
fn from(attested_query_messages: Vec<attest::Message>) -> MultiViewStoreQueryRequest {
let mut multi_view_store_query_request = MultiViewStoreQueryRequest::new();
multi_view_store_query_request.set_queries(attested_query_messages.into());

multi_view_store_query_request
}
}

impl From<&common::BlockRange> for fog_common::BlockRange {
fn from(common_block_range: &common::BlockRange) -> fog_common::BlockRange {
let mut proto_block_range = fog_common::BlockRange::new();
Expand Down
26 changes: 0 additions & 26 deletions fog/uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ impl UriScheme for FogViewRouterScheme {
const DEFAULT_INSECURE_PORT: u16 = 3225;
}

/// Fog View Store Scheme
#[derive(Debug, Hash, Ord, PartialOrd, Eq, PartialEq, Clone)]
pub struct FogViewStoreScheme {}

impl UriScheme for FogViewStoreScheme {
/// The part before the '://' of a URL.
const SCHEME_SECURE: &'static str = "fog-view-store";
const SCHEME_INSECURE: &'static str = "insecure-fog-view-store";

/// Default port numbers
const DEFAULT_SECURE_PORT: u16 = 443;
const DEFAULT_INSECURE_PORT: u16 = 3225;
}

/// Fog View Uri Scheme
#[derive(Debug, Hash, Ord, PartialOrd, Eq, PartialEq, Clone)]
pub struct FogViewScheme {}
Expand Down Expand Up @@ -95,8 +81,6 @@ pub type FogIngestUri = Uri<FogIngestScheme>;
pub type FogLedgerUri = Uri<FogLedgerScheme>;
/// Uri used when talking to fog view router service.
pub type FogViewRouterUri = Uri<FogViewRouterScheme>;
/// Uri used when talking to fog view store service.
pub type FogViewStoreUri = Uri<FogViewStoreScheme>;
/// Uri used when talking to fog-view service, with the right default ports and
/// scheme.
pub type FogViewUri = Uri<FogViewScheme>;
Expand Down Expand Up @@ -171,16 +155,6 @@ mod tests {
ResponderId::from_str("node1.test.mobilecoin.com:3225").unwrap()
);
assert!(!uri.use_tls());

let uri =
FogViewStoreUri::from_str("insecure-fog-view-store://node1.test.mobilecoin.com:3225/")
.unwrap();
assert_eq!(uri.addr(), "node1.test.mobilecoin.com:3225");
assert_eq!(
uri.responder_id().unwrap(),
ResponderId::from_str("node1.test.mobilecoin.com:3225").unwrap()
);
assert!(!uri.use_tls());
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion fog/view/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ mc-util-serial = { path = "../../../util/serial" }
mc-util-test-helper = { path = "../../../util/test-helper" }
mc-util-uri = { path = "../../../util/uri" }

mc-fog-test-infra = { path = "../../test_infra" }
mc-fog-types = { path = "../../types" }
mc-fog-view-connection = { path = "../connection" }
mc-fog-view-enclave-measurement = { path = "../enclave/measurement" }
Expand Down
28 changes: 19 additions & 9 deletions fog/view/server/src/bin/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
#![deny(missing_docs)]

//! MobileCoin Fog View Router target
use grpcio::ChannelBuilder;
use mc_common::logger::log;
use mc_fog_uri::FogViewStoreUri;
use mc_fog_api::view_grpc::FogViewApiClient;
use mc_fog_uri::FogViewUri;
use mc_fog_view_enclave::{SgxViewEnclave, ENCLAVE_FILE};
use mc_fog_view_server::{
config::FogViewRouterConfig, fog_view_router_server::FogViewRouterServer,
};
use mc_util_cli::ParserWithBuildInfo;
use std::{env, str::FromStr};
use mc_util_grpc::ConnectionUriGrpcioChannel;
use std::{env, str::FromStr, sync::Arc};

fn main() {
mc_common::setup_panic_handler();
Expand All @@ -34,17 +37,24 @@ fn main() {
);

// TODO: Remove and get from a config.
let mut shard_uris: Vec<FogViewStoreUri> = Vec::new();
let mut fog_view_grpc_clients= Vec::new();
let grpc_env = Arc::new(
grpcio::EnvBuilder::new()
.name_prefix("Main-RPC".to_string())
.build(),
);
for i in 0..50 {
let shard_uri_string = format!(
"insecure-fog-view-store://node{}.test.mobilecoin.com:3225",
i
let shard_uri_string = format!("insecure-fog-view://node{}.test.mobilecoin.com:3225", i);
let shard_uri = FogViewUri::from_str(&shard_uri_string).unwrap();
let fog_view_grpc_client = FogViewApiClient::new(
ChannelBuilder::default_channel_builder(grpc_env.clone())
.connect_to_uri(&shard_uri, &logger),
);
let shard_uri = FogViewStoreUri::from_str(&shard_uri_string).unwrap();
shard_uris.push(shard_uri);
fog_view_grpc_clients.push(fog_view_grpc_client);
}

let mut router_server = FogViewRouterServer::new(config, sgx_enclave, shard_uris, logger);
let mut router_server =
FogViewRouterServer::new(config, sgx_enclave, fog_view_grpc_clients, logger);
router_server.start();

loop {
Expand Down
50 changes: 50 additions & 0 deletions fog/view/server/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
// Copyright (c) 2018-2022 The MobileCoin Foundation

use displaydoc::Display;
use grpcio::RpcStatus;
use mc_common::logger::Logger;
use mc_fog_view_enclave::Error as ViewEnclaveError;
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 View Store: {0}
ViewStoreError(String),
/// View Enclave error: {0}
Enclave(ViewEnclaveError),
}

impl From<grpcio::Error> for RouterServerError {
fn from(src: grpcio::Error) -> Self {
RouterServerError::ViewStoreError(format!("{}", src))
}
}

impl From<mc_common::ResponderIdParseError> for RouterServerError {
fn from(src: mc_common::ResponderIdParseError) -> Self {
RouterServerError::ViewStoreError(format!("{}", src))
}
}

impl From<mc_util_uri::UriParseError> for RouterServerError {
fn from(src: mc_util_uri::UriParseError) -> Self {
RouterServerError::ViewStoreError(format!("{}", src))
}
}

pub fn router_server_err_to_rpc_status(
context: &str,
src: RouterServerError,
logger: Logger,
) -> RpcStatus {
match src {
RouterServerError::ViewStoreError(_) => {
rpc_internal_error(context, format!("{}", src), &logger)
}
RouterServerError::Enclave(_) => {
rpc_permissions_error(context, format!("{}", src), &logger)
}
}
}

impl From<ViewEnclaveError> for RouterServerError {
fn from(src: ViewEnclaveError) -> Self {
RouterServerError::Enclave(src)
}
}

#[derive(Debug, Display)]
pub enum ViewServerError {
Expand Down
Loading