fixed to return receipts grouped by requested block

This commit is contained in:
Nikolay Volf 2016-03-12 19:23:17 +01:00
parent bd9cfb4ee5
commit 0684abd345
2 changed files with 15 additions and 10 deletions

View File

@ -24,6 +24,7 @@ use header::{Header as BlockHeader, BlockNumber};
use filter::Filter; use filter::Filter;
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use receipt::Receipt; use receipt::Receipt;
use extras::BlockReceipts;
use error::{ImportResult, Error}; use error::{ImportResult, Error};
use block_queue::BlockQueueInfo; use block_queue::BlockQueueInfo;
use block::ClosedBlock; use block::ClosedBlock;
@ -254,10 +255,10 @@ impl BlockChainClient for TestBlockChainClient {
fn block_receipts(&self, hash: &H256) -> Option<Bytes> { fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
// starts with 'f' ? // starts with 'f' ?
if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") {
let receipt = Receipt::new( let receipt = BlockReceipts::new(vec![Receipt::new(
H256::zero(), H256::zero(),
U256::zero(), U256::zero(),
vec![]); vec![])]);
let mut rlp = RlpStream::new(); let mut rlp = RlpStream::new();
rlp.append(&receipt); rlp.append(&receipt);
return Some(rlp.out()); return Some(rlp.out());

View File

@ -66,6 +66,7 @@ const MAX_BODIES_TO_SEND: usize = 256;
const MAX_HEADERS_TO_SEND: usize = 512; const MAX_HEADERS_TO_SEND: usize = 512;
const MAX_NODE_DATA_TO_SEND: usize = 1024; const MAX_NODE_DATA_TO_SEND: usize = 1024;
const MAX_RECEIPTS_TO_SEND: usize = 1024; const MAX_RECEIPTS_TO_SEND: usize = 1024;
const MAX_RECEIPTS_HEADERS_TO_SEND: usize = 16;
const MAX_HEADERS_TO_REQUEST: usize = 512; const MAX_HEADERS_TO_REQUEST: usize = 512;
const MAX_BODIES_TO_REQUEST: usize = 256; const MAX_BODIES_TO_REQUEST: usize = 256;
const MIN_PEERS_PROPAGATION: usize = 4; const MIN_PEERS_PROPAGATION: usize = 4;
@ -1060,17 +1061,20 @@ impl ChainSync {
debug!(target: "sync", "Empty GetReceipts request, ignoring."); debug!(target: "sync", "Empty GetReceipts request, ignoring.");
return Ok(None); return Ok(None);
} }
count = min(count, MAX_RECEIPTS_TO_SEND); count = min(count, MAX_RECEIPTS_HEADERS_TO_SEND);
let mut added = 0usize; let mut added_headers = 0usize;
let mut added_receipts = 0usize;
let mut data = Bytes::new(); let mut data = Bytes::new();
for i in 0..count { for i in 0..count {
if let Some(mut hdr) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(i))) { if let Some(mut receipts_bytes) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(i))) {
data.append(&mut hdr); data.append(&mut receipts_bytes);
added += 1; added_receipts += receipts_bytes.len();
added_headers += 1;
if added_receipts > MAX_RECEIPTS_TO_SEND { break; }
} }
} }
let mut rlp_result = RlpStream::new_list(added); let mut rlp_result = RlpStream::new_list(added_headers);
rlp_result.append_raw(&data, added); rlp_result.append_raw(&data, added_headers);
Ok(Some((RECEIPTS_PACKET, rlp_result))) Ok(Some((RECEIPTS_PACKET, rlp_result)))
} }
@ -1396,7 +1400,7 @@ mod tests {
assert!(rlp_result.is_some()); assert!(rlp_result.is_some());
// the length of two rlp-encoded receipts // the length of two rlp-encoded receipts
assert_eq!(597, rlp_result.unwrap().1.out().len()); assert_eq!(603, rlp_result.unwrap().1.out().len());
let mut sync = dummy_sync_with_peer(H256::new()); let mut sync = dummy_sync_with_peer(H256::new());
io.sender = Some(2usize); io.sender = Some(2usize);