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 all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
655dc45
Initial commit
cecton May 6, 2020
9a47c09
Added subcommand to run polkadot
cecton May 6, 2020
32e81cf
Add command validation-worker
cecton May 6, 2020
df0f832
Add storage_append to runtime
cecton May 6, 2020
892d057
WIP
cecton May 7, 2020
41f50ee
WIP
cecton May 8, 2020
214e50d
WIP
cecton May 8, 2020
cd131ff
WIP
cecton May 11, 2020
3212554
clean exit if possible
cecton May 11, 2020
0286a88
wip
cecton May 11, 2020
d38edea
WIP
cecton May 11, 2020
3d162e0
WIP
cecton May 11, 2020
62b544e
WIP
cecton May 11, 2020
17887fc
.editorconfig
cecton May 12, 2020
a0eb356
register working
cecton May 12, 2020
9961be4
WIP
cecton May 12, 2020
baa4357
clean-up
cecton May 13, 2020
fc408e4
Rename ProcessCleanUp to ChildHelper
cecton May 13, 2020
22b64de
More clean-up
cecton May 13, 2020
a978970
Runs integration test separately
cecton May 13, 2020
ee3832a
Merge commit 3acb6d0d835c3589f50bf0911729baaea41981fc (no conflict)
cecton May 13, 2020
1267f80
Merge commit c163d8702b27e542caebd0df585d45ec761edc2a (conflicts)
cecton May 13, 2020
368a582
Simplify toml
cecton May 13, 2020
de2b666
Merge commit e810cf3b5ba4b6b1a2848bc57a6302146fc54d78 (conflicts)
cecton May 13, 2020
a17dd34
Merge commit d6ab13c00f555674212b0c86620fdb504d8cf505 (no conflict)
cecton May 13, 2020
31768ce
Initial commit
cecton May 13, 2020
68b0dcf
Update substrate & polkadot branch
cecton May 13, 2020
e2f3fdc
Update test/parachain/tests/integration_test.rs
cecton May 13, 2020
0361e14
Split polkadot service creation from service building/running
cecton May 13, 2020
cde8935
Applied suggestions
cecton May 13, 2020
145ec00
Renamed _child to _helper
cecton May 13, 2020
0d21e75
Use JustifiedBlockAnnounceValidator
cecton May 13, 2020
671d5f9
Update test/parachain/tests/integration_test.rs
cecton May 14, 2020
a5c89b0
Make a function for generate_genesis_state
cecton May 14, 2020
9697b62
Move std::io::Read import
cecton May 14, 2020
a300ea9
wait_for_tcp indefinitely + remove 10s wait for relay blocks
cecton May 14, 2020
87489c5
Implement max time allowed for the test
cecton May 14, 2020
6f0075a
rpc call to monitor new blocks
cecton May 14, 2020
9c7af42
Removed unused helpers
cecton May 14, 2020
19b7942
Update test/parachain/tests/integration_test.rs
cecton May 14, 2020
6eca4f0
Not sure why I made a helper for this in the first place...
cecton May 15, 2020
6e43fd4
WIP
cecton May 15, 2020
2564cce
cleanup
cecton May 15, 2020
542eb35
CLEANUP
cecton May 15, 2020
ddb111f
Merge branch 'cecton-int-test' into cecton-use-custom-block-announce-…
cecton May 15, 2020
d985af8
WIP
cecton May 15, 2020
e4fb6aa
Apply suggestions
cecton May 15, 2020
bf68f24
Fix p2p ports
cecton May 15, 2020
8c24090
Merge branch 'cecton-int-test' into cecton-use-custom-block-announce-…
cecton May 18, 2020
a633fdd
Add test in int test scenario
cecton May 18, 2020
865542d
CLEANUP
cecton May 18, 2020
56929d6
CLEANUP
cecton May 18, 2020
0b1f21b
Merge commit e183d8bd30514d941586bb9bb6decce322572fca (no conflict)
cecton May 18, 2020
c9f95a3
Merge commit 0a7cde66102efe59f4041e5fe5603eace6443328 (conflicts)
cecton May 18, 2020
e7fe457
Refactor
cecton May 19, 2020
bb89a33
Removes some unwrap & introduce parking_lot
cecton May 19, 2020
9cc6f21
Replace match by expect
cecton May 19, 2020
5a257d6
Update network/src/lib.rs
cecton May 19, 2020
934fd5c
Add doc
cecton May 19, 2020
21dba8c
Reduce comment
cecton May 19, 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

//! Cumulus Collator implementation for Substrate.

use cumulus_network::WaitToAnnounce;
use cumulus_network::{
DelayedBlockAnnounceValidator, JustifiedBlockAnnounceValidator, WaitToAnnounce,
};
use cumulus_primitives::{
inherents::VALIDATION_FUNCTION_PARAMS_IDENTIFIER as VFP_IDENT,
validation_function_params::ValidationFunctionParams,
Expand Down Expand Up @@ -295,6 +297,7 @@ pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Client> {
para_id: ParaId,
client: Arc<Client>,
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
delayed_block_announce_validator: DelayedBlockAnnounceValidator<Block>,
_marker: PhantomData<(Block, Backend)>,
}

Expand All @@ -309,6 +312,7 @@ impl<Block: BlockT, PF, BI, Backend, Client>
para_id: ParaId,
client: Arc<Client>,
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
delayed_block_announce_validator: DelayedBlockAnnounceValidator<Block>,
) -> Self {
Self {
proposer_factory,
Expand All @@ -317,6 +321,7 @@ impl<Block: BlockT, PF, BI, Backend, Client>
para_id,
client,
announce_block,
delayed_block_announce_validator,
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -351,6 +356,10 @@ where
Spawner: Spawn + Clone + Send + Sync + 'static,
Extrinsic: codec::Codec + Send + Sync + 'static,
{
self.delayed_block_announce_validator.set(
Box::new(JustifiedBlockAnnounceValidator::new(Vec::new(), polkadot_client.clone())),
);

let follow =
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
Ok(follow) => follow,
Expand Down Expand Up @@ -502,6 +511,7 @@ mod tests {
let _ = env_logger::try_init();
let spawner = futures::executor::ThreadPool::new().unwrap();
let announce_block = |_, _| ();
let block_announce_validator = DelayedBlockAnnounceValidator::new();

let builder = CollatorBuilder::new(
DummyFactory,
Expand All @@ -510,6 +520,7 @@ mod tests {
id,
Arc::new(TestClientBuilder::new().build()),
Arc::new(announce_block),
block_announce_validator,
);
let context = builder
.build(
Expand Down
1 change: 1 addition & 0 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ polkadot-network = { git = "https://github.com/paritytech/polkadot", branch = "c
codec = { package = "parity-scale-codec", version = "1.3.0", features = [ "derive" ] }
futures = { version = "0.3.1", features = ["compat"] }
log = "0.4.8"
parking_lot = "0.10.2"
33 changes: 33 additions & 0 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use futures::task::Spawn;
use log::{error, trace};

use std::{marker::PhantomData, sync::Arc};
use parking_lot::Mutex;

/// Validate that data is a valid justification from a relay-chain validator that the block is a
/// valid parachain-block candidate.
Expand Down Expand Up @@ -148,6 +149,38 @@ where
}
}

/// A `BlockAnnounceValidator` that will be able to validate data when its internal
/// `BlockAnnounceValidator` is set.
pub struct DelayedBlockAnnounceValidator<B: BlockT>(Arc<Mutex<Option<Box<dyn BlockAnnounceValidator<B> + Send>>>>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs and especially why we do this! + an issue that we need to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should create an issue for this. And this should contain this info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Sorry, created #104

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


impl<B: BlockT> DelayedBlockAnnounceValidator<B> {
pub fn new() -> DelayedBlockAnnounceValidator<B> {
DelayedBlockAnnounceValidator(Arc::new(Mutex::new(None)))
}

pub fn set(&self, validator: Box<dyn BlockAnnounceValidator<B> + Send>) {
*self.0.lock() = Some(validator);
}
}

impl<B: BlockT> Clone for DelayedBlockAnnounceValidator<B> {
fn clone(&self) -> DelayedBlockAnnounceValidator<B> {
DelayedBlockAnnounceValidator(self.0.clone())
}
}

impl<B: BlockT> BlockAnnounceValidator<B> for DelayedBlockAnnounceValidator<B> {
fn validate(
&mut self,
header: &B::Header,
data: &[u8],
) -> Result<Validation, Box<dyn std::error::Error + Send>> {
self.0.lock().as_mut()
.expect("BlockAnnounceValidator is set before validating the first announcement; qed")
.validate(header, data)
}
}

/// Wait before announcing a block that a candidate message has been received for this block, then
/// add this message as justification for the block announcement.
///
Expand Down
1 change: 1 addition & 0 deletions test/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch
# Cumulus dependencies
cumulus-consensus = { path = "../../consensus" }
cumulus-collator = { path = "../../collator" }
cumulus-network = { path = "../../network" }

# Polkadot dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
Expand Down
7 changes: 7 additions & 0 deletions test/parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use polkadot_primitives::parachain::CollatorPair;
use cumulus_collator::{CollatorBuilder, prepare_collator_config};
use futures::FutureExt;
pub use sc_executor::NativeExecutor;
use cumulus_network::DelayedBlockAnnounceValidator;

// Our native executor instance.
native_executor_instance!(
Expand Down Expand Up @@ -78,12 +79,17 @@ pub fn run_collator(
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();

let block_announce_validator = DelayedBlockAnnounceValidator::new();
let block_announce_validator_copy = block_announce_validator.clone();
let service = builder
.with_finality_proof_provider(|client, backend| {
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.with_block_announce_validator(|_client| {
Box::new(block_announce_validator_copy)
})?
.build()?;

let proposer_factory = sc_basic_authorship::ProposerFactory::new(
Expand All @@ -104,6 +110,7 @@ pub fn run_collator(
crate::PARA_ID,
client,
announce_block,
block_announce_validator,
);

let polkadot_future = polkadot_collator::start_collator(
Expand Down
82 changes: 59 additions & 23 deletions test/parachain/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use assert_cmd::cargo::cargo_bin;
use async_std::{net, task::sleep};
use codec::Encode;
use futures::{future::FutureExt, join, pin_mut, select};
use jsonrpsee::{raw::RawClient, transport::http::HttpTransportClient};
use polkadot_primitives::parachain::{Info, Scheduling};
use polkadot_primitives::Hash as PHash;
use polkadot_runtime::{Header, OnlyStakingAndClaims, Runtime, SignedExtra, SignedPayload};
Expand Down Expand Up @@ -144,6 +145,25 @@ async fn wait_for_tcp<A: net::ToSocketAddrs + std::fmt::Display>(address: A) {
}
}

/// wait for parachain blocks to be produced
async fn wait_for_blocks(number_of_blocks: usize, mut client: &mut RawClient<HttpTransportClient>) {
let mut previous_blocks = HashSet::with_capacity(number_of_blocks);

loop {
let current_block_hash = Chain::block_hash(&mut client, None).await.unwrap().unwrap();

if previous_blocks.insert(current_block_hash) {
eprintln!("new parachain block: {}", current_block_hash);

if previous_blocks.len() == number_of_blocks {
break;
}
}

sleep(Duration::from_secs(2)).await;
}
}

#[async_std::test]
#[ignore]
async fn integration_test() {
Expand Down Expand Up @@ -310,13 +330,13 @@ async fn integration_test() {
.await
.unwrap();

// run cumulus
let cumulus_dir = tempdir().unwrap();
let mut cumulus = Command::new(cargo_bin("cumulus-test-parachain-collator"))
// run cumulus charlie
let cumulus_charlie_dir = tempdir().unwrap();
let mut cumulus_charlie = Command::new(cargo_bin("cumulus-test-parachain-collator"))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("--base-path")
.arg(cumulus_dir.path())
.arg(cumulus_charlie_dir.path())
.arg("--unsafe-rpc-expose")
.arg("--rpc-port=27017")
.arg("--port=27117")
Expand All @@ -329,35 +349,51 @@ async fn integration_test() {
"--bootnodes=/ip4/127.0.0.1/tcp/27116/p2p/{}",
polkadot_bob_id
))
.arg("--charlie")
.spawn()
.unwrap();
let cumulus_helper = ChildHelper::new("cumulus", &mut cumulus);
let cumulus_charlie_helper = ChildHelper::new("cumulus-charlie", &mut cumulus_charlie);
wait_for_tcp("127.0.0.1:27017").await;

// connect rpc client to cumulus
let transport_client_cumulus =
let transport_client_cumulus_charlie =
jsonrpsee::transport::http::HttpTransportClient::new("http://127.0.0.1:27017");
let mut client_cumulus = jsonrpsee::raw::RawClient::new(transport_client_cumulus);
let mut client_cumulus_charlie =
jsonrpsee::raw::RawClient::new(transport_client_cumulus_charlie);

// wait for parachain blocks to be produced
let number_of_blocks = 4;
let mut previous_blocks = HashSet::with_capacity(number_of_blocks);
loop {
let current_block_hash = Chain::block_hash(&mut client_cumulus, None)
.await
.unwrap()
.unwrap();
wait_for_blocks(4, &mut client_cumulus_charlie).await;

if previous_blocks.insert(current_block_hash) {
eprintln!("new parachain block: {}", current_block_hash);
// run cumulus dave
let cumulus_dave_dir = tempdir().unwrap();
let mut cumulus_dave = Command::new(cargo_bin("cumulus-test-parachain-collator"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in #96 (comment)

I also added a test in the integration test but it is not super useful, it will only detect something if the implementation is broken but not if the implementation returns always Success like the default implementation of BlockAnnounceValidator.

So for example if the implementation is broken and no block at all are validated, then we would see on Dave that no block are being imported and the test would fail.

.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("--base-path")
.arg(cumulus_dave_dir.path())
.arg("--unsafe-rpc-expose")
.arg("--rpc-port=27018")
.arg("--port=27118")
.arg("--")
.arg(format!(
"--bootnodes=/ip4/127.0.0.1/tcp/27115/p2p/{}",
polkadot_alice_id
))
.arg(format!(
"--bootnodes=/ip4/127.0.0.1/tcp/27116/p2p/{}",
polkadot_bob_id
))
.arg("--dave")
.spawn()
.unwrap();
let cumulus_dave_helper = ChildHelper::new("cumulus-dave", &mut cumulus_dave);
wait_for_tcp("127.0.0.1:27018").await;

if previous_blocks.len() == number_of_blocks {
break;
}
}
// connect rpc client to cumulus
let transport_client_cumulus_dave =
jsonrpsee::transport::http::HttpTransportClient::new("http://127.0.0.1:27018");
let mut client_cumulus_dave = jsonrpsee::raw::RawClient::new(transport_client_cumulus_dave);

sleep(Duration::from_secs(2)).await;
}
wait_for_blocks(4, &mut client_cumulus_dave).await;
}
.fuse();

Expand Down