rlp deserialization refactor, 30% faster (#4901)

* fixed naming of rlp modules

* RlpStream cleanup

* appending short rlp lists (0...55 bytes) is 25% faster

* RlpStream does not use bytes module, nor trait Stream

* removed unused code from rlp module

* compiling ethcore-util with new rlp serialization

* compiling parity with new rlp serialization

* fixed compiling ethcore-light with new rlp serialization

* fixed compiling ethsync with new rlp serialization

* moved rlp benches and rlp tests

* rlp deserialization refactor, 30% faster

* removed redundant comment, print

* fixed compiling parity with new rlp deserialization

* removed redundant double-space

* fixed failing test

* updated rlp docs, removed unused traits

* fixed rlp benchmarks

* replace usage of WriteBytesExt with ByteOrder

* removed unused, commented out code

* fixed merge conflict
This commit is contained in:
Marek Kotewicz
2017-03-22 14:41:46 +01:00
committed by GitHub
parent b6f9cf4ba7
commit 044d070667
71 changed files with 618 additions and 834 deletions

View File

@@ -481,7 +481,7 @@ impl Discovery {
fn on_neighbours(&mut self, rlp: &UntrustedRlp, _node: &NodeId, from: &SocketAddr) -> Result<Option<TableUpdates>, NetworkError> {
// TODO: validate packet
let mut added = HashMap::new();
trace!(target: "discovery", "Got {} Neighbours from {:?}", rlp.at(0)?.item_count(), &from);
trace!(target: "discovery", "Got {} Neighbours from {:?}", rlp.at(0)?.item_count()?, &from);
for r in rlp.at(0)?.iter() {
let endpoint = NodeEndpoint::from_rlp(&r)?;
if !endpoint.is_valid() {

View File

@@ -116,9 +116,8 @@ pub struct PeerCapabilityInfo {
}
impl Decodable for PeerCapabilityInfo {
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
let c = decoder.as_rlp();
let p: Vec<u8> = c.val_at(0)?;
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
let p: Vec<u8> = rlp.val_at(0)?;
if p.len() != 3 {
return Err(DecoderError::Custom("Invalid subprotocol string length. Should be 3"));
}
@@ -126,7 +125,7 @@ impl Decodable for PeerCapabilityInfo {
p2.clone_from_slice(&p);
Ok(PeerCapabilityInfo {
protocol: p2,
version: c.val_at(1)?
version: rlp.val_at(1)?
})
}
}
@@ -473,7 +472,7 @@ impl Session {
where Message: Send + Sync + Clone {
let protocol = rlp.val_at::<u32>(0)?;
let client_version = rlp.val_at::<String>(1)?;
let peer_caps = rlp.val_at::<Vec<PeerCapabilityInfo>>(2)?;
let peer_caps: Vec<PeerCapabilityInfo> = rlp.list_at(2)?;
let id = rlp.val_at::<NodeId>(4)?;
// Intersect with host capabilities