Fixed GetNodeData output (#2892)

This commit is contained in:
Arkadiy Paronyan 2016-10-27 15:25:54 +02:00 committed by GitHub
parent 176dc0e945
commit 3edd9e4bee

View File

@ -1428,16 +1428,18 @@ impl ChainSync {
} }
count = min(count, MAX_NODE_DATA_TO_SEND); count = min(count, MAX_NODE_DATA_TO_SEND);
let mut added = 0usize; let mut added = 0usize;
let mut data = Bytes::new(); let mut data = Vec::new();
for i in 0..count { for i in 0..count {
if let Some(mut hdr) = io.chain().state_data(&try!(r.val_at::<H256>(i))) { if let Some(hdr) = io.chain().state_data(&try!(r.val_at::<H256>(i))) {
data.append(&mut hdr); data.push(hdr);
added += 1; added += 1;
} }
} }
trace!(target: "sync", "{} -> GetNodeData: return {} entries", peer_id, added); trace!(target: "sync", "{} -> GetNodeData: return {} entries", peer_id, added);
let mut rlp = RlpStream::new_list(added); let mut rlp = RlpStream::new_list(added);
rlp.append_raw(&data, added); for d in data.into_iter() {
rlp.append(&d);
}
Ok(Some((NODE_DATA_PACKET, rlp))) Ok(Some((NODE_DATA_PACKET, rlp)))
} }
@ -2026,7 +2028,9 @@ mod tests {
assert!(rlp_result.is_some()); assert!(rlp_result.is_some());
// the length of one rlp-encoded hashe // the length of one rlp-encoded hashe
assert_eq!(34, rlp_result.unwrap().1.out().len()); let rlp = rlp_result.unwrap().1.out();
let rlp = Rlp::new(&rlp);
assert_eq!(1, rlp.item_count());
io.sender = Some(2usize); io.sender = Some(2usize);