From c3f33aefddadcbe89888805105f837cb73590ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 4 May 2016 14:03:29 +0200 Subject: [PATCH 1/5] Fixing RPC modules compatibility --- Cargo.lock | 1 + parity/rpc.rs | 2 +- rpc/src/v1/impls/rpc.rs | 28 +++++++++++++++++++++++----- rpc/src/v1/tests/mod.rs | 2 ++ rpc/src/v1/tests/rpc.rs | 18 ++++++++++++++++-- rpc/src/v1/traits/rpc.rs | 7 +++++-- 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9c963809..fd99ff8f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,6 +348,7 @@ dependencies = [ "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.4.3 (git+https://github.com/arkpar/rust-rocksdb.git)", "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/parity/rpc.rs b/parity/rpc.rs index ff853d478..77b3b7f88 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -112,7 +112,7 @@ pub fn setup_rpc_server( server.add_delegate(PersonalClient::new(&deps.secret_store).to_delegate()) }, "ethcore" => { - // not adding to modules, since `ethcore` is not supported in geth + modules.insert("ethcore".to_owned(), "1.0".to_owned()); server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate()) }, "traces" => { diff --git a/rpc/src/v1/impls/rpc.rs b/rpc/src/v1/impls/rpc.rs index 215834f17..ebbef5025 100644 --- a/rpc/src/v1/impls/rpc.rs +++ b/rpc/src/v1/impls/rpc.rs @@ -22,23 +22,41 @@ use v1::traits::Rpc; /// RPC generic methods implementation. pub struct RpcClient { modules: BTreeMap, + valid_apis: Vec, } impl RpcClient { /// Creates new `RpcClient`. pub fn new(modules: BTreeMap) -> Self { + // geth 1.3.6 fails upon receiving unknown api + let valid_apis = vec!["web3", "eth", "net", "personal", "rpc"]; + RpcClient { - modules: modules + modules: modules, + valid_apis: valid_apis.into_iter().map(|x| x.to_owned()).collect(), } } } impl Rpc for RpcClient { + fn rpc_modules(&self, _: Params) -> Result { + let modules = self.modules.iter() + .fold(BTreeMap::new(), |mut map, (k, v)| { + map.insert(k.to_owned(), Value::String(v.to_owned())); + map + }); + Ok(Value::Object(modules)) + } + fn modules(&self, _: Params) -> Result { - let modules = self.modules.iter().fold(BTreeMap::new(), |mut map, (k, v)| { - map.insert(k.to_owned(), Value::String(v.to_owned())); - map - }); + let modules = self.modules.iter() + .filter(|&(k, _v)| { + self.valid_apis.contains(k) + }) + .fold(BTreeMap::new(), |mut map, (k, v)| { + map.insert(k.to_owned(), Value::String(v.to_owned())); + map + }); Ok(Value::Object(modules)) } } diff --git a/rpc/src/v1/tests/mod.rs b/rpc/src/v1/tests/mod.rs index e09b09db1..04e0dc142 100644 --- a/rpc/src/v1/tests/mod.rs +++ b/rpc/src/v1/tests/mod.rs @@ -27,3 +27,5 @@ mod web3; mod personal; #[cfg(test)] mod ethcore; +#[cfg(test)] +mod rpc; diff --git a/rpc/src/v1/tests/rpc.rs b/rpc/src/v1/tests/rpc.rs index b2c58dda6..4415f39e5 100644 --- a/rpc/src/v1/tests/rpc.rs +++ b/rpc/src/v1/tests/rpc.rs @@ -22,17 +22,31 @@ use v1::{Rpc, RpcClient}; fn rpc_client() -> RpcClient { let mut modules = BTreeMap::new(); modules.insert("rpc".to_owned(), "1.0".to_owned()); + modules.insert("web3".to_owned(), "1.0".to_owned()); + modules.insert("ethcore".to_owned(), "1.0".to_owned()); RpcClient::new(modules) } +#[test] +fn modules() { + let rpc = rpc_client().to_delegate(); + let io = IoHandler::new(); + io.add_delegate(rpc); + + let request = r#"{"jsonrpc": "2.0", "method": "modules", "params": [], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"rpc":"1.0","web3":"1.0"},"id":1}"#; + + assert_eq!(io.handle_request(request), Some(response.to_owned())); +} + #[test] fn rpc_modules() { let rpc = rpc_client().to_delegate(); let io = IoHandler::new(); io.add_delegate(rpc); - let request = r#"{"jsonrpc": "2.0", "method": "modules", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":{"eth": "1.0"},"id":1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "rpc_modules", "params": [], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"ethcore":"1.0","rpc":"1.0","web3":"1.0"},"id":1}"#; assert_eq!(io.handle_request(request), Some(response.to_owned())); } diff --git a/rpc/src/v1/traits/rpc.rs b/rpc/src/v1/traits/rpc.rs index 9d19efcd7..5c981c8a1 100644 --- a/rpc/src/v1/traits/rpc.rs +++ b/rpc/src/v1/traits/rpc.rs @@ -22,16 +22,19 @@ use jsonrpc_core::*; /// RPC Interface. pub trait Rpc: Sized + Send + Sync + 'static { - /// Returns supported modules. + /// Returns supported modules for Geth 1.3.6 fn modules(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Returns supported modules for Geth 1.4.0 + fn rpc_modules(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { let mut delegate = IoDelegate::new(Arc::new(self)); // Geth 1.3.6 compatibility delegate.add_method("modules", Rpc::modules); // Geth 1.4.0 compatibility - delegate.add_method("rpc_modules", Rpc::modules); + delegate.add_method("rpc_modules", Rpc::rpc_modules); delegate } } From 0a49efd0181778e799a449810dd20f9b0f21b0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 4 May 2016 15:10:04 +0200 Subject: [PATCH 2/5] Fixing hyper-mio revision --- Cargo.lock | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9c963809..70bc38f01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,6 +348,7 @@ dependencies = [ "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.4.3 (git+https://github.com/arkpar/rust-rocksdb.git)", "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", @@ -369,7 +370,7 @@ dependencies = [ "clippy 0.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-rpc 1.2.0", "ethcore-util 1.2.0", - "hyper 0.9.0-mio (git+https://github.com/hyperium/hyper?branch=mio)", + "hyper 0.9.1 (git+https://github.com/hyperium/hyper?branch=mio)", "jsonrpc-core 2.0.3 (git+https://github.com/tomusdrw/jsonrpc-core.git)", "jsonrpc-http-server 5.1.0 (git+https://github.com/tomusdrw/jsonrpc-http-server.git)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -504,8 +505,8 @@ dependencies = [ [[package]] name = "hyper" -version = "0.9.0-mio" -source = "git+https://github.com/hyperium/hyper?branch=mio#fab6c4173063a10f2aacfe3872150537da3dcfdd" +version = "0.9.1" +source = "git+https://github.com/hyperium/hyper?branch=mio#8d121824231651cf22e7ad929e404032b28406df" dependencies = [ "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -586,7 +587,7 @@ name = "jsonrpc-http-server" version = "5.1.0" source = "git+https://github.com/tomusdrw/jsonrpc-http-server.git#fafd6410284710b7e662fe7d76249cc496451f27" dependencies = [ - "hyper 0.9.0-mio (git+https://github.com/hyperium/hyper?branch=mio)", + "hyper 0.9.1 (git+https://github.com/hyperium/hyper?branch=mio)", "jsonrpc-core 2.0.3 (git+https://github.com/tomusdrw/jsonrpc-core.git)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] From 15a8860e8a0a6c993a3c2a4324c9542869a2bfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 4 May 2016 15:22:22 +0200 Subject: [PATCH 3/5] Fixing clippy warnings --- Cargo.lock | 1 + ethcore/src/basic_authority.rs | 6 +++--- ethcore/src/client/client.rs | 2 +- miner/src/miner.rs | 8 ++++---- parity/main.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9c963809..fd99ff8f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,6 +348,7 @@ dependencies = [ "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.4.3 (git+https://github.com/arkpar/rust-rocksdb.git)", "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ethcore/src/basic_authority.rs b/ethcore/src/basic_authority.rs index af0bcb207..e1dab7c17 100644 --- a/ethcore/src/basic_authority.rs +++ b/ethcore/src/basic_authority.rs @@ -24,7 +24,7 @@ use engine::*; use evm::{Schedule, Factory}; use ethjson; -/// BasicAuthority params. +/// `BasicAuthority` params. #[derive(Debug, PartialEq)] pub struct BasicAuthorityParams { /// Gas limit divisor. @@ -45,7 +45,7 @@ impl From for BasicAuthorityParams { } } -/// Engine using BasicAuthority proof-of-work consensus algorithm, suitable for Ethereum +/// Engine using `BasicAuthority` proof-of-work consensus algorithm, suitable for Ethereum /// mainnet chains in the Olympic, Frontier and Homestead eras. pub struct BasicAuthority { params: CommonParams, @@ -192,7 +192,7 @@ impl Header { } } -/// Create a new test chain spec with BasicAuthority consensus engine. +/// Create a new test chain spec with `BasicAuthority` consensus engine. pub fn new_test_authority() -> Spec { Spec::load(include_bytes!("../res/test_authority.json")) } #[cfg(test)] diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index ed5460ffd..23b81b34e 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -42,7 +42,7 @@ use env_info::EnvInfo; use executive::{Executive, Executed, TransactOptions, contract_address}; use receipt::LocalizedReceipt; pub use blockchain::CacheSize as BlockChainCacheSize; -use trace::{TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase, Filter as TracedbFilter}; +use trace::{TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase}; use trace; /// General block status diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 66545c8e1..78ff824f6 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -166,9 +166,9 @@ impl Miner { trace!(target: "miner", "prepare_sealing: block has transaction - attempting internal seal."); // block with transactions - see if we can seal immediately. let a = self.accounts.read().unwrap(); - let s = chain.generate_seal(block.block(), match a.deref() { - &Some(ref x) => Some(x.deref() as &AccountProvider), - &None => None, + let s = chain.generate_seal(block.block(), match *a.deref() { + Some(ref x) => Some(x.deref() as &AccountProvider), + None => None, }); if let Some(seal) = s { trace!(target: "miner", "prepare_sealing: managed internal seal. importing..."); @@ -183,7 +183,7 @@ impl Miner { } return; } else { - trace!(target: "miner", "prepare_sealing: unable to generate seal internally"); + trace!(target: "miner", "prepare_sealing: unable to generate seal internally"); } } if sealing_work.peek_last_ref().map_or(true, |pb| pb.block().fields().header.hash() != block.block().fields().header.hash()) { diff --git a/parity/main.rs b/parity/main.rs index 4fa18bd4d..0228527dd 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -208,7 +208,7 @@ fn execute_client(conf: Configuration) { } fn flush_stdout() { - ::std::io::stdout().flush().ok().expect("stdout is flushable; qed"); + ::std::io::stdout().flush().expect("stdout is flushable; qed"); } fn execute_account_cli(conf: Configuration) { From 0d507922cecdc383c8d39972e642086e074067b7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 4 May 2016 22:44:42 +0200 Subject: [PATCH 4/5] Tidy up CLI options and make JSONRPC & webapps on by default. (#1045) * Tidy up CLI options and make JSONRPC & webapps on by default. * Fix test. --- parity/cli.rs | 48 +++++++++++++++++++++++++---------------- parity/configuration.rs | 11 +++++----- parity/main.rs | 5 +++-- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/parity/cli.rs b/parity/cli.rs index 106d65aa3..e5a5a0983 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -59,7 +59,7 @@ Networking Options: string or input to SHA3 operation. API and Console Options: - -j --jsonrpc Enable the JSON-RPC API server. + --jsonrpc-off Disable the JSON-RPC API server. --jsonrpc-port PORT Specify the port portion of the JSONRPC API server [default: 8545]. --jsonrpc-interface IP Specify the hostname portion of the JSONRPC API @@ -68,10 +68,18 @@ API and Console Options: --jsonrpc-cors URL Specify CORS header for JSON-RPC API responses. --jsonrpc-apis APIS Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API - name. Possible name are web3, eth and net. + name. Possible name are web3, eth, net, personal, + ethcore, traces. [default: web3,eth,net,personal,ethcore,traces]. - -w --webapp Enable the web applications server (e.g. - status page). + + --ipc-off Disable JSON-RPC over IPC service. + --ipc-path PATH Specify custom path for JSON-RPC over IPC service + [default: $HOME/.parity/jsonrpc.ipc]. + --ipc-apis APIS Specify custom API set available via JSON-RPC over + IPC [default: web3,eth,net,personal,ethcore]. + + --webapp-off Disable the web applications server (e.g. status + page). --webapp-port PORT Specify the port portion of the WebApps server [default: 8080]. --webapp-interface IP Specify the hostname portion of the WebApps @@ -84,12 +92,6 @@ API and Console Options: --webapp-pass PASSWORD Specify password for WebApps server. Use only in conjunction with --webapp-user. - --ipc-disable Disable JSON-RPC over IPC service - --ipc-path PATH Specify custom path for IPC service - [default: $HOME/.parity/jsonrpc.ipc] - --ipc-api APIS Specify custom API set available via IPC service - [default: web3,eth,net,personal,ethcore] - Sealing/Mining Options: --force-sealing Force the node to author new blocks as if it were always sealing/mining. @@ -133,18 +135,23 @@ Footprint Options: the entire system, overrides other cache and queue options. -Geth-compatibility Options: +Legacy Options: --datadir PATH Equivalent to --db-path PATH. --testnet Equivalent to --chain testnet. --networkid INDEX Equivalent to --network-id INDEX. --maxpeers COUNT Equivalent to --peers COUNT. --nodekey KEY Equivalent to --node-key KEY. --nodiscover Equivalent to --no-discovery. - --rpc Equivalent to --jsonrpc. + -j --jsonrpc Does nothing; JSON-RPC is on by default now. + -w --webapp Does nothing; web app server is on by default now. + --rpc Does nothing; JSON-RPC is on by default now. --rpcaddr IP Equivalent to --jsonrpc-interface IP. --rpcport PORT Equivalent to --jsonrpc-port PORT. --rpcapi APIS Equivalent to --jsonrpc-apis APIS. --rpccorsdomain URL Equivalent to --jsonrpc-cors URL. + --ipcdisable Equivalent to --ipc-off. + --ipcapi APIS Equivalent to --ipc-apis APIS. + --ipcpath PATH Equivalent to --ipc-path PATH. --gasprice WEI Minimum amount of Wei per GAS to be paid for a transaction to be accepted for mining. Overrides --basic-tx-usd. @@ -184,12 +191,15 @@ pub struct Args { pub flag_cache_pref_size: usize, pub flag_cache_max_size: usize, pub flag_queue_max_size: usize, - pub flag_jsonrpc: bool, + pub flag_jsonrpc_off: bool, pub flag_jsonrpc_interface: String, pub flag_jsonrpc_port: u16, pub flag_jsonrpc_cors: Option, pub flag_jsonrpc_apis: String, - pub flag_webapp: bool, + pub flag_ipc_off: bool, + pub flag_ipc_path: String, + pub flag_ipc_apis: String, + pub flag_webapp_off: bool, pub flag_webapp_port: u16, pub flag_webapp_interface: String, pub flag_webapp_user: Option, @@ -203,10 +213,7 @@ pub struct Args { pub flag_tx_limit: usize, pub flag_logging: Option, pub flag_version: bool, - pub flag_ipc_disable: bool, - pub flag_ipc_path: String, - pub flag_ipc_api: String, - // geth-compatibility... + // legacy... pub flag_nodekey: Option, pub flag_nodiscover: bool, pub flag_maxpeers: Option, @@ -214,6 +221,8 @@ pub struct Args { pub flag_extradata: Option, pub flag_etherbase: Option, pub flag_gasprice: Option, + pub flag_jsonrpc: bool, + pub flag_webapp: bool, pub flag_rpc: bool, pub flag_rpcaddr: Option, pub flag_rpcport: Option, @@ -221,6 +230,9 @@ pub struct Args { pub flag_rpcapi: Option, pub flag_testnet: bool, pub flag_networkid: Option, + pub flag_ipcdisable: bool, + pub flag_ipcpath: Option, + pub flag_ipcapi: Option, } pub fn print_version() { diff --git a/parity/configuration.rs b/parity/configuration.rs index 0b32d5232..83eadbc2e 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -269,20 +269,21 @@ impl Configuration { pub fn ipc_settings(&self) -> IpcConfiguration { IpcConfiguration { - enabled: !self.args.flag_ipc_disable, - socket_addr: self.args.flag_ipc_path.clone() + enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off), + socket_addr: self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone()) .replace("$HOME", env::home_dir().unwrap().to_str().unwrap()), - apis: self.args.flag_ipc_api.clone(), + apis: self.args.flag_ipcapi.clone().unwrap_or(self.args.flag_ipc_apis.clone()), } } pub fn network_settings(&self) -> NetworkSettings { + if self.args.flag_jsonrpc { println!("WARNING: Flag -j/--json-rpc is deprecated. JSON-RPC is now on by default. Ignoring."); } NetworkSettings { name: self.args.flag_identity.clone(), chain: self.chain(), max_peers: self.max_peers(), network_port: self.net_port(), - rpc_enabled: self.args.flag_rpc || self.args.flag_jsonrpc, + rpc_enabled: !self.args.flag_jsonrpc_off, rpc_interface: self.args.flag_rpcaddr.clone().unwrap_or(self.args.flag_jsonrpc_interface.clone()), rpc_port: self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port), } @@ -315,7 +316,7 @@ mod tests { chain: "morden".to_owned(), max_peers: 25, network_port: 30303, - rpc_enabled: false, + rpc_enabled: true, rpc_interface: "local".to_owned(), rpc_port: 8545, }); diff --git a/parity/main.rs b/parity/main.rs index 9da523fd2..c143f0b05 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -181,10 +181,11 @@ fn execute_client(conf: Configuration) { }, &dependencies); // setup ipc rpc - let ipc_server = rpc::new_ipc(conf.ipc_settings(), &dependencies); + let _ipc_server = rpc::new_ipc(conf.ipc_settings(), &dependencies); + if conf.args.flag_webapp { println!("WARNING: Flag -w/--webapp is deprecated. Web app server is now on by default. Ignoring."); } let webapp_server = webapp::new(webapp::Configuration { - enabled: conf.args.flag_webapp, + enabled: !conf.args.flag_webapp_off, interface: conf.args.flag_webapp_interface.clone(), port: conf.args.flag_webapp_port, user: conf.args.flag_webapp_user.clone(), From b99825bcacb8dfc2368c39f4fed0e438d00407a9 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Wed, 4 May 2016 23:45:17 +0300 Subject: [PATCH 5/5] bump lib version (#1046) --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ee5dc82ef..98fa9797a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -557,7 +557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "json-ipc-server" version = "0.1.0" -source = "git+https://github.com/NikVolf/json-ipc-server.git#bd987c75b5f23c35eb7e2b0bd8b30ba88f758338" +source = "git+https://github.com/NikVolf/json-ipc-server.git#6515f27c7b41e5e62bc87ef4e0947b838a6c7d01" dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.3 (git+https://github.com/tomusdrw/jsonrpc-core.git)",