diff --git a/Cargo.lock b/Cargo.lock index 925535d8a..78f04a9ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 667b40ace..825d9ffd1 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -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" diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 72356e91d..788596d86 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -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), } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 713c55056..91f0b18ff 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -655,7 +655,7 @@ impl BlockChainClient for TestBlockChainClient { fn pruning_info(&self) -> PruningInfo { PruningInfo { earliest_chain: 1, - earlest_state: 1, + earliest_state: 1, } } } diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index bf3e59171..2c07e7de6 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -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; diff --git a/ethcore/src/light/client.rs b/ethcore/src/light/client.rs index e3b5745b2..7b821d971 100644 --- a/ethcore/src/light/client.rs +++ b/ethcore/src/light/client.rs @@ -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 { diff --git a/ethcore/src/light/mod.rs b/ethcore/src/light/mod.rs index d96cedeaf..a7b2d3922 100644 --- a/ethcore/src/light/mod.rs +++ b/ethcore/src/light/mod.rs @@ -34,7 +34,5 @@ pub mod client; pub mod net; pub mod provider; -pub mod request; -#[macro_use] -extern crate log; \ No newline at end of file +pub use types::les_request as request; \ No newline at end of file diff --git a/ethcore/src/light/net/buffer_flow.rs b/ethcore/src/light/net/buffer_flow.rs index b7bd30f82..62f351515 100644 --- a/ethcore/src/light/net/buffer_flow.rs +++ b/ethcore/src/light/net/buffer_flow.rs @@ -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; diff --git a/ethcore/src/light/net/mod.rs b/ethcore/src/light/net/mod.rs index e72ce4bb2..47146a2f9 100644 --- a/ethcore/src/light/net/mod.rs +++ b/ethcore/src/light/net/mod.rs @@ -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)), diff --git a/ethcore/src/light/provider.rs b/ethcore/src/light/provider.rs index 3cabe3feb..481865643 100644 --- a/ethcore/src/light/provider.rs +++ b/ethcore/src/light/provider.rs @@ -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; /// 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; /// Provide a list of headers starting at the requested block, /// possibly in reverse and skipping `skip` at a time. @@ -83,11 +83,11 @@ impl Provider for T { } fn reorg_depth(&self, a: &H256, b: &H256) -> Option { - 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 { + Some(self.pruning_info().earliest_state) } fn block_headers(&self, req: request::Headers) -> Vec { @@ -95,16 +95,18 @@ impl Provider for T { } fn block_bodies(&self, req: request::Bodies) -> Vec { + 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 { 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 Provider for T { unimplemented!() } - fn code(&self, req: request::ContractCodes) -> Vec; + fn code(&self, req: request::ContractCodes) -> Vec { + unimplemented!() + } fn header_proofs(&self, req: request::HeaderProofs) -> Vec { // 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; + fn pending_transactions(&self) -> Vec { + unimplemented!() + } } \ No newline at end of file diff --git a/ethcore/src/light/request.rs b/ethcore/src/types/les_request.rs similarity index 80% rename from ethcore/src/light/request.rs rename to ethcore/src/types/les_request.rs index f043f0f25..e947c654d 100644 --- a/ethcore/src/light/request.rs +++ b/ethcore/src/types/les_request.rs @@ -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 @@ -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, } /// 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, } /// 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, } /// 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, } /// 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), diff --git a/ethcore/src/types/mod.rs.in b/ethcore/src/types/mod.rs.in index 6ef67009a..05c2c4dba 100644 --- a/ethcore/src/types/mod.rs.in +++ b/ethcore/src/types/mod.rs.in @@ -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; \ No newline at end of file diff --git a/ethcore/src/types/pruning_info.rs b/ethcore/src/types/pruning_info.rs index c49b7825b..40564f488 100644 --- a/ethcore/src/types/pruning_info.rs +++ b/ethcore/src/types/pruning_info.rs @@ -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, } \ No newline at end of file