Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 3839099

Browse files
authored
* Companion for paritytech/substrate#12764 * Remove `async-trait` * Fix trait * update lockfile for {"substrate", "polkadot"} Co-authored-by: parity-processbot <>
1 parent 40c197d commit 3839099

File tree

7 files changed

+260
-320
lines changed

7 files changed

+260
-320
lines changed

Cargo.lock

Lines changed: 190 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/pov-recovery/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//! make sure that the blocks are imported in the correct order.
4343
4444
use sc_client_api::{BlockBackend, BlockchainEvents, UsageProvider};
45-
use sc_consensus::import_queue::{ImportQueue, IncomingBlock};
45+
use sc_consensus::import_queue::{ImportQueueService, IncomingBlock};
4646
use sp_consensus::{BlockOrigin, BlockStatus};
4747
use sp_runtime::{
4848
generic::BlockId,
@@ -103,7 +103,7 @@ impl RecoveryDelay {
103103
}
104104

105105
/// Encapsulates the logic of the pov recovery.
106-
pub struct PoVRecovery<Block: BlockT, PC, IQ, RC> {
106+
pub struct PoVRecovery<Block: BlockT, PC, RC> {
107107
/// All the pending candidates that we are waiting for to be imported or that need to be
108108
/// recovered when `next_candidate_to_recover` tells us to do so.
109109
pending_candidates: HashMap<Block::Hash, PendingCandidate<Block>>,
@@ -119,23 +119,22 @@ pub struct PoVRecovery<Block: BlockT, PC, IQ, RC> {
119119
waiting_for_parent: HashMap<Block::Hash, Vec<Block>>,
120120
recovery_delay: RecoveryDelay,
121121
parachain_client: Arc<PC>,
122-
parachain_import_queue: IQ,
122+
parachain_import_queue: Box<dyn ImportQueueService<Block>>,
123123
relay_chain_interface: RC,
124124
para_id: ParaId,
125125
}
126126

127-
impl<Block: BlockT, PC, IQ, RCInterface> PoVRecovery<Block, PC, IQ, RCInterface>
127+
impl<Block: BlockT, PC, RCInterface> PoVRecovery<Block, PC, RCInterface>
128128
where
129129
PC: BlockBackend<Block> + BlockchainEvents<Block> + UsageProvider<Block>,
130130
RCInterface: RelayChainInterface + Clone,
131-
IQ: ImportQueue<Block>,
132131
{
133132
/// Create a new instance.
134133
pub fn new(
135134
overseer_handle: OverseerHandle,
136135
recovery_delay: RecoveryDelay,
137136
parachain_client: Arc<PC>,
138-
parachain_import_queue: IQ,
137+
parachain_import_queue: Box<dyn ImportQueueService<Block>>,
139138
relay_chain_interface: RCInterface,
140139
para_id: ParaId,
141140
) -> Self {

client/relay-chain-minimal-node/src/network.rs

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use polkadot_node_network_protocol::PeerId;
2121
use sc_network::{NetworkService, SyncState};
2222

2323
use sc_client_api::HeaderBackend;
24+
use sc_consensus::{BlockImportError, BlockImportStatus, JustificationSyncLink, Link};
2425
use sc_network_common::{
2526
config::{
2627
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig,
@@ -29,12 +30,10 @@ use sc_network_common::{
2930
service::NetworkSyncForkRequest,
3031
sync::{
3132
message::{BlockAnnouncesHandshake, BlockRequest},
32-
Metrics, SyncStatus,
33+
BadPeer, Metrics, OnBlockData, PollBlockAnnounceValidation, SyncStatus,
3334
},
3435
};
3536
use sc_service::{error::Error, Configuration, NetworkStarter, SpawnTaskHandle};
36-
use sp_consensus::BlockOrigin;
37-
use sp_runtime::Justifications;
3837

3938
use std::{iter, sync::Arc};
4039

@@ -80,7 +79,6 @@ pub(crate) fn build_collator_network(
8079
chain_sync: Box::new(chain_sync),
8180
network_config: config.network.clone(),
8281
chain: client.clone(),
83-
import_queue: Box::new(DummyImportQueue),
8482
protocol_id,
8583
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
8684
block_announce_config,
@@ -253,28 +251,6 @@ impl<B: BlockT> sc_network_common::sync::ChainSync<B> for DummyChainSync {
253251
unimplemented!("Not supported on the RPC collator")
254252
}
255253

256-
fn on_blocks_processed(
257-
&mut self,
258-
_imported: usize,
259-
_count: usize,
260-
_results: Vec<(
261-
Result<
262-
sc_consensus::BlockImportStatus<polkadot_service::NumberFor<B>>,
263-
sc_consensus::BlockImportError,
264-
>,
265-
<B as BlockT>::Hash,
266-
)>,
267-
) -> Box<
268-
dyn Iterator<
269-
Item = Result<
270-
(PeerId, sc_network_common::sync::message::BlockRequest<B>),
271-
sc_network_common::sync::BadPeer,
272-
>,
273-
>,
274-
> {
275-
Box::new(std::iter::empty())
276-
}
277-
278254
fn on_justification_import(
279255
&mut self,
280256
_hash: <B as BlockT>::Hash,
@@ -307,12 +283,7 @@ impl<B: BlockT> sc_network_common::sync::ChainSync<B> for DummyChainSync {
307283
std::task::Poll::Pending
308284
}
309285

310-
fn peer_disconnected(
311-
&mut self,
312-
_who: &PeerId,
313-
) -> Option<sc_network_common::sync::OnBlockData<B>> {
314-
None
315-
}
286+
fn peer_disconnected(&mut self, _who: &PeerId) {}
316287

317288
fn metrics(&self) -> sc_network_common::sync::Metrics {
318289
Metrics {
@@ -338,7 +309,7 @@ impl<B: BlockT> sc_network_common::sync::ChainSync<B> for DummyChainSync {
338309
fn poll(
339310
&mut self,
340311
_cx: &mut std::task::Context,
341-
) -> std::task::Poll<sc_network_common::sync::PollResult<B>> {
312+
) -> std::task::Poll<PollBlockAnnounceValidation<B::Header>> {
342313
std::task::Poll::Pending
343314
}
344315

@@ -349,37 +320,39 @@ impl<B: BlockT> sc_network_common::sync::ChainSync<B> for DummyChainSync {
349320
fn num_active_peers(&self) -> usize {
350321
0
351322
}
323+
324+
fn process_block_response_data(&mut self, _blocks_to_import: Result<OnBlockData<B>, BadPeer>) {}
352325
}
353326

354-
struct DummyImportQueue;
327+
struct DummyChainSyncService<B>(std::marker::PhantomData<B>);
355328

356-
impl sc_service::ImportQueue<Block> for DummyImportQueue {
357-
fn import_blocks(
358-
&mut self,
359-
_origin: BlockOrigin,
360-
_blocks: Vec<sc_consensus::IncomingBlock<Block>>,
361-
) {
362-
}
329+
impl<B: BlockT> NetworkSyncForkRequest<B::Hash, NumberFor<B>> for DummyChainSyncService<B> {
330+
fn set_sync_fork_request(&self, _peers: Vec<PeerId>, _hash: B::Hash, _number: NumberFor<B>) {}
331+
}
332+
333+
impl<B: BlockT> JustificationSyncLink<B> for DummyChainSyncService<B> {
334+
fn request_justification(&self, _hash: &B::Hash, _number: NumberFor<B>) {}
335+
336+
fn clear_justification_requests(&self) {}
337+
}
363338

364-
fn import_justifications(
339+
impl<B: BlockT> Link<B> for DummyChainSyncService<B> {
340+
fn blocks_processed(
365341
&mut self,
366-
_who: PeerId,
367-
_hash: Hash,
368-
_number: NumberFor<Block>,
369-
_justifications: Justifications,
342+
_imported: usize,
343+
_count: usize,
344+
_results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
370345
) {
371346
}
372347

373-
fn poll_actions(
348+
fn justification_imported(
374349
&mut self,
375-
_cx: &mut futures::task::Context,
376-
_link: &mut dyn sc_consensus::import_queue::Link<Block>,
350+
_who: PeerId,
351+
_hash: &B::Hash,
352+
_number: NumberFor<B>,
353+
_success: bool,
377354
) {
378355
}
379-
}
380356

381-
struct DummyChainSyncService<B>(std::marker::PhantomData<B>);
382-
383-
impl<B: BlockT> NetworkSyncForkRequest<B::Hash, NumberFor<B>> for DummyChainSyncService<B> {
384-
fn set_sync_fork_request(&self, _peers: Vec<PeerId>, _hash: B::Hash, _number: NumberFor<B>) {}
357+
fn request_justification(&mut self, _hash: &B::Hash, _number: NumberFor<B>) {}
385358
}

client/service/src/lib.rs

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,16 @@ use polkadot_primitives::v2::CollatorPair;
2525
use sc_client_api::{
2626
Backend as BackendT, BlockBackend, BlockchainEvents, Finalizer, UsageProvider,
2727
};
28-
use sc_consensus::{
29-
import_queue::{ImportQueue, IncomingBlock, Link, RuntimeOrigin},
30-
BlockImport,
31-
};
28+
use sc_consensus::{import_queue::ImportQueueService, BlockImport};
3229
use sc_service::{Configuration, TaskManager};
3330
use sp_api::ProvideRuntimeApi;
3431
use sp_blockchain::HeaderBackend;
35-
use sp_consensus::BlockOrigin;
3632
use sp_core::traits::SpawnNamed;
37-
use sp_runtime::{
38-
traits::{Block as BlockT, NumberFor},
39-
Justifications,
40-
};
33+
use sp_runtime::traits::Block as BlockT;
4134
use std::{sync::Arc, time::Duration};
4235

4336
/// Parameters given to [`start_collator`].
44-
pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawner, IQ> {
37+
pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawner> {
4538
pub block_status: Arc<BS>,
4639
pub client: Arc<Client>,
4740
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
@@ -50,7 +43,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawn
5043
pub relay_chain_interface: RCInterface,
5144
pub task_manager: &'a mut TaskManager,
5245
pub parachain_consensus: Box<dyn ParachainConsensus<Block>>,
53-
pub import_queue: IQ,
46+
pub import_queue: Box<dyn ImportQueueService<Block>>,
5447
pub collator_key: CollatorPair,
5548
pub relay_chain_slot_duration: Duration,
5649
}
@@ -60,7 +53,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawn
6053
/// A collator is similar to a validator in a normal blockchain.
6154
/// It is responsible for producing blocks and sending the blocks to a
6255
/// parachain validator for validation and inclusion into the relay chain.
63-
pub async fn start_collator<'a, Block, BS, Client, Backend, RCInterface, Spawner, IQ>(
56+
pub async fn start_collator<'a, Block, BS, Client, Backend, RCInterface, Spawner>(
6457
StartCollatorParams {
6558
block_status,
6659
client,
@@ -73,7 +66,7 @@ pub async fn start_collator<'a, Block, BS, Client, Backend, RCInterface, Spawner
7366
import_queue,
7467
collator_key,
7568
relay_chain_slot_duration,
76-
}: StartCollatorParams<'a, Block, BS, Client, RCInterface, Spawner, IQ>,
69+
}: StartCollatorParams<'a, Block, BS, Client, RCInterface, Spawner>,
7770
) -> sc_service::error::Result<()>
7871
where
7972
Block: BlockT,
@@ -92,7 +85,6 @@ where
9285
Spawner: SpawnNamed + Clone + Send + Sync + 'static,
9386
RCInterface: RelayChainInterface + Clone + 'static,
9487
Backend: BackendT<Block> + 'static,
95-
IQ: ImportQueue<Block> + 'static,
9688
{
9789
let consensus = cumulus_client_consensus_common::run_parachain_consensus(
9890
para_id,
@@ -139,21 +131,21 @@ where
139131
}
140132

141133
/// Parameters given to [`start_full_node`].
142-
pub struct StartFullNodeParams<'a, Block: BlockT, Client, RCInterface, IQ> {
134+
pub struct StartFullNodeParams<'a, Block: BlockT, Client, RCInterface> {
143135
pub para_id: ParaId,
144136
pub client: Arc<Client>,
145137
pub relay_chain_interface: RCInterface,
146138
pub task_manager: &'a mut TaskManager,
147139
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
148140
pub relay_chain_slot_duration: Duration,
149-
pub import_queue: IQ,
141+
pub import_queue: Box<dyn ImportQueueService<Block>>,
150142
}
151143

152144
/// Start a full node for a parachain.
153145
///
154146
/// A full node will only sync the given parachain and will follow the
155147
/// tip of the chain.
156-
pub fn start_full_node<Block, Client, Backend, RCInterface, IQ>(
148+
pub fn start_full_node<Block, Client, Backend, RCInterface>(
157149
StartFullNodeParams {
158150
client,
159151
announce_block,
@@ -162,7 +154,7 @@ pub fn start_full_node<Block, Client, Backend, RCInterface, IQ>(
162154
para_id,
163155
relay_chain_slot_duration,
164156
import_queue,
165-
}: StartFullNodeParams<Block, Client, RCInterface, IQ>,
157+
}: StartFullNodeParams<Block, Client, RCInterface>,
166158
) -> sc_service::error::Result<()>
167159
where
168160
Block: BlockT,
@@ -176,7 +168,6 @@ where
176168
for<'a> &'a Client: BlockImport<Block>,
177169
Backend: BackendT<Block> + 'static,
178170
RCInterface: RelayChainInterface + Clone + 'static,
179-
IQ: ImportQueue<Block> + 'static,
180171
{
181172
let consensus = cumulus_client_consensus_common::run_parachain_consensus(
182173
para_id,
@@ -226,36 +217,3 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
226217

227218
parachain_config
228219
}
229-
230-
/// A shared import queue
231-
///
232-
/// This is basically a hack until the Substrate side is implemented properly.
233-
#[derive(Clone)]
234-
pub struct SharedImportQueue<Block: BlockT>(Arc<parking_lot::Mutex<dyn ImportQueue<Block>>>);
235-
236-
impl<Block: BlockT> SharedImportQueue<Block> {
237-
/// Create a new instance of the shared import queue.
238-
pub fn new<IQ: ImportQueue<Block> + 'static>(import_queue: IQ) -> Self {
239-
Self(Arc::new(parking_lot::Mutex::new(import_queue)))
240-
}
241-
}
242-
243-
impl<Block: BlockT> ImportQueue<Block> for SharedImportQueue<Block> {
244-
fn import_blocks(&mut self, origin: BlockOrigin, blocks: Vec<IncomingBlock<Block>>) {
245-
self.0.lock().import_blocks(origin, blocks)
246-
}
247-
248-
fn import_justifications(
249-
&mut self,
250-
who: RuntimeOrigin,
251-
hash: Block::Hash,
252-
number: NumberFor<Block>,
253-
justifications: Justifications,
254-
) {
255-
self.0.lock().import_justifications(who, hash, number, justifications)
256-
}
257-
258-
fn poll_actions(&mut self, cx: &mut std::task::Context, link: &mut dyn Link<Block>) {
259-
self.0.lock().poll_actions(cx, link)
260-
}
261-
}

parachain-template/node/src/service.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayC
2222
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;
2323

2424
// Substrate Imports
25+
use sc_consensus::ImportQueue;
2526
use sc_executor::NativeElseWasmExecutor;
2627
use sc_network::NetworkService;
2728
use sc_network_common::service::NetworkBlock;
@@ -196,14 +197,15 @@ async fn start_node_impl(
196197
let validator = parachain_config.role.is_authority();
197198
let prometheus_registry = parachain_config.prometheus_registry().cloned();
198199
let transaction_pool = params.transaction_pool.clone();
199-
let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);
200+
let import_queue_service = params.import_queue.service();
201+
200202
let (network, system_rpc_tx, tx_handler_controller, start_network) =
201203
sc_service::build_network(sc_service::BuildNetworkParams {
202204
config: &parachain_config,
203205
client: client.clone(),
204206
transaction_pool: transaction_pool.clone(),
205207
spawn_handle: task_manager.spawn_handle(),
206-
import_queue: import_queue.clone(),
208+
import_queue: params.import_queue,
207209
block_announce_validator_builder: Some(Box::new(|_| {
208210
Box::new(block_announce_validator)
209211
})),
@@ -293,7 +295,7 @@ async fn start_node_impl(
293295
relay_chain_interface,
294296
spawner,
295297
parachain_consensus,
296-
import_queue,
298+
import_queue: import_queue_service,
297299
collator_key: collator_key.expect("Command line arguments do not allow this. qed"),
298300
relay_chain_slot_duration,
299301
};
@@ -307,7 +309,7 @@ async fn start_node_impl(
307309
para_id: id,
308310
relay_chain_interface,
309311
relay_chain_slot_duration,
310-
import_queue,
312+
import_queue: import_queue_service,
311313
};
312314

313315
start_full_node(params)?;

0 commit comments

Comments
 (0)