From 90a034fce80e3b32f474044ff205bd696dfd8c42 Mon Sep 17 00:00:00 2001 From: eauge Date: Wed, 13 Feb 2019 16:58:45 -0800 Subject: [PATCH 01/12] warnings as errors --- api/src/lib.rs | 1 + common/src/confidential/confidential_ctx.rs | 1 + common/src/lib.rs | 1 + gateway/bin/main.rs | 1 + gateway/src/client.rs | 9 +++------ gateway/src/impls/confidential.rs | 12 +++--------- gateway/src/impls/oasis.rs | 7 +++---- gateway/src/informant.rs | 13 ------------- gateway/src/lib.rs | 5 ++--- gateway/src/rpc.rs | 6 ------ gateway/src/rpc_apis.rs | 3 --- gateway/src/traits/confidential.rs | 3 +-- gateway/src/traits/oasis.rs | 4 ++-- genesis/src/main.rs | 1 + inspector/parity_patricia_trie/src/lib.rs | 1 + inspector/src/main.rs | 1 + src/lib.rs | 1 + 17 files changed, 22 insertions(+), 48 deletions(-) diff --git a/api/src/lib.rs b/api/src/lib.rs index 8119bdc24..2a5e8a26d 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(warnings)] extern crate protobuf; extern crate serde; diff --git a/common/src/confidential/confidential_ctx.rs b/common/src/confidential/confidential_ctx.rs index 8d3678128..e86d76a3f 100644 --- a/common/src/confidential/confidential_ctx.rs +++ b/common/src/confidential/confidential_ctx.rs @@ -1,3 +1,4 @@ +#![deny(warnings)] use super::key_manager::KeyManagerClient; use ekiden_core::mrae::{ nonce::{Nonce, NONCE_SIZE}, diff --git a/common/src/lib.rs b/common/src/lib.rs index e15273eb1..679aba248 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,5 +1,6 @@ //! Common data structures shared by runtime and gateway. +#![deny(warnings)] extern crate ekiden_core; extern crate ekiden_keymanager_client; extern crate ekiden_keymanager_common; diff --git a/gateway/bin/main.rs b/gateway/bin/main.rs index bfb019f7f..51dcdb1b7 100644 --- a/gateway/bin/main.rs +++ b/gateway/bin/main.rs @@ -16,6 +16,7 @@ //! web3 gateway for Oasis Ethereum runtime. +#![deny(warnings)] extern crate ctrlc; extern crate fdlimit; extern crate log; diff --git a/gateway/src/client.rs b/gateway/src/client.rs index f013bbc2a..6b04b1558 100644 --- a/gateway/src/client.rs +++ b/gateway/src/client.rs @@ -28,12 +28,11 @@ use hash::keccak; use parity_rpc::v1::types::Bytes as RpcBytes; use runtime_ethereum; use runtime_ethereum_common::{confidential::has_confidential_prefix, State as EthState}; -use std::time::{SystemTime, UNIX_EPOCH}; use traits::confidential::PublicKeyResult; use transaction::{Action, LocalizedTransaction, SignedTransaction}; use client_utils::{self, db::Snapshot}; -use ekiden_common::{bytes::B512, environment::Environment}; +use ekiden_common::{environment::Environment}; use ekiden_core::{error::Error, futures::prelude::*}; use ekiden_db_trusted::Database; use ekiden_keymanager_client::KeyManager as EkidenKeyManager; @@ -817,9 +816,9 @@ impl Client { .is_confidential(transaction) .map_err(|_| CallError::StateCorrupt)? { - self.confidential_estimate_gas(transaction, id) + self.confidential_estimate_gas(transaction) } else { - self._estimate_gas(transaction, id, db, state) + self._estimate_gas(transaction, db, state) } } @@ -828,7 +827,6 @@ impl Client { fn _estimate_gas( &self, transaction: &SignedTransaction, - id: BlockId, db: StateDb, mut state: EthState, ) -> Result { @@ -849,7 +847,6 @@ impl Client { fn confidential_estimate_gas( &self, transaction: &SignedTransaction, - id: BlockId, ) -> Result { info!("estimating gas for a confidential contract"); diff --git a/gateway/src/impls/confidential.rs b/gateway/src/impls/confidential.rs index c1fac58bb..9bc009333 100644 --- a/gateway/src/impls/confidential.rs +++ b/gateway/src/impls/confidential.rs @@ -1,34 +1,28 @@ use client::Client; -use ekiden_common::bytes::B512; -use ekiden_core::futures::FutureExt; -use ekiden_keymanager_common::confidential; use ethereum_api::TransactionRequest; use ethereum_types::Address; use impls::eth::EthClient; use jsonrpc_core::{ - futures::{future, Future}, + futures::{Future}, BoxFuture, Error, ErrorCode, Result, }; use jsonrpc_macros::Trailing; use parity_rpc::v1::{ helpers::errors, metadata::Metadata, - traits::Eth, - types::{BlockNumber, Bytes, CallRequest, H256}, + types::{BlockNumber, Bytes, CallRequest}, }; use std::sync::Arc; use traits::confidential::{Confidential, PublicKeyResult}; pub struct ConfidentialClient { client: Arc, - eth_client: EthClient, } impl ConfidentialClient { pub fn new(client: Arc) -> Self { ConfidentialClient { client: client.clone(), - eth_client: EthClient::new(&client), } } } @@ -45,7 +39,7 @@ impl Confidential for ConfidentialClient { fn call_enc( &self, - meta: Self::Metadata, + _meta: Self::Metadata, request: CallRequest, tag: Trailing, ) -> BoxFuture { diff --git a/gateway/src/impls/oasis.rs b/gateway/src/impls/oasis.rs index 0a8fc629b..12b475aea 100644 --- a/gateway/src/impls/oasis.rs +++ b/gateway/src/impls/oasis.rs @@ -1,12 +1,11 @@ -use std::{str::FromStr, sync::Arc}; +use std::{sync::Arc}; -use ekiden_common::bytes::H256; use ekiden_core::futures::Future; use ethereum_types::Address; -use jsonrpc_core::{futures::future, BoxFuture, Error, ErrorCode, Result}; +use jsonrpc_core::{BoxFuture, Error, ErrorCode}; use jsonrpc_macros::Trailing; -use parity_rpc::v1::types::{BlockNumber, H160 as RpcH160, H256 as RpcH256}; +use parity_rpc::v1::types::{BlockNumber, H160 as RpcH160}; use client::Client; use impls::eth::EthClient; diff --git a/gateway/src/informant.rs b/gateway/src/informant.rs index a2839fd5d..cfc50ae43 100644 --- a/gateway/src/informant.rs +++ b/gateway/src/informant.rs @@ -110,19 +110,6 @@ impl RpcStats { .unwrap_or(0) } - /// Returns number of open sessions - pub fn sessions(&self) -> usize { - self.sessions.read().len() - } - - /// Returns requests rate - pub fn requests_rate(&self, id: &H256) -> usize { - self.sessions - .read() - .get(id) - .map(|calc| calc.read().rate()) - .unwrap_or(0) - } } #[cfg(test)] diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 4933f24b7..49d43cf33 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -15,11 +15,11 @@ // along with Parity. If not, see . //! Ethcore client application. +#![deny(warnings)] #[macro_use] extern crate clap; extern crate env_logger; -#[macro_use] extern crate futures; #[macro_use] extern crate lazy_static; @@ -45,7 +45,6 @@ extern crate jsonrpc_pubsub; extern crate jsonrpc_ws_server; extern crate common_types; -#[macro_use] extern crate ethcore; extern crate ethcore_bytes as bytes; extern crate ethcore_transaction as transaction; @@ -119,7 +118,7 @@ use ethereum_types::U256; use ekiden_core::{environment::Environment, x509}; use ekiden_runtime_client::create_runtime_client; -use ekiden_storage_base::{BackendIdentityMapper, StorageBackend}; +use ekiden_storage_base::{BackendIdentityMapper}; use ethereum_api::with_api; pub use self::run::RunningClient; diff --git a/gateway/src/rpc.rs b/gateway/src/rpc.rs index 6cd5f53c0..0a3bea952 100644 --- a/gateway/src/rpc.rs +++ b/gateway/src/rpc.rs @@ -42,12 +42,6 @@ pub struct HttpConfiguration { pub max_batch_size: usize, } -impl HttpConfiguration { - pub fn address(&self) -> Option { - address(self.enabled, &self.interface, self.port, &self.hosts) - } -} - impl Default for HttpConfiguration { fn default() -> Self { HttpConfiguration { diff --git a/gateway/src/rpc_apis.rs b/gateway/src/rpc_apis.rs index 13ed2704a..68de828c7 100644 --- a/gateway/src/rpc_apis.rs +++ b/gateway/src/rpc_apis.rs @@ -63,8 +63,6 @@ impl FromStr for Api { #[derive(Debug, Clone)] pub enum ApiSet { - // Safe context (like token-protected WS interface) - SafeContext, // Unsafe context (like jsonrpc over http) UnsafeContext, // All possible APIs @@ -239,7 +237,6 @@ impl ApiSet { match *self { ApiSet::List(ref apis) => apis.clone(), ApiSet::UnsafeContext => public_list, - ApiSet::SafeContext => public_list, ApiSet::All => public_list, } } diff --git a/gateway/src/traits/confidential.rs b/gateway/src/traits/confidential.rs index 2592d151c..2621d88d8 100644 --- a/gateway/src/traits/confidential.rs +++ b/gateway/src/traits/confidential.rs @@ -1,8 +1,7 @@ -use ekiden_common::bytes::B512; use ethereum_types::Address; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_macros::Trailing; -use parity_rpc::v1::types::{BlockNumber, Bytes, CallRequest, H256}; +use parity_rpc::v1::types::{BlockNumber, Bytes, CallRequest}; build_rpc_trait! { pub trait Confidential { diff --git a/gateway/src/traits/oasis.rs b/gateway/src/traits/oasis.rs index 68fe1a472..2e8f90cfa 100644 --- a/gateway/src/traits/oasis.rs +++ b/gateway/src/traits/oasis.rs @@ -1,9 +1,9 @@ //! Oasis rpc interface. -use jsonrpc_core::{BoxFuture, Result}; +use jsonrpc_core::{BoxFuture}; use jsonrpc_macros::Trailing; -use parity_rpc::v1::types::{BlockNumber, H160, H256}; +use parity_rpc::v1::types::{BlockNumber, H160}; build_rpc_trait! { pub trait Oasis { diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 67377d512..4540e59c0 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -1,3 +1,4 @@ +#![deny(warnings)] extern crate clap; extern crate ethcore; extern crate ethereum_types; diff --git a/inspector/parity_patricia_trie/src/lib.rs b/inspector/parity_patricia_trie/src/lib.rs index 60d55e49d..85670511a 100644 --- a/inspector/parity_patricia_trie/src/lib.rs +++ b/inspector/parity_patricia_trie/src/lib.rs @@ -16,6 +16,7 @@ //! Trie interface and implementation. // extern crate rand; +#![deny(warnings)] extern crate elastic_array; extern crate ethcore_bytes as bytes; extern crate ethereum_types; diff --git a/inspector/src/main.rs b/inspector/src/main.rs index d2a211c37..f2ab78343 100644 --- a/inspector/src/main.rs +++ b/inspector/src/main.rs @@ -1,3 +1,4 @@ +#![deny(warnings)] extern crate clap; extern crate ethcore; extern crate ethereum_types; diff --git a/src/lib.rs b/src/lib.rs index a4de17b93..2df07265e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(warnings)] extern crate common_types as ethcore_types; extern crate ekiden_common; extern crate ekiden_core; From 79dea7daf9ff020130f6faaf0fd4e83ea7c6256a Mon Sep 17 00:00:00 2001 From: eauge Date: Wed, 13 Feb 2019 17:04:42 -0800 Subject: [PATCH 02/12] address fmt errors --- gateway/src/client.rs | 2 +- gateway/src/impls/confidential.rs | 5 +---- gateway/src/impls/oasis.rs | 2 +- gateway/src/lib.rs | 2 +- gateway/src/traits/oasis.rs | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/gateway/src/client.rs b/gateway/src/client.rs index 6b04b1558..18f59df9c 100644 --- a/gateway/src/client.rs +++ b/gateway/src/client.rs @@ -32,7 +32,7 @@ use traits::confidential::PublicKeyResult; use transaction::{Action, LocalizedTransaction, SignedTransaction}; use client_utils::{self, db::Snapshot}; -use ekiden_common::{environment::Environment}; +use ekiden_common::environment::Environment; use ekiden_core::{error::Error, futures::prelude::*}; use ekiden_db_trusted::Database; use ekiden_keymanager_client::KeyManager as EkidenKeyManager; diff --git a/gateway/src/impls/confidential.rs b/gateway/src/impls/confidential.rs index 9bc009333..abc642fe6 100644 --- a/gateway/src/impls/confidential.rs +++ b/gateway/src/impls/confidential.rs @@ -2,10 +2,7 @@ use client::Client; use ethereum_api::TransactionRequest; use ethereum_types::Address; use impls::eth::EthClient; -use jsonrpc_core::{ - futures::{Future}, - BoxFuture, Error, ErrorCode, Result, -}; +use jsonrpc_core::{futures::{Future}, BoxFuture, Error, ErrorCode, Result}; use jsonrpc_macros::Trailing; use parity_rpc::v1::{ helpers::errors, diff --git a/gateway/src/impls/oasis.rs b/gateway/src/impls/oasis.rs index 12b475aea..bbbeec27e 100644 --- a/gateway/src/impls/oasis.rs +++ b/gateway/src/impls/oasis.rs @@ -1,4 +1,4 @@ -use std::{sync::Arc}; +use std::sync::Arc; use ekiden_core::futures::Future; diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 49d43cf33..041b8fb08 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -118,7 +118,7 @@ use ethereum_types::U256; use ekiden_core::{environment::Environment, x509}; use ekiden_runtime_client::create_runtime_client; -use ekiden_storage_base::{BackendIdentityMapper}; +use ekiden_storage_base::BackendIdentityMapper; use ethereum_api::with_api; pub use self::run::RunningClient; diff --git a/gateway/src/traits/oasis.rs b/gateway/src/traits/oasis.rs index 2e8f90cfa..bdeb48e25 100644 --- a/gateway/src/traits/oasis.rs +++ b/gateway/src/traits/oasis.rs @@ -1,6 +1,6 @@ //! Oasis rpc interface. -use jsonrpc_core::{BoxFuture}; +use jsonrpc_core::BoxFuture; use jsonrpc_macros::Trailing; use parity_rpc::v1::types::{BlockNumber, H160}; From 7dad571acdd1fbe995fe2000ddc3275a170ff680 Mon Sep 17 00:00:00 2001 From: eauge Date: Wed, 13 Feb 2019 17:09:31 -0800 Subject: [PATCH 03/12] fix fmt issues --- .gitignore | 6 +++++- gateway/src/impls/confidential.rs | 2 +- gateway/src/informant.rs | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 677408317..73d9e0ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Mac things .DS_Store -# Build. +n# Build. tests/build target/ **/*.rs.bk @@ -52,3 +52,7 @@ tests/rpc-tests/ # Coverage report from Tarpaulin cobertura.xml + +# in case credentials are put in the repo for using +# inside the docker container +.git-credentials \ No newline at end of file diff --git a/gateway/src/impls/confidential.rs b/gateway/src/impls/confidential.rs index abc642fe6..b0ed2d068 100644 --- a/gateway/src/impls/confidential.rs +++ b/gateway/src/impls/confidential.rs @@ -2,7 +2,7 @@ use client::Client; use ethereum_api::TransactionRequest; use ethereum_types::Address; use impls::eth::EthClient; -use jsonrpc_core::{futures::{Future}, BoxFuture, Error, ErrorCode, Result}; +use jsonrpc_core::{futures::Future, BoxFuture, Error, ErrorCode, Result}; use jsonrpc_macros::Trailing; use parity_rpc::v1::{ helpers::errors, diff --git a/gateway/src/informant.rs b/gateway/src/informant.rs index cfc50ae43..a66fbb80c 100644 --- a/gateway/src/informant.rs +++ b/gateway/src/informant.rs @@ -109,7 +109,6 @@ impl RpcStats { .map(|calc| calc.write().tick()) .unwrap_or(0) } - } #[cfg(test)] From 526fa241b11b8e70ab152491573ca7eafdf9a4b5 Mon Sep 17 00:00:00 2001 From: eauge Date: Wed, 13 Feb 2019 17:30:23 -0800 Subject: [PATCH 04/12] fix for tests --- common/src/confidential/key_manager.rs | 54 +------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index cbf3c6b7a..8127a6f91 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -1,13 +1,11 @@ #[cfg(feature = "test")] use ekiden_core::random; -use ekiden_keymanager_client::KeyManager as EkidenKeyManager; -use ekiden_keymanager_common::{ContractId, ContractKey}; +use ekiden_keymanager_common::ContractKey; #[cfg(feature = "test")] use ekiden_keymanager_common::{ PublicKeyType, EMPTY_PRIVATE_KEY, EMPTY_PUBLIC_KEY, EMPTY_STATE_KEY, }; use ethereum_types::Address; -use keccak_hash::keccak; #[cfg(feature = "test")] use std::collections::HashMap; #[cfg(feature = "test")] @@ -41,56 +39,6 @@ impl KeyManagerClient { } } -/// Wrapper around the Ekiden key manager client to provide a more convenient -/// Ethereum address based interface along with runtime-specific utility methods. -struct KeyManager; -impl KeyManager { - /// Returns the contract id for the given contract address. The contract_id - /// is used to fetch keys for a contract. - fn contract_id(contract: Address) -> ContractId { - ContractId::from(&keccak(contract.to_vec())[..]) - } - - /// Creates and returns the long term public key for the given contract. - /// If the key already exists, returns the existing key. - /// Returns the tuple (public_key, signature_{KeyManager}(public_key)). - fn create_long_term_public_key(contract: Address) -> Result<(Vec, Vec), String> { - let contract_id = Self::contract_id(contract); - let mut km = EkidenKeyManager::instance().expect("Should always have a key manager client"); - - // first create the keys - km.get_or_create_secret_keys(contract_id) - .map_err(|err| err.description().to_string())?; - // then extract the long term key - km.long_term_public_key(contract_id) - .map_err(|err| err.description().to_string()) - .map(|pk_payload| { - ( - pk_payload.public_key.to_vec(), - pk_payload.signature.to_vec(), - ) - }) - } - - fn contract_key(address: Address) -> Result { - let contract_id = Self::contract_id(address); - let mut km = EkidenKeyManager::instance().expect("Should always have a key manager client"); - - let (secret_key, state_key) = km - .get_or_create_secret_keys(contract_id) - .map_err(|err| err.description().to_string())?; - let public_key_payload = km - .get_public_key(contract_id) - .map_err(|err| err.description().to_string())?; - - Ok(ContractKey::new( - public_key_payload.public_key, - secret_key, - state_key, - )) - } -} - #[cfg(feature = "test")] lazy_static! { static ref TEST_KEY_MANAGER: Mutex = Mutex::new(TestKeyManager::new()); From 34fa6c32f46ce77c5b36669f3de4ea5743ad2a89 Mon Sep 17 00:00:00 2001 From: eauge Date: Thu, 14 Feb 2019 10:22:34 -0800 Subject: [PATCH 05/12] remove deny warning --- .gitignore | 4 ++-- api/src/lib.rs | 1 - common/src/lib.rs | 1 - gateway/src/lib.rs | 1 - inspector/parity_patricia_trie/src/lib.rs | 1 - src/lib.rs | 1 - 6 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 73d9e0ac6..6f87e4e78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Mac things .DS_Store -n# Build. +# Build. tests/build target/ **/*.rs.bk @@ -55,4 +55,4 @@ cobertura.xml # in case credentials are put in the repo for using # inside the docker container -.git-credentials \ No newline at end of file +.git-credentials diff --git a/api/src/lib.rs b/api/src/lib.rs index 2a5e8a26d..8119bdc24 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] extern crate protobuf; extern crate serde; diff --git a/common/src/lib.rs b/common/src/lib.rs index 679aba248..e15273eb1 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,5 @@ //! Common data structures shared by runtime and gateway. -#![deny(warnings)] extern crate ekiden_core; extern crate ekiden_keymanager_client; extern crate ekiden_keymanager_common; diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 041b8fb08..97489b866 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -15,7 +15,6 @@ // along with Parity. If not, see . //! Ethcore client application. -#![deny(warnings)] #[macro_use] extern crate clap; diff --git a/inspector/parity_patricia_trie/src/lib.rs b/inspector/parity_patricia_trie/src/lib.rs index 85670511a..60d55e49d 100644 --- a/inspector/parity_patricia_trie/src/lib.rs +++ b/inspector/parity_patricia_trie/src/lib.rs @@ -16,7 +16,6 @@ //! Trie interface and implementation. // extern crate rand; -#![deny(warnings)] extern crate elastic_array; extern crate ethcore_bytes as bytes; extern crate ethereum_types; diff --git a/src/lib.rs b/src/lib.rs index 2df07265e..a4de17b93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] extern crate common_types as ethcore_types; extern crate ekiden_common; extern crate ekiden_core; From fb8e23fd40aa7bda6c26e10d6ace02f36423ca36 Mon Sep 17 00:00:00 2001 From: eauge Date: Thu, 14 Feb 2019 11:09:50 -0800 Subject: [PATCH 06/12] readd key manager --- .buildkite/rust/common.sh | 12 ++++++ .buildkite/rust/lint.sh | 32 +++++++++++++++ api/build.rs | 2 + build.rs | 2 + common/src/confidential/key_manager.rs | 54 +++++++++++++++++++++++++- 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 .buildkite/rust/lint.sh diff --git a/.buildkite/rust/common.sh b/.buildkite/rust/common.sh index b533d7333..e9121aea9 100644 --- a/.buildkite/rust/common.sh +++ b/.buildkite/rust/common.sh @@ -12,6 +12,18 @@ export INTEL_SGX_SDK="/opt/sgxsdk" export EKIDEN_UNSAFE_SKIP_AVR_VERIFY="1" export RUST_BACKTRACE="1" +################################## +# Set up RUSTFLAGS for the build # +################################## +if [ -z $(echo $RUSTLINT | awk '{print $1}') ]; then + RUSTLINT="" + for opt in $(cat lint.sh); do + RUSTLINT=$RUSTLINT" -D "$opt + done + export RUSTLINT + export RUSTFLAGS=$RUSTFLAGS" "$RUSTLINT +fi + #################################################### # By default, .bashrc will quit if the shell # is not interactive. It checks whether $PS1 is diff --git a/.buildkite/rust/lint.sh b/.buildkite/rust/lint.sh new file mode 100644 index 000000000..8f1bffad8 --- /dev/null +++ b/.buildkite/rust/lint.sh @@ -0,0 +1,32 @@ +bad-style +const-err +dead-code +extra-requirement-in-impl +improper-ctypes +legacy-directory-ownership +non-shorthand-field-patterns +no-mangle-generic-items +overflowing-literals +path-statements +patterns-in-fns-without-body +plugin-as-library +private-in-public +private-no-mangle-fns +private-no-mangle-statics +raw-pointer-derive +safe-extern-statics +unconditional-recursion +unions-with-drop-fields +unused +unused-allocation +unused-comparisons +unused-parens +while-true +missing-debug-implementations +missing-docs +trivial-casts +trivial-numeric-casts +unused-extern-crates +unused-import-braces +unused-qualifications +unused-results diff --git a/api/build.rs b/api/build.rs index 4921aeb28..aaade5755 100644 --- a/api/build.rs +++ b/api/build.rs @@ -1,3 +1,5 @@ +//! build crate for the ekiden api + extern crate ekiden_tools; fn main() { diff --git a/build.rs b/build.rs index f5bd71779..f3d16c98a 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +//! build crate for the ekiden runtime based enclave + extern crate ekiden_edl; extern crate ekiden_tools; diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index 8127a6f91..cbf3c6b7a 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -1,11 +1,13 @@ #[cfg(feature = "test")] use ekiden_core::random; -use ekiden_keymanager_common::ContractKey; +use ekiden_keymanager_client::KeyManager as EkidenKeyManager; +use ekiden_keymanager_common::{ContractId, ContractKey}; #[cfg(feature = "test")] use ekiden_keymanager_common::{ PublicKeyType, EMPTY_PRIVATE_KEY, EMPTY_PUBLIC_KEY, EMPTY_STATE_KEY, }; use ethereum_types::Address; +use keccak_hash::keccak; #[cfg(feature = "test")] use std::collections::HashMap; #[cfg(feature = "test")] @@ -39,6 +41,56 @@ impl KeyManagerClient { } } +/// Wrapper around the Ekiden key manager client to provide a more convenient +/// Ethereum address based interface along with runtime-specific utility methods. +struct KeyManager; +impl KeyManager { + /// Returns the contract id for the given contract address. The contract_id + /// is used to fetch keys for a contract. + fn contract_id(contract: Address) -> ContractId { + ContractId::from(&keccak(contract.to_vec())[..]) + } + + /// Creates and returns the long term public key for the given contract. + /// If the key already exists, returns the existing key. + /// Returns the tuple (public_key, signature_{KeyManager}(public_key)). + fn create_long_term_public_key(contract: Address) -> Result<(Vec, Vec), String> { + let contract_id = Self::contract_id(contract); + let mut km = EkidenKeyManager::instance().expect("Should always have a key manager client"); + + // first create the keys + km.get_or_create_secret_keys(contract_id) + .map_err(|err| err.description().to_string())?; + // then extract the long term key + km.long_term_public_key(contract_id) + .map_err(|err| err.description().to_string()) + .map(|pk_payload| { + ( + pk_payload.public_key.to_vec(), + pk_payload.signature.to_vec(), + ) + }) + } + + fn contract_key(address: Address) -> Result { + let contract_id = Self::contract_id(address); + let mut km = EkidenKeyManager::instance().expect("Should always have a key manager client"); + + let (secret_key, state_key) = km + .get_or_create_secret_keys(contract_id) + .map_err(|err| err.description().to_string())?; + let public_key_payload = km + .get_public_key(contract_id) + .map_err(|err| err.description().to_string())?; + + Ok(ContractKey::new( + public_key_payload.public_key, + secret_key, + state_key, + )) + } +} + #[cfg(feature = "test")] lazy_static! { static ref TEST_KEY_MANAGER: Mutex = Mutex::new(TestKeyManager::new()); From 18a22a95deaeb34178b816f5b16d125ca1f83e55 Mon Sep 17 00:00:00 2001 From: eauge Date: Thu, 14 Feb 2019 12:02:38 -0800 Subject: [PATCH 07/12] fix unbound variable use --- .buildkite/rust/common.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.buildkite/rust/common.sh b/.buildkite/rust/common.sh index e9121aea9..90b93a9ec 100644 --- a/.buildkite/rust/common.sh +++ b/.buildkite/rust/common.sh @@ -15,13 +15,18 @@ export RUST_BACKTRACE="1" ################################## # Set up RUSTFLAGS for the build # ################################## -if [ -z $(echo $RUSTLINT | awk '{print $1}') ]; then +if [ -v RUSTLINT ]; then RUSTLINT="" - for opt in $(cat lint.sh); do + for opt in $(cat .buildkite/rust/lint.sh); do RUSTLINT=$RUSTLINT" -D "$opt done + export RUSTLINT - export RUSTFLAGS=$RUSTFLAGS" "$RUSTLINT + if [ -v RUSTFLAG ]; then + export RUSTFLAGS=$RUSTLINT + else + export RUSTFLAGS=$RUSTFLAGS" "$RUSTLINT + fi fi #################################################### From edba5eeeaa0ac22b63059e39e9fff9a6d9f291dc Mon Sep 17 00:00:00 2001 From: eauge Date: Thu, 14 Feb 2019 13:28:16 -0800 Subject: [PATCH 08/12] fix lint issues --- .buildkite/rust/common.sh | 4 +++- .buildkite/rust/{lint.sh => lint.txt} | 3 --- api/src/lib.rs | 1 - common/src/confidential/confidential_ctx.rs | 2 +- common/src/confidential/key_manager.rs | 2 ++ common/src/lib.rs | 4 +--- gateway/src/informant.rs | 18 ++++++++++++++++++ gateway/src/rpc_apis.rs | 4 ++++ 8 files changed, 29 insertions(+), 9 deletions(-) rename .buildkite/rust/{lint.sh => lint.txt} (90%) diff --git a/.buildkite/rust/common.sh b/.buildkite/rust/common.sh index 90b93a9ec..363d32205 100644 --- a/.buildkite/rust/common.sh +++ b/.buildkite/rust/common.sh @@ -17,7 +17,7 @@ export RUST_BACKTRACE="1" ################################## if [ -v RUSTLINT ]; then RUSTLINT="" - for opt in $(cat .buildkite/rust/lint.sh); do + for opt in $(cat .buildkite/rust/lint.txt); do RUSTLINT=$RUSTLINT" -D "$opt done @@ -27,6 +27,8 @@ if [ -v RUSTLINT ]; then else export RUSTFLAGS=$RUSTFLAGS" "$RUSTLINT fi + + echo "Using RUSTFLAGS="$RUSTFLAGS fi #################################################### diff --git a/.buildkite/rust/lint.sh b/.buildkite/rust/lint.txt similarity index 90% rename from .buildkite/rust/lint.sh rename to .buildkite/rust/lint.txt index 8f1bffad8..01d50fe0a 100644 --- a/.buildkite/rust/lint.sh +++ b/.buildkite/rust/lint.txt @@ -22,11 +22,8 @@ unused-allocation unused-comparisons unused-parens while-true -missing-debug-implementations -missing-docs trivial-casts trivial-numeric-casts unused-extern-crates unused-import-braces unused-qualifications -unused-results diff --git a/api/src/lib.rs b/api/src/lib.rs index 8119bdc24..696cb37da 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,5 +1,4 @@ extern crate protobuf; -extern crate serde; #[macro_use] extern crate serde_derive; diff --git a/common/src/confidential/confidential_ctx.rs b/common/src/confidential/confidential_ctx.rs index e86d76a3f..f072f0854 100644 --- a/common/src/confidential/confidential_ctx.rs +++ b/common/src/confidential/confidential_ctx.rs @@ -13,7 +13,7 @@ use ethereum_types::Address; /// nonce to use--to be encrypting under for a *single* transaction. Each /// transaction for a confidential contract should have it's own ConfidentialCtx /// that is closed at the end of the transaction's execution. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ConfidentialCtx { /// The peer public key used for encryption. This should not change for an /// open confidential context. This is implicitly set by the `open` method. diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index cbf3c6b7a..f9cdc7b9d 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -41,9 +41,11 @@ impl KeyManagerClient { } } +#[derive(Debug)] /// Wrapper around the Ekiden key manager client to provide a more convenient /// Ethereum address based interface along with runtime-specific utility methods. struct KeyManager; + impl KeyManager { /// Returns the contract id for the given contract address. The contract_id /// is used to fetch keys for a contract. diff --git a/common/src/lib.rs b/common/src/lib.rs index e15273eb1..e4d70e433 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -16,9 +16,6 @@ extern crate keccak_hash; #[macro_use] extern crate lazy_static; -#[cfg(not(target_env = "sgx"))] -extern crate rand; - #[cfg(target_env = "sgx")] extern crate sgx_rand; @@ -318,6 +315,7 @@ where } } +#[derive(Debug)] /// Blockchain state database. pub struct BlockchainStateDb { db: Mutex, diff --git a/gateway/src/informant.rs b/gateway/src/informant.rs index a66fbb80c..f31a69b86 100644 --- a/gateway/src/informant.rs +++ b/gateway/src/informant.rs @@ -109,6 +109,24 @@ impl RpcStats { .map(|calc| calc.write().tick()) .unwrap_or(0) } + + // used for tests + #[allow(dead_code)] + /// Returns number of open sessions + pub fn sessions(&self) -> usize { + self.sessions.read().len() + } + + // used for tests + #[allow(dead_code)] + /// Returns requests rate + pub fn requests_rate(&self, id: &H256) -> usize { + self.sessions + .read() + .get(id) + .map(|calc| calc.read().rate()) + .unwrap_or(0) + } } #[cfg(test)] diff --git a/gateway/src/rpc_apis.rs b/gateway/src/rpc_apis.rs index 68de828c7..d55aaa8a8 100644 --- a/gateway/src/rpc_apis.rs +++ b/gateway/src/rpc_apis.rs @@ -63,6 +63,10 @@ impl FromStr for Api { #[derive(Debug, Clone)] pub enum ApiSet { + // Used in tests. + #[allow(dead_code)] + // Safe context (like token-protected WS interface) + SafeContext, // Unsafe context (like jsonrpc over http) UnsafeContext, // All possible APIs From d453276abcfef7a6fd1fc59eb6a49ee0737f915a Mon Sep 17 00:00:00 2001 From: eauge Date: Fri, 15 Feb 2019 09:16:31 -0800 Subject: [PATCH 09/12] address PR comments --- api/build.rs | 2 +- common/src/confidential/key_manager.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/api/build.rs b/api/build.rs index aaade5755..bde94f10c 100644 --- a/api/build.rs +++ b/api/build.rs @@ -1,4 +1,4 @@ -//! build crate for the ekiden api +//! Build crate for the ekiden api. extern crate ekiden_tools; diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index 205f0802d..a9d86ce17 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -41,8 +41,7 @@ impl KeyManagerClient { } } -// used for the integration tests -#[allow(dead_code)] +#[cfg(not(test))] #[derive(Debug)] /// Wrapper around the Ekiden key manager client to provide a more convenient /// Ethereum address based interface along with runtime-specific utility methods. From b3d38a3c859d61eef86f35690e0409f41bcaaf07 Mon Sep 17 00:00:00 2001 From: eauge Date: Fri, 15 Feb 2019 10:11:34 -0800 Subject: [PATCH 10/12] remove dependencies --- common/Cargo.toml | 3 --- common/src/confidential/key_manager.rs | 2 +- gateway/Cargo.toml | 12 ------------ 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/common/Cargo.toml b/common/Cargo.toml index 43f7d2457..2a8edad02 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -18,9 +18,6 @@ keccak-hash = { git = "https://github.com/oasislabs/parity", branch = "ekiden" } lazy_static = { version = "1.1.0", features = ["spin_no_std"] } sodalite = "0.3.0" -[target.'cfg(not(target_env = "sgx"))'.dependencies] -rand = "0.4.2" - [dev-dependencies] ekiden-storage-dummy = { git = "https://github.com/oasislabs/ekiden", branch = "master" } diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index a9d86ce17..45d110aac 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -41,7 +41,7 @@ impl KeyManagerClient { } } -#[cfg(not(test))] +#[allow(dead_code)] #[derive(Debug)] /// Wrapper around the Ekiden key manager client to provide a more convenient /// Ethereum address based interface along with runtime-specific utility methods. diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index ce3a77e97..76bd1ccd8 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -6,12 +6,8 @@ authors = ["Oasis Labs Inc. ", "Parity Technologies Date: Fri, 15 Feb 2019 10:31:32 -0800 Subject: [PATCH 11/12] key manager not undead code --- common/src/confidential/key_manager.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/src/confidential/key_manager.rs b/common/src/confidential/key_manager.rs index 45d110aac..25e76c3b1 100644 --- a/common/src/confidential/key_manager.rs +++ b/common/src/confidential/key_manager.rs @@ -41,21 +41,20 @@ impl KeyManagerClient { } } -#[allow(dead_code)] +#[cfg(not(feature = "test"))] #[derive(Debug)] /// Wrapper around the Ekiden key manager client to provide a more convenient /// Ethereum address based interface along with runtime-specific utility methods. struct KeyManager; +#[cfg(not(feature = "test"))] impl KeyManager { - #[allow(dead_code)] /// Returns the contract id for the given contract address. The contract_id /// is used to fetch keys for a contract. fn contract_id(contract: Address) -> ContractId { ContractId::from(&keccak(contract.to_vec())[..]) } - #[allow(dead_code)] /// Creates and returns the long term public key for the given contract. /// If the key already exists, returns the existing key. /// Returns the tuple (public_key, signature_{KeyManager}(public_key)). @@ -77,7 +76,6 @@ impl KeyManager { }) } - #[allow(dead_code)] fn contract_key(address: Address) -> Result { let contract_id = Self::contract_id(address); let mut km = EkidenKeyManager::instance().expect("Should always have a key manager client"); From e87692917209a7360a140a99b50dc77c5ec0469c Mon Sep 17 00:00:00 2001 From: eauge Date: Fri, 15 Feb 2019 14:06:01 -0800 Subject: [PATCH 12/12] remove allow dead code --- gateway/src/client.rs | 8 ++++---- gateway/src/informant.rs | 6 ++---- gateway/src/middleware.rs | 12 ++++++------ gateway/src/rpc_apis.rs | 3 ++- gateway/src/test_helpers.rs | 2 +- src/lib.rs | 11 +++++++---- src/state.rs | 3 --- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/gateway/src/client.rs b/gateway/src/client.rs index 9f6f9cd79..d98e1aed4 100644 --- a/gateway/src/client.rs +++ b/gateway/src/client.rs @@ -85,11 +85,11 @@ pub trait ChainNotify: Send + Sync { pub struct Client { client: runtime_ethereum::Client, engine: Arc, - #[allow(dead_code)] + #[cfg(not(test))] snapshot_manager: Option, eip86_transition: u64, environment: Arc, - #[allow(dead_code)] + #[cfg(not(test))] storage_backend: Arc, /// The most recent block for which we have sent notifications. notified_block_number: Mutex, @@ -119,9 +119,11 @@ impl Client { Self { client: client, engine: spec.engine.clone(), + #[cfg(not(test))] snapshot_manager: snapshot_manager, eip86_transition: spec.params().eip86_transition, environment, + #[cfg(not(test))] storage_backend: backend, // start at current block notified_block_number: Mutex::new(current_block_number), @@ -141,10 +143,8 @@ impl Client { Self { client: test_helpers::get_test_runtime_client(), engine: spec.engine.clone(), - snapshot_manager: None, eip86_transition: spec.params().eip86_transition, environment: environment, - storage_backend: Arc::new(DummyStorageBackend::new()), notified_block_number: Mutex::new(0), listeners: RwLock::new(vec![]), gas_price: U256::from(1_000_000_000), diff --git a/gateway/src/informant.rs b/gateway/src/informant.rs index f31a69b86..da4913edb 100644 --- a/gateway/src/informant.rs +++ b/gateway/src/informant.rs @@ -110,15 +110,13 @@ impl RpcStats { .unwrap_or(0) } - // used for tests - #[allow(dead_code)] + #[cfg(test)] /// Returns number of open sessions pub fn sessions(&self) -> usize { self.sessions.read().len() } - // used for tests - #[allow(dead_code)] + #[cfg(test)] /// Returns requests rate pub fn requests_rate(&self, id: &H256) -> usize { self.sessions diff --git a/gateway/src/middleware.rs b/gateway/src/middleware.rs index 457780fd3..78bddc741 100644 --- a/gateway/src/middleware.rs +++ b/gateway/src/middleware.rs @@ -252,7 +252,7 @@ mod tests { let request_1 = make_request(1); let response = dispatcher - .on_request(request_1, metadata.clone(), |request, meta| { + .on_request(request_1, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -284,15 +284,15 @@ mod tests { let request_1 = make_request(1); let request_2 = make_request(2); - let response = dispatcher - .on_request(request_1, metadata.clone(), |request, meta| { + let _response = dispatcher + .on_request(request_1, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() .unwrap(); let response = dispatcher - .on_request(request_2, metadata.clone(), |request, meta| { + .on_request(request_2, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -348,7 +348,7 @@ mod tests { // batch size: 1 (should pass) let response_1 = middleware - .on_request(batch_1, (), |request, meta| { + .on_request(batch_1, (), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -359,7 +359,7 @@ mod tests { // batch size: 2 (should fail) let response_2 = middleware - .on_request(batch_2, (), |request, meta| { + .on_request(batch_2, (), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() diff --git a/gateway/src/rpc_apis.rs b/gateway/src/rpc_apis.rs index c790fcb3f..19f73b108 100644 --- a/gateway/src/rpc_apis.rs +++ b/gateway/src/rpc_apis.rs @@ -64,7 +64,7 @@ impl FromStr for Api { #[derive(Debug, Clone)] pub enum ApiSet { // Used in tests. - #[allow(dead_code)] + #[cfg(test)] // Safe context (like token-protected WS interface) SafeContext, // Unsafe context (like jsonrpc over http) @@ -241,6 +241,7 @@ impl ApiSet { match *self { ApiSet::List(ref apis) => apis.clone(), ApiSet::UnsafeContext => public_list, + #[cfg(test)] ApiSet::SafeContext => public_list, ApiSet::All => public_list, } diff --git a/gateway/src/test_helpers.rs b/gateway/src/test_helpers.rs index 53b278879..dffe3fbb5 100644 --- a/gateway/src/test_helpers.rs +++ b/gateway/src/test_helpers.rs @@ -342,7 +342,7 @@ impl Database for MockDb { unimplemented!(); } - fn with_encryption_key(&mut self, key: StateKeyType, _f: F) -> R + fn with_encryption_key(&mut self, _key: StateKeyType, _f: F) -> R where F: FnOnce(&mut DatabaseHandle) -> R, { diff --git a/src/lib.rs b/src/lib.rs index 84f89d0c7..fa6067e1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ use std::sync::Arc; use ekiden_core::error::{Error, Result}; use ekiden_storage_base::StorageBackend; #[cfg(not(target_env = "sgx"))] -#[allow(dead_code)] +#[cfg(test)] use ekiden_storage_dummy::DummyStorageBackend; #[cfg(target_env = "sgx")] use ekiden_trusted::db::untrusted::UntrustedStorageBackend; @@ -155,7 +155,8 @@ pub fn get_block_height(_request: &bool, ctx: &mut RuntimeCallContext) -> Result Ok(ectx.cache.get_latest_block_number().into()) } -#[allow(dead_code)] +#[cfg(not(feature = "test"))] +#[cfg(not(test))] fn get_block_hash(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result> { let ectx = ctx.runtime.downcast_mut::().unwrap(); @@ -168,7 +169,8 @@ fn get_block_hash(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result Result>> { let ectx = ctx.runtime.downcast_mut::().unwrap(); @@ -189,7 +191,8 @@ fn get_block(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result Result> { let ectx = ctx.runtime.downcast_mut::().unwrap(); diff --git a/src/state.rs b/src/state.rs index 33de0abcb..176af54bf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -400,9 +400,6 @@ mod tests { use self::ekiden_storage_dummy::DummyStorageBackend; - #[allow(dead_code)] - use lazy_static; - use super::*; #[test]