Skip to content

Commit f1f315c

Browse files
Juhyung Parkmergify[bot]
authored andcommitted
Split import_verified_headers method
1 parent 5536779 commit f1f315c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/src/client/importer.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::time::Instant;
2121

2222
use cio::IoChannel;
2323
use kvdb::DBTransaction;
24-
use parking_lot::Mutex;
24+
use parking_lot::{Mutex, MutexGuard};
2525
use primitives::H256;
2626
use rlp::Encodable;
2727

@@ -365,14 +365,24 @@ impl Importer {
365365
/// This is triggered by a message coming from a header queue when the header is ready for insertion
366366
pub fn import_verified_headers(&self, client: &Client) -> usize {
367367
let max_headers_to_import = 256;
368+
let lock = self.import_lock.lock();
369+
let headers = self.header_queue.drain(max_headers_to_import);
370+
self.import_headers(&headers, client, &lock)
371+
}
368372

369-
let _lock = self.import_lock.lock();
373+
fn import_headers<'a>(
374+
&'a self,
375+
headers: impl IntoIterator<Item = &'a Header>,
376+
client: &Client,
377+
_importer_lock: &MutexGuard<()>,
378+
) -> usize {
370379
let prev_best_proposal_header_hash = client.block_chain().best_proposal_header().hash();
371380

372381
let mut bad = HashSet::new();
373382
let mut imported = Vec::new();
374383
let mut routes = Vec::new();
375-
for header in self.header_queue.drain(max_headers_to_import) {
384+
385+
for header in headers {
376386
let hash = header.hash();
377387
ctrace!(CLIENT, "Importing header {}", header.number());
378388

0 commit comments

Comments
 (0)