From 325c6aaf6af793b2c34c4c1ce33ed5de54f4ae4e Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Feb 2017 19:58:29 +0100 Subject: [PATCH] verify raw transactions against Engine --- ethcore/light/src/client/mod.rs | 10 ++++++++++ rpc/src/v1/impls/light/eth.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index 29b812aa6..bb43a9f5b 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -16,9 +16,12 @@ //! Light client implementation. Stores data from light sync +use std::sync::Arc; + use ethcore::block_import_error::BlockImportError; use ethcore::block_status::BlockStatus; use ethcore::client::ClientReport; +use ethcore::engines::Engine; use ethcore::ids::BlockId; use ethcore::header::Header; use ethcore::verification::queue::{self, HeaderQueue}; @@ -91,6 +94,7 @@ impl AsLightClient for T { /// Light client implementation. pub struct Client { queue: HeaderQueue, + engine: Arc, chain: HeaderChain, report: RwLock, import_lock: Mutex<()>, @@ -101,6 +105,7 @@ impl Client { pub fn new(config: Config, spec: &Spec, io_channel: IoChannel) -> Self { Client { queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true), + engine: spec.engine.clone(), chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())), report: RwLock::new(ClientReport::default()), import_lock: Mutex::new(()), @@ -200,6 +205,11 @@ impl Client { self.chain.heap_size_of_children() } + + /// Get a handle to the verification engine. + pub fn engine(&self) -> &Engine { + &*self.engine + } } impl LightChainClient for Client { diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 614174b73..f72a9bb69 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -305,11 +305,18 @@ impl Eth for EthClient { } fn send_raw_transaction(&self, raw: Bytes) -> Result { + let best_header = self.client.block_header(BlockId::Latest) + .expect("best block header always stored; qed").decode(); + UntrustedRlp::new(&raw.into_vec()).as_val() .map_err(errors::from_rlp_error) - .and_then(|tx| SignedTransaction::new(tx).map_err(errors::from_transaction_error)) - .and_then(|signed| { + .and_then(|tx| { + self.client.engine().verify_transaction_basic(&tx, &best_header) + .map_err(errors::from_transaction_error)?; + + let signed = SignedTransaction::new(tx).map_err(errors::from_transaction_error)?; let hash = signed.hash(); + self.transaction_queue.write().import(signed.into()) .map(|_| hash) .map_err(Into::into)