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-network = { path = "../../util/network" }
ethcore-io = { path = "../../util/io" }
ethcore-ipc = { path = "../../ipc/rpc" }
rlp = { path = "../../util/rlp" }
time = "0.1"

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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};

View File

@ -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<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
fn chain_info(&self) -> BlockChainInfo {
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> {
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<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
}
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
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<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
}
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());
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),
};
let mut stream = RlpStream::new_list(proof.len());
for node in proof {
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
@ -170,16 +153,7 @@ impl<T: ProvingBlockChainClient + ?Sized> light::Provider for T {
fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> {
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()
}