Skip to content

Commit 46c83b3

Browse files
nazar-pcbkchr
authored andcommitted
Block import cleanups (paritytech#4842)
I carried these things in a fork for a long time, I think wouldn't hurt to have it upstream. Originally submitted as part of paritytech#1598 that went nowhere. --------- Co-authored-by: Bastian Köcher <git@kchr.de>
1 parent 4c52973 commit 46c83b3

4 files changed

Lines changed: 9 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/client/consensus/common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ targets = ["x86_64-unknown-linux-gnu"]
1818
[dependencies]
1919
async-trait = "0.1.79"
2020
futures = { version = "0.3.30", features = ["thread-pool"] }
21-
futures-timer = "3.0.1"
2221
log = { workspace = true, default-features = true }
2322
mockall = "0.11.3"
2423
parking_lot = "0.12.1"

substrate/client/consensus/common/src/import_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ pub trait Verifier<B: BlockT>: Send {
104104
///
105105
/// The `import_*` methods can be called in order to send elements for the import queue to verify.
106106
pub trait ImportQueueService<B: BlockT>: Send {
107-
/// Import bunch of blocks.
107+
/// Import bunch of blocks, every next block must be an ancestor of the previous block in the
108+
/// list.
108109
fn import_blocks(&mut self, origin: BlockOrigin, blocks: Vec<IncomingBlock<B>>);
109110

110111
/// Import block justifications.

substrate/client/consensus/common/src/import_queue/basic_queue.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use futures::{
1919
prelude::*,
2020
task::{Context, Poll},
2121
};
22-
use futures_timer::Delay;
2322
use log::{debug, trace};
2423
use prometheus_endpoint::Registry;
2524
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
@@ -28,7 +27,7 @@ use sp_runtime::{
2827
traits::{Block as BlockT, Header as HeaderT, NumberFor},
2928
Justification, Justifications,
3029
};
31-
use std::{pin::Pin, time::Duration};
30+
use std::pin::Pin;
3231

3332
use crate::{
3433
import_queue::{
@@ -224,7 +223,6 @@ async fn block_import_process<B: BlockT>(
224223
mut result_sender: BufferedLinkSender<B>,
225224
mut block_import_receiver: TracingUnboundedReceiver<worker_messages::ImportBlocks<B>>,
226225
metrics: Option<Metrics>,
227-
delay_between_blocks: Duration,
228226
) {
229227
loop {
230228
let worker_messages::ImportBlocks(origin, blocks) = match block_import_receiver.next().await
@@ -239,15 +237,9 @@ async fn block_import_process<B: BlockT>(
239237
},
240238
};
241239

242-
let res = import_many_blocks(
243-
&mut block_import,
244-
origin,
245-
blocks,
246-
&mut verifier,
247-
delay_between_blocks,
248-
metrics.clone(),
249-
)
250-
.await;
240+
let res =
241+
import_many_blocks(&mut block_import, origin, blocks, &mut verifier, metrics.clone())
242+
.await;
251243

252244
result_sender.blocks_processed(res.imported, res.block_count, res.results);
253245
}
@@ -276,13 +268,11 @@ impl<B: BlockT> BlockImportWorker<B> {
276268
let (justification_sender, mut justification_port) =
277269
tracing_unbounded("mpsc_import_queue_worker_justification", 100_000);
278270

279-
let (block_import_sender, block_import_port) =
271+
let (block_import_sender, block_import_receiver) =
280272
tracing_unbounded("mpsc_import_queue_worker_blocks", 100_000);
281273

282274
let mut worker = BlockImportWorker { result_sender, justification_import, metrics };
283275

284-
let delay_between_blocks = Duration::default();
285-
286276
let future = async move {
287277
// Let's initialize `justification_import`
288278
if let Some(justification_import) = worker.justification_import.as_mut() {
@@ -295,9 +285,8 @@ impl<B: BlockT> BlockImportWorker<B> {
295285
block_import,
296286
verifier,
297287
worker.result_sender.clone(),
298-
block_import_port,
288+
block_import_receiver,
299289
worker.metrics.clone(),
300-
delay_between_blocks,
301290
);
302291
futures::pin_mut!(block_import_process);
303292

@@ -394,7 +383,6 @@ async fn import_many_blocks<B: BlockT, V: Verifier<B>>(
394383
blocks_origin: BlockOrigin,
395384
blocks: Vec<IncomingBlock<B>>,
396385
verifier: &mut V,
397-
delay_between_blocks: Duration,
398386
metrics: Option<Metrics>,
399387
) -> ImportManyBlocksResult<B> {
400388
let count = blocks.len();
@@ -460,11 +448,7 @@ async fn import_many_blocks<B: BlockT, V: Verifier<B>>(
460448

461449
results.push((import_result, block_hash));
462450

463-
if delay_between_blocks != Duration::default() && !has_error {
464-
Delay::new(delay_between_blocks).await;
465-
} else {
466-
Yield::new().await
467-
}
451+
Yield::new().await
468452
}
469453
}
470454

0 commit comments

Comments
 (0)