Skip to content

Commit

Permalink
Make some DI responses synchronous (#1920)
Browse files Browse the repository at this point in the history
* add top_hash

* skeleton for rpc responses

* add rpc value setters

* basic SetUserShieldingKeyResponse

* adjust ts

* clippy

* cargo update

* try to fix tests

* try to address streamed trusted calls

* watch callback ext

* update ts

* yarn format

* clippy

* fix tests

* rename

* cargo update
  • Loading branch information
Kailai-Wang authored Jul 25, 2023
1 parent ef2a58f commit a85f627
Show file tree
Hide file tree
Showing 60 changed files with 1,775 additions and 1,067 deletions.
383 changes: 197 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

767 changes: 377 additions & 390 deletions tee-worker/Cargo.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions tee-worker/app-libs/stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod stf_sgx_tests;
pub mod test_genesis;
pub mod trusted_call;
pub mod trusted_call_litentry;
pub mod trusted_call_rpc_response;

pub(crate) const ENCLAVE_ACCOUNT_KEY: &str = "Enclave_Account_Key";

Expand Down Expand Up @@ -93,6 +94,7 @@ pub enum StfError {
#[display(fmt = "SetIdentityNetworksFailed: {:?}", _0)]
SetIdentityNetworksFailed(ErrorDetail),
InvalidAccount,
UnclassifiedError,
}

impl From<MetadataError> for StfError {
Expand All @@ -107,6 +109,27 @@ impl From<MetadataProviderError> for StfError {
}
}

impl From<IMPError> for StfError {
fn from(e: IMPError) -> Self {
match e {
IMPError::SetUserShieldingKeyFailed(d) => StfError::SetIdentityNetworksFailed(d),
IMPError::LinkIdentityFailed(d) => StfError::LinkIdentityFailed(d),
IMPError::DeactivateIdentityFailed(d) => StfError::DeactivateIdentityFailed(d),
IMPError::ActivateIdentityFailed(d) => StfError::ActivateIdentityFailed(d),
_ => StfError::UnclassifiedError,
}
}
}

impl From<VCMPError> for StfError {
fn from(e: VCMPError) -> Self {
match e {
VCMPError::RequestVCFailed(a, d) => StfError::RequestVCFailed(a, d),
_ => StfError::UnclassifiedError,
}
}
}

impl StfError {
// Convert StfError to IMPError that would be sent to parentchain
pub fn to_imp_error(&self) -> IMPError {
Expand Down
7 changes: 4 additions & 3 deletions tee-worker/app-libs/stf/src/stf_sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use itp_stf_interface::{
};
use itp_stf_primitives::types::ShardIdentifier;
use itp_storage::storage_value_key;
use itp_types::OpaqueCall;
use itp_types::{OpaqueCall, H256};
use itp_utils::stringify::account_id_to_string;
use log::*;
use sp_runtime::traits::StaticLookup;
Expand Down Expand Up @@ -136,10 +136,11 @@ where
state: &mut State,
shard: &ShardIdentifier,
call: Call,
top_hash: H256,
calls: &mut Vec<OpaqueCall>,
node_metadata_repo: Arc<NodeMetadataRepository>,
) -> Result<(), Self::Error> {
state.execute_with(|| call.execute(shard, calls, node_metadata_repo))
) -> Result<Vec<u8>, Self::Error> {
state.execute_with(|| call.execute(shard, top_hash, calls, node_metadata_repo))
}
}

Expand Down
10 changes: 9 additions & 1 deletion tee-worker/app-libs/stf/src/stf_sgx_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ pub fn shield_funds_increments_signer_account_nonce() {

let repo = Arc::new(NodeMetadataRepository::new(NodeMetadataMock::new()));
let shard = ShardIdentifier::default();
StfState::execute_call(&mut state, &shard, shield_funds_call, &mut Vec::new(), repo).unwrap();
StfState::execute_call(
&mut state,
&shard,
shield_funds_call,
Default::default(),
&mut Vec::new(),
repo,
)
.unwrap();
assert_eq!(1, StfState::get_account_nonce(&mut state, &enclave_signer_account_id));
}

Expand Down
Loading

0 comments on commit a85f627

Please sign in to comment.