Minor optimizations
This commit is contained in:
@@ -107,6 +107,10 @@ pub struct SyncStatus {
|
||||
pub blocks_total: usize,
|
||||
/// Number of blocks downloaded so far.
|
||||
pub blocks_received: usize,
|
||||
/// Total number of connected peers
|
||||
pub num_peers: usize,
|
||||
/// Total number of active peers
|
||||
pub num_active_peers: usize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
@@ -195,8 +199,10 @@ impl ChainSync {
|
||||
start_block_number: self.starting_block,
|
||||
last_imported_block_number: self.last_imported_block,
|
||||
highest_block_number: self.highest_block,
|
||||
blocks_total: (self.last_imported_block - self.starting_block) as usize,
|
||||
blocks_received: (self.highest_block - self.starting_block) as usize,
|
||||
blocks_received: (self.last_imported_block - self.starting_block) as usize,
|
||||
blocks_total: (self.highest_block - self.starting_block) as usize,
|
||||
num_peers: self.peers.len(),
|
||||
num_active_peers: self.peers.values().filter(|p| p.asking != PeerAsking::Nothing).count(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,7 +550,7 @@ impl ChainSync {
|
||||
fn request_blocks(&mut self, io: &mut SyncIo, peer_id: PeerId) {
|
||||
self.clear_peer_download(peer_id);
|
||||
|
||||
if io.chain().queue_status().full {
|
||||
if io.chain().queue_info().full {
|
||||
self.pause_sync();
|
||||
return;
|
||||
}
|
||||
@@ -971,7 +977,7 @@ impl ChainSync {
|
||||
}
|
||||
|
||||
/// Maintain other peers. Send out any new blocks and transactions
|
||||
pub fn maintain_sync(&mut self, _io: &mut SyncIo) {
|
||||
pub fn _maintain_sync(&mut self, _io: &mut SyncIo) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ use std::sync::*;
|
||||
use client::Client;
|
||||
use util::network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId};
|
||||
use sync::chain::ChainSync;
|
||||
use util::TimerToken;
|
||||
use service::SyncMessage;
|
||||
use sync::io::NetSyncIo;
|
||||
|
||||
@@ -38,8 +37,6 @@ mod range_collection;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
const SYNC_TIMER: usize = 0;
|
||||
|
||||
/// Ethereum network protocol handler
|
||||
pub struct EthSync {
|
||||
/// Shared blockchain client. TODO: this should evetually become an IPC endpoint
|
||||
@@ -52,12 +49,13 @@ pub use self::chain::SyncStatus;
|
||||
|
||||
impl EthSync {
|
||||
/// Creates and register protocol with the network service
|
||||
pub fn register(service: &mut NetworkService<SyncMessage>, chain: Arc<Client>) {
|
||||
pub fn register(service: &mut NetworkService<SyncMessage>, chain: Arc<Client>) -> Arc<EthSync> {
|
||||
let sync = Arc::new(EthSync {
|
||||
chain: chain,
|
||||
sync: RwLock::new(ChainSync::new()),
|
||||
});
|
||||
service.register_protocol(sync.clone(), "eth", &[62u8, 63u8]).expect("Error registering eth protocol handler");
|
||||
sync
|
||||
}
|
||||
|
||||
/// Get sync status
|
||||
@@ -77,8 +75,7 @@ impl EthSync {
|
||||
}
|
||||
|
||||
impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
||||
fn initialize(&self, io: &NetworkContext<SyncMessage>) {
|
||||
io.register_timer(SYNC_TIMER, 1000).unwrap();
|
||||
fn initialize(&self, _io: &NetworkContext<SyncMessage>) {
|
||||
}
|
||||
|
||||
fn read(&self, io: &NetworkContext<SyncMessage>, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||
@@ -92,12 +89,6 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
||||
fn disconnected(&self, io: &NetworkContext<SyncMessage>, peer: &PeerId) {
|
||||
self.sync.write().unwrap().on_peer_aborting(&mut NetSyncIo::new(io, self.chain.deref()), *peer);
|
||||
}
|
||||
|
||||
fn timeout(&self, io: &NetworkContext<SyncMessage>, timer: TimerToken) {
|
||||
if timer == SYNC_TIMER {
|
||||
self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user