From 5db93cd4337f47527bb6d0bbd8df1bd167dee22f Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 5 Dec 2016 17:09:05 +0100 Subject: [PATCH] light: fix compile errors --- ethcore/light/Cargo.toml | 3 +- ethcore/light/src/client.rs | 20 +++++------ ethcore/light/src/lib.rs | 1 + ethcore/light/src/net/buffer_flow.rs | 2 +- ethcore/light/src/net/mod.rs | 6 ++-- ethcore/light/src/provider.rs | 54 ++++++++-------------------- 6 files changed, 31 insertions(+), 55 deletions(-) diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 3aca67c64..74400d7ab 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -16,5 +16,6 @@ ethcore = { path = ".." } ethcore-util = { path = "../../util" } ethcore-network = { path = "../../util/network" } ethcore-io = { path = "../../util/io" } +ethcore-ipc = { path = "../../ipc/rpc" } rlp = { path = "../../util/rlp" } -time = "0.1" \ No newline at end of file +time = "0.1" \ No newline at end of file diff --git a/ethcore/light/src/client.rs b/ethcore/light/src/client.rs index 699db743a..8a5c43c48 100644 --- a/ethcore/light/src/client.rs +++ b/ethcore/light/src/client.rs @@ -19,21 +19,21 @@ use std::sync::Arc; -use engines::Engine; -use ids::BlockID; -use service::ClientIoMessage; -use block_import_error::BlockImportError; -use block_status::BlockStatus; -use verification::queue::{HeaderQueue, QueueInfo}; -use transaction::SignedTransaction; -use blockchain_info::BlockChainInfo; +use ethcore::engines::Engine; +use ethcore::ids::BlockID; +use ethcore::service::ClientIoMessage; +use ethcore::block_import_error::BlockImportError; +use ethcore::block_status::BlockStatus; +use ethcore::verification::queue::{HeaderQueue, QueueInfo}; +use ethcore::transaction::SignedTransaction; +use ethcore::blockchain_info::BlockChainInfo; use io::IoChannel; use util::hash::H256; use util::{Bytes, Mutex}; -use light::provider::Provider; -use light::request; +use provider::Provider; +use request; /// Light client implementation. pub struct Client { diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index e698905e8..e150f4ee5 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -47,5 +47,6 @@ extern crate ethcore; extern crate ethcore_util as util; extern crate ethcore_network as network; extern crate ethcore_io as io; +extern crate ethcore_ipc as ipc; extern crate rlp; extern crate time; \ No newline at end of file diff --git a/ethcore/light/src/net/buffer_flow.rs b/ethcore/light/src/net/buffer_flow.rs index 7f653f826..6730c71a7 100644 --- a/ethcore/light/src/net/buffer_flow.rs +++ b/ethcore/light/src/net/buffer_flow.rs @@ -23,7 +23,7 @@ //! This module provides an interface for configuration of buffer //! flow costs and recharge rates. -use light::request; +use request; use super::packet; use super::error::Error; diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index 2d38d4fd5..a1b3b30b0 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -19,6 +19,7 @@ //! This uses a "Provider" to answer requests. //! See https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES) +use ethcore::transaction::SignedTransaction; use io::TimerToken; use network::{NetworkProtocolHandler, NetworkContext, NetworkError, PeerId}; use rlp::{RlpStream, Stream, UntrustedRlp, View}; @@ -29,9 +30,8 @@ use time::SteadyTime; use std::collections::{HashMap, HashSet}; use std::sync::atomic::{AtomicUsize, Ordering}; -use light::provider::Provider; -use light::request::{self, Request}; -use transaction::SignedTransaction; +use provider::Provider; +use request::{self, Request}; use self::buffer_flow::{Buffer, FlowParams}; use self::error::{Error, Punishment}; diff --git a/ethcore/light/src/provider.rs b/ethcore/light/src/provider.rs index 64357e540..264df0397 100644 --- a/ethcore/light/src/provider.rs +++ b/ethcore/light/src/provider.rs @@ -20,10 +20,11 @@ use ethcore::blockchain_info::BlockChainInfo; use ethcore::client::{BlockChainClient, ProvingBlockChainClient}; use ethcore::transaction::SignedTransaction; +use ethcore::ids::BlockID; use util::{Bytes, H256}; -use light::request; +use request; /// Defines the operations that a provider for `LES` must fulfill. /// @@ -78,7 +79,7 @@ pub trait Provider: Send + Sync { } // Implementation of a light client data provider for a client. -impl light::Provider for T { +impl Provider for T { fn chain_info(&self) -> BlockChainInfo { BlockChainClient::chain_info(self) } @@ -92,7 +93,7 @@ impl light::Provider for T { } fn block_headers(&self, req: request::Headers) -> Vec { - let best_num = self.chain.read().best_block_number(); + let best_num = self.chain_info().best_block_number; let start_num = req.block_num; match self.block_hash(BlockID::Number(req.block_num)) { @@ -114,8 +115,6 @@ impl light::Provider for T { } fn block_bodies(&self, req: request::Bodies) -> Vec { - use ids::BlockID; - req.block_hashes.into_iter() .map(|hash| self.block_body(BlockID::Hash(hash))) .map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec())) @@ -130,38 +129,22 @@ impl light::Provider for T { } fn proofs(&self, req: request::StateProofs) -> Vec { - use rlp::{EMPTY_LIST_RLP, RlpStream, Stream}; + use rlp::{RlpStream, Stream}; let mut results = Vec::with_capacity(req.requests.len()); for request in req.requests { - let state = match self.state_at(BlockID::Hash(request.block)) { - Some(state) => state, - None => { - trace!(target: "light_provider", "state for {} not available", request.block); - results.push(EMPTY_LIST_RLP.to_vec()); - continue; - } + let proof = match request.key2 { + Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockID::Hash(request.block)), + None => self.prove_account(request.key1, request.from_level, BlockID::Hash(request.block)), }; - let res = match request.key2 { - Some(storage_key) => state.prove_storage(request.key1, storage_key, request.from_level), - None => state.prove_account(request.key1, request.from_level), - }; - - match res { - Ok(records) => { - let mut stream = RlpStream::new_list(records.len()); - for record in records { - stream.append_raw(&record, 1); - } - results.push(stream.out()) - } - Err(e) => { - debug!(target: "light_provider", "encountered error {} while forming proof of state at {}", e, request.block); - results.push(EMPTY_LIST_RLP.to_vec()); - } + let mut stream = RlpStream::new_list(proof.len()); + for node in proof { + stream.append_raw(&node, 1); } + + results.push(stream.out()); } results @@ -170,16 +153,7 @@ impl light::Provider for T { fn contract_code(&self, req: request::ContractCodes) -> Vec { req.code_requests.into_iter() .map(|req| { - self.state_at(BlockID::Hash(req.block_hash)) - .map(|state| { - match state.code_by_address_hash(req.account_key) { - Ok(code) => code.unwrap_or_else(Vec::new), - Err(e) => { - debug!(target: "light_provider", "encountered error {} while fetching code.", e); - Vec::new() - } - } - }).unwrap_or_else(Vec::new) + self.code_by_hash(req.account_key, BlockID::Hash(req.block_hash)) }) .collect() }