clean up errors

This commit is contained in:
Robert Habermeier 2016-11-10 14:05:47 +01:00
parent 11e6b08f02
commit 8c2c048444
13 changed files with 78 additions and 55 deletions

1
Cargo.lock generated
View File

@ -289,6 +289,7 @@ dependencies = [
"ethcore-ipc 1.4.0",
"ethcore-ipc-codegen 1.4.0",
"ethcore-ipc-nano 1.4.0",
"ethcore-network 1.5.0",
"ethcore-util 1.5.0",
"ethjson 0.1.0",
"ethkey 0.2.0",

View File

@ -41,6 +41,7 @@ ethcore-ipc-nano = { path = "../ipc/nano" }
rlp = { path = "../util/rlp" }
lru-cache = "0.1.0"
ethcore-bloom-journal = { path = "../util/bloom" }
ethcore-network = { path = "../util/network" }
[dependencies.hyper]
git = "https://github.com/ethcore/hyper"

View File

@ -1229,7 +1229,7 @@ impl BlockChainClient for Client {
fn pruning_info(&self) -> PruningInfo {
PruningInfo {
earliest_chain: self.chain.read().first_block().unwrap_or(1),
earliest_chain: self.chain.read().first_block_number().unwrap_or(1),
earliest_state: self.state_db.lock().journal_db().earliest_era().unwrap_or(0),
}
}

View File

@ -655,7 +655,7 @@ impl BlockChainClient for TestBlockChainClient {
fn pruning_info(&self) -> PruningInfo {
PruningInfo {
earliest_chain: 1,
earlest_state: 1,
earliest_state: 1,
}
}
}

View File

@ -102,6 +102,7 @@ extern crate rlp;
extern crate ethcore_bloom_journal as bloom_journal;
extern crate byteorder;
extern crate transient_hashmap;
extern crate ethcore_network as network;
#[macro_use]
extern crate log;
@ -138,6 +139,7 @@ pub mod snapshot;
pub mod action_params;
pub mod db;
pub mod verification;
pub mod light;
#[macro_use] pub mod evm;
mod cache_manager;

View File

@ -19,21 +19,21 @@
use std::sync::Arc;
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 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 io::IoChannel;
use util::hash::H256;
use util::{Bytes, Mutex};
use provider::Provider;
use request;
use light::provider::Provider;
use light::request;
/// Light client implementation.
pub struct Client {

View File

@ -34,7 +34,5 @@
pub mod client;
pub mod net;
pub mod provider;
pub mod request;
#[macro_use]
extern crate log;
pub use types::les_request as request;

View File

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

View File

@ -28,8 +28,8 @@ use util::RwLock;
use std::collections::{HashMap, HashSet};
use std::sync::atomic::AtomicUsize;
use provider::Provider;
use request::{self, Request};
use light::provider::Provider;
use light::request::{self, Request};
use self::buffer_flow::{Buffer, FlowParams};
use self::error::{Error, Punishment};
@ -287,11 +287,14 @@ impl LightProtocol {
self.flow_params.recharge(&mut present_buffer);
let req_id: u64 = try!(data.val_at(0));
let block = {
let rlp = try!(data.at(1));
(try!(rlp.val_at(0)), try!(rlp.val_at(1)))
};
let req = request::Headers {
block: {
let rlp = try!(data.at(1));
(try!(rlp.val_at(0)), try!(rlp.val_at(1)))
},
block_num: block.0,
block_hash: block.1,
max: ::std::cmp::min(MAX_HEADERS, try!(data.val_at(2))),
skip: try!(data.val_at(3)),
reverse: try!(data.val_at(4)),

View File

@ -17,14 +17,14 @@
//! A provider for the LES protocol. This is typically a full node, who can
//! give as much data as necessary to its peers.
use ethcore::client::BlockChainClient;
use ethcore::transaction::SignedTransaction;
use ethcore::blockchain_info::BlockChainInfo;
use client::BlockChainClient;
use transaction::SignedTransaction;
use blockchain_info::BlockChainInfo;
use rlp::EMPTY_LIST_RLP;
use util::{Bytes, H256};
use request;
use light::request;
/// Defines the operations that a provider for `LES` must fulfill.
///
@ -40,8 +40,8 @@ pub trait Provider: Send + Sync {
fn reorg_depth(&self, a: &H256, b: &H256) -> Option<u64>;
/// Earliest block where state queries are available.
/// All states between this value and
fn earliest_state(&self) -> u64;
/// If `None`, no state queries are servable.
fn earliest_state(&self) -> Option<u64>;
/// Provide a list of headers starting at the requested block,
/// possibly in reverse and skipping `skip` at a time.
@ -83,11 +83,11 @@ impl<T: BlockChainClient + ?Sized> Provider for T {
}
fn reorg_depth(&self, a: &H256, b: &H256) -> Option<u64> {
self.tree_route.map(|route| route.index as u64)
self.tree_route(a, b).map(|route| route.index as u64)
}
fn earliest_state(&self) -> u64 {
self.pruning_info().earliest_state
fn earliest_state(&self) -> Option<u64> {
Some(self.pruning_info().earliest_state)
}
fn block_headers(&self, req: request::Headers) -> Vec<Bytes> {
@ -95,16 +95,18 @@ impl<T: BlockChainClient + ?Sized> 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(hash.into()))
.map(|body| body.unwrap_or_else(|| EMPTY_LIST_RLP.into()))
.map(|hash| self.block_body(BlockID::Hash(hash)))
.map(|body| body.unwrap_or_else(|| EMPTY_LIST_RLP.to_vec()))
.collect()
}
fn receipts(&self, req: request::Receipts) -> Vec<Bytes> {
req.block_hashes.into_iter()
.map(|hash| self.block_receipts(&hash)
.map(|receipts| receips.unwrap_or_else(|| EMPTY_LIST_RLP.into()))
.map(|hash| self.block_receipts(&hash))
.map(|receipts| receipts.unwrap_or_else(|| EMPTY_LIST_RLP.to_vec()))
.collect()
}
@ -112,12 +114,16 @@ impl<T: BlockChainClient + ?Sized> Provider for T {
unimplemented!()
}
fn code(&self, req: request::ContractCodes) -> Vec<Bytes>;
fn code(&self, req: request::ContractCodes) -> Vec<Bytes> {
unimplemented!()
}
fn header_proofs(&self, req: request::HeaderProofs) -> Vec<Bytes> {
// TODO: [rob] implement CHT stuff on `ethcore` side.
req.requests.into_iter().map(|_| EMPTY_LIST_RLP.into()).collect()
req.requests.into_iter().map(|_| EMPTY_LIST_RLP.to_vec()).collect()
}
fn pending_transactions(&self) -> Vec<SignedTransaction>;
fn pending_transactions(&self) -> Vec<SignedTransaction> {
unimplemented!()
}
}

View File

@ -16,15 +16,16 @@
//! LES request types.
// TODO: make IPC compatible.
use util::H256;
/// A request for block headers.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct Headers {
/// Block information for the request being made.
pub block: (u64, H256),
/// Starting block number
pub block_num: u64,
/// Starting block hash. This and number could be combined but IPC codegen is
/// not robust enough to support it.
pub block_hash: H256,
/// The maximum amount of headers which can be returned.
pub max: usize,
/// The amount of headers to skip between each response entry.
@ -34,7 +35,7 @@ pub struct Headers {
}
/// A request for specific block bodies.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct Bodies {
/// Hashes which bodies are being requested for.
pub block_hashes: Vec<H256>
@ -44,14 +45,14 @@ pub struct Bodies {
///
/// This request is answered with a list of transaction receipts for each block
/// requested.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct Receipts {
/// Block hashes to return receipts for.
pub block_hashes: Vec<H256>,
}
/// A request for a state proof
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct StateProof {
/// Block hash to query state from.
pub block: H256,
@ -65,21 +66,30 @@ pub struct StateProof {
}
/// A request for state proofs.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct StateProofs {
/// All the proof requests.
pub requests: Vec<StateProof>,
}
/// A request for contract code.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct ContractCode {
/// Block hash
pub block_hash: H256,
/// Account key (== sha3(address))
pub account_key: H256,
}
/// A request for contract code.
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct ContractCodes {
/// Block hash and account key (== sha3(address)) pairs to fetch code for.
pub code_requests: Vec<(H256, H256)>,
pub code_requests: Vec<ContractCode>,
}
/// A request for a header proof from the Canonical Hash Trie.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct HeaderProof {
/// Number of the CHT.
pub cht_number: u64,
@ -90,14 +100,14 @@ pub struct HeaderProof {
}
/// A request for header proofs from the CHT.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub struct HeaderProofs {
/// All the proof requests.
pub requests: Vec<HeaderProofs>,
}
/// Kinds of requests.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Binary)]
pub enum Kind {
/// Requesting headers.
Headers,
@ -114,7 +124,7 @@ pub enum Kind {
}
/// Encompasses all possible types of requests in a single structure.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
pub enum Request {
/// Requesting headers.
Headers(Headers),

View File

@ -34,3 +34,5 @@ pub mod block_import_error;
pub mod restoration_status;
pub mod snapshot_manifest;
pub mod mode;
pub mod pruning_info;
pub mod les_request;

View File

@ -24,7 +24,7 @@
#[derive(Debug, Clone, Binary)]
pub struct PruningInfo {
/// The first block which everything can be served after.
pub earliest_chain: u64
pub earliest_chain: u64,
/// The first block where state requests may be served.
pub earliest_state: u64
pub earliest_state: u64,
}