Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
74c6876
Initial commit
cecton Feb 14, 2020
3d0a82f
Use cecton-start-collator for polkadot
cecton Feb 14, 2020
1a07ba1
WIP
cecton Feb 14, 2020
1f2fce7
WIP
cecton Feb 14, 2020
cca92fd
WIP
cecton Feb 14, 2020
680578b
WIP
cecton Feb 14, 2020
4c6b5c9
WIP
cecton Feb 17, 2020
919a6f8
WIP
cecton Feb 17, 2020
a0feb45
WIP
cecton Feb 17, 2020
4b63f7c
WIP
cecton Feb 17, 2020
1a495a0
WIP
cecton Feb 17, 2020
373e3f1
Update substrate branch to cecton-start-collator
cecton Feb 17, 2020
930aa6d
Update Cargo.lock
cecton Feb 17, 2020
3952bd5
Update Cargo.lock
cecton Feb 17, 2020
1f5191f
Update Cargo.lock
cecton Feb 17, 2020
cd08979
Update Cargo.lock
cecton Feb 17, 2020
5134aa5
Update Cargo.lock
cecton Feb 17, 2020
f9d7ecd
Update Cargo.lock
cecton Feb 18, 2020
8a1493a
WIP
cecton Feb 18, 2020
9ed020d
Update Cargo.lock
cecton Feb 18, 2020
d685eed
Update Cargo.lock
cecton Feb 18, 2020
4f6dbb0
Update Cargo.lock
cecton Feb 18, 2020
fc68c2d
Update Cargo.lock
cecton Feb 18, 2020
d0b81d0
WIP
cecton Feb 18, 2020
65c80e1
WIP
cecton Feb 18, 2020
84d29e6
Update Cargo.lock
cecton Feb 18, 2020
c8cd73c
WIP
cecton Feb 18, 2020
5a4f0ba
Update Cargo.lock
cecton Feb 20, 2020
4b97e73
Removed closure
cecton Feb 20, 2020
e26658b
Apply suggestions from code review
cecton Feb 27, 2020
c626b44
Revert "Use cecton-start-collator for polkadot"
cecton Feb 27, 2020
5832f71
Revert "Update substrate branch to cecton-start-collator"
cecton Feb 27, 2020
509ad26
Update cargo.lock branch cumulus
cecton Feb 27, 2020
94025e3
Update from parent 'origin/master' (no conflict)
cecton Feb 27, 2020
e457b3e
Fix conflict
cecton Feb 27, 2020
8b2db31
Upgrade Cargo.lock polkadot only
cecton Feb 27, 2020
cbc14e3
Apply suggestions from code review
cecton Feb 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
Forked at: ea65c31
Parent branch: origin/master
  • Loading branch information
cecton committed Feb 17, 2020
commit 919a6f8008710f94593d499d9e8b3e195de0e00e
32 changes: 16 additions & 16 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use cumulus_runtime::ParachainBlockData;

use sc_client::Client;
use sp_consensus::{
BlockImport, BlockImportParams, BlockOrigin, Environment, Error as ConsensusError,
ForkChoiceStrategy, Proposal, Proposer, RecordProof,
Expand Down Expand Up @@ -255,30 +256,33 @@ where
}

/// Implements `BuildParachainContext` to build a collator instance.
pub struct CollatorBuilder<Block, PF, BI, S> {
pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Executor, Runtime>
{
proposer_factory: PF,
inherent_data_providers: InherentDataProviders,
block_import: BI,
service: S,
para_id: ParaId,
client: Arc<Client<Backend, Executor, Block, Runtime>>,
_marker: PhantomData<Block>,
}

impl<Block, PF, BI, S> CollatorBuilder<Block, PF, BI, S> {
impl<Block: BlockT, PF, BI, Backend, Executor, Runtime>
CollatorBuilder<Block, PF, BI, Backend, Executor, Runtime>
{
/// Create a new instance of self.
pub fn new(
proposer_factory: PF,
inherent_data_providers: InherentDataProviders,
block_import: BI,
service: S,
para_id: ParaId,
client: Arc<Client<Backend, Executor, Block, Runtime>>,
) -> Self {
Self {
proposer_factory,
inherent_data_providers,
block_import,
service,
para_id,
client,
_marker: PhantomData,
}
}
Expand All @@ -287,14 +291,17 @@ impl<Block, PF, BI, S> CollatorBuilder<Block, PF, BI, S> {
type TransactionFor<E, Block> =
<<E as Environment<Block>>::Proposer as Proposer<Block>>::Transaction;

impl<Block: BlockT, PF, BI, S> BuildParachainContext for CollatorBuilder<Block, PF, BI, S>
impl<Block: BlockT, PF, BI, Backend, Executor, Runtime> BuildParachainContext
for CollatorBuilder<Block, PF, BI, Backend, Executor, Runtime>
where
S: sc_service::AbstractService,
PF: Environment<Block> + Send + 'static,
BI: BlockImport<Block, Error = sp_consensus::Error, Transaction = TransactionFor<PF, Block>>
+ Send
+ Sync
+ 'static,
Backend: sc_client_api::Backend<Block> + 'static,
Executor: sc_client_api::CallExecutor<Block> + Send + Sync + 'static,
Runtime: Send + Sync + 'static,
{
type ParachainContext = Collator<Block, PF, BI>;

Expand All @@ -319,10 +326,8 @@ where
// Rust bug: https://github.com/rust-lang/rust/issues/24159
B::State: sp_api::StateBackend<sp_core::Blake2Hasher>,
{
let client = self.service.client();

let follow =
match cumulus_consensus::follow_polkadot(self.para_id, client, polkadot_client) {
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
Ok(follow) => follow,
Err(e) => {
return Err(error!("Could not start following polkadot: {:?}", e));
Expand All @@ -332,12 +337,7 @@ where
spawner
.spawn_obj(
Box::new(
future::select(
self.service
.map_err(|e| error!("Parachain service error: {:?}", e)),
follow,
)
.map(|_| ()),
follow.map(|_| ()),
)
.into(),
)
Expand Down
46 changes: 33 additions & 13 deletions test/parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use polkadot_service::IsKusama;

use cumulus_collator::CollatorBuilder;

use futures::{future, task::Spawn, FutureExt, TryFutureExt};
use futures::{future, task::Spawn, FutureExt, TryFutureExt, select, pin_mut};

use log::error;

Expand Down Expand Up @@ -102,25 +102,45 @@ pub fn run_collator<E: sc_service::ChainSpecExtension>(
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.build()?;

let builder = || {
let proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};

let block_import = service.client();
let proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};

let builder = CollatorBuilder::new(
let block_import = service.client();
let client = service.client();
let builder = move || {
CollatorBuilder::new(
proposer_factory,
inherent_data_providers,
block_import,
service,
crate::PARA_ID,
);
client,
)
};

/*
let f = async {
//let f: Box<dyn future::Future<Output = Result<(), sc_cli::error::Error>>> = async {
let polkadot_future = polkadot_collator::build_collator(polkadot_config, crate::PARA_ID, key, Box::new(builder)).fuse();
let parachain_future = service.map(|_| ());

pin_mut!(polkadot_future, parachain_future);

select! {
_ = polkadot_future => {
return Err(sc_cli::error::Error::Other("boo".into()));
},
_ = parachain_future => {},
}

builder
Ok(())
};
*/
let polkadot_future = polkadot_collator::build_collator(polkadot_config, crate::PARA_ID, key, Box::new(builder));
let parachain_future = service.map_err(|e| error!("Parachain service error: {:?}", e));
let f = future::select(polkadot_future, parachain_future).map(|_| Ok(()));

Ok(polkadot_collator::build_collator(polkadot_config, crate::PARA_ID, key, Box::new(builder)))
Ok(f)
})
}