mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Optimize offchain worker api by re-using http-client (#6454)
* Fix typo in offchain's docs * Use Self keyword in AsyncApi::new() * Move httpclient to be part of OffchainWorkers to optimize block import * Fix compilation errors for tests * Add wrapper struct for HyperClient * Use lazy_static share SharedClient amongst OffchainWorkers. Remove the need to raise the fd limit * Revert "Use lazy_static share SharedClient amongst OffchainWorkers. Remove the need to raise the fd limit" This reverts commit 7af97498a2383b5d7405e27823db8fd97245da41. * Add lazy_static for tests
This commit is contained in:
@@ -31,6 +31,7 @@ use sp_core::offchain::{
|
||||
OpaqueNetworkState, OpaquePeerId, OpaqueMultiaddr, StorageKind,
|
||||
};
|
||||
pub use sp_offchain::STORAGE_PREFIX;
|
||||
pub use http::SharedClient;
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
mod http;
|
||||
@@ -260,8 +261,9 @@ impl AsyncApi {
|
||||
db: S,
|
||||
network_state: Arc<dyn NetworkStateInfo + Send + Sync>,
|
||||
is_validator: bool,
|
||||
) -> (Api<S>, AsyncApi) {
|
||||
let (http_api, http_worker) = http::http();
|
||||
shared_client: SharedClient,
|
||||
) -> (Api<S>, Self) {
|
||||
let (http_api, http_worker) = http::http(shared_client);
|
||||
|
||||
let api = Api {
|
||||
db,
|
||||
@@ -270,7 +272,7 @@ impl AsyncApi {
|
||||
http: http_api,
|
||||
};
|
||||
|
||||
let async_api = AsyncApi {
|
||||
let async_api = Self {
|
||||
http: Some(http_worker),
|
||||
};
|
||||
|
||||
@@ -308,11 +310,14 @@ mod tests {
|
||||
let _ = env_logger::try_init();
|
||||
let db = LocalStorage::new_test();
|
||||
let mock = Arc::new(MockNetworkStateInfo());
|
||||
let shared_client = SharedClient::new();
|
||||
|
||||
|
||||
AsyncApi::new(
|
||||
db,
|
||||
mock,
|
||||
false,
|
||||
shared_client,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user