Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into issue1881
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtau committed Jul 22, 2020
2 parents 80854bc + 48ddd62 commit 0de009f
Show file tree
Hide file tree
Showing 53 changed files with 1,456 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ steps:
- export CARGO_TARGET_DIR=/tmp
- LD_LIBRARY_PATH=/opt/intel/sgx-aesm-service/aesm /opt/intel/sgx-aesm-service/aesm/aesm_service --no-daemon &
- make -C chain-tx-enclave/tx-validation
- cargo build --features sgx-test --manifest-path chain-abci/Cargo.toml
- cargo build --no-default-features --features sgx-test --manifest-path chain-abci/Cargo.toml
- cd $CARGO_TARGET_DIR/debug
- ./chain-abci

Expand Down Expand Up @@ -138,4 +138,5 @@ trigger:
kind: signature
hmac: b7ce5bbe4adf4bb87ecceb5c3d41ea6faf86f018c7200ea0b39bb5ddb25d8e7b


...
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ rust: &rust
- SGX_MODE=SW
- NETWORK_ID=ab
before_install: # versions from https://github.com/erickt/rust-zmq/blob/master/.travis.yml
- ./ci-scripts/install_sgxsdk.sh
- |
if [[ "$TRAVIS_RUST_VERSION" != nightly ]]; then
sed -i.bak -E "s/default = \[\".+\"\]/default = \[\"mock-enclave\"\]/" chain-abci/Cargo.toml;
fi
- |
if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then
./ci-scripts/install_kcov.sh
Expand All @@ -82,9 +85,13 @@ rust: &rust
# a small hack, as kcov doesn't have an option to only build default members
sed 's/"chain-tx-enclave\//#"chain-tx-enclave\//g' -i Cargo.toml;
# more hacks for kcov :(
sed 's/default = \[\]/default = \["mock-enclave"\]/g' -i chain-abci/Cargo.toml;
sed 's/sgx/#sgx/g' -i chain-abci/Cargo.toml;
sed 's/enclave-u-common/#enclave-u-common/g' -i chain-abci/Cargo.toml;
# sed 's/default = \[\]/default = \["mock-enclave"\]/g' -i chain-abci/Cargo.toml;
# sed 's/sgx/#sgx/g' -i chain-abci/Cargo.toml;
sed 's/legacy/#legacy/g' -i chain-abci/Cargo.toml;
sed 's/enclave-u-common =/#enclave-u-common =/g' -i chain-abci/Cargo.toml;
sed 's/sgx_types =/#sgx_types =/g' -i chain-abci/Cargo.toml;
sed 's/sgx_urts =/#sgx_urts =/g' -i chain-abci/Cargo.toml;
sed 's/CARGO/_CARGO/g' -i chain-abci/build.rs;
travis_wait 30 cargo kcov --all;
Expand Down
64 changes: 59 additions & 5 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ members = [
"chain-tx-enclave-next/enclave-ra/ra-enclave",
"chain-tx-enclave-next/enclave-ra/ra-sp-client",
"chain-tx-enclave-next/enclave-ra/ra-sp-server",
"chain-tx-enclave-next/tdbe/tdbe-common",
"chain-tx-enclave-next/tdbe/app-runner",
"chain-tx-enclave-next/tdbe/enclave-app",
"chain-tx-enclave/tx-validation/enclave",
"chain-tx-enclave-next/tx-query-next/app-runner",
"chain-tx-enclave-next/tx-query-next/enclave-app",
Expand Down
17 changes: 12 additions & 5 deletions chain-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ readme = "README.md"
edition = "2018"

[features]
default = []
sgx-test = []
default = ["edp"]
sgx-test = ["legacy"]
mock-enclave = []
edp = ["aesm-client", "enclave-runner", "sgxs-loaders", "tokio"]
legacy = ["enclave-u-common", "sgx_types", "sgx_urts"]

[dependencies]
abci = "0.7"
Expand All @@ -22,6 +24,11 @@ mock-utils = { path = "../chain-tx-enclave/mock-utils" }
mls = { path = "../chain-tx-enclave-next/mls" }
ra-client = { path = "../chain-tx-enclave-next/enclave-ra/ra-client" }

aesm-client = {version = "0.5", features = ["sgxs"], optional = true }
enclave-runner = {version = "0.4", optional = true}
sgxs-loaders = {version = "0.2", optional = true}
tokio = { version = "0.2", optional = true }

log = "0.4.11"
env_logger = "0.7.1"
bit-vec = { version = "0.6.2", features = ["serde_no_std"] }
Expand All @@ -39,9 +46,9 @@ parity-scale-codec = { features = ["derive"], version = "1.3" }
thiserror = "1.0"

[target.'cfg(target_os = "linux")'.dependencies]
enclave-u-common = { path = "../chain-tx-enclave/enclave-u-common" }
sgx_types = { rev = "v1.1.2", git = "https://github.com/apache/teaclave-sgx-sdk.git" }
sgx_urts = { rev = "v1.1.2", git = "https://github.com/apache/teaclave-sgx-sdk.git" }
enclave-u-common = { path = "../chain-tx-enclave/enclave-u-common", optional = true }
sgx_types = { rev = "v1.1.2", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }
sgx_urts = { rev = "v1.1.2", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }
zmq = "0.9"
rand = "0.7"

Expand Down
27 changes: 23 additions & 4 deletions chain-abci/src/app/app_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use parity_scale_codec::{Decode, Encode};
use protobuf::Message;
use serde::{Deserialize, Serialize};

#[cfg(all(not(feature = "mock-enclave"), target_os = "linux"))]
#[cfg(all(
not(feature = "mock-enclave"),
not(feature = "legacy"),
feature = "edp",
target_os = "linux"
))]
use crate::enclave_bridge::edp::start_zmq;
#[cfg(all(not(feature = "mock-enclave"), feature = "legacy", target_os = "linux"))]
use crate::enclave_bridge::real::start_zmq;
use crate::enclave_bridge::EnclaveProxy;
use crate::staking::StakingTable;
Expand Down Expand Up @@ -240,7 +247,7 @@ pub fn init_app_hash(conf: &InitConfig, genesis_time: Timespec) -> H256 {
)
}

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
fn restore_from_storage(
tx_validator: T,
last_app_state: ChainNodeState,
Expand Down Expand Up @@ -298,7 +305,7 @@ impl<T: EnclaveProxy> ChainNodeApp<T> {
/// * `tx_query_address` - address of tx query enclave to supply to clients (if any)
/// * `enclave_server` - connection string which ZeroMQ server wrapper around the transaction validation enclave will listen on
pub fn new_with_storage(
tx_validator: T,
mut tx_validator: T,
gah: &str,
chain_id: &str,
mut storage: Storage,
Expand All @@ -312,8 +319,20 @@ impl<T: EnclaveProxy> ChainNodeApp<T> {
.expect("failed to decode two last hex digits in chain ID")[0];

if let (Some(_), Some(_conn_str)) = (tx_query_address.as_ref(), enclave_server.as_ref()) {
#[cfg(all(not(feature = "mock-enclave"), target_os = "linux"))]
#[cfg(all(not(feature = "mock-enclave"), feature = "legacy", target_os = "linux"))]
let _ = start_zmq(_conn_str, chain_hex_id, storage.get_read_only());
#[cfg(all(
not(feature = "mock-enclave"),
not(feature = "legacy"),
feature = "edp",
target_os = "linux"
))]
let _ = start_zmq(
tx_validator.clone(),
_conn_str,
chain_hex_id,
storage.get_read_only(),
);
}

if let Some(data) = storage.get_last_app_state() {
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn process_txs(delivered_txs: &[TxAux], db: &mut impl StoreKV) {
}
}

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
/// Commits delivered TX: flushes updates to the underlying storage
pub fn commit_handler(&mut self, _req: &RequestCommit) -> ResponseCommit {
let new_state = self.last_state.as_mut().expect("executing block commit, but no app state stored (i.e. no initchain or recovery was executed)");
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/end_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use chain_core::common::TendermintEventType;
use chain_tx_filter::BlockFilter;
use enclave_protocol::{IntraEnclaveRequest, IntraEnclaveResponseOk};

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
/// tags the block with the transaction filter + computes validator set changes
pub fn end_block_handler(&mut self, req: &RequestEndBlock) -> ResponseEndBlock {
let mut resp = ResponseEndBlock::new();
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> BeginBlockInfo<'a> {
}

/// TODO: sanity checks in abci https://github.com/tendermint/rust-abci/issues/49
impl<T: EnclaveProxy> abci::Application for ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> abci::Application for ChainNodeApp<T> {
/// Query Connection: Called on startup from Tendermint. The application should normally
/// return the last know state so Tendermint can determine if it needs to replay blocks
/// to the application.
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn get_key(resp: &mut ResponseQuery, data_key: &[u8]) -> Option<H256> {
}
}

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
fn lookup_key(
&self,
resp: &mut ResponseQuery,
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn mul_micro(n: u64, rate: u64) -> u64 {

pub type RewardsDistribution = Vec<(StakedStateAddress, Coin)>;

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
/// Distribute rewards pool
pub fn rewards_try_distribute(&mut self) -> Option<(RewardsDistribution, Coin)> {
let state = self.last_state.as_mut().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion chain-abci/src/app/validate_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ResponseWithCodeAndLog for ResponseDeliverTx {
}
}

impl<T: EnclaveProxy> ChainNodeApp<T> {
impl<T: EnclaveProxy + 'static> ChainNodeApp<T> {
pub fn process_tx(
&mut self,
req: &impl RequestWithTx,
Expand Down
Loading

0 comments on commit 0de009f

Please sign in to comment.