From 60bb2d9c74c7762e277a1c508408920714f6020c Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Thu, 2 Nov 2017 12:50:08 +0100 Subject: [PATCH] Set zero nonce and gasprice for calls by default (#6954) --- parity/rpc_apis.rs | 2 +- rpc/src/v1/helpers/fake_sign.rs | 15 +++------------ rpc/src/v1/impls/eth.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 2 +- rpc/src/v1/impls/traces.rs | 15 ++++++--------- rpc/src/v1/tests/mocked/traces.rs | 2 +- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index dbd037bb8..be9dbdeb1 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -348,7 +348,7 @@ impl FullDependencies { ).to_delegate()) }, Api::Traces => { - handler.extend_with(TracesClient::new(&self.client, &self.miner).to_delegate()) + handler.extend_with(TracesClient::new(&self.client).to_delegate()) }, Api::Rpc => { let modules = to_modules(&apis); diff --git a/rpc/src/v1/helpers/fake_sign.rs b/rpc/src/v1/helpers/fake_sign.rs index 02259a9db..1f3a09474 100644 --- a/rpc/src/v1/helpers/fake_sign.rs +++ b/rpc/src/v1/helpers/fake_sign.rs @@ -14,22 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::sync::Arc; -use ethcore::client::MiningBlockChainClient; -use ethcore::miner::MinerService; use ethcore::transaction::{Transaction, SignedTransaction, Action}; use bigint::prelude::U256; use jsonrpc_core::Error; use v1::helpers::CallRequest; -use v1::helpers::dispatch::default_gas_price; -pub fn sign_call ( - client: &Arc, - miner: &Arc, - request: CallRequest, - gas_cap: bool, -) -> Result { +pub fn sign_call(request: CallRequest, gas_cap: bool) -> Result { let max_gas = 50_000_000.into(); let gas = match request.gas { Some(gas) if gas_cap && gas > max_gas => { @@ -43,10 +34,10 @@ pub fn sign_call ( let from = request.from.unwrap_or(0.into()); Ok(Transaction { - nonce: request.nonce.unwrap_or_else(|| client.latest_nonce(&from)), + nonce: request.nonce.unwrap_or_else(|| 0.into()), action: request.to.map_or(Action::Create, Action::Call), gas, - gas_price: request.gas_price.unwrap_or_else(|| default_gas_price(&**client, &**miner)), + gas_price: request.gas_price.unwrap_or_else(|| 0.into()), value: request.value.unwrap_or(0.into()), data: request.data.unwrap_or_default(), }.fake_sign(from)) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 48ac617c0..8de7a31db 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -625,7 +625,7 @@ impl Eth for EthClient where fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing) -> BoxFuture { let request = CallRequest::into(request); - let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())); + let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp())); let num = num.unwrap_or_default(); let result = self.client.call(&signed, Default::default(), num.into()); @@ -638,7 +638,7 @@ impl Eth for EthClient where fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing) -> BoxFuture { let request = CallRequest::into(request); - let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())); + let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp())); Box::new(future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into()) .map(Into::into) .map_err(errors::call) diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index a08d60efd..c586ea985 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -418,7 +418,7 @@ impl Parity for ParityClient where let requests = requests .into_iter() .map(|request| Ok(( - fake_sign::sign_call(&self.client, &self.miner, request.into(), meta.is_dapp())?, + fake_sign::sign_call(request.into(), meta.is_dapp())?, Default::default() ))) .collect::, Error>>()?; diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index f9797c1dc..8fca11efe 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -19,7 +19,6 @@ use std::sync::Arc; use ethcore::client::{MiningBlockChainClient, CallAnalytics, TransactionId, TraceId}; -use ethcore::miner::MinerService; use ethcore::transaction::SignedTransaction; use rlp::UntrustedRlp; @@ -39,22 +38,20 @@ fn to_call_analytics(flags: TraceOptions) -> CallAnalytics { } /// Traces api implementation. -pub struct TracesClient { +pub struct TracesClient { client: Arc, - miner: Arc, } -impl TracesClient { +impl TracesClient { /// Creates new Traces client. - pub fn new(client: &Arc, miner: &Arc) -> Self { + pub fn new(client: &Arc) -> Self { TracesClient { client: client.clone(), - miner: miner.clone(), } } } -impl Traces for TracesClient where C: MiningBlockChainClient + 'static, M: MinerService + 'static { +impl Traces for TracesClient where C: MiningBlockChainClient + 'static { type Metadata = Metadata; fn filter(&self, filter: TraceFilter) -> Result>, Error> { @@ -86,7 +83,7 @@ impl Traces for TracesClient where C: MiningBlockChainClient + 'stat let block = block.unwrap_or_default(); let request = CallRequest::into(request); - let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?; + let signed = fake_sign::sign_call(request, meta.is_dapp())?; self.client.call(&signed, to_call_analytics(flags), block.into()) .map(TraceResults::from) @@ -99,7 +96,7 @@ impl Traces for TracesClient where C: MiningBlockChainClient + 'stat let requests = requests.into_iter() .map(|(request, flags)| { let request = CallRequest::into(request); - let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?; + let signed = fake_sign::sign_call(request, meta.is_dapp())?; Ok((signed, to_call_analytics(flags))) }) .collect::, Error>>()?; diff --git a/rpc/src/v1/tests/mocked/traces.rs b/rpc/src/v1/tests/mocked/traces.rs index 71b0ea3bb..491e9dadb 100644 --- a/rpc/src/v1/tests/mocked/traces.rs +++ b/rpc/src/v1/tests/mocked/traces.rs @@ -66,7 +66,7 @@ fn io() -> Tester { state_diff: None, })); let miner = Arc::new(TestMinerService::default()); - let traces = TracesClient::new(&client, &miner); + let traces = TracesClient::new(&client); let mut io = IoHandler::default(); io.extend_with(traces.to_delegate());