Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
code fixes after itp-utils change
  • Loading branch information
clangenb committed Nov 2, 2023
commit 0c01c4344eee30abe0aedab303cbea57a0c2f2cf
4 changes: 0 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,6 @@ dependencies = [
"derive_more",
"frame-support",
"frame-system",
"hex",
"integritee-node-runtime",
"ita-sgx-runtime",
"itp-hashing",
Expand Down Expand Up @@ -3733,7 +3732,6 @@ dependencies = [
name = "itp-stf-primitives"
version = "0.9.0"
dependencies = [
"itp-sgx-runtime-primitives",
"parity-scale-codec",
"sp-core",
"sp-runtime",
Expand Down Expand Up @@ -3907,7 +3905,6 @@ dependencies = [
"frame-system",
"integritee-node-runtime",
"itp-sgx-runtime-primitives",
"itp-utils",
"pallet-balances",
"parity-scale-codec",
"primitive-types",
Expand All @@ -3916,7 +3913,6 @@ dependencies = [
"sp-core",
"sp-runtime",
"sp-std",
"substrate-api-client",
"teerex-primitives",
]

Expand Down
2 changes: 2 additions & 0 deletions core/direct-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#[cfg(all(feature = "std", feature = "sgx"))]
compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time");

extern crate alloc;

#[cfg(all(not(feature = "std"), feature = "sgx"))]
extern crate sgx_tstd as std;

Expand Down
5 changes: 3 additions & 2 deletions core/direct-rpc-server/src/rpc_responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ use crate::{
response_channel::ResponseChannel, DirectRpcError, DirectRpcResult, RpcConnectionRegistry,
RpcHash, SendRpcResponse,
};
use alloc::format;
use itp_rpc::{RpcResponse, RpcReturnValue};
use itp_types::{DirectRequestStatus, TrustedOperationStatus};
use itp_utils::{FromHexPrefixed, ToHexPrefixed};
use log::*;
use std::{boxed::Box, sync::Arc, vec::Vec};
use std::{sync::Arc, vec::Vec};

pub struct RpcResponder<Registry, Hash, ResponseChannelType>
where
Expand Down Expand Up @@ -85,7 +86,7 @@ where
let mut new_response = rpc_response.clone();

let mut result = RpcReturnValue::from_hex(&rpc_response.result)
.map_err(|e| DirectRpcError::Other(Box::new(e)))?;
.map_err(|e| DirectRpcError::Other(format!("{:?}", e).into()))?;

let do_watch = continue_watching(&status_update);

Expand Down
5 changes: 3 additions & 2 deletions core/direct-rpc-server/src/rpc_watch_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
*/

use crate::{DetermineWatch, DirectRpcError, DirectRpcResult, RpcHash};
use alloc::format;
use codec::Decode;
use itp_rpc::{RpcResponse, RpcReturnValue};
use itp_types::DirectRequestStatus;
use itp_utils::FromHexPrefixed;
use std::{boxed::Box, marker::PhantomData};
use std::marker::PhantomData;

pub struct RpcWatchExtractor<Hash>
where
Expand Down Expand Up @@ -55,7 +56,7 @@ where

fn must_be_watched(&self, rpc_response: &RpcResponse) -> DirectRpcResult<Option<Self::Hash>> {
let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result)
.map_err(|e| DirectRpcError::Other(Box::new(e)))?;
.map_err(|e| DirectRpcError::Other(format!("{:?}", e).into()))?;

if !rpc_return_value.do_watch {
return Ok(None)
Expand Down
7 changes: 4 additions & 3 deletions core/rpc-client/src/direct_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl DirectApi for DirectClient {
// Decode rpc response.
let rpc_response: RpcResponse = serde_json::from_str(&response_str)?;
let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result)
.map_err(|e| Error::Custom(Box::new(e)))?;
.map_err(|e| Error::Custom(format!("{:?}", e).into()))?;

// Decode Metadata.
let metadata = RuntimeMetadataPrefixed::decode(&mut rpc_return_value.value.as_slice())?;
Expand All @@ -166,8 +166,9 @@ impl DirectApi for DirectClient {

fn decode_from_rpc_response(json_rpc_response: &str) -> Result<String> {
let rpc_response: RpcResponse = serde_json::from_str(json_rpc_response)?;
let rpc_return_value =
RpcReturnValue::from_hex(&rpc_response.result).map_err(|e| Error::Custom(Box::new(e)))?;
let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result)
.map_err(|e| Error::Custom(format!("{:?}", e).into()))?;

let response_message = String::decode(&mut rpc_return_value.value.as_slice())?;
match rpc_return_value.status {
DirectRequestStatus::Ok => Ok(response_message),
Expand Down
4 changes: 0 additions & 4 deletions enclave-runtime/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2397,12 +2397,8 @@ dependencies = [
name = "itp-utils"
version = "0.9.0"
dependencies = [
"frame-support",
"hex",
"parity-scale-codec",
"sgx_tstd",
"sp-core",
"thiserror 1.0.9",
]

[[package]]
Expand Down
10 changes: 5 additions & 5 deletions enclave-runtime/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub unsafe extern "C" fn generate_ias_ra_extrinsic(
};

if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) {
return EnclaveError::Other(Box::new(e)).into()
return EnclaveError::BufferError(e).into()
};

sgx_status_t::SGX_SUCCESS
Expand Down Expand Up @@ -180,7 +180,7 @@ pub unsafe extern "C" fn generate_dcap_ra_extrinsic(
};

if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) {
return EnclaveError::Other(Box::new(e)).into()
return EnclaveError::BufferError(e).into()
};
sgx_status_t::SGX_SUCCESS
}
Expand Down Expand Up @@ -232,7 +232,7 @@ pub unsafe extern "C" fn generate_dcap_ra_quote(
let dcap_quote_slice = slice::from_raw_parts_mut(dcap_quote_p, dcap_quote_size as usize);

if let Err(e) = write_slice_and_whitespace_pad(dcap_quote_slice, dcap_quote) {
return EnclaveError::Other(Box::new(e)).into()
return EnclaveError::BufferError(e).into()
};

sgx_status_t::SGX_SUCCESS
Expand Down Expand Up @@ -280,7 +280,7 @@ pub unsafe extern "C" fn generate_dcap_ra_extrinsic_from_quote(
};

if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) {
return EnclaveError::Other(Box::new(e)).into()
return EnclaveError::BufferError(e).into()
};
sgx_status_t::SGX_SUCCESS
}
Expand Down Expand Up @@ -470,7 +470,7 @@ where

let extrinsic = extrinsics_factory.create_extrinsics(&[call], None)?[0].clone();
if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) {
return EnclaveError::Other(Box::new(e)).into()
return EnclaveError::BufferError(e).into()
};
Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ use once_cell::sync::OnceCell;
use sgx_types::sgx_status_t;
use sp_runtime::traits::BlakeTwo256;
use std::{
boxed::Box,
path::PathBuf,
slice,
string::{String, ToString},
Expand Down Expand Up @@ -189,7 +188,7 @@ pub unsafe extern "C" fn get_rsa_encryption_pubkey(
if let Err(e) =
write_slice_and_whitespace_pad(pubkey_slice, rsa_pubkey_json.as_bytes().to_vec())
{
return Error::Other(Box::new(e)).into()
return Error::BufferError(e).into()
};

sgx_status_t::SGX_SUCCESS
Expand Down Expand Up @@ -323,7 +322,7 @@ pub unsafe extern "C" fn call_rpc_methods(

let response_slice = slice::from_raw_parts_mut(response, response_len as usize);
if let Err(e) = write_slice_and_whitespace_pad(response_slice, res.into_bytes()) {
return Error::Other(Box::new(e)).into()
return Error::BufferError(e).into()
};

sgx_status_t::SGX_SUCCESS
Expand Down
5 changes: 3 additions & 2 deletions sidechain/block-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use its_primitives::{
};
use log::*;
pub use sp_consensus_slots::Slot;
use sp_core::ByteArray;
use sp_runtime::{
app_crypto::Pair,
traits::{Block as ParentchainBlockTrait, Header as ParentchainHeaderTrait},
Expand Down Expand Up @@ -127,8 +128,8 @@ where
expected_author == block.block_data().block_author(),
ConsensusError::InvalidAuthority(format!(
"Expected author: {}, author found in block: {}",
public_to_string(expected_author),
public_to_string(block.block_data().block_author())
public_to_string(&expected_author.to_raw_vec()),
public_to_string(&block.block_data().block_author().to_raw_vec())
))
);

Expand Down
2 changes: 1 addition & 1 deletion sidechain/rpc-handler/src/direct_top_pool_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
Ok(acc) => acc,
Err(msg) => {
let error_msg: String =
format!("Could not retrieve pending trusted calls due to: {}", msg);
format!("Could not retrieve pending trusted calls due to: {:?}", msg);
return Ok(json!(compute_hex_encoded_return_error(error_msg.as_str())))
},
};
Expand Down