Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ fn main() {
.runner(|_args: &str, matches: &ArgMatches<'_>| {
let api = get_chain_api(matches);
let _api = api.set_signer(AccountKeyring::Alice.pair());
let accounts: Vec<_> = matches.values_of("accounts").unwrap().collect();
let accounts = matches.values_of("accounts").unwrap();

let mut nonce = _api.get_nonce().unwrap();
for account in accounts.into_iter() {
for account in accounts {
let to = get_accountid_from_str(account);
#[allow(clippy::redundant_clone)]
let xt: UncheckedExtrinsicV4<_> = compose_extrinsic_offline!(
Expand Down Expand Up @@ -273,7 +273,7 @@ fn main() {
let api = get_chain_api(matches);
let arg_from = matches.value_of("from").unwrap();
let arg_to = matches.value_of("to").unwrap();
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
let amount = matches.value_of("amount").unwrap().parse()
.expect("amount can be converted to u128");
let from = get_pair_from_str(arg_from);
let to = get_accountid_from_str(arg_to);
Expand Down Expand Up @@ -376,7 +376,7 @@ fn main() {
})
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let chain_api = get_chain_api(matches);
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
let amount = matches.value_of("amount").unwrap().parse()
.expect("amount can't be converted to u128");

let shard_opt = match matches.value_of("shard") {
Expand Down
7 changes: 2 additions & 5 deletions enclave/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub fn verify_mra_cert(cert_der: &[u8]) -> Result<(), sgx_status_t> {
let ias_ca_core: &[u8] = &ias_ca_stripped[head_len..full_len - tail_len];
let ias_cert_dec = base64::decode_config(ias_ca_core, base64::STANDARD).sgx_error()?;

let mut ca_reader = BufReader::new(&IAS_REPORT_CA[..]);
let mut ca_reader = BufReader::new(IAS_REPORT_CA);

let mut root_store = rustls::RootCertStore::empty();
root_store
Expand All @@ -295,15 +295,12 @@ pub fn verify_mra_cert(cert_der: &[u8]) -> Result<(), sgx_status_t> {
.map(|cert| cert.to_trust_anchor())
.collect();

let mut chain: Vec<&[u8]> = Vec::new();
chain.push(&ias_cert_dec);

let now_func = webpki::Time::try_from(SystemTime::now());

match sig_cert.verify_is_valid_tls_server_cert(
SUPPORTED_SIG_ALGS,
&webpki::TLSServerTrustAnchors(&trust_anchors),
&chain,
&[ias_cert_dec.as_slice()],
now_func.sgx_error()?,
) {
Ok(_) => info!("Cert is good"),
Expand Down
2 changes: 1 addition & 1 deletion enclave/src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn test_verification_ok_for_correct_content() {
let content: Vec<u8> = vec![20; 512 * 1024];
let mut ipfs_content = IpfsContent::new(cid, content);
let verification = ipfs_content.verify();
assert_eq!(verification.is_ok(), true);
assert!(verification.is_ok());
}

#[allow(unused)]
Expand Down
5 changes: 2 additions & 3 deletions enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ pub unsafe extern "C" fn mock_register_enclave_xt(
slice::from_raw_parts_mut(unchecked_extrinsic, unchecked_extrinsic_size as usize);

let signer = ed25519::unseal_pair().unwrap();

let call = [SUBSTRATEE_REGISTRY_MODULE, REGISTER_ENCLAVE];
let call = ([SUBSTRATEE_REGISTRY_MODULE, REGISTER_ENCLAVE], Vec::<u8>::new(), url);

let xt = compose_extrinsic_offline!(
signer,
(call, Vec::<u8>::new(), url.clone()),
call,
*nonce,
Era::Immortal,
genesis_hash,
Expand Down
4 changes: 4 additions & 0 deletions enclave/src/rpc/worker_api_direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ pub unsafe extern "C" fn call_rpc_methods(
sgx_status_t::SGX_SUCCESS
}

// todo: remove unit err in refactoring process
#[allow(clippy::result_unit_err)]
pub fn update_status_event<H: Encode>(
hash: H,
status_update: TrustedOperationStatus,
Expand Down Expand Up @@ -441,6 +443,8 @@ pub fn update_status_event<H: Encode>(
Ok(())
}

// todo: remove unit err in refactoring process
#[allow(clippy::result_unit_err)]
pub fn send_state<H: Encode>(hash: H, value_opt: Option<Vec<u8>>) -> Result<(), ()> {
let mut rt: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED;

Expand Down
31 changes: 13 additions & 18 deletions enclave/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,26 @@ fn test_ocall_read_write_ipfs() {
)
};

if res == sgx_status_t::SGX_SUCCESS {
let cid = std::str::from_utf8(&cid_buf).unwrap();
let mut f = File::open(&cid).unwrap();
let mut content_buf = Vec::new();
f.read_to_end(&mut content_buf).unwrap();
info!("reading file {:?} of size {} bytes", f, &content_buf.len());

let mut ipfs_content = IpfsContent::new(cid, content_buf);
let verification = ipfs_content.verify();
assert_eq!(verification.is_ok(), true);
} else {
error!("was not able to write to file");
assert!(false);
}
assert_eq!(res, sgx_status_t::SGX_SUCCESS);

let cid = std::str::from_utf8(&cid_buf).unwrap();
let mut f = File::open(&cid).unwrap();
let mut content_buf = Vec::new();
f.read_to_end(&mut content_buf).unwrap();
info!("reading file {:?} of size {} bytes", f, &content_buf.len());

let mut ipfs_content = IpfsContent::new(cid, content_buf);
let verification = ipfs_content.verify();
assert!(verification.is_ok());
}

#[allow(unused)]
fn test_ocall_worker_request() {
info!("testing ocall_worker_request. Hopefully substraTEE-node is running...");
let mut requests = Vec::new();

requests.push(WorkerRequest::ChainStorage(
let requests = vec![WorkerRequest::ChainStorage(
storage_key("Balances", "TotalIssuance").0,
None,
));
)];

let mut resp: Vec<WorkerResponse<Vec<u8>>> = match crate::worker_request(requests) {
Ok(response) => response,
Expand Down
6 changes: 2 additions & 4 deletions enclave/src/tls_ra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ fn tls_server_config(sign_type: sgx_quote_sign_type_t) -> SgxResult<ServerConfig
let (key_der, cert_der) = create_ra_report_and_signature(sign_type).sgx_error()?;

let mut cfg = rustls::ServerConfig::new(Arc::new(ClientAuth::new(true)));
let mut certs = Vec::new();
certs.push(rustls::Certificate(cert_der));
let certs = vec![rustls::Certificate(cert_der)];
let privkey = rustls::PrivateKey(key_der);
cfg.set_single_cert_with_ocsp_and_sct(certs, privkey, vec![], vec![])
.sgx_error()?;
Expand Down Expand Up @@ -264,8 +263,7 @@ fn tls_client_config(sign_type: sgx_quote_sign_type_t) -> SgxResult<ClientConfig
let (key_der, cert_der) = create_ra_report_and_signature(sign_type).sgx_error()?;

let mut cfg = rustls::ClientConfig::new();
let mut certs = Vec::new();
certs.push(rustls::Certificate(cert_der));
let certs = vec![rustls::Certificate(cert_der)];
let privkey = rustls::PrivateKey(key_der);

cfg.set_single_client_cert(certs, privkey).unwrap();
Expand Down
20 changes: 9 additions & 11 deletions enclave/src/top_pool/base_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ impl<Hash: hash::Hash + Member + Ord, Ex: fmt::Debug> BasePool<Hash, Ex> {
}

PruneStatus {
pruned,
failed,
promoted,
failed,
pruned,
}
}

Expand Down Expand Up @@ -1270,7 +1270,7 @@ source: External, requires: [03,02], provides: [04], data: [4]}"
}

pub fn test_transaction_propagation() {
assert_eq!(
assert!(
TrustedOperation {
data: vec![4u8],
bytes: 1,
Expand All @@ -1282,12 +1282,11 @@ pub fn test_transaction_propagation() {
propagate: true,
source: Source::External,
}
.is_propagable(),
true
.is_propagable()
);

assert_eq!(
TrustedOperation {
assert!(
!TrustedOperation {
data: vec![4u8],
bytes: 1,
hash: 4,
Expand All @@ -1298,8 +1297,7 @@ pub fn test_transaction_propagation() {
propagate: false,
source: Source::External,
}
.is_propagable(),
false
.is_propagable()
);
}

Expand Down Expand Up @@ -1393,7 +1391,7 @@ pub fn test_should_accept_future_transactions_when_explicitly_asked_to() {
});

// then
assert_eq!(flag_value, true);
assert_eq!(pool.reject_future_operations, true);
assert!(flag_value);
assert!(pool.reject_future_operations);
assert_eq!(pool.future.len(shard), 1);
}
3 changes: 2 additions & 1 deletion enclave/src/top_pool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@ where
shard: ShardIdentifier,
) -> Result<(), B::Error> {
// Get details of all extrinsics that are already in the pool
#[allow(clippy::filter_map_identity)] // false positive. Filter map does filter because x is an option
let in_pool_tags = self
.validated_pool
.extrinsics_tags(hashes, shard)
.into_iter()
.filter_map(|x| x)
.flat_map(|x| x);
.flatten();

// Prune all operations that provide given tags
let prune_status = self.validated_pool.prune_tags(in_pool_tags, shard)?;
Expand Down
19 changes: 7 additions & 12 deletions enclave/src/top_pool/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl<Hash: hash::Hash + Member + Ord, Ex> ReadyOperations<Hash, Ex> {
}

let operation = OperationRef {
insertion_id,
operation,
insertion_id,
};

// insert to best if it doesn't require any other operation to be included before it
Expand Down Expand Up @@ -566,19 +566,16 @@ impl<Hash: hash::Hash + Member + Ord, Ex> ReadyOperations<Hash, Ex> {
}

/// Returns number of operations in this queue.
#[allow(clippy::len_without_is_empty)]
pub fn len(&self, shard: ShardIdentifier) -> usize {
if let Some(ready_map) = self.ready.get(&shard) {
return ready_map.len();
}
0
self.ready.get(&shard)
.map_or(0, |ready_map| ready_map.len())
}

/// Returns sum of encoding lengths of all operations in this queue.
pub fn bytes(&self, shard: ShardIdentifier) -> usize {
if let Some(ready_map) = self.ready.get(&shard) {
return ready_map.bytes();
}
0
self.ready.get(&shard)
.map_or(0, |ready_map| ready_map.bytes())
}
}

Expand Down Expand Up @@ -636,10 +633,8 @@ impl<Hash: hash::Hash + Member + Ord, Ex> Iterator for BestIterator<Hash, Ex> {
satisfied += 1;
Some((satisfied, tx_ref))
// then get from the pool
} else if let Some(next) = self.all.read().get(hash) {
Some((next.requires_offset + 1, next.operation.clone()))
} else {
None
self.all.read().get(hash).map(|next| (next.requires_offset + 1, next.operation.clone()))
};

if let Some((satisfied, tx_ref)) = res {
Expand Down
2 changes: 1 addition & 1 deletion enclave/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::Hash;

pub fn hash_from_slice(hash_slize: &[u8]) -> Hash {
let mut g = [0; 32];
g.copy_from_slice(&hash_slize[..]);
g.copy_from_slice(hash_slize);
Hash::from(&mut g)
}

Expand Down
6 changes: 3 additions & 3 deletions stf/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn cmd<'a>(
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let arg_from = matches.value_of("from").unwrap();
let arg_to = matches.value_of("to").unwrap();
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
let amount = matches.value_of("amount").unwrap().parse()
.expect("amount can be converted to u128");
let from = get_pair_from_str(matches, arg_from);
let to = get_accountid_from_str(arg_to);
Expand Down Expand Up @@ -210,7 +210,7 @@ pub fn cmd<'a>(
})
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let arg_who = matches.value_of("account").unwrap();
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
let amount = matches.value_of("amount").unwrap().parse()
.expect("amount can be converted to u128");
let who = get_pair_from_str(matches, arg_who);
let signer = get_pair_from_str(matches, "//Alice");
Expand Down Expand Up @@ -327,7 +327,7 @@ pub fn cmd<'a>(
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let arg_from = matches.value_of("from").unwrap();
let arg_to = matches.value_of("to").unwrap();
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
let amount = matches.value_of("amount").unwrap().parse()
.expect("amount can be converted to u128");
let from = get_pair_from_str(matches, arg_from);
let to = get_accountid_from_str(arg_to);
Expand Down
2 changes: 2 additions & 0 deletions worker/rpc/client/src/direct_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct DirectClient {
}

pub trait DirectApi {
// will remove unit err in refactoring process
#[allow(clippy::result_unit_err)]
fn watch(&self, request: String, sender: MpscSender<String>) -> Result<(), ()>;
fn get_rsa_pubkey(&self) -> Result<Rsa3072PubKey, String>;
}
Expand Down
4 changes: 2 additions & 2 deletions worker/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pub fn enclaves() -> Vec<Enclave> {
vec![
Enclave::new(
[0;32].into(),
[1;32].into(),
[1;32],
1,
format!("ws://{}", W1_URL),
),
Enclave::new(
[2;32].into(),
[3;32].into(),
[3;32],
2,
format!("ws://{}", W2_URL),
),
Expand Down
4 changes: 2 additions & 2 deletions worker/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ where
/// in rpc/server.
pub fn worker_url_into_async_rpc_url(url: &str) -> WorkerResult<String> {
// [Option("ws"), //ip, port]
let mut url_vec: Vec<&str> = url.split(":").collect();
let mut url_vec: Vec<&str> = url.split(':').collect();
match url_vec.len() {
3 | 2 => (),
_ => Err(Error::Custom("Invalid worker url format".into()))?,
_ => return Err(Error::Custom("Invalid worker url format".into())),
};

let ip = if url_vec.len() == 3 {
Expand Down