Update jsonrpc dependencies and rewrite dapps to futures. (#6522)
* Bump version. * Fix RPC crate. * Fix BoxFuture in crates. * Compiles and passes tests! * Get rid of .boxed() * Fixing issues with the UI. * Remove minihttp. Support threads. * Reimplement files serving to do it in chunks. * Increase chunk size. * Remove some unecessary copying. * Fix tests. * Fix stratum warning and ipfs todo. * Switch to proper branch of jsonrpc. * Update Cargo.lock. * Update docs. * Include dapps-glue in workspace. * fixed merge artifacts * Fix test compilation.
This commit is contained in:
committed by
Arkadiy Paronyan
parent
492da38d67
commit
e8b418ca03
@@ -480,7 +480,7 @@ usage! {
|
||||
|
||||
ARG arg_jsonrpc_server_threads: (Option<usize>) = None, or |c: &Config| otry!(c.rpc).server_threads,
|
||||
"--jsonrpc-server-threads=[NUM]",
|
||||
"Enables experimental faster implementation of JSON-RPC server. Requires Dapps server to be disabled using --no-dapps.",
|
||||
"Enables multiple threads handling incoming connections for HTTP JSON-RPC server.",
|
||||
|
||||
["API and console options – WebSockets"]
|
||||
FLAG flag_no_ws: (bool) = false, or |c: &Config| otry!(c.websockets).disable.clone(),
|
||||
|
||||
@@ -141,16 +141,11 @@ impl Configuration {
|
||||
}
|
||||
let warp_sync = !self.args.flag_no_warp && fat_db != Switch::On && tracing != Switch::On && pruning != Pruning::Specific(Algorithm::Archive);
|
||||
let geth_compatibility = self.args.flag_geth;
|
||||
let mut dapps_conf = self.dapps_config();
|
||||
let dapps_conf = self.dapps_config();
|
||||
let ipfs_conf = self.ipfs_config();
|
||||
let secretstore_conf = self.secretstore_config()?;
|
||||
let format = self.format()?;
|
||||
|
||||
if self.args.arg_jsonrpc_server_threads.is_some() && dapps_conf.enabled {
|
||||
dapps_conf.enabled = false;
|
||||
writeln!(&mut stderr(), "Warning: Disabling Dapps server because fast RPC server was enabled.").expect("Error writing to stderr.");
|
||||
}
|
||||
|
||||
let cmd = if self.args.flag_version {
|
||||
Cmd::Version
|
||||
} else if self.args.cmd_signer {
|
||||
@@ -867,9 +862,8 @@ impl Configuration {
|
||||
hosts: self.rpc_hosts(),
|
||||
cors: self.rpc_cors(),
|
||||
server_threads: match self.args.arg_jsonrpc_server_threads {
|
||||
Some(threads) if threads > 0 => Some(threads),
|
||||
None => None,
|
||||
_ => return Err("--jsonrpc-server-threads number needs to be positive.".into()),
|
||||
Some(threads) if threads > 0 => threads,
|
||||
_ => 1,
|
||||
},
|
||||
processing_threads: self.args.arg_jsonrpc_threads,
|
||||
};
|
||||
|
||||
@@ -21,7 +21,8 @@ use dir::default_data_path;
|
||||
use ethcore::client::{Client, BlockChainClient, BlockId};
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
use ethsync::LightSync;
|
||||
use futures::{future, IntoFuture, Future, BoxFuture};
|
||||
use futures::{future, IntoFuture, Future};
|
||||
use jsonrpc_core::BoxFuture;
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use hash_fetch::urlhint::ContractClient;
|
||||
use helpers::replace_home;
|
||||
@@ -30,7 +31,6 @@ use light::on_demand::{self, OnDemand};
|
||||
use node_health::{SyncStatus, NodeHealth};
|
||||
use rpc;
|
||||
use rpc_apis::SignerService;
|
||||
use parity_reactor;
|
||||
use util::Address;
|
||||
use bytes::Bytes;
|
||||
|
||||
@@ -81,9 +81,8 @@ impl ContractClient for FullRegistrar {
|
||||
}
|
||||
|
||||
fn call(&self, address: Address, data: Bytes) -> BoxFuture<Bytes, String> {
|
||||
self.client.call_contract(BlockId::Latest, address, data)
|
||||
.into_future()
|
||||
.boxed()
|
||||
Box::new(self.client.call_contract(BlockId::Latest, address, data)
|
||||
.into_future())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ impl<T: LightChainClient + 'static> ContractClient for LightRegistrar<T> {
|
||||
|
||||
let env_info = match env_info {
|
||||
Ok(x) => x,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
Err(e) => return Box::new(future::err(e)),
|
||||
};
|
||||
|
||||
let maybe_future = self.sync.with_context(move |ctx| {
|
||||
@@ -140,8 +139,8 @@ impl<T: LightChainClient + 'static> ContractClient for LightRegistrar<T> {
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(fut) => fut.boxed(),
|
||||
None => future::err("cannot query registry: network disabled".into()).boxed(),
|
||||
Some(fut) => Box::new(fut),
|
||||
None => Box::new(future::err("cannot query registry: network disabled".into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +152,6 @@ pub struct Dependencies {
|
||||
pub node_health: NodeHealth,
|
||||
pub sync_status: Arc<SyncStatus>,
|
||||
pub contract_client: Arc<ContractClient>,
|
||||
pub remote: parity_reactor::TokioRemote,
|
||||
pub fetch: FetchClient,
|
||||
pub signer: Arc<SignerService>,
|
||||
pub ui_address: Option<(String, u16)>,
|
||||
@@ -235,7 +233,6 @@ mod server {
|
||||
use rpc_apis;
|
||||
|
||||
use parity_dapps;
|
||||
use parity_reactor;
|
||||
|
||||
pub use parity_dapps::Middleware;
|
||||
|
||||
@@ -248,12 +245,11 @@ mod server {
|
||||
extra_script_src: Vec<(String, u16)>,
|
||||
) -> Result<Middleware, String> {
|
||||
let signer = deps.signer;
|
||||
let parity_remote = parity_reactor::Remote::new(deps.remote.clone());
|
||||
let web_proxy_tokens = Arc::new(move |token| signer.web_proxy_access_token_domain(&token));
|
||||
|
||||
Ok(parity_dapps::Middleware::dapps(
|
||||
deps.fetch.pool(),
|
||||
deps.node_health,
|
||||
parity_remote,
|
||||
deps.ui_address,
|
||||
extra_embed_on,
|
||||
extra_script_src,
|
||||
@@ -271,10 +267,9 @@ mod server {
|
||||
deps: Dependencies,
|
||||
dapps_domain: &str,
|
||||
) -> Result<Middleware, String> {
|
||||
let parity_remote = parity_reactor::Remote::new(deps.remote.clone());
|
||||
Ok(parity_dapps::Middleware::ui(
|
||||
deps.fetch.pool(),
|
||||
deps.node_health,
|
||||
parity_remote,
|
||||
dapps_domain,
|
||||
deps.contract_client,
|
||||
deps.sync_status,
|
||||
|
||||
@@ -23,7 +23,8 @@ use ethcore::machine::EthereumMachine;
|
||||
use ethcore::receipt::Receipt;
|
||||
use ethsync::LightSync;
|
||||
|
||||
use futures::{future, Future, BoxFuture};
|
||||
use futures::{future, Future};
|
||||
use futures::future::Either;
|
||||
|
||||
use light::client::fetch::ChainDataFetcher;
|
||||
use light::on_demand::{request, OnDemand};
|
||||
@@ -33,6 +34,8 @@ use bigint::hash::H256;
|
||||
|
||||
const ALL_VALID_BACKREFS: &str = "no back-references, therefore all back-references valid; qed";
|
||||
|
||||
type BoxFuture<T, E> = Box<Future<Item = T, Error = E>>;
|
||||
|
||||
/// Allows on-demand fetch of data useful for the light client.
|
||||
pub struct EpochFetch {
|
||||
/// A handle to the sync service.
|
||||
@@ -45,7 +48,7 @@ impl EpochFetch {
|
||||
fn request<T>(&self, req: T) -> BoxFuture<T::Out, &'static str>
|
||||
where T: Send + request::RequestAdapter + 'static, T::Out: Send + 'static
|
||||
{
|
||||
match self.sync.read().upgrade() {
|
||||
Box::new(match self.sync.read().upgrade() {
|
||||
Some(sync) => {
|
||||
let on_demand = &self.on_demand;
|
||||
let maybe_future = sync.with_context(move |ctx| {
|
||||
@@ -53,12 +56,12 @@ impl EpochFetch {
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(x) => x.map_err(|_| "Request canceled").boxed(),
|
||||
None => future::err("Unable to access network.").boxed(),
|
||||
Some(x) => Either::A(x.map_err(|_| "Request canceled")),
|
||||
None => Either::B(future::err("Unable to access network.")),
|
||||
}
|
||||
}
|
||||
None => future::err("Unable to access network").boxed(),
|
||||
}
|
||||
None => Either::B(future::err("Unable to access network")),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,11 +94,11 @@ impl<T: LightChainClient + 'static> IoHandler<ClientIoMessage> for QueueCull<T>
|
||||
});
|
||||
|
||||
match maybe_fetching {
|
||||
Some(fut) => fut.boxed(),
|
||||
Some(fut) => future::Either::A(fut),
|
||||
None => {
|
||||
debug!(target: "cull", "Unable to acquire network context; qed");
|
||||
future::ok(()).boxed()
|
||||
}
|
||||
future::Either::B(future::ok(()))
|
||||
},
|
||||
}
|
||||
}, Duration::from_millis(PURGE_TIMEOUT_MS), || {})
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ pub struct HttpConfiguration {
|
||||
pub apis: ApiSet,
|
||||
pub cors: Option<Vec<String>>,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub server_threads: Option<usize>,
|
||||
pub server_threads: usize,
|
||||
pub processing_threads: usize,
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl Default for HttpConfiguration {
|
||||
apis: ApiSet::UnsafeContext,
|
||||
cors: None,
|
||||
hosts: Some(Vec::new()),
|
||||
server_threads: None,
|
||||
server_threads: 1,
|
||||
processing_threads: 0,
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl From<UiConfiguration> for HttpConfiguration {
|
||||
apis: rpc_apis::ApiSet::UnsafeContext,
|
||||
cors: None,
|
||||
hosts: conf.hosts,
|
||||
server_threads: None,
|
||||
server_threads: 1,
|
||||
processing_threads: 0,
|
||||
}
|
||||
}
|
||||
@@ -278,13 +278,8 @@ pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
handler,
|
||||
remote,
|
||||
rpc::RpcExtractor,
|
||||
match (conf.server_threads, middleware) {
|
||||
(Some(threads), None) => rpc::HttpSettings::Threads(threads),
|
||||
(None, middleware) => rpc::HttpSettings::Dapps(middleware),
|
||||
(Some(_), Some(_)) => {
|
||||
return Err("Dapps and fast multi-threaded RPC server cannot be enabled at the same time.".into())
|
||||
},
|
||||
}
|
||||
middleware,
|
||||
conf.server_threads,
|
||||
);
|
||||
|
||||
match start_result {
|
||||
|
||||
@@ -327,7 +327,6 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
sync_status,
|
||||
node_health,
|
||||
contract_client: contract_client,
|
||||
remote: event_loop.raw_remote(),
|
||||
fetch: fetch.clone(),
|
||||
signer: signer_service.clone(),
|
||||
ui_address: cmd.ui_conf.redirection_address(),
|
||||
@@ -721,7 +720,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
sync_status,
|
||||
node_health,
|
||||
contract_client: contract_client,
|
||||
remote: event_loop.raw_remote(),
|
||||
fetch: fetch.clone(),
|
||||
signer: signer_service.clone(),
|
||||
ui_address: cmd.ui_conf.redirection_address(),
|
||||
|
||||
Reference in New Issue
Block a user