Client app
This commit is contained in:
@@ -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().last_block_number;
|
||||
self.starting_block = io.chain().info().best_block_number;
|
||||
self.state = SyncState::NotSynced;
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ impl ChainSync {
|
||||
if !self.have_common_block {
|
||||
// download backwards until common block is found 1 header at a time
|
||||
let chain_info = io.chain().info();
|
||||
start = chain_info.last_block_number as usize;
|
||||
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);
|
||||
}
|
||||
@@ -724,7 +724,7 @@ impl ChainSync {
|
||||
packet.append(&(PROTOCOL_VERSION as u32));
|
||||
packet.append(&0u32); //TODO: network id
|
||||
packet.append(&chain.total_difficulty);
|
||||
packet.append(&chain.last_block_hash);
|
||||
packet.append(&chain.best_block_hash);
|
||||
packet.append(&chain.genesis_hash);
|
||||
//TODO: handle timeout for status request
|
||||
match io.send(*peer_id, STATUS_PACKET, packet.out()) {
|
||||
@@ -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().last_block_number;
|
||||
let last = io.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);
|
||||
|
||||
@@ -63,6 +63,13 @@ pub struct EthSync {
|
||||
pub use self::chain::SyncStatus;
|
||||
|
||||
impl EthSync {
|
||||
pub fn new(chain: Arc<BlockChainClient+Send+Sized>) -> EthSync {
|
||||
EthSync {
|
||||
chain: chain,
|
||||
sync: ChainSync::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_syncing(&self) -> bool {
|
||||
self.sync.is_syncing()
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ impl<K, V> RangeCollection<K, V> for Vec<(K, Vec<V>)> where K: Ord + PartialEq +
|
||||
fn test_range() {
|
||||
use std::cmp::{Ordering};
|
||||
|
||||
let mut ranges: Vec<(u32, Vec<char>)> = Vec::new();
|
||||
let mut ranges: Vec<(u64, Vec<char>)> = Vec::new();
|
||||
assert_eq!(ranges.range_iter().next(), None);
|
||||
assert_eq!(ranges.find_item(&1), None);
|
||||
assert!(!ranges.have_item(&1));
|
||||
|
||||
@@ -169,8 +169,8 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
total_difficulty: self.difficulty,
|
||||
pending_total_difficulty: self.difficulty,
|
||||
genesis_hash: self.genesis_hash.clone(),
|
||||
last_block_hash: self.last_hash.clone(),
|
||||
last_block_number: self.blocks.len() as BlockNumber - 1,
|
||||
best_block_hash: self.last_hash.clone(),
|
||||
best_block_number: self.blocks.len() as BlockNumber - 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user