From 45c3600d5ab2012f0f7c083ec774c77c76c5d57c Mon Sep 17 00:00:00 2001 From: arkpar Date: Sun, 13 Mar 2016 23:20:26 +0100 Subject: [PATCH 1/4] Fixed splitting Neighbours packet --- util/src/network/discovery.rs | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/util/src/network/discovery.rs b/util/src/network/discovery.rs index a381b49f8..f5c4592f0 100644 --- a/util/src/network/discovery.rs +++ b/util/src/network/discovery.rs @@ -407,25 +407,37 @@ impl Discovery { let target: NodeId = try!(rlp.val_at(0)); let timestamp: u64 = try!(rlp.val_at(1)); try!(self.check_timestamp(timestamp)); - let limit = (MAX_DATAGRAM_SIZE - 109) / 90; let nearest = Discovery::nearest_node_entries(&target, &self.node_buckets); if nearest.is_empty() { return Ok(None); } + let mut packets = Discovery::prepare_neighbours_packets(&nearest); + for p in packets.drain(..) { + self.send_packet(PACKET_NEIGHBOURS, &from, &p); + } + trace!(target: "discovery", "Sent {} Neighbours to {:?}", nearest.len(), &from); + Ok(None) + } + + fn prepare_neighbours_packets(nearest: &[NodeEntry]) -> Vec { + let mut packets = Vec::new(); let mut rlp = RlpStream::new_list(1); - rlp.begin_list(cmp::min(limit, nearest.len())); + let limit = (MAX_DATAGRAM_SIZE - 109) / 90; + let mut count = cmp::min(limit, nearest.len()); + rlp.begin_list(count); for n in 0 .. nearest.len() { rlp.begin_list(4); nearest[n].endpoint.to_rlp(&mut rlp); rlp.append(&nearest[n].id); - if (n + 1) % limit == 0 || n == nearest.len() - 1 { - self.send_packet(PACKET_NEIGHBOURS, &from, &rlp.drain()); - trace!(target: "discovery", "Sent {} Neighbours to {:?}", n, &from); + count -= 1; + if count == 0 { + packets.push(rlp.out()); rlp = RlpStream::new_list(1); - rlp.begin_list(cmp::min(limit, nearest.len() - n)); + count = cmp::min(limit, nearest.len() - n); + rlp.begin_list(count); } } - Ok(None) + packets } fn on_neighbours(&mut self, rlp: &UntrustedRlp, _node: &NodeId, from: &SocketAddr) -> Result, NetworkError> { @@ -506,6 +518,23 @@ mod tests { use crypto::KeyPair; use std::str::FromStr; use rustc_serialize::hex::FromHex; + use rlp::*; + + #[test] + fn find_node() { + let mut nearest = Vec::new(); + let node = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@127.0.0.1:7770").unwrap(); + for _ in 0..1000 { + nearest.push( NodeEntry { id: node.id.clone(), endpoint: node.endpoint.clone() }); + } + + let packets = Discovery::prepare_neighbours_packets(&nearest); + assert_eq!(packets.len(), 76); + for p in &packets { + assert!(p.len() > 1280/2); + assert!(p.len() <= 1280); + } + } #[test] fn discovery() { From 615e03542ebb6ff4f60262a3cf7426c1ce74f821 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 14 Mar 2016 00:41:25 +0100 Subject: [PATCH 2/4] Use slice.chunks --- util/src/network/discovery.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/util/src/network/discovery.rs b/util/src/network/discovery.rs index f5c4592f0..6fda99cdb 100644 --- a/util/src/network/discovery.rs +++ b/util/src/network/discovery.rs @@ -18,7 +18,6 @@ use bytes::Bytes; use std::net::SocketAddr; use std::collections::{HashSet, HashMap, BTreeMap, VecDeque}; use std::mem; -use std::cmp; use std::default::Default; use mio::*; use mio::udp::*; @@ -420,24 +419,19 @@ impl Discovery { } fn prepare_neighbours_packets(nearest: &[NodeEntry]) -> Vec { - let mut packets = Vec::new(); - let mut rlp = RlpStream::new_list(1); let limit = (MAX_DATAGRAM_SIZE - 109) / 90; - let mut count = cmp::min(limit, nearest.len()); - rlp.begin_list(count); - for n in 0 .. nearest.len() { - rlp.begin_list(4); - nearest[n].endpoint.to_rlp(&mut rlp); - rlp.append(&nearest[n].id); - count -= 1; - if count == 0 { - packets.push(rlp.out()); - rlp = RlpStream::new_list(1); - count = cmp::min(limit, nearest.len() - n); - rlp.begin_list(count); + let chunks = nearest.chunks(limit); + let packets = chunks.map(|c| { + let mut rlp = RlpStream::new_list(1); + rlp.begin_list(c.len()); + for n in 0 .. c.len() { + rlp.begin_list(4); + c[n].endpoint.to_rlp(&mut rlp); + rlp.append(&c[n].id); } - } - packets + rlp.out() + }); + packets.collect() } fn on_neighbours(&mut self, rlp: &UntrustedRlp, _node: &NodeId, from: &SocketAddr) -> Result, NetworkError> { @@ -529,11 +523,12 @@ mod tests { } let packets = Discovery::prepare_neighbours_packets(&nearest); - assert_eq!(packets.len(), 76); - for p in &packets { + assert_eq!(packets.len(), 77); + for p in &packets[0..76] { assert!(p.len() > 1280/2); assert!(p.len() <= 1280); } + assert!(packets.last().unwrap().len() > 0); } #[test] From 7bc3c0b0269a007f0b0ff1d69ba318a97b280793 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 14 Mar 2016 01:27:27 +0100 Subject: [PATCH 3/4] Removed rocksdb build dependency --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c614ca5d..6ae41379e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,10 +33,6 @@ addons: - libcurl4-openssl-dev - libelf-dev - libdw-dev -before_script: | - sudo add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main" && - sudo apt-get update && - sudo apt-get install -y --force-yes librocksdb script: - cargo build --release --verbose ${FEATURES} - cargo test --release --verbose ${FEATURES} ${TARGETS} From 6827ff9319893fe5283ab1e110951f375db79f13 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 14 Mar 2016 09:37:32 +0100 Subject: [PATCH 4/4] [ci skip] fix tesh.sh --- test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test.sh b/test.sh index e1881a8ad..0bf08e67f 100755 --- a/test.sh +++ b/test.sh @@ -1,5 +1,4 @@ #!/bin/sh # Running Parity Full Test Sute -cargo test --features ethcore/json-tests $1 -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p -ethminer +cargo test --features ethcore/json-tests $1 -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethminer