verify raw transactions against Engine

This commit is contained in:
Robert Habermeier 2017-02-09 19:58:29 +01:00
parent a559dfe9a1
commit 325c6aaf6a
2 changed files with 19 additions and 2 deletions

View File

@ -16,9 +16,12 @@
//! Light client implementation. Stores data from light sync //! Light client implementation. Stores data from light sync
use std::sync::Arc;
use ethcore::block_import_error::BlockImportError; use ethcore::block_import_error::BlockImportError;
use ethcore::block_status::BlockStatus; use ethcore::block_status::BlockStatus;
use ethcore::client::ClientReport; use ethcore::client::ClientReport;
use ethcore::engines::Engine;
use ethcore::ids::BlockId; use ethcore::ids::BlockId;
use ethcore::header::Header; use ethcore::header::Header;
use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::verification::queue::{self, HeaderQueue};
@ -91,6 +94,7 @@ impl<T: LightChainClient> AsLightClient for T {
/// Light client implementation. /// Light client implementation.
pub struct Client { pub struct Client {
queue: HeaderQueue, queue: HeaderQueue,
engine: Arc<Engine>,
chain: HeaderChain, chain: HeaderChain,
report: RwLock<ClientReport>, report: RwLock<ClientReport>,
import_lock: Mutex<()>, import_lock: Mutex<()>,
@ -101,6 +105,7 @@ impl Client {
pub fn new(config: Config, spec: &Spec, io_channel: IoChannel<ClientIoMessage>) -> Self { pub fn new(config: Config, spec: &Spec, io_channel: IoChannel<ClientIoMessage>) -> Self {
Client { Client {
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true), queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true),
engine: spec.engine.clone(),
chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())), chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())),
report: RwLock::new(ClientReport::default()), report: RwLock::new(ClientReport::default()),
import_lock: Mutex::new(()), import_lock: Mutex::new(()),
@ -200,6 +205,11 @@ impl Client {
self.chain.heap_size_of_children() self.chain.heap_size_of_children()
} }
/// Get a handle to the verification engine.
pub fn engine(&self) -> &Engine {
&*self.engine
}
} }
impl LightChainClient for Client { impl LightChainClient for Client {

View File

@ -305,11 +305,18 @@ impl Eth for EthClient {
} }
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> { fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
let best_header = self.client.block_header(BlockId::Latest)
.expect("best block header always stored; qed").decode();
UntrustedRlp::new(&raw.into_vec()).as_val() UntrustedRlp::new(&raw.into_vec()).as_val()
.map_err(errors::from_rlp_error) .map_err(errors::from_rlp_error)
.and_then(|tx| SignedTransaction::new(tx).map_err(errors::from_transaction_error)) .and_then(|tx| {
.and_then(|signed| { 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(); let hash = signed.hash();
self.transaction_queue.write().import(signed.into()) self.transaction_queue.write().import(signed.into())
.map(|_| hash) .map(|_| hash)
.map_err(Into::into) .map_err(Into::into)