light: fix compile errors

This commit is contained in:
Robert Habermeier 2016-12-05 17:09:05 +01:00
parent a6c2408562
commit 5db93cd433
6 changed files with 31 additions and 55 deletions

View File

@ -16,5 +16,6 @@ ethcore = { path = ".." }
ethcore-util = { path = "../../util" } ethcore-util = { path = "../../util" }
ethcore-network = { path = "../../util/network" } ethcore-network = { path = "../../util/network" }
ethcore-io = { path = "../../util/io" } ethcore-io = { path = "../../util/io" }
ethcore-ipc = { path = "../../ipc/rpc" }
rlp = { path = "../../util/rlp" } rlp = { path = "../../util/rlp" }
time = "0.1" time = "0.1"

View File

@ -19,21 +19,21 @@
use std::sync::Arc; use std::sync::Arc;
use engines::Engine; use ethcore::engines::Engine;
use ids::BlockID; use ethcore::ids::BlockID;
use service::ClientIoMessage; use ethcore::service::ClientIoMessage;
use block_import_error::BlockImportError; use ethcore::block_import_error::BlockImportError;
use block_status::BlockStatus; use ethcore::block_status::BlockStatus;
use verification::queue::{HeaderQueue, QueueInfo}; use ethcore::verification::queue::{HeaderQueue, QueueInfo};
use transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
use blockchain_info::BlockChainInfo; use ethcore::blockchain_info::BlockChainInfo;
use io::IoChannel; use io::IoChannel;
use util::hash::H256; use util::hash::H256;
use util::{Bytes, Mutex}; use util::{Bytes, Mutex};
use light::provider::Provider; use provider::Provider;
use light::request; use request;
/// Light client implementation. /// Light client implementation.
pub struct Client { pub struct Client {

View File

@ -47,5 +47,6 @@ extern crate ethcore;
extern crate ethcore_util as util; extern crate ethcore_util as util;
extern crate ethcore_network as network; extern crate ethcore_network as network;
extern crate ethcore_io as io; extern crate ethcore_io as io;
extern crate ethcore_ipc as ipc;
extern crate rlp; extern crate rlp;
extern crate time; extern crate time;

View File

@ -23,7 +23,7 @@
//! This module provides an interface for configuration of buffer //! This module provides an interface for configuration of buffer
//! flow costs and recharge rates. //! flow costs and recharge rates.
use light::request; use request;
use super::packet; use super::packet;
use super::error::Error; use super::error::Error;

View File

@ -19,6 +19,7 @@
//! This uses a "Provider" to answer requests. //! This uses a "Provider" to answer requests.
//! See https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES) //! See https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES)
use ethcore::transaction::SignedTransaction;
use io::TimerToken; use io::TimerToken;
use network::{NetworkProtocolHandler, NetworkContext, NetworkError, PeerId}; use network::{NetworkProtocolHandler, NetworkContext, NetworkError, PeerId};
use rlp::{RlpStream, Stream, UntrustedRlp, View}; use rlp::{RlpStream, Stream, UntrustedRlp, View};
@ -29,9 +30,8 @@ use time::SteadyTime;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use light::provider::Provider; use provider::Provider;
use light::request::{self, Request}; use request::{self, Request};
use transaction::SignedTransaction;
use self::buffer_flow::{Buffer, FlowParams}; use self::buffer_flow::{Buffer, FlowParams};
use self::error::{Error, Punishment}; use self::error::{Error, Punishment};

View File

@ -20,10 +20,11 @@
use ethcore::blockchain_info::BlockChainInfo; use ethcore::blockchain_info::BlockChainInfo;
use ethcore::client::{BlockChainClient, ProvingBlockChainClient}; use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
use ethcore::transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
use ethcore::ids::BlockID;
use util::{Bytes, H256}; use util::{Bytes, H256};
use light::request; use request;
/// Defines the operations that a provider for `LES` must fulfill. /// 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. // Implementation of a light client data provider for a client.
impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T { impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
fn chain_info(&self) -> BlockChainInfo { fn chain_info(&self) -> BlockChainInfo {
BlockChainClient::chain_info(self) BlockChainClient::chain_info(self)
} }
@ -92,7 +93,7 @@ impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
} }
fn block_headers(&self, req: request::Headers) -> Vec<Bytes> { fn block_headers(&self, req: request::Headers) -> Vec<Bytes> {
let best_num = self.chain.read().best_block_number(); let best_num = self.chain_info().best_block_number;
let start_num = req.block_num; let start_num = req.block_num;
match self.block_hash(BlockID::Number(req.block_num)) { match self.block_hash(BlockID::Number(req.block_num)) {
@ -114,8 +115,6 @@ impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
} }
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> { fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
use ids::BlockID;
req.block_hashes.into_iter() req.block_hashes.into_iter()
.map(|hash| self.block_body(BlockID::Hash(hash))) .map(|hash| self.block_body(BlockID::Hash(hash)))
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec())) .map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
@ -130,38 +129,22 @@ impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
} }
fn proofs(&self, req: request::StateProofs) -> Vec<Bytes> { fn proofs(&self, req: request::StateProofs) -> Vec<Bytes> {
use rlp::{EMPTY_LIST_RLP, RlpStream, Stream}; use rlp::{RlpStream, Stream};
let mut results = Vec::with_capacity(req.requests.len()); let mut results = Vec::with_capacity(req.requests.len());
for request in req.requests { for request in req.requests {
let state = match self.state_at(BlockID::Hash(request.block)) { let proof = match request.key2 {
Some(state) => state, Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockID::Hash(request.block)),
None => { None => self.prove_account(request.key1, request.from_level, BlockID::Hash(request.block)),
trace!(target: "light_provider", "state for {} not available", request.block);
results.push(EMPTY_LIST_RLP.to_vec());
continue;
}
}; };
let res = match request.key2 { let mut stream = RlpStream::new_list(proof.len());
Some(storage_key) => state.prove_storage(request.key1, storage_key, request.from_level), for node in proof {
None => state.prove_account(request.key1, request.from_level), stream.append_raw(&node, 1);
};
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());
}
} }
results.push(stream.out());
} }
results results
@ -170,16 +153,7 @@ impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> { fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> {
req.code_requests.into_iter() req.code_requests.into_iter()
.map(|req| { .map(|req| {
self.state_at(BlockID::Hash(req.block_hash)) self.code_by_hash(req.account_key, 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)
}) })
.collect() .collect()
} }