Move all light client work to own crate
This commit is contained in:
parent
5cabb3008f
commit
c1a6dbe75f
15
ethcore/light/Cargo.toml
Normal file
15
ethcore/light/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
description = "Parity LES primitives"
|
||||||
|
homepage = "https://ethcore.io"
|
||||||
|
license = "GPL-3.0"
|
||||||
|
name = "ethcore-light"
|
||||||
|
version = "1.5.0"
|
||||||
|
authors = ["Ethcore <admin@ethcore.io>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.3"
|
||||||
|
ethcore = { path = ".." }
|
||||||
|
ethcore-util = { path = "../../util" }
|
||||||
|
ethcore-network = { path = "../../util/network" }
|
||||||
|
ethcore-io = { path = "../../util/io" }
|
||||||
|
rlp = { path = "../../util/rlp" }
|
@ -19,22 +19,23 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use engines::Engine;
|
use ethcore::engines::Engine;
|
||||||
use ids::BlockID;
|
use ethcore::ids::BlockID;
|
||||||
use miner::TransactionQueue;
|
use ethcore::miner::TransactionQueue;
|
||||||
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::{Config as QueueConfig, HeaderQueue, QueueInfo, Status};
|
use ethcore::verification::queue::{Config as QueueConfig, HeaderQueue, QueueInfo, Status};
|
||||||
use transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use types::blockchain_info::BlockChainInfo;
|
use ethcore::blockchain_info::BlockChainInfo;
|
||||||
|
|
||||||
use super::provider::{CHTProofRequest, Provider, ProofRequest};
|
|
||||||
|
|
||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
use util::hash::H256;
|
use util::hash::H256;
|
||||||
use util::{Bytes, Mutex};
|
use util::{Bytes, Mutex};
|
||||||
|
|
||||||
|
use provider::Provider;
|
||||||
|
use request;
|
||||||
|
|
||||||
/// Light client implementation.
|
/// Light client implementation.
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
engine: Arc<Engine>,
|
engine: Arc<Engine>,
|
||||||
@ -78,27 +79,31 @@ impl Provider for Client {
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_headers(&self, block: (u64, H256), skip: usize, max: usize, reverse: bool) -> Vec<Bytes> {
|
fn block_headers(&self, _req: request::Headers) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_bodies(&self, blocks: Vec<H256>) -> Vec<Bytes> {
|
fn block_bodies(&self, _req: request::Bodies) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receipts(&self, blocks: Vec<H256>) -> Vec<Bytes> {
|
fn receipts(&self, _req: request::Receipts) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proofs(&self, requests: Vec<(H256, ProofRequest)>) -> Vec<Bytes> {
|
fn proofs(&self, _req: request::StateProofs) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(&self, accounts: Vec<(H256, H256)>) -> Vec<Bytes> {
|
fn code(&self, _req: request::ContractCodes) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header_proofs(&self, requests: Vec<CHTProofRequest>) -> Vec<Bytes> {
|
fn header_proofs(&self, _req: request::HeaderProofs) -> Vec<Bytes> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn block_deltas(&self, _req: request::BlockDeltas) -> Vec<Bytes> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
@ -28,9 +28,16 @@
|
|||||||
//! It starts by performing a header-only sync, verifying every header in
|
//! It starts by performing a header-only sync, verifying every header in
|
||||||
//! the chain.
|
//! the chain.
|
||||||
|
|
||||||
mod client;
|
pub mod client;
|
||||||
mod provider;
|
pub mod net;
|
||||||
mod sync;
|
pub mod provider;
|
||||||
|
pub mod request;
|
||||||
|
|
||||||
pub use self::client::Client;
|
extern crate ethcore_util as util;
|
||||||
pub use self::provider::{CHTProofRequest, ProofRequest, Provider};
|
extern crate ethcore_network as network;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
|
extern crate ethcore;
|
||||||
|
extern crate rlp;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
@ -19,19 +19,17 @@
|
|||||||
//! This uses a "Provider" to answer requests and syncs to a `Client`.
|
//! This uses a "Provider" to answer requests and syncs to a `Client`.
|
||||||
//! See https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES)
|
//! See https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES)
|
||||||
|
|
||||||
use ethcore::light::{Client, Provider};
|
|
||||||
use io::TimerToken;
|
use io::TimerToken;
|
||||||
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, NetworkError, PeerId};
|
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, NetworkError, PeerId};
|
||||||
use rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
|
use rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
|
||||||
use util::hash::H256;
|
use util::hash::H256;
|
||||||
use parking_lot::{Mutex, RwLock};
|
use util::{Mutex, RwLock};
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
use self::request::Request;
|
use provider::Provider;
|
||||||
|
use request::Request;
|
||||||
mod request;
|
|
||||||
|
|
||||||
const TIMEOUT: TimerToken = 0;
|
const TIMEOUT: TimerToken = 0;
|
||||||
const TIMEOUT_INTERVAL_MS: u64 = 1000;
|
const TIMEOUT_INTERVAL_MS: u64 = 1000;
|
||||||
@ -163,7 +161,7 @@ impl LightProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn send_status(&self, peer: PeerId, io: &NetworkContext) -> Result<(), NetworkError> {
|
fn send_status(&self, peer: PeerId, io: &NetworkContext) -> Result<(), NetworkError> {
|
||||||
let chain_info = self.client.chain_info();
|
let chain_info = self.provider.chain_info();
|
||||||
|
|
||||||
// TODO [rob] use optional keys too.
|
// TODO [rob] use optional keys too.
|
||||||
let mut stream = RlpStream::new_list(6);
|
let mut stream = RlpStream::new_list(6);
|
||||||
@ -210,14 +208,13 @@ impl LightProtocol {
|
|||||||
fn get_block_headers(&self, peer: &PeerId, io: &NetworkContext, data: UntrustedRlp) {
|
fn get_block_headers(&self, peer: &PeerId, io: &NetworkContext, data: UntrustedRlp) {
|
||||||
const MAX_HEADERS: usize = 512;
|
const MAX_HEADERS: usize = 512;
|
||||||
|
|
||||||
let req_id: u64 = try_dc!(io, peer, data.val_at(0));
|
let req_id: u64 = try_dc!(io, *peer, data.val_at(0));
|
||||||
let block = try_dc!(io, peer, data.at(1).and_then(|block_list| {
|
let block: (u64, H256) = try_dc!(io, *peer, data.at(1).and_then(|block_list| {
|
||||||
(try!(block_list.val_at(0)), try!(block_list.val_at(1))
|
Ok((try!(block_list.val_at(0)), try!(block_list.val_at(1))))
|
||||||
}));
|
}));
|
||||||
let max = ::std::cmp::min(MAX_HEADERS, try_dc!(io, peer, data.val_at(2)));
|
let max = ::std::cmp::min(MAX_HEADERS, try_dc!(io, *peer, data.val_at(2)));
|
||||||
let reverse = try_dc!(io, peer, data.val_at(3));
|
let reverse: bool = try_dc!(io, *peer, data.val_at(3));
|
||||||
|
|
||||||
let headers = self.provider.block_headers()
|
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
@ -17,21 +17,20 @@
|
|||||||
//! A provider for the LES protocol. This is typically a full node, who can
|
//! A provider for the LES protocol. This is typically a full node, who can
|
||||||
//! give as much data as necessary to its peers.
|
//! give as much data as necessary to its peers.
|
||||||
|
|
||||||
pub use proof_request::{CHTProofRequest, ProofRequest};
|
use ethcore::transaction::SignedTransaction;
|
||||||
|
use ethcore::blockchain_info::BlockChainInfo;
|
||||||
use transaction::SignedTransaction;
|
|
||||||
use blockchain_info::BlockChainInfo;
|
|
||||||
|
|
||||||
use util::Bytes;
|
use util::Bytes;
|
||||||
use util::hash::H256;
|
use util::hash::H256;
|
||||||
|
|
||||||
|
use request;
|
||||||
|
|
||||||
/// Defines the operations that a provider for `LES` must fulfill.
|
/// Defines the operations that a provider for `LES` must fulfill.
|
||||||
///
|
///
|
||||||
/// These are defined at [1], but may be subject to change.
|
/// These are defined at [1], but may be subject to change.
|
||||||
/// Requests which can't be fulfilled should return an empty RLP list.
|
/// Requests which can't be fulfilled should return an empty RLP list.
|
||||||
///
|
///
|
||||||
/// [1]: https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES)
|
/// [1]: https://github.com/ethcore/parity/wiki/Light-Ethereum-Subprotocol-(LES)
|
||||||
pub trait Provider: Sync {
|
pub trait Provider: Send + Sync {
|
||||||
/// Provide current blockchain info.
|
/// Provide current blockchain info.
|
||||||
fn chain_info(&self) -> BlockChainInfo;
|
fn chain_info(&self) -> BlockChainInfo;
|
||||||
|
|
||||||
@ -40,27 +39,30 @@ pub trait Provider: Sync {
|
|||||||
///
|
///
|
||||||
/// The returned vector may have any length in the range [0, `max`], but the
|
/// The returned vector may have any length in the range [0, `max`], but the
|
||||||
/// results within must adhere to the `skip` and `reverse` parameters.
|
/// results within must adhere to the `skip` and `reverse` parameters.
|
||||||
fn block_headers(&self, block: (u64, H256), skip: usize, max: usize, reverse: bool) -> Vec<Bytes>;
|
fn block_headers(&self, req: request::Headers) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide as many as possible of the requested blocks (minus the headers) encoded
|
/// Provide as many as possible of the requested blocks (minus the headers) encoded
|
||||||
/// in RLP format.
|
/// in RLP format.
|
||||||
fn block_bodies(&self, blocks: Vec<H256>) -> Vec<Bytes>;
|
fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide the receipts as many as possible of the requested blocks.
|
/// Provide the receipts as many as possible of the requested blocks.
|
||||||
/// Returns a vector of RLP-encoded lists of receipts.
|
/// Returns a vector of RLP-encoded lists of receipts.
|
||||||
fn receipts(&self, blocks: Vec<H256>) -> Vec<Bytes>;
|
fn receipts(&self, req: request::Receipts) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide a set of merkle proofs, as requested. Each request is a
|
/// Provide a set of merkle proofs, as requested. Each request is a
|
||||||
/// block hash and request parameters.
|
/// block hash and request parameters.
|
||||||
///
|
///
|
||||||
/// Returns a vector to RLP-encoded lists satisfying the requests.
|
/// Returns a vector to RLP-encoded lists satisfying the requests.
|
||||||
fn proofs(&self, requests: Vec<(H256, ProofRequest)>) -> Vec<Bytes>;
|
fn proofs(&self, req: request::StateProofs) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide contract code for the specified (block_hash, account_hash) pairs.
|
/// Provide contract code for the specified (block_hash, account_hash) pairs.
|
||||||
fn code(&self, accounts: Vec<(H256, H256)>) -> Vec<Bytes>;
|
fn code(&self, req: request::ContractCodes) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide header proofs from the Canonical Hash Tries.
|
/// Provide header proofs from the Canonical Hash Tries.
|
||||||
fn header_proofs(&self, requests: Vec<CHTProofRequest>) -> Vec<Bytes>;
|
fn header_proofs(&self, req: request::HeaderProofs) -> Vec<Bytes>;
|
||||||
|
|
||||||
|
/// Provide block deltas.
|
||||||
|
fn block_deltas(&self, req: request::BlockDeltas) -> Vec<Bytes>;
|
||||||
|
|
||||||
/// Provide pending transactions.
|
/// Provide pending transactions.
|
||||||
fn pending_transactions(&self) -> Vec<SignedTransaction>;
|
fn pending_transactions(&self) -> Vec<SignedTransaction>;
|
@ -14,7 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/// LES request types.
|
//! LES request types.
|
||||||
|
|
||||||
|
// TODO: make IPC compatible.
|
||||||
|
|
||||||
use ethcore::transaction::Transaction;
|
use ethcore::transaction::Transaction;
|
||||||
use util::{Address, H256};
|
use util::{Address, H256};
|
@ -1,33 +0,0 @@
|
|||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//! A light sync target.
|
|
||||||
|
|
||||||
use block_import_error::BlockImportError;
|
|
||||||
use client::BlockChainInfo;
|
|
||||||
|
|
||||||
use util::hash::H256;
|
|
||||||
|
|
||||||
pub trait Sync {
|
|
||||||
/// Whether syncing is enabled.
|
|
||||||
fn enabled(&self) -> bool;
|
|
||||||
|
|
||||||
/// Current chain info.
|
|
||||||
fn chain_info(&self) -> BlockChainInfo;
|
|
||||||
|
|
||||||
/// Import a header.
|
|
||||||
fn import_header(&self, header_bytes: Vec<u8>) -> Result<H256, BlockImportError>;
|
|
||||||
}
|
|
@ -33,5 +33,4 @@ pub mod transaction_import;
|
|||||||
pub mod block_import_error;
|
pub mod block_import_error;
|
||||||
pub mod restoration_status;
|
pub mod restoration_status;
|
||||||
pub mod snapshot_manifest;
|
pub mod snapshot_manifest;
|
||||||
pub mod proof_request;
|
|
||||||
pub mod mode;
|
pub mod mode;
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//! Merkle proof request.
|
|
||||||
use util::hash::H256;
|
|
||||||
|
|
||||||
/// A request for a state merkle proof.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
|
|
||||||
pub enum ProofRequest {
|
|
||||||
/// Request a proof of the given account's (denoted by sha3(address))
|
|
||||||
/// node in the state trie. Nodes with depth less than the second item
|
|
||||||
/// may be omitted.
|
|
||||||
Account(H256, usize),
|
|
||||||
|
|
||||||
/// Request a proof for a key in the given account's storage trie.
|
|
||||||
/// Both values are hashes of their actual values. Nodes with depth
|
|
||||||
/// less than the third item may be omitted.
|
|
||||||
Storage(H256, H256, usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A request for a Canonical Hash Trie proof for the given block number.
|
|
||||||
/// Nodes with depth less than the second item may be omitted.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
|
|
||||||
pub struct CHTProofRequest {
|
|
||||||
/// The number of the block the proof is requested for.
|
|
||||||
/// The CHT's number can be deduced from this (`number` / 4096)
|
|
||||||
pub number: u64,
|
|
||||||
|
|
||||||
/// Nodes with depth less than this can be omitted from the proof.
|
|
||||||
pub depth: usize,
|
|
||||||
}
|
|
@ -51,7 +51,6 @@ mod blocks;
|
|||||||
mod block_sync;
|
mod block_sync;
|
||||||
mod sync_io;
|
mod sync_io;
|
||||||
mod snapshot;
|
mod snapshot;
|
||||||
mod light;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
Loading…
Reference in New Issue
Block a user