Client consolidation and docs
This commit is contained in:
parent
2a4d470039
commit
24ecd0091a
58
src/eth.rs
58
src/eth.rs
@ -1,58 +0,0 @@
|
||||
use util::hash::H256;
|
||||
use util::bytes::Bytes;
|
||||
use util::uint::U256;
|
||||
|
||||
pub enum QueueStatus {
|
||||
/// Part of the known chain
|
||||
Known,
|
||||
/// Part of the unknown chain
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub enum BlockStatus {
|
||||
InChain,
|
||||
Queued(QueueStatus),
|
||||
Bad,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub enum ImportResult {
|
||||
Queued(QueueStatus),
|
||||
AlreadyInChain,
|
||||
AlreadyQueued(QueueStatus),
|
||||
Bad,
|
||||
}
|
||||
|
||||
pub struct BlockChainInfo {
|
||||
pub total_difficulty: U256,
|
||||
pub pending_total_difficulty: U256,
|
||||
pub genesis_hash: H256,
|
||||
pub best_block_hash: H256,
|
||||
pub best_block_number: BlockNumber
|
||||
}
|
||||
|
||||
pub struct BlockQueueStatus {
|
||||
pub full: bool,
|
||||
}
|
||||
|
||||
pub type TreeRoute = ::blockchain::TreeRoute;
|
||||
|
||||
pub type BlockNumber = u64;
|
||||
|
||||
pub trait BlockChainClient : Sync {
|
||||
fn block_header(&self, hash: &H256) -> Option<Bytes>;
|
||||
fn block_body(&self, hash: &H256) -> Option<Bytes>;
|
||||
fn block(&self, hash: &H256) -> Option<Bytes>;
|
||||
fn block_status(&self, hash: &H256) -> BlockStatus;
|
||||
fn block_header_at(&self, n: BlockNumber) -> Option<Bytes>;
|
||||
fn block_body_at(&self, n: BlockNumber) -> Option<Bytes>;
|
||||
fn block_at(&self, n: BlockNumber) -> Option<Bytes>;
|
||||
fn block_status_at(&self, n: BlockNumber) -> BlockStatus;
|
||||
fn tree_route(&self, from: &H256, to: &H256) -> TreeRoute;
|
||||
fn state_data(&self, hash: &H256) -> Option<Bytes>;
|
||||
fn block_receipts(&self, hash: &H256) -> Option<Bytes>;
|
||||
fn import_block(&mut self, byte: &[u8]) -> ImportResult;
|
||||
fn queue_status(&self) -> BlockQueueStatus;
|
||||
fn clear_queue(&mut self);
|
||||
fn info(&self) -> BlockChainInfo;
|
||||
}
|
@ -106,6 +106,5 @@ pub mod blockchain;
|
||||
pub mod extras;
|
||||
pub mod client;
|
||||
|
||||
pub mod eth;
|
||||
pub mod sync;
|
||||
|
||||
|
@ -8,7 +8,7 @@ use util::uint::{U256};
|
||||
use util::rlp::{Rlp, RlpStream, self}; //TODO: use UntrustedRlp
|
||||
use util::rlp::rlptraits::{Stream, View};
|
||||
use util::sha3::Hashable;
|
||||
use eth::{BlockNumber, BlockChainClient, BlockStatus, QueueStatus, ImportResult};
|
||||
use client::{BlockNumber, BlockChainClient, BlockStatus, QueueStatus, ImportResult};
|
||||
use views::{HeaderView};
|
||||
use sync::range_collection::{RangeCollection, ToUsize, FromUsize};
|
||||
use sync::{SyncIo};
|
||||
@ -202,7 +202,7 @@ impl ChainSync {
|
||||
self.highest_block = 0;
|
||||
self.have_common_block = false;
|
||||
io.chain().clear_queue();
|
||||
self.starting_block = io.chain().info().best_block_number;
|
||||
self.starting_block = io.chain().chain_info().best_block_number;
|
||||
self.state = SyncState::NotSynced;
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ impl ChainSync {
|
||||
(peer.latest.clone(), peer.difficulty.clone())
|
||||
};
|
||||
|
||||
let td = io.chain().info().pending_total_difficulty;
|
||||
let td = io.chain().chain_info().pending_total_difficulty;
|
||||
let syncing_difficulty = max(self.syncing_difficulty, td);
|
||||
if force || peer_difficulty > syncing_difficulty {
|
||||
// start sync
|
||||
@ -515,7 +515,7 @@ impl ChainSync {
|
||||
let mut start = 0usize;
|
||||
if !self.have_common_block {
|
||||
// download backwards until common block is found 1 header at a time
|
||||
let chain_info = io.chain().info();
|
||||
let chain_info = io.chain().chain_info();
|
||||
start = chain_info.best_block_number as usize;
|
||||
if !self.headers.is_empty() {
|
||||
start = min(start, self.headers.range_iter().next().unwrap().0 as usize - 1);
|
||||
@ -720,7 +720,7 @@ impl ChainSync {
|
||||
|
||||
fn send_status(&mut self, io: &mut SyncIo, peer_id: &PeerId) {
|
||||
let mut packet = RlpStream::new_list(5);
|
||||
let chain = io.chain().info();
|
||||
let chain = io.chain().chain_info();
|
||||
packet.append(&(PROTOCOL_VERSION as u32));
|
||||
packet.append(&0u32); //TODO: network id
|
||||
packet.append(&chain.total_difficulty);
|
||||
@ -742,7 +742,7 @@ impl ChainSync {
|
||||
let max_headers: usize = r.val_at(1);
|
||||
let skip: usize = r.val_at(2);
|
||||
let reverse: bool = r.val_at(3);
|
||||
let last = io.chain().info().best_block_number;
|
||||
let last = io.chain().chain_info().best_block_number;
|
||||
let mut number = if r.at(0).size() == 32 {
|
||||
// id is a hash
|
||||
let hash: H256 = r.val_at(0);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::sync::{Arc};
|
||||
use eth::{BlockChainClient};
|
||||
use std::sync::Arc;
|
||||
use client::BlockChainClient;
|
||||
use util::network::{ProtocolHandler, NetworkService, HandlerIo, TimerToken, PeerId, PacketId, Message, Error as NetworkError};
|
||||
use sync::chain::{ChainSync};
|
||||
use sync::chain::ChainSync;
|
||||
|
||||
mod chain;
|
||||
mod range_collection;
|
||||
|
@ -5,7 +5,7 @@ use util::uint::{U256};
|
||||
use util::sha3::Hashable;
|
||||
use util::rlp::{self, Rlp, RlpStream, View, Stream};
|
||||
use util::network::{PeerId, PacketId, Error as NetworkError};
|
||||
use eth::{BlockChainClient, BlockStatus, BlockNumber, TreeRoute, BlockQueueStatus, BlockChainInfo, ImportResult, QueueStatus};
|
||||
use client::{BlockChainClient, BlockStatus, BlockNumber, TreeRoute, BlockQueueStatus, BlockChainInfo, ImportResult, QueueStatus};
|
||||
use header::Header as BlockHeader;
|
||||
use sync::{SyncIo};
|
||||
use sync::chain::{ChainSync};
|
||||
@ -164,7 +164,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
fn clear_queue(&mut self) {
|
||||
}
|
||||
|
||||
fn info(&self) -> BlockChainInfo {
|
||||
fn chain_info(&self) -> BlockChainInfo {
|
||||
BlockChainInfo {
|
||||
total_difficulty: self.difficulty,
|
||||
pending_total_difficulty: self.difficulty,
|
||||
|
Loading…
Reference in New Issue
Block a user