openethereum/crates/rpc/src/lib.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

245 lines
7.1 KiB
Rust
Raw Normal View History

2020-09-22 14:53:52 +02:00
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of OpenEthereum.
2016-02-05 13:40:41 +01:00
2020-09-22 14:53:52 +02:00
// OpenEthereum is free software: you can redistribute it and/or modify
2016-02-05 13:40:41 +01:00
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2020-09-22 14:53:52 +02:00
// OpenEthereum is distributed in the hope that it will be useful,
2016-02-05 13:40:41 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
2020-09-22 14:53:52 +02:00
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
2016-02-05 13:40:41 +01:00
2020-09-22 14:53:52 +02:00
//! OpenEthereum JSON-RPC Servers (WS, HTTP, IPC).
#![warn(missing_docs, unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", warn(clippy::all, clippy::pedantic))]
#![cfg_attr(
feature = "cargo-clippy",
allow(
// things are often more readable this way
clippy::cast_lossless,
clippy::module_name_repetitions,
clippy::single_match_else,
clippy::type_complexity,
clippy::use_self,
// not practical
clippy::match_bool,
clippy::needless_pass_by_value,
clippy::similar_names,
// don't require markdown syntax for docs
clippy::doc_markdown,
),
warn(clippy::indexing_slicing)
)]
2016-01-26 13:14:22 +01:00
#[macro_use]
extern crate futures;
2017-09-01 16:57:57 +02:00
extern crate ansi_term;
extern crate itertools;
extern crate order_stat;
extern crate parking_lot;
extern crate rand;
extern crate rustc_hex;
2016-01-26 13:14:22 +01:00
extern crate serde;
2016-01-26 19:24:33 +01:00
extern crate serde_json;
extern crate tokio_timer;
extern crate transient_hashmap;
2016-01-21 01:19:29 +01:00
extern crate jsonrpc_core;
extern crate jsonrpc_derive;
extern crate jsonrpc_http_server as http;
extern crate jsonrpc_ipc_server as ipc;
extern crate jsonrpc_pubsub;
2016-09-01 14:49:12 +02:00
extern crate common_types as types;
extern crate eip_712;
extern crate ethash;
2016-01-26 13:14:22 +01:00
extern crate ethcore;
2018-04-10 12:13:49 +02:00
extern crate ethcore_logger;
extern crate ethcore_miner as miner;
Increase number of requested block bodies in chain sync (#10247) * Increase the number of block bodies requested during Sync. * Increase the number of block bodies requested during Sync. * Check if our peer is an older parity client with the bug of not handling large requests properly * Add a ClientVersion struct and a ClientCapabilites trait * Make ClientVersion its own module * Refactor and extend use of ClientVersion * Replace strings with ClientVersion in PeerInfo * Group further functionality in ClientCapabilities * Move parity client version data from tuple to its own struct. * Implement accessor methods for ParityClientData and remove them from ClientVersion. * Minor fixes * Make functions specific to parity return types specific to parity. * Test for shorter ID strings * Fix formatting and remove unneeded dependencies. * Roll back Cargo.lock * Commit last Cargo.lock * Convert from string to ClientVersion * * When checking if peer accepts service transactions just check if it's parity, remove version check. * Remove dependency on semver in ethcore-sync * Remove unnecessary String instantiation * Rename peer_info to peer_version * Update RPC test helpers * Simplify From<String> * Parse static version string only once * Update RPC tests to new ClientVersion struct * Document public members * More robust parsing of ID string * Minor changes. * Update version in which large block bodies requests appear. * Update ethcore/sync/src/block_sync.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update util/network/src/client_version.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update util/network/src/client_version.rs Co-Authored-By: elferdo <elferdo@gmail.com> * Update tests. * Minor fixes.
2019-02-07 15:27:09 +01:00
extern crate ethcore_network as network;
2018-04-10 12:13:49 +02:00
extern crate ethcore_sync as sync;
extern crate ethereum_types;
extern crate ethkey;
extern crate ethstore;
extern crate fetch;
extern crate keccak_hash as hash;
extern crate parity_bytes as bytes;
extern crate parity_crypto as crypto;
extern crate parity_runtime;
extern crate parity_version as version;
extern crate rlp;
2017-02-17 16:18:31 +01:00
extern crate stats;
extern crate tempdir;
extern crate vm;
#[cfg(any(test, feature = "ethcore-accounts"))]
extern crate ethcore_accounts as accounts;
2016-09-01 14:49:12 +02:00
#[cfg(any(test, feature = "ethcore-accounts"))]
extern crate tiny_keccak;
2016-09-01 14:49:12 +02:00
#[macro_use]
extern crate log;
2016-12-13 14:59:19 +01:00
#[macro_use]
extern crate serde_derive;
2016-01-21 01:19:29 +01:00
#[cfg(test)]
extern crate ethjson;
New Transaction Queue implementation (#8074) * Implementation of Verifier, Scoring and Ready. * Queue in progress. * TransactionPool. * Prepare for txpool release. * Miner refactor [WiP] * WiP reworking miner. * Make it compile. * Add some docs. * Split blockchain access to a separate file. * Work on miner API. * Fix ethcore tests. * Refactor miner interface for sealing/work packages. * Implement next nonce. * RPC compiles. * Implement couple of missing methdods for RPC. * Add transaction queue listeners. * Compiles! * Clean-up and parallelize. * Get rid of RefCell in header. * Revert "Get rid of RefCell in header." This reverts commit 0f2424c9b7319a786e1565ea2a8a6d801a21b4fb. * Override Sync requirement. * Fix status display. * Unify logging. * Extract some cheap checks. * Measurements and optimizations. * Fix scoring bug, heap size of bug and add cache * Disable tx queueing and parallel verification. * Make ethcore and ethcore-miner compile again. * Make RPC compile again. * Bunch of txpool tests. * Migrate transaction queue tests. * Nonce Cap * Nonce cap cache and tests. * Remove stale future transactions from the queue. * Optimize scoring and write some tests. * Simple penalization. * Clean up and support for different scoring algorithms. * Add CLI parameters for the new queue. * Remove banning queue. * Disable debug build. * Change per_sender limit to be 1% instead of 5% * Avoid cloning when propagating transactions. * Remove old todo. * Post-review fixes. * Fix miner options default. * Implement back ready transactions for light client. * Get rid of from_pending_block * Pass rejection reason. * Add more details to drop. * Rollback heap size of. * Avoid cloning hashes when propagating and include more details on rejection. * Fix tests. * Introduce nonces cache. * Remove uneccessary hashes allocation. * Lower the mem limit. * Re-enable parallel verification. * Add miner log. Don't check the type if not below min_gas_price. * Add more traces, fix disabling miner. * Fix creating pending blocks twice on AuRa authorities. * Fix tests. * re-use pending blocks in AuRa * Use reseal_min_period to prevent too frequent update_sealing. * Fix log to contain hash not sender. * Optimize local transactions. * Fix aura tests. * Update locks comments. * Get rid of unsafe Sync impl. * Review fixes. * Remove excessive matches. * Fix compilation errors. * Use new pool in private transactions. * Fix private-tx test. * Fix secret store tests. * Actually use gas_floor_target * Fix config tests. * Fix pool tests. * Address grumbles.
2018-04-13 17:34:27 +02:00
#[cfg(test)]
extern crate transaction_pool as txpool;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[cfg(test)]
#[macro_use]
extern crate macros;
#[cfg(test)]
extern crate fake_fetch;
#[cfg(test)]
extern crate ethcore_io as io;
pub extern crate jsonrpc_ws_server as ws;
mod authcodes;
mod http_common;
pub mod v1;
pub mod tests;
pub use http::{
cors::AccessControlAllowHeaders, hyper, AccessControlAllowOrigin, DomainsValidation, Host,
RequestMiddleware, RequestMiddlewareAction,
};
pub use ipc::{
MetaExtractor as IpcMetaExtractor, RequestContext as IpcRequestContext, Server as IpcServer,
2020-08-05 06:08:03 +02:00
};
parity-clib: `async C bindings to RPC requests` + `subscribe/unsubscribe to websocket events` (#9920) * feat(parity-clib asynchronous rpc queries) * feat(seperate bindings for ws and rpc) * Subscribing to websockets for the full-client works * feat(c binding unsubscribe_from_websocket) * fix(tests): tweak CMake build config * Enforce C+11 * refactor(parity-cpp-example) : `cpp:ify` * fix(typedefs) : revert typedefs parity-clib * docs(nits) * fix(simplify websocket_unsubscribe) * refactor(cpp example) : more subscriptions * fix(callback type) : address grumbles on callback * Use it the example to avoid using global variables * docs(nits) - don't mention `arc` * fix(jni bindings): fix compile errors * feat(java example and updated java bindings) * fix(java example) : run both full and light client * fix(Java shutdown) : unsubscribe to sessions Forgot to pass the JNIEnv environment since it is an instance method * feat(return valid JString) * Remove Java dependency by constructing a valid Java String in the callback * fix(logger) : remove `rpc` trace log * fix(format) * fix(parity-clib): remove needless callback `type` * fix(parity-clib-examples) : update examples * `cpp` example pass in a struct instead to determines `callback kind` * `java` add a instance variable the class `Callback` to determine `callback kind` * fix(review comments): docs and format * Update parity-clib/src/java.rs Co-Authored-By: niklasad1 <niklasadolfsson1@gmail.com> * fix(bad merge + spelling) * fix(move examples to parity-clib/examples)
2019-01-02 16:49:01 +01:00
pub use jsonrpc_core::{FutureOutput, FutureResponse, FutureResult, FutureRpcResult};
pub use jsonrpc_pubsub::Session as PubSubSession;
pub use authcodes::{AuthCodes, TimeProvider};
pub use http_common::HttpMetaExtractor;
pub use v1::{
block_import::{is_major_importing, is_major_importing_or_waiting},
dispatch,
extractors::{RpcExtractor, WsDispatcher, WsExtractor, WsStats},
informant, signer, Metadata, NetworkSettings, Origin,
2020-08-05 06:08:03 +02:00
};
use std::net::SocketAddr;
/// RPC HTTP Server instance
pub type HttpServer = http::Server;
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_http<M, S, H, T>(
addr: &SocketAddr,
cors_domains: http::DomainsValidation<http::AccessControlAllowOrigin>,
allowed_hosts: http::DomainsValidation<http::Host>,
handler: H,
extractor: T,
threads: usize,
max_payload: usize,
keep_alive: bool,
2017-11-14 11:38:17 +01:00
) -> ::std::io::Result<HttpServer>
where
M: jsonrpc_core::Metadata,
S: jsonrpc_core::Middleware<M>,
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
T: HttpMetaExtractor<Metadata = M>,
{
2018-02-07 16:13:54 +01:00
let extractor = http_common::MetaExtractor::new(extractor);
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
.keep_alive(keep_alive)
.threads(threads)
.cors(cors_domains)
.allowed_hosts(allowed_hosts)
.health_api(("/api/health", "parity_nodeStatus"))
.cors_allow_headers(AccessControlAllowHeaders::Any)
.max_request_body_size(max_payload * 1024 * 1024)
.start_http(addr)?)
}
/// Same as `start_http`, but takes an additional `middleware` parameter that is introduced as a
/// hyper middleware.
pub fn start_http_with_middleware<M, S, H, T, R>(
addr: &SocketAddr,
cors_domains: http::DomainsValidation<http::AccessControlAllowOrigin>,
allowed_hosts: http::DomainsValidation<http::Host>,
handler: H,
extractor: T,
middleware: R,
threads: usize,
max_payload: usize,
keep_alive: bool,
) -> ::std::io::Result<HttpServer>
where
M: jsonrpc_core::Metadata,
S: jsonrpc_core::Middleware<M>,
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
T: HttpMetaExtractor<Metadata = M>,
R: RequestMiddleware,
{
let extractor = http_common::MetaExtractor::new(extractor);
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
.keep_alive(keep_alive)
.threads(threads)
.cors(cors_domains)
.allowed_hosts(allowed_hosts)
.cors_allow_headers(AccessControlAllowHeaders::Any)
.max_request_body_size(max_payload * 1024 * 1024)
.request_middleware(middleware)
.start_http(addr)?)
}
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_ipc<M, S, H, T>(addr: &str, handler: H, extractor: T) -> ::std::io::Result<ipc::Server>
where
M: jsonrpc_core::Metadata,
S: jsonrpc_core::Middleware<M>,
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
T: IpcMetaExtractor<M>,
{
2018-02-07 16:13:54 +01:00
ipc::ServerBuilder::with_meta_extractor(handler, extractor).start(addr)
}
/// Start WS server and return `Server` handle.
pub fn start_ws<M, S, H, T, U, V>(
addr: &SocketAddr,
handler: H,
allowed_origins: ws::DomainsValidation<ws::Origin>,
allowed_hosts: ws::DomainsValidation<ws::Host>,
max_connections: usize,
extractor: T,
middleware: V,
stats: U,
2020-12-09 11:48:27 +01:00
max_payload: usize,
) -> Result<ws::Server, ws::Error>
where
M: jsonrpc_core::Metadata,
S: jsonrpc_core::Middleware<M>,
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
T: ws::MetaExtractor<M>,
U: ws::SessionStats,
V: ws::RequestMiddleware,
{
2018-02-07 16:13:54 +01:00
ws::ServerBuilder::with_meta_extractor(handler, extractor)
.request_middleware(middleware)
.allowed_origins(allowed_origins)
.allowed_hosts(allowed_hosts)
.max_connections(max_connections)
2020-12-09 11:48:27 +01:00
.max_payload(max_payload * 1024 * 1024)
.session_stats(stats)
.start(addr)
}