Skip to content

Commit

Permalink
Merge pull request #68 from olisystems/cl/merge-upstream-cargo-test
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
m-yahya authored Nov 14, 2023
2 parents da4150e + d46fb87 commit 1ed4f0f
Show file tree
Hide file tree
Showing 157 changed files with 4,955 additions and 4,065 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
buildkitd-flags: --debug
driver: docker-container

- name: Build Worker & Run Cargo Test
- name: Build Worker
env:
DOCKER_BUILDKIT: 1
run: >
Expand All @@ -83,7 +83,7 @@ jobs:
- run: docker images --all

- name: Test Enclave # cargo test is not supported in the enclave, see: https://github.com/apache/incubator-teaclave-sgx-sdk/issues/232
run: docker run ${{ env.DOCKER_DEVICES }} ${{ env.DOCKER_VOLUMES }} integritee-worker-${{ env.IMAGE_SUFFIX }} test --all
run: docker run --rm ${{ env.DOCKER_DEVICES }} ${{ env.DOCKER_VOLUMES }} integritee-worker-${{ env.IMAGE_SUFFIX }} test --all

- name: Export worker image(s)
run: |
Expand Down Expand Up @@ -130,6 +130,8 @@ jobs:
fail-fast: false
matrix:
check: [
# Workspace
cargo test --release,
# Worker
# Use release mode as the CI runs out of disk space otherwise.
cargo clippy --release -- -D warnings,
Expand Down
29 changes: 17 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,6 @@ dependencies = [
"sgx-verify",
"sgx_crypto_helper",
"sgx_types",
"sgx_urts",
"sha2 0.7.1",
"sp-consensus-grandpa",
"sp-core",
Expand Down Expand Up @@ -3087,6 +3086,7 @@ dependencies = [
"sp-io 7.0.0",
"sp-keyring",
"sp-runtime",
"sp-std",
]

[[package]]
Expand All @@ -3113,7 +3113,6 @@ dependencies = [
name = "itc-offchain-worker-executor"
version = "0.9.0"
dependencies = [
"ita-stf",
"itc-parentchain-light-client",
"itp-extrinsics-factory",
"itp-sgx-externalities",
Expand Down Expand Up @@ -3707,7 +3706,6 @@ name = "itp-stf-executor"
version = "0.9.0"
dependencies = [
"hex",
"ita-stf",
"itc-parentchain-test",
"itp-node-api",
"itp-ocall-api",
Expand All @@ -3720,6 +3718,7 @@ dependencies = [
"itp-storage",
"itp-test",
"itp-time-utils",
"itp-top-pool",
"itp-top-pool-author",
"itp-types",
"log 0.4.19",
Expand All @@ -3739,23 +3738,28 @@ version = "0.8.0"
dependencies = [
"itp-node-api-metadata",
"itp-node-api-metadata-provider",
"itp-stf-primitives",
"itp-types",
"parity-scale-codec",
]

[[package]]
name = "itp-stf-primitives"
version = "0.9.0"
dependencies = [
"derive_more",
"itp-hashing",
"itp-sgx-runtime-primitives",
"parity-scale-codec",
"sp-core",
"sp-runtime",
"sp-std",
]

[[package]]
name = "itp-stf-state-handler"
version = "0.9.0"
dependencies = [
"ita-stf",
"itp-hashing",
"itp-settings",
"itp-sgx-crypto",
Expand Down Expand Up @@ -3825,22 +3829,26 @@ name = "itp-test"
version = "0.9.0"
dependencies = [
"derive_more",
"ita-stf",
"itp-enclave-bridge-storage",
"itp-node-api",
"itp-node-api-metadata-provider",
"itp-ocall-api",
"itp-sgx-crypto",
"itp-sgx-externalities",
"itp-stf-interface",
"itp-stf-primitives",
"itp-stf-state-handler",
"itp-storage",
"itp-time-utils",
"itp-types",
"jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)",
"log 0.4.19",
"parity-scale-codec",
"sgx_crypto_helper",
"sgx_tstd",
"sgx_types",
"sp-core",
"sp-io 7.0.0",
"sp-runtime",
"sp-std",
]
Expand All @@ -3858,9 +3866,10 @@ version = "0.9.0"
dependencies = [
"byteorder 1.4.3",
"derive_more",
"ita-stf",
"itc-direct-rpc-server",
"itp-sgx-runtime-primitives",
"itp-stf-primitives",
"itp-test",
"itp-types",
"its-primitives",
"jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand All @@ -3886,7 +3895,6 @@ version = "0.9.0"
dependencies = [
"derive_more",
"futures 0.3.28",
"ita-stf",
"itp-enclave-metrics",
"itp-ocall-api",
"itp-sgx-crypto",
Expand Down Expand Up @@ -3934,13 +3942,8 @@ dependencies = [
name = "itp-utils"
version = "0.9.0"
dependencies = [
"frame-support",
"hex",
"parity-scale-codec",
"sgx_tstd",
"sp-core",
"thiserror 1.0.40",
"thiserror 1.0.9",
]

[[package]]
Expand All @@ -3954,6 +3957,7 @@ dependencies = [
"itp-sgx-externalities",
"itp-stf-executor",
"itp-stf-interface",
"itp-stf-primitives",
"itp-time-utils",
"itp-top-pool-author",
"itp-types",
Expand Down Expand Up @@ -4005,6 +4009,7 @@ dependencies = [
"itp-sgx-crypto",
"itp-sgx-externalities",
"itp-stf-executor",
"itp-stf-primitives",
"itp-stf-state-handler",
"itp-storage",
"itp-test",
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ ifeq ($(SGX_PRODUCTION), 1)
SGX_ENCLAVE_CONFIG = "enclave-runtime/Enclave.config.production.xml"
SGX_SIGN_KEY = $(SGX_COMMERCIAL_KEY)
SGX_SIGN_PASSFILE = $(SGX_PASSFILE)
WORKER_FEATURES := --features=production,$(WORKER_MODE),$(WORKER_FEATURES),$(ADDITIONAL_FEATURES)
WORKER_FEATURES := --features=production,link-binary,$(WORKER_MODE),$(WORKER_FEATURES),$(ADDITIONAL_FEATURES)
else
SGX_ENCLAVE_MODE = "Development Mode"
SGX_ENCLAVE_CONFIG = "enclave-runtime/Enclave.config.xml"
SGX_SIGN_KEY = "enclave-runtime/Enclave_private.pem"
SGX_SIGN_PASSFILE = ""
WORKER_FEATURES := --features=default,$(WORKER_MODE),$(WORKER_FEATURES),$(ADDITIONAL_FEATURES)
WORKER_FEATURES := --features=default,link-binary,$(WORKER_MODE),$(WORKER_FEATURES),$(ADDITIONAL_FEATURES)
endif

CLIENT_FEATURES = --features=$(WORKER_MODE),$(ADDITIONAL_FEATURES)
Expand Down Expand Up @@ -170,15 +170,15 @@ $(Worker_Enclave_u_Object): service/Enclave_u.o

$(Worker_Name): $(Worker_Enclave_u_Object) $(SRC_Files)
@echo
@echo "Building the integritee-service"
@echo "Building the integritee-service: $(Worker_Rust_Flags)"
@SGX_SDK=$(SGX_SDK) SGX_MODE=$(SGX_MODE) cargo build -p integritee-service $(Worker_Rust_Flags)
@echo "Cargo => $@"
cp $(Worker_Rust_Path)/integritee-service ./bin

######## Integritee-client objects ########
$(Client_Name): $(SRC_Files)
@echo
@echo "Building the integritee-cli"
@echo "Building the integritee-cli $(Client_Rust_Flags)"
@cargo build -p integritee-cli $(Client_Rust_Flags)
@echo "Cargo => $@"
cp $(Client_Rust_Path)/$(Client_Binary) ./bin
Expand Down
4 changes: 2 additions & 2 deletions app-libs/oracle/src/oracle_sources/coin_gecko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ impl<OracleSourceInfo: Into<TradingInfo>> OracleSource<OracleSourceInfo> for Coi
let response = match response {
Ok(response) => response,
Err(e) => {
error!("coingecko execute_exchange_rate_request() failed with: {:#?}", &e);
error!("coingecko execute_exchange_rate_request() failed with: {:?}", &e);
return Err(Error::RestClient(e))
},
};

debug!("coingecko received response: {:#?}", &response);
debug!("coingecko received response: {:?}", &response);
let list = response.0;
if list.is_empty() {
return Err(Error::NoValidData(COINGECKO_URL.to_string(), trading_pair.key()))
Expand Down
2 changes: 1 addition & 1 deletion app-libs/oracle/src/oracles/exchange_rate_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where
Err(e) =>
if tries < number_of_tries {
error!(
"Getting exchange rate from {} failed with {}, trying again in {:#?}.",
"Getting exchange rate from {} failed with {}, trying again in {:?}.",
&base_url, e, request_timeout
);
debug!("Check that the API endpoint is available, for coingecko: https://status.coingecko.com/");
Expand Down
3 changes: 1 addition & 2 deletions app-libs/stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pallet-sudo = { default-features = false, git = "https://github.com/paritytech/s
sp-application-crypto = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

# scs / integritee
my-node-runtime = { package = "integritee-node-runtime", optional = true, git = "https://github.com/integritee-network/integritee-node.git", branch = "sdk-v0.12.0-polkadot-v0.9.42" }
Expand All @@ -58,7 +59,6 @@ evm_std = ["evm", "ita-sgx-runtime/evm_std"]
sgx = [
"sgx_tstd",
"itp-sgx-externalities/sgx",
"itp-utils/sgx",
"sp-io/sgx",
"itp-node-api/sgx",
"itp-node-api-metadata-provider/sgx",
Expand All @@ -75,7 +75,6 @@ std = [
"itp-stf-interface/std",
"itp-storage/std",
"itp-types/std",
"itp-utils/std",
"itp-node-api/std",
"itp-node-api-metadata/std",
"itp-node-api-metadata-provider/std",
Expand Down
3 changes: 2 additions & 1 deletion app-libs/stf/src/best_energy_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{MerkleProofWithCodec, StfError};
use crate::MerkleProofWithCodec;
use binary_merkle_tree::merkle_proof;
use codec::Encode;
use itp_stf_primitives::error::StfError;
use simplyr_lib::{MarketOutput, Order};
use sp_core::H256;
use sp_runtime::traits::Keccak256;
Expand Down
8 changes: 3 additions & 5 deletions app-libs/stf/src/evm_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
limitations under the License.
*/
use crate::{
helpers::{get_storage_double_map, get_storage_map},
AccountId, Index,
};
use crate::helpers::{get_storage_double_map, get_storage_map};
use itp_storage::StorageHasher;
use itp_types::{AccountId, Nonce};
use sha3::{Digest, Keccak256};
use sp_core::{H160, H256};
use std::prelude::v1::*;
Expand All @@ -39,7 +37,7 @@ pub fn get_evm_account_storages(evm_account: &H160, index: &H256) -> Option<H256
}

// FIXME: Once events are available, these addresses should be read from events.
pub fn evm_create_address(caller: H160, nonce: Index) -> H160 {
pub fn evm_create_address(caller: H160, nonce: Nonce) -> H160 {
let mut stream = rlp::RlpStream::new_list(2);
stream.append(&caller);
stream.append(&nonce);
Expand Down
51 changes: 47 additions & 4 deletions app-libs/stf/src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,34 @@ use crate::best_energy_helpers::{get_merkle_proof_for_actor_from_file, read_mark
use binary_merkle_tree::MerkleProof;
use codec::{Decode, Encode};
use ita_sgx_runtime::System;
#[cfg(feature = "evm")]
use ita_sgx_runtime::{AddressMapping, HashedAddressMapping};
use itp_stf_interface::ExecuteGetter;
use itp_stf_primitives::types::{AccountId, ActorId, KeyPair, Signature, Timestamp};
use itp_stf_primitives::{
traits::GetterAuthorization,
types::{AccountId, KeyPair, Signature},
};
use itp_utils::stringify::account_id_to_string;
use log::*;
use serde::{Deserialize, Serialize};
use sp_runtime::traits::Verify;
use std::{prelude::v1::*, time::Instant};
use sp_std::vec;
use std::prelude::v1::*;

// Oli only
use itp_stf_primitives::types::{ActorId, Timestamp};
use std::time::Instant;

#[cfg(feature = "evm")]
use ita_sgx_runtime::{AddressMapping, HashedAddressMapping};

#[cfg(feature = "evm")]
use crate::evm_helpers::{get_evm_account, get_evm_account_codes, get_evm_account_storages};

use itp_stf_primitives::traits::PoolTransactionValidation;
#[cfg(feature = "evm")]
use sp_core::{H160, H256};
use sp_runtime::transaction_validity::{
TransactionValidityError, UnknownTransaction, ValidTransaction,
};

/// Custom Merkle proof that implements codec
/// The difference to the original one is that implements the scale-codec and that the fields contain u32 instead of usize.
Expand Down Expand Up @@ -79,6 +92,11 @@ pub enum Getter {
trusted(TrustedGetterSigned),
}

impl Default for Getter {
fn default() -> Self {
Getter::public(PublicGetter::some_value)
}
}
impl From<PublicGetter> for Getter {
fn from(item: PublicGetter) -> Self {
Getter::public(item)
Expand All @@ -91,6 +109,31 @@ impl From<TrustedGetterSigned> for Getter {
}
}

impl GetterAuthorization for Getter {
fn is_authorized(&self) -> bool {
match self {
Self::trusted(ref getter) => getter.verify_signature(),
Self::public(_) => true,
}
}
}

impl PoolTransactionValidation for Getter {
fn validate(&self) -> Result<ValidTransaction, TransactionValidityError> {
match self {
Self::public(_) =>
Err(TransactionValidityError::Unknown(UnknownTransaction::CannotLookup)),
Self::trusted(trusted_getter_signed) => Ok(ValidTransaction {
priority: 1 << 20,
requires: vec![],
provides: vec![trusted_getter_signed.signature.encode()],
longevity: 64,
propagate: true,
}),
}
}
}

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum PublicGetter {
Expand Down
Loading

0 comments on commit 1ed4f0f

Please sign in to comment.