Do not queue empty blocks set for import (#431)

* do not queue empty blocks set for import

* fixed grumbles
This commit is contained in:
Svyatoslav Nikolsky
2018-07-27 17:09:31 +03:00
committed by Gav Wood
parent 94be7783e2
commit 4491a9fac5
2 changed files with 25 additions and 1 deletions
@@ -133,6 +133,10 @@ impl<B: BlockT> ImportQueue<B> for AsyncImportQueue<B> {
}
fn import_blocks(&self, _sync: &mut ChainSync<B>, _protocol: &mut Context<B>, blocks: (BlockOrigin, Vec<BlockData<B>>)) {
if blocks.1.is_empty() {
return;
}
trace!(target:"sync", "Scheduling {} blocks for import", blocks.1.len());
let mut queue = self.data.queue.lock();
@@ -249,6 +253,16 @@ fn import_many_blocks<'a, B: BlockT>(
let count = blocks.len();
let mut imported = 0;
let blocks_range = match (
blocks.first().and_then(|b| b.block.header.as_ref().map(|h| h.number())),
blocks.last().and_then(|b| b.block.header.as_ref().map(|h| h.number())),
) {
(Some(first), Some(last)) if first != last => format!(" ({}..{})", first, last),
(Some(first), Some(_)) => format!(" ({})", first),
_ => Default::default(),
};
trace!(target:"sync", "Starting import of {} blocks{}", count, blocks_range);
// Blocks in the response/drain should be in ascending order.
for block in blocks {
let import_result = import_single_block(link.chain(), blocks_origin.clone(), block);
+11 -1
View File
@@ -353,7 +353,17 @@ impl<B: BlockT, S: Specialization<B>> Protocol<B, S> {
fn on_block_response(&self, io: &mut SyncIo, peer: NodeIndex, request: message::BlockRequest<B>, response: message::BlockResponse<B>) {
// TODO: validate response
trace!(target: "sync", "BlockResponse {} from {} with {} blocks", response.id, peer, response.blocks.len());
let blocks_range = match (
response.blocks.first().and_then(|b| b.header.as_ref().map(|h| h.number())),
response.blocks.last().and_then(|b| b.header.as_ref().map(|h| h.number())),
) {
(Some(first), Some(last)) if first != last => format!(" ({}..{})", first, last),
(Some(first), Some(_)) => format!(" ({})", first),
_ => Default::default(),
};
trace!(target: "sync", "BlockResponse {} from {} with {} blocks{}",
response.id, peer, response.blocks.len(), blocks_range);
self.sync.write().on_block_data(&mut ProtocolContext::new(&self.context_data, io), peer, request, response);
}