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

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed May 6, 2023
1 parent 496c688 commit 32e3b28
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 186 deletions.
67 changes: 25 additions & 42 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
//! Cumulus Collator implementation for Substrate.
use cumulus_primitives_core::{
relay_chain::Hash as PHash, CollectCollationInfo,
PersistedValidationData,
relay_chain::Hash as PHash, CollectCollationInfo, PersistedValidationData,
};

use sc_client_api::BlockBackend;
Expand Down Expand Up @@ -118,11 +117,7 @@ where

let block_hash = candidate.block.header().hash();

let (collation, b) = self.service.build_collation(
&last_head,
block_hash,
candidate,
)?;
let (collation, b) = self.service.build_collation(&last_head, block_hash, candidate)?;

tracing::info!(
target: LOG_TARGET,
Expand Down Expand Up @@ -155,17 +150,16 @@ where
/// This method of driving collators is not suited to anything but the most simple parachain
/// consensus mechanisms, and this module may soon be deprecated.
pub mod relay_chain_driven {
use futures::{prelude::*, channel::{mpsc, oneshot}};
use polkadot_primitives::{CollatorPair, Id as ParaId};
use polkadot_overseer::Handle as OverseerHandle;
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
use polkadot_node_primitives::{
CollationGenerationConfig, CollationResult,
use futures::{
channel::{mpsc, oneshot},
prelude::*,
};
use polkadot_node_primitives::{CollationGenerationConfig, CollationResult};
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
use polkadot_overseer::Handle as OverseerHandle;
use polkadot_primitives::{CollatorPair, Id as ParaId};

use cumulus_primitives_core::{
relay_chain::Hash as PHash, PersistedValidationData,
};
use cumulus_primitives_core::{relay_chain::Hash as PHash, PersistedValidationData};

/// A request to author a collation, based on the advancement of the relay chain.
///
Expand Down Expand Up @@ -215,11 +209,8 @@ pub mod relay_chain_driven {
let validation_data = validation_data.clone();
Box::pin(async move {
let (this_tx, this_rx) = oneshot::channel();
let request = CollationRequest {
relay_parent,
pvd: validation_data,
sender: this_tx,
};
let request =
CollationRequest { relay_parent, pvd: validation_data, sender: this_tx };

if stream_tx.send(request).await.is_err() {
return None
Expand Down Expand Up @@ -273,30 +264,22 @@ pub async fn start_collator<Block, RA, BS, Spawner>(
RA: ProvideRuntimeApi<Block> + Send + Sync + 'static,
RA::Api: CollectCollationInfo<Block>,
{
let collator_service = CollatorService::new(
block_status,
Arc::new(spawner.clone()),
announce_block,
runtime_api,
);
let collator_service =
CollatorService::new(block_status, Arc::new(spawner.clone()), announce_block, runtime_api);

let collator = Collator::new(
collator_service,
parachain_consensus,
);
let collator = Collator::new(collator_service, parachain_consensus);

let mut request_stream = relay_chain_driven::init(
key,
para_id,
overseer_handle,
).await;
let mut request_stream = relay_chain_driven::init(key, para_id, overseer_handle).await;

let collation_future = Box::pin(async move {
while let Some(request) = request_stream.next().await {
let collation = collator.clone().produce_candidate(
*request.relay_parent(),
request.persisted_validation_data().clone(),
).await;
let collation = collator
.clone()
.produce_candidate(
*request.relay_parent(),
request.persisted_validation_data().clone(),
)
.await;

request.complete(collation);
}
Expand All @@ -310,15 +293,15 @@ mod tests {
use super::*;
use async_trait::async_trait;
use cumulus_client_consensus_common::ParachainCandidate;
use cumulus_primitives_core::ParachainBlockData;
use cumulus_test_client::{
Client, ClientBlockImportExt, DefaultTestClientBuilderExt, InitBlockBuilder,
TestClientBuilder, TestClientBuilderExt,
};
use cumulus_test_runtime::{Block, Header};
use cumulus_primitives_core::ParachainBlockData;
use futures::{channel::mpsc, executor::block_on, StreamExt};
use polkadot_node_subsystem_test_helpers::ForwardSubsystem;
use polkadot_node_subsystem::messages::CollationGenerationMessage;
use polkadot_node_subsystem_test_helpers::ForwardSubsystem;
use polkadot_overseer::{dummy::dummy_overseer_builder, HeadSupportsParachains};
use sp_consensus::BlockOrigin;
use sp_core::{testing::TaskExecutor, Pair};
Expand Down
30 changes: 17 additions & 13 deletions client/collator/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
//! operations used in parachain consensus/authoring.
use cumulus_client_network::WaitToAnnounce;
use cumulus_primitives_core::{
CollationInfo, CollectCollationInfo, ParachainBlockData,
};
use cumulus_primitives_core::{CollationInfo, CollectCollationInfo, ParachainBlockData};

use sc_client_api::BlockBackend;
use sp_api::{ApiExt, ProvideRuntimeApi};
Expand All @@ -30,8 +28,7 @@ use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT, Zero};

use cumulus_client_consensus_common::ParachainCandidate;
use polkadot_node_primitives::{
BlockData, Collation, MaybeCompressedPoV, PoV,
CollationSecondedSignal,
BlockData, Collation, CollationSecondedSignal, MaybeCompressedPoV, PoV,
};

use codec::Encode;
Expand Down Expand Up @@ -63,7 +60,10 @@ pub trait ServiceInterface<Block: BlockT> {

/// Inform networking systems that the block should be announced after an appropriate
/// signal has been received. This returns the sending half of the signal.
fn announce_with_barrier(&self, block_hash: Block::Hash) -> oneshot::Sender<CollationSecondedSignal>;
fn announce_with_barrier(
&self,
block_hash: Block::Hash,
) -> oneshot::Sender<CollationSecondedSignal>;
}

/// The [`CollatorService`] provides common utilities for parachain consensus and authoring.
Expand Down Expand Up @@ -237,9 +237,9 @@ where

let block_data = ParachainBlockData::<Block>::new(header, extrinsics, compact_proof);

let pov = polkadot_node_primitives::maybe_compress_pov(
PoV { block_data: BlockData(block_data.encode()) },
);
let pov = polkadot_node_primitives::maybe_compress_pov(PoV {
block_data: BlockData(block_data.encode()),
});

let upward_messages = collation_info
.upward_messages
Expand Down Expand Up @@ -279,7 +279,10 @@ where

/// Inform the networking systems that the block should be announced after an appropriate
/// signal has been received. This returns the sending half of the signal.
pub fn announce_with_barrier(&self, block_hash: Block::Hash) -> oneshot::Sender<CollationSecondedSignal> {
pub fn announce_with_barrier(
&self,
block_hash: Block::Hash,
) -> oneshot::Sender<CollationSecondedSignal> {
let (result_sender, signed_stmt_recv) = oneshot::channel();
self.wait_to_announce.lock().wait_to_announce(block_hash, signed_stmt_recv);
result_sender
Expand All @@ -306,9 +309,10 @@ where
CollatorService::build_collation(self, parent_header, block_hash, candidate)
}

fn announce_with_barrier(&self, block_hash: Block::Hash)
-> oneshot::Sender<CollationSecondedSignal>
{
fn announce_with_barrier(
&self,
block_hash: Block::Hash,
) -> oneshot::Sender<CollationSecondedSignal> {
CollatorService::announce_with_barrier(self, block_hash)
}
}
Loading

0 comments on commit 32e3b28

Please sign in to comment.