Code cleanup in the sync module (#11552)
* Code cleanup `flush_queue()` is mostly used by tests remove some unused params avoid clones in a few places * Consistent params naming Consistent use of log calls * Fix todo It'a actually not trivial to find out the size of these collections, likely we keep blocks from all kinds of forks in the `self.blocks`/`self.parents` collections and there's no good way to anticipate how many blocks we're going to drain. Most of the time we end up draining 0 blocks and then we drain a whole bunch of them, up to 30 000. * Revert making flush_queue() test-only Address review grumbles * More review grumbles * fix build
This commit is contained in:
@@ -178,7 +178,7 @@ struct Importer {
|
||||
}
|
||||
|
||||
/// Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue.
|
||||
/// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue.
|
||||
/// Call `import_block()` to import a block asynchronously.
|
||||
pub struct Client {
|
||||
/// Flag used to disable the client forever. Not to be confused with `liveness`.
|
||||
///
|
||||
@@ -870,7 +870,7 @@ impl Client {
|
||||
*self.on_user_defaults_change.lock() = Some(Box::new(f));
|
||||
}
|
||||
|
||||
/// Flush the block import queue.
|
||||
/// Flush the block import queue. Used mostly for tests.
|
||||
pub fn flush_queue(&self) {
|
||||
self.importer.block_queue.flush();
|
||||
while !self.importer.block_queue.is_empty() {
|
||||
@@ -1444,6 +1444,7 @@ impl ImportBlock for Client {
|
||||
return Err(EthcoreError::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
||||
}
|
||||
|
||||
// If the queue is empty we propagate the block in a `PriorityTask`.
|
||||
let raw = if self.importer.block_queue.is_empty() {
|
||||
Some((unverified.bytes.clone(), *unverified.header.difficulty()))
|
||||
} else {
|
||||
@@ -2729,6 +2730,7 @@ impl ImportExportBlocks for Client {
|
||||
}
|
||||
};
|
||||
self.flush_queue();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user