Skip to content

Commit

Permalink
fix: use async threadpool for stf (#2597)
Browse files Browse the repository at this point in the history
Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com>
  • Loading branch information
felixfaisal and Kailai-Wang committed Mar 20, 2024
1 parent 45882c1 commit c27495d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
4 changes: 0 additions & 4 deletions tee-worker/litentry/core/stf-task/receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ version = "0.1.0"
# std dependencies
futures = { version = "0.3.8", optional = true }
thiserror = { version = "1.0.26", optional = true }
threadpool = { version = "1.8.0", optional = true }

# sgx dependencies
futures_sgx = { package = "futures", git = "https://github.com/mesalock-linux/futures-rs-sgx", optional = true }
hex-sgx = { package = "hex", git = "https://github.com/mesalock-linux/rust-hex-sgx", tag = "sgx_1.1.3", features = ["sgx_tstd"], optional = true }
sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git", branch = "master", features = ["net", "thread"], optional = true }
thiserror_sgx = { package = "thiserror", git = "https://github.com/mesalock-linux/thiserror-sgx", tag = "sgx_1.1.3", optional = true }
threadpool_sgx = { git = "https://github.com/mesalock-linux/rust-threadpool-sgx", package = "threadpool", tag = "sgx_1.1.3", optional = true }
url_sgx = { package = "url", git = "https://github.com/mesalock-linux/rust-url-sgx", tag = "sgx_1.1.3", optional = true }

# no_std dependencies
Expand Down Expand Up @@ -63,7 +61,6 @@ hex = "0.4.2"
[features]
default = ["std"]
sgx = [
"threadpool_sgx",
"futures_sgx",
"hex-sgx",
"sgx_tstd",
Expand All @@ -85,7 +82,6 @@ sgx = [
"lc-data-providers/sgx",
]
std = [
"threadpool",
"futures",
"log/std",
"thiserror",
Expand Down
10 changes: 3 additions & 7 deletions tee-worker/litentry/core/stf-task/receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod sgx_reexport_prelude {
pub use futures_sgx as futures;
pub use hex_sgx as hex;
pub use thiserror_sgx as thiserror;
pub use threadpool_sgx as threadpool;
pub use url_sgx as url;
}

Expand All @@ -39,7 +38,7 @@ pub mod handler;

use codec::Encode;
use frame_support::sp_tracing::warn;
use futures::executor;
use futures::{executor, executor::ThreadPoolBuilder};
use handler::{
assertion::AssertionHandler, identity_verification::IdentityVerificationHandler, TaskHandler,
};
Expand All @@ -65,7 +64,6 @@ use std::{
thread,
time::Instant,
};
use threadpool::ThreadPool;

#[cfg(test)]
mod mock;
Expand Down Expand Up @@ -218,7 +216,7 @@ where
let stf_task_receiver = stf_task_sender::init_stf_task_sender_storage()
.map_err(|e| Error::OtherError(format!("read storage error:{:?}", e)))?;
let n_workers = 4;
let pool = ThreadPool::new(n_workers);
let pool = ThreadPoolBuilder::new().pool_size(n_workers).create().unwrap();

let (sender, receiver) = channel::<(ShardIdentifier, H256, TrustedCall)>();

Expand All @@ -238,7 +236,7 @@ where
let context_pool = context.clone();
let sender_pool = sender.clone();

pool.execute(move || {
pool.spawn_ok(async move {
let start_time = Instant::now();

match &req {
Expand All @@ -259,8 +257,6 @@ where
}
});
}

pool.join();
warn!("stf_task_receiver loop terminated");
Ok(())
}

0 comments on commit c27495d

Please sign in to comment.