From ce7b5b03adfade17ab1412ebf774651d15e933ad Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 03:44:40 +0300 Subject: [PATCH 1/6] sync test temp fix --- ethcore/src/block_queue.rs | 4 +++- sync/src/chain.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index 1fe31ba19..009ab6bf7 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -79,6 +79,8 @@ struct Verification { bad: HashSet, } +const MAX_UNVERIFIED_QUEUE_SIZE: usize = 50000; + impl BlockQueue { /// Creates a new queue instance. pub fn new(engine: Arc>, message_channel: IoChannel) -> BlockQueue { @@ -290,7 +292,7 @@ impl BlockQueue { pub fn queue_info(&self) -> BlockQueueInfo { let verification = self.verification.lock().unwrap(); BlockQueueInfo { - full: false, + full: verification.unverified.len() + verification.verifying.len() >= MAX_UNVERIFIED_QUEUE_SIZE, verified_queue_size: verification.verified.len(), unverified_queue_size: verification.unverified.len(), verifying_queue_size: verification.verifying.len(), diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 9752a5013..9ae00670f 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -292,7 +292,7 @@ impl ChainSync { trace!(target: "sync", "Ignored unexpected block headers"); return Ok(()); } - if self.state == SyncState::Waiting { + if io.chain().queue_info().full { trace!(target: "sync", "Ignored block headers while waiting"); return Ok(()); } @@ -376,7 +376,7 @@ impl ChainSync { trace!(target: "sync", "Ignored unexpected block bodies"); return Ok(()); } - if self.state == SyncState::Waiting { + if io.chain().queue_info().full { trace!(target: "sync", "Ignored block bodies while waiting"); return Ok(()); } @@ -532,7 +532,7 @@ impl ChainSync { /// Enter waiting state fn pause_sync(&mut self) { trace!(target: "sync", "Block queue full, pausing sync"); - self.state = SyncState::Waiting; + //self.state = SyncState::Waiting; } /// Find something to do for a peer. Called for a new peer or when a peer is done with it's task. From a20600c9d17263a9e665250de6a252dac84ec2b7 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 04:04:12 +0300 Subject: [PATCH 2/6] verified as well --- ethcore/src/block_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index 009ab6bf7..e14f2a06a 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -292,7 +292,7 @@ impl BlockQueue { pub fn queue_info(&self) -> BlockQueueInfo { let verification = self.verification.lock().unwrap(); BlockQueueInfo { - full: verification.unverified.len() + verification.verifying.len() >= MAX_UNVERIFIED_QUEUE_SIZE, + full: verification.unverified.len() + verification.verifying.len() + verification.verified.len() >= MAX_UNVERIFIED_QUEUE_SIZE, verified_queue_size: verification.verified.len(), unverified_queue_size: verification.unverified.len(), verifying_queue_size: verification.verifying.len(), From c3d0ed6e69c214a73f2dd0462c9052a4e5827677 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 04:11:27 +0300 Subject: [PATCH 3/6] proper status setting --- sync/src/chain.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 9ae00670f..51341826f 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -292,7 +292,7 @@ impl ChainSync { trace!(target: "sync", "Ignored unexpected block headers"); return Ok(()); } - if io.chain().queue_info().full { + if self.state == SyncState::Waiting { trace!(target: "sync", "Ignored block headers while waiting"); return Ok(()); } @@ -376,7 +376,7 @@ impl ChainSync { trace!(target: "sync", "Ignored unexpected block bodies"); return Ok(()); } - if io.chain().queue_info().full { + if self.state == SyncState::Waiting { trace!(target: "sync", "Ignored block bodies while waiting"); return Ok(()); } @@ -987,6 +987,11 @@ impl ChainSync { /// Handle peer timeouts pub fn maintain_peers(&self, io: &mut SyncIo) { let tick = time::precise_time_s(); + + if !io.chain().queue_info().full { + self.state == SyncState::Idle; + } + for (peer_id, peer) in &self.peers { if peer.asking != PeerAsking::Nothing && (tick - peer.ask_time) > CONNECTION_TIMEOUT_SEC { io.disconnect_peer(*peer_id); From 20ca72ee0cb7048d581bbecb19a2691d2661911c Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 04:12:41 +0300 Subject: [PATCH 4/6] status waiting --- sync/src/chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 51341826f..53c6c142d 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -532,7 +532,7 @@ impl ChainSync { /// Enter waiting state fn pause_sync(&mut self) { trace!(target: "sync", "Block queue full, pausing sync"); - //self.state = SyncState::Waiting; + self.state = SyncState::Waiting; } /// Find something to do for a peer. Called for a new peer or when a peer is done with it's task. From 86cfe951136b9f1861e518118c80497be30f16f6 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 04:24:10 +0300 Subject: [PATCH 5/6] continueing sync --- sync/src/chain.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 53c6c142d..7a3f5ee97 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -985,11 +985,12 @@ impl ChainSync { } /// Handle peer timeouts - pub fn maintain_peers(&self, io: &mut SyncIo) { + pub fn maintain_peers(&mut self, io: &mut SyncIo) { let tick = time::precise_time_s(); - if !io.chain().queue_info().full { - self.state == SyncState::Idle; + if !io.chain().queue_info().full && self.state == SyncState::Waiting { + self.state = SyncState::Idle; + self.continue_sync(io); } for (peer_id, peer) in &self.peers { From 376c99c247003748af78aea650d6f3c411b10ce0 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 04:28:16 +0300 Subject: [PATCH 6/6] moving to mainaint_sync --- sync/src/chain.rs | 14 ++++++-------- sync/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 7a3f5ee97..8b0b52080 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -985,14 +985,8 @@ impl ChainSync { } /// Handle peer timeouts - pub fn maintain_peers(&mut self, io: &mut SyncIo) { + pub fn maintain_peers(&self, io: &mut SyncIo) { let tick = time::precise_time_s(); - - if !io.chain().queue_info().full && self.state == SyncState::Waiting { - self.state = SyncState::Idle; - self.continue_sync(io); - } - for (peer_id, peer) in &self.peers { if peer.asking != PeerAsking::Nothing && (tick - peer.ask_time) > CONNECTION_TIMEOUT_SEC { io.disconnect_peer(*peer_id); @@ -1001,7 +995,11 @@ 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) { + if !io.chain().queue_info().full && self.state == SyncState::Waiting { + self.state = SyncState::Idle; + self.continue_sync(io); + } } } diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 40b67dc5b..f3b43396c 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -107,6 +107,7 @@ impl NetworkProtocolHandler for EthSync { fn timeout(&self, io: &NetworkContext, _timer: TimerToken) { self.sync.write().unwrap().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref())); + self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref())); } }