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

TOP pool synchronization #2211

Merged
merged 36 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8da59e6
first working version
kziemianek Oct 9, 2023
866b341
Merge branch 'dev' into 1935-broadcast-top
kziemianek Oct 17, 2023
98203b5
small tweaks
kziemianek Oct 17, 2023
8b0dddc
updating peers
kziemianek Oct 19, 2023
65c5a0d
trusted call broadcasting tweaks
kziemianek Oct 20, 2023
0769dcc
remove broadcasted request encryption/decryption
kziemianek Oct 23, 2023
57026c6
test
kziemianek Oct 23, 2023
00e96fb
add more unit tests
kziemianek Oct 23, 2023
9827919
cargo cleanup
kziemianek Oct 23, 2023
acdea60
fix
kziemianek Oct 24, 2023
4fc0ca3
small adjustments
kziemianek Oct 24, 2023
3384f21
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Oct 24, 2023
03ae3d9
adjust waiting time and add comment
kziemianek Oct 26, 2023
02b4521
one thread per trusted rpc ws client
kziemianek Oct 27, 2023
da2793d
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Oct 27, 2023
29f8d38
add/remove peers
kziemianek Oct 28, 2023
5e4fd97
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Oct 28, 2023
51fa858
restore peer connections
kziemianek Oct 30, 2023
c5935a4
broadcast aes trusted calls
kziemianek Nov 2, 2023
fe6ab25
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 3, 2023
724d736
broadcast stf-task created trusted calls
kziemianek Nov 6, 2023
97ca7bb
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 7, 2023
470a985
remove mutex from DirectRpcClient
kziemianek Nov 7, 2023
702c3d8
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 8, 2023
95f1a53
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 13, 2023
d26429f
review suggestions
kziemianek Nov 13, 2023
6aa26e3
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 13, 2023
0275af1
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 14, 2023
95aad63
Merge branch 'dev' into p-100-linear-processing-of-di-requests
Kailai-Wang Nov 14, 2023
1dade5b
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 15, 2023
c0a3beb
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 16, 2023
79d909e
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 22, 2023
f77057c
move broadcasting to Author
kziemianek Nov 24, 2023
3c9c6ed
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 24, 2023
a010e7f
add author_tests
kziemianek Nov 24, 2023
d303863
Merge branch 'dev' into p-100-linear-processing-of-di-requests
kziemianek Nov 24, 2023
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
41 changes: 41 additions & 0 deletions tee-worker/Cargo.lock

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

2 changes: 2 additions & 0 deletions tee-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ members = [
"app-libs/sgx-runtime",
"app-libs/stf",
"cli",
"core/direct-rpc-client",
"core/direct-rpc-server",
"core/peer-top-broadcaster",
"core/offchain-worker-executor",
"core/parentchain/block-import-dispatcher",
"core/parentchain/block-importer",
Expand Down
10 changes: 7 additions & 3 deletions tee-worker/cli/src/attesteer/commands/send_dcap_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::{command_utils::get_worker_api_direct, Cli};
use itc_rpc_client::direct_client::DirectApi;
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_rpc::{Id, RpcRequest, RpcResponse, RpcReturnValue};
use itp_types::DirectRequestStatus;
use itp_utils::FromHexPrefixed;
use log::*;
Expand All @@ -39,8 +39,12 @@ impl SendDcapQuoteCmd {
};

let rpc_method = "attesteer_forwardDcapQuote".to_owned();
let jsonrpc_call: String =
RpcRequest::compose_jsonrpc_call(rpc_method, vec![hex_encoded_quote]).unwrap();
let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
rpc_method,
vec![hex_encoded_quote],
)
.unwrap();

let rpc_response_str = direct_api.get(&jsonrpc_call).unwrap();

Expand Down
10 changes: 7 additions & 3 deletions tee-worker/cli/src/attesteer/commands/send_ias_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

use itc_rpc_client::direct_client::DirectApi;
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_rpc::{Id, RpcRequest, RpcResponse, RpcReturnValue};
use itp_types::DirectRequestStatus;
use itp_utils::FromHexPrefixed;
use log::*;
Expand All @@ -40,8 +40,12 @@ impl SendIasAttestationReportCmd {
};

let rpc_method = "attesteer_forwardIasAttestationReport".to_owned();
let jsonrpc_call: String =
RpcRequest::compose_jsonrpc_call(rpc_method, vec![hex_encoded_report]).unwrap();
let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
rpc_method,
vec![hex_encoded_report],
)
.unwrap();

let rpc_response_str = direct_api.get(&jsonrpc_call).unwrap();

Expand Down
3 changes: 2 additions & 1 deletion tee-worker/cli/src/trusted_base_cli/commands/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codec::Decode;
use frame_metadata::{RuntimeMetadata, StorageEntryType, StorageHasher};
use ita_sgx_runtime::Runtime;
use itc_rpc_client::direct_client::{DirectApi, DirectClient};
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_rpc::{Id, RpcRequest, RpcResponse, RpcReturnValue};
use itp_types::DirectRequestStatus;
use itp_utils::FromHexPrefixed;
use log::{error, warn};
Expand Down Expand Up @@ -144,6 +144,7 @@ fn send_get_storage_request(
storage_entry_key: &Vec<u8>,
) -> Option<Vec<u8>> {
let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
"state_getStorage".to_string(),
vec![mrenclave, format!("0x{}", hex::encode(storage_entry_key))],
)
Expand Down
3 changes: 2 additions & 1 deletion tee-worker/cli/src/trusted_command_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use base58::{FromBase58, ToBase58};
use codec::{Decode, Encode};
use ita_stf::{TrustedGetter, TrustedOperation};
use itc_rpc_client::direct_client::DirectApi;
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_rpc::{Id, RpcRequest, RpcResponse, RpcReturnValue};
use itp_stf_primitives::types::{AccountId, KeyPair, ShardIdentifier};
use itp_types::DirectRequestStatus;
use itp_utils::{FromHexPrefixed, ToHexPrefixed};
Expand Down Expand Up @@ -147,6 +147,7 @@ pub(crate) fn get_pending_trusted_calls_for(
let direct_api = get_worker_api_direct(cli);
let rpc_method = "author_pendingTrustedCallsFor".to_owned();
let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
rpc_method,
vec![shard.encode().to_base58(), who.to_hex()],
)
Expand Down
19 changes: 14 additions & 5 deletions tee-worker/cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use codec::{Decode, Encode};
use ita_stf::{Getter, StfError, TrustedCall, TrustedOperation};
use itc_rpc_client::direct_client::{DirectApi, DirectClient};
use itp_node_api::api_client::{ParentchainApi, TEEREX};
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_rpc::{Id, RpcRequest, RpcResponse, RpcReturnValue};
use itp_sgx_crypto::ShieldingCryptoEncrypt;
use itp_stf_primitives::types::ShardIdentifier;
use itp_types::{BlockNumber, DirectRequestStatus, RsaRequest, TrustedOperationStatus};
Expand Down Expand Up @@ -105,8 +105,12 @@ pub(crate) fn get_state<T: Decode>(
// Compose jsonrpc call.
let data = RsaRequest::new(shard, getter.encode());
let rpc_method = "state_executeGetter".to_owned();
let jsonrpc_call: String =
RpcRequest::compose_jsonrpc_call(rpc_method, vec![data.to_hex()]).unwrap();
let jsonrpc_call: String = RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
rpc_method,
vec![data.to_hex()],
)
.unwrap();

let rpc_response_str = direct_api.get(&jsonrpc_call).unwrap();

Expand Down Expand Up @@ -437,8 +441,12 @@ pub(crate) fn get_vc_json_request(

// compose jsonrpc call
let request = AesRequest { shard, payload: operation_call_encrypted, key: encrypted_key };
RpcRequest::compose_jsonrpc_call("author_submitVCRequest".to_string(), vec![request.to_hex()])
.unwrap()
RpcRequest::compose_jsonrpc_call(
Id::Number(1),
"author_submitVCRequest".to_string(),
vec![request.to_hex()],
)
.unwrap()
}

pub(crate) fn get_json_request(
Expand All @@ -451,6 +459,7 @@ pub(crate) fn get_json_request(
// compose jsonrpc call
let request = RsaRequest::new(shard, operation_call_encrypted);
RpcRequest::compose_jsonrpc_call(
Id::Text("1".to_string()),
"author_submitAndWatchRsaRequest".to_string(),
vec![request.to_hex()],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
Usurped: null,
Dropped: null,
Invalid: null,
TopExecuted: "Bytes",
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion tee-worker/core-primitives/ocall-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pub extern crate alloc;

use alloc::vec::Vec;
use alloc::{string::String, vec::Vec};
use codec::{Decode, Encode};
use core::result::Result as StdResult;
use derive_more::{Display, From};
Expand Down Expand Up @@ -142,6 +142,8 @@ pub trait EnclaveSidechainOCallApi: Clone + Send + Sync {
maybe_until_block_hash: Option<BlockHash>,
shard_identifier: ShardIdentifier,
) -> SgxResult<Vec<SignedSidechainBlock>>;

fn get_trusted_peers_urls(&self) -> SgxResult<Vec<String>>;
kziemianek marked this conversation as resolved.
Show resolved Hide resolved
}

/// Newtype for IPFS CID
Expand Down
12 changes: 4 additions & 8 deletions tee-worker/core-primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use itp_types::DirectRequestStatus;
use serde::{Deserialize, Serialize};
use std::{borrow::ToOwned, string::String, vec::Vec};

#[derive(Encode, Decode, Debug)]
#[derive(Encode, Decode, Debug, Eq, PartialEq)]
pub struct RpcReturnValue {
pub value: Vec<u8>,
pub do_watch: bool,
Expand All @@ -48,7 +48,7 @@ impl RpcReturnValue {
}
}

#[derive(Clone, Encode, Decode, Debug, Serialize, Deserialize)]
#[derive(Clone, Encode, Decode, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[serde(untagged)]
pub enum Id {
#[codec(index = 0)]
Expand All @@ -74,15 +74,11 @@ pub struct RpcRequest {

impl RpcRequest {
pub fn compose_jsonrpc_call(
id: Id,
method: String,
params: Vec<String>,
) -> Result<String, serde_json::Error> {
serde_json::to_string(&RpcRequest {
jsonrpc: "2.0".to_owned(),
method,
params,
id: Id::Number(1),
})
serde_json::to_string(&RpcRequest { jsonrpc: "2.0".to_owned(), method, params, id })
}
}

Expand Down
6 changes: 5 additions & 1 deletion tee-worker/core-primitives/test/src/mock/onchain_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sgx_types::*;
use sp_core::H256;
use sp_runtime::{traits::Header as HeaderTrait, AccountId32, OpaqueExtrinsic};
use sp_std::prelude::*;
use std::collections::HashMap;
use std::{collections::HashMap, string::String};

#[derive(Default, Clone, Debug)]
pub struct OnchainMock {
Expand Down Expand Up @@ -158,6 +158,10 @@ impl EnclaveSidechainOCallApi for OnchainMock {
) -> SgxResult<Vec<SignedSidechainBlock>> {
Ok(Vec::new())
}

fn get_trusted_peers_urls(&self) -> SgxResult<Vec<String>> {
Ok(Vec::default())
}
}

impl EnclaveMetricsOCallApi for OnchainMock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use core::marker::PhantomData;
use itp_ocall_api::EnclaveSidechainOCallApi;
use itp_types::{BlockHash, ShardIdentifier};
use sgx_types::{sgx_status_t, SgxResult};
use std::vec::Vec;
use std::{string::String, vec::Vec};

pub struct SidechainOCallApiMock<SignedSidechainBlockType> {
fetch_from_peer_blocks: Option<Vec<SignedSidechainBlockType>>,
Expand Down Expand Up @@ -107,4 +107,8 @@ where
None => Err(sgx_status_t::SGX_ERROR_UNEXPECTED),
}
}

fn get_trusted_peers_urls(&self) -> SgxResult<Vec<String>> {
Ok(Vec::default())
}
}
8 changes: 6 additions & 2 deletions tee-worker/core-primitives/top-pool-author/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ itp-stf-state-handler = { path = "../stf-state-handler", default-features = fals
itp-test = { path = "../test", default-features = false, optional = true }
itp-top-pool = { path = "../top-pool", default-features = false }
itp-types = { path = "../types", default-features = false }
itp-utils = { path = "../utils", default-features = false }

# litentry
litentry-primitives = { path = "../../litentry/primitives", default-features = false }

# sgx enabled external libraries
jsonrpc-core_sgx = { package = "jsonrpc-core", git = "https://github.com/scs/jsonrpc", branch = "no_std_v18", default-features = false, optional = true }
Expand All @@ -42,8 +46,6 @@ itp-test = { path = "../test" }
itp-top-pool = { path = "../top-pool", features = ["mocks"] }
sgx-crypto-helper = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", package = "sgx_crypto_helper", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
# litentry
litentry-primitives = { path = "../../litentry/primitives", default-features = false }


[features]
Expand All @@ -56,6 +58,7 @@ std = [
"itp-stf-state-handler/std",
"itp-top-pool/std",
"itp-types/std",
"itp-utils/std",
"jsonrpc-core",
"log/std",
# litentry
Expand All @@ -69,6 +72,7 @@ sgx = [
"itp-sgx-crypto/sgx",
"itp-stf-state-handler/sgx",
"itp-top-pool/sgx",
"itp-utils/sgx",
"thiserror_sgx",
# litentry
"litentry-primitives/sgx",
Expand Down
Loading