From 8d7244c09fe2c796b62f62863fab6627bca964df Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 5 Oct 2016 15:35:31 +0200 Subject: [PATCH] light client sync stubs --- ethcore/src/light/client.rs | 40 ++++++++----------------------------- ethcore/src/light/mod.rs | 1 + sync/src/lib.rs | 1 + sync/src/light/mod.rs | 27 +++++++++++++++++++++++++ sync/src/sync_io.rs | 4 ++-- 5 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 sync/src/light/mod.rs diff --git a/ethcore/src/light/client.rs b/ethcore/src/light/client.rs index de79ad922..18635aa44 100644 --- a/ethcore/src/light/client.rs +++ b/ethcore/src/light/client.rs @@ -39,57 +39,33 @@ pub struct Client { engine: Arc, header_queue: HeaderQueue, message_channel: IoChannel, - transaction_queue: TransactionQueue, } impl Client { /// Import a header as rlp-encoded bytes. - fn import_header(&self, bytes: Bytes) -> Result { + pub fn import_header(&self, bytes: Bytes) -> Result { let header = ::rlp::decode(&bytes); self.header_queue.import(header).map_err(Into::into) } /// Whether the block is already known (but not necessarily part of the canonical chain) - fn is_known(&self, id: BlockID) -> bool { + pub fn is_known(&self, id: BlockID) -> bool { false } /// Fetch a vector of all pending transactions. - fn pending_transactions(&self) -> Vec { - self.transaction_queue.top_transactions() + pub fn pending_transactions(&self) -> Vec { + vec![] } /// Inquire about the status of a given block. - fn status(&self, id: BlockID) -> BlockStatus { + pub fn status(&self, id: BlockID) -> BlockStatus { BlockStatus::Unknown } -} -// stub implementation, can be partially implemented using LRU-caches -// but will almost definitely never be able to provide complete responses. -impl Provider for Client { - fn block_headers(&self, _block: H256, _skip: usize, _max: usize, _reverse: bool) -> Vec { - vec![] - } - - fn block_bodies(&self, _blocks: Vec) -> Vec { - vec![] - } - - fn receipts(&self, _blocks: Vec) -> Vec { - vec![] - } - - fn proofs(&self, _requests: Vec<(H256, ProofRequest)>) -> Vec { - vec![] - } - - fn code(&self, _accounts: Vec<(H256, H256)>) -> Vec { - vec![] - } - - fn header_proofs(&self, _requests: Vec) -> Vec { - vec![] + /// Get the header queue info. + pub fn queue_info(&self) -> QueueInfo { + self.header_queue.queue_info() } } \ No newline at end of file diff --git a/ethcore/src/light/mod.rs b/ethcore/src/light/mod.rs index 32d4e9d8a..22b446074 100644 --- a/ethcore/src/light/mod.rs +++ b/ethcore/src/light/mod.rs @@ -15,4 +15,5 @@ mod provider; mod client; +pub use self::client::Client; pub use self::provider::{CHTProofRequest, ProofRequest, Provider}; diff --git a/sync/src/lib.rs b/sync/src/lib.rs index d2c6e2583..e13e3b8b1 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -50,6 +50,7 @@ mod chain; mod blocks; mod sync_io; mod snapshot; +mod light; #[cfg(test)] mod tests; diff --git a/sync/src/light/mod.rs b/sync/src/light/mod.rs new file mode 100644 index 000000000..13ba38c5a --- /dev/null +++ b/sync/src/light/mod.rs @@ -0,0 +1,27 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! LES Protocol Version 1 implementation. +//! +//! This uses a "Provider" to answer requests. + +use ethcore::light::{Client, Provider}; + +/// This handles synchronization of the header chain for a light client. +pub struct Chain { + client: Client, + peers: Vec, +} \ No newline at end of file diff --git a/sync/src/sync_io.rs b/sync/src/sync_io.rs index 445939399..867a75f38 100644 --- a/sync/src/sync_io.rs +++ b/sync/src/sync_io.rs @@ -18,7 +18,7 @@ use network::{NetworkContext, PeerId, PacketId, NetworkError}; use ethcore::client::BlockChainClient; use ethcore::snapshot::SnapshotService; -/// IO interface for the syning handler. +/// IO interface for the syncing handler. /// Provides peer connection management and an interface to the blockchain client. // TODO: ratings pub trait SyncIo { @@ -38,7 +38,7 @@ pub trait SyncIo { fn peer_info(&self, peer_id: PeerId) -> String { peer_id.to_string() } - /// Maximum mutuallt supported ETH protocol version + /// Maximum mutually supported ETH protocol version fn eth_protocol_version(&self, peer_id: PeerId) -> u8; /// Returns if the chain block queue empty fn is_chain_queue_empty(&self) -> bool {