diff --git a/chain/src/txhashset.rs b/chain/src/txhashset.rs index 026afa4d2..bf6717032 100644 --- a/chain/src/txhashset.rs +++ b/chain/src/txhashset.rs @@ -792,6 +792,13 @@ impl<'a> Extension<'a> { return Err(Error::OutputNotFound); } proof_count += 1; + + if proof_count % 500 == 0 { + debug!( + LOGGER, + "txhashset: verify_rangeproofs: verified {} rangeproofs", proof_count, + ); + } } } } diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index a4aa45684..258a86190 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -199,7 +199,9 @@ impl Server { Some(b) => b, }; - sync::run_sync( + let syncer = sync::Syncer::new(); + + syncer.run_sync( currently_syncing.clone(), awaiting_peers.clone(), p2p_server.peers.clone(), diff --git a/servers/src/grin/sync.rs b/servers/src/grin/sync.rs index 0c0fede63..34e1d5546 100644 --- a/servers/src/grin/sync.rs +++ b/servers/src/grin/sync.rs @@ -19,13 +19,43 @@ use std::sync::atomic::{AtomicBool, Ordering}; use time; use chain; +use common::types::Error; use core::core::hash::{Hash, Hashed}; use core::core::target::Difficulty; use core::global; +use grin::sync; use p2p::{self, Peer, Peers}; -use common::types::Error; use util::LOGGER; +pub struct Syncer {} + +impl Syncer { + pub fn new() -> Syncer { + Syncer {} + } + + pub fn run_sync( + &self, + currently_syncing: Arc, + awaiting_peers: Arc, + peers: Arc, + chain: Arc, + skip_sync_wait: bool, + archive_mode: bool, + stop: Arc, + ) { + sync::run_sync( + currently_syncing, + awaiting_peers, + peers, + chain, + skip_sync_wait, + archive_mode, + stop, + ) + } +} + /// Starts the syncing loop, just spawns two threads that loop forever pub fn run_sync( currently_syncing: Arc, @@ -75,30 +105,28 @@ pub fn run_sync( si.highest_height = most_work_height; } - // in archival nodes (no fast sync) we just consider we have the whole - // state already, then fast sync triggers if other peers are much - // further ahead - let fast_sync_enabled = - !archive_mode && si.highest_height.saturating_sub(head.height) > horizon; - if syncing { + let fast_sync_enabled = + !archive_mode && si.highest_height.saturating_sub(head.height) > horizon; + // run the header sync every 10s if si.header_sync_due(&header_head) { header_sync(peers.clone(), chain.clone()); } - // run the body_sync every 5s - if !fast_sync_enabled && si.body_sync_due(&head) { - body_sync(peers.clone(), chain.clone()); - } - - // run fast sync if applicable, every 5 min - if fast_sync_enabled && header_head.height == si.highest_height - && si.fast_sync_due() - { - fast_sync(peers.clone(), chain.clone(), &header_head); + if fast_sync_enabled { + // run fast sync if applicable, every 5 min + if header_head.height == si.highest_height && si.fast_sync_due() { + fast_sync(peers.clone(), chain.clone(), &header_head); + } + } else { + // run the body_sync every 5s + if si.body_sync_due(&head) { + body_sync(peers.clone(), chain.clone()); + } } } + currently_syncing.store(syncing, Ordering::Relaxed); thread::sleep(Duration::from_secs(1)); @@ -265,10 +293,6 @@ fn needs_syncing( if is_syncing { if let Some(peer) = peer { if let Ok(peer) = peer.try_read() { - debug!( - LOGGER, - "needs_syncing {} {}", local_diff, peer.info.total_difficulty - ); most_work_height = peer.info.height; if peer.info.total_difficulty <= local_diff { @@ -360,7 +384,7 @@ fn get_locator_heights(height: u64) -> Vec { struct SyncInfo { prev_body_sync: (time::Tm, u64), prev_header_sync: (time::Tm, u64), - prev_fast_sync: time::Tm, + prev_fast_sync: Option, highest_height: u64, } @@ -370,7 +394,7 @@ impl SyncInfo { SyncInfo { prev_body_sync: (now.clone(), 0), prev_header_sync: (now.clone(), 0), - prev_fast_sync: now.clone() - time::Duration::seconds(5 * 60), + prev_fast_sync: None, highest_height: 0, } } @@ -399,13 +423,15 @@ impl SyncInfo { false } + // For now this is a one-time thing (it can be slow) at initial startup. fn fast_sync_due(&mut self) -> bool { - let now = time::now_utc(); - if now - self.prev_fast_sync > time::Duration::seconds(5 * 60) { - self.prev_fast_sync = now; - return true; + if let None = self.prev_fast_sync { + let now = time::now_utc(); + self.prev_fast_sync = Some(now); + true + } else { + false } - false } }