Skip to content

Commit

Permalink
New genesis (paritytech#327)
Browse files Browse the repository at this point in the history
* Update Substrate & Polkadot

* Update chainspecs

* Update again to fix test
  • Loading branch information
bkchr authored Feb 15, 2021
1 parent 886a1e1 commit ec08d11
Show file tree
Hide file tree
Showing 13 changed files with 651 additions and 607 deletions.
981 changes: 512 additions & 469 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sp_runtime::{
};
use sp_state_machine::InspectState;

use polkadot_node_primitives::{Collation, CollationGenerationConfig};
use polkadot_node_primitives::{Collation, CollationGenerationConfig, CollationResult};
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
use polkadot_overseer::OverseerHandler;
use polkadot_primitives::v1::{
Expand All @@ -48,7 +48,7 @@ use codec::{Decode, Encode};

use log::{debug, error, info, trace};

use futures::prelude::*;
use futures::{channel::oneshot, prelude::*};

use std::{marker::PhantomData, sync::Arc, time::Duration};

Expand Down Expand Up @@ -100,10 +100,10 @@ where
PF: Environment<Block> + 'static + Send,
PF::Proposer: Send,
BI: BlockImport<
Block,
Error = ConsensusError,
Transaction = <PF::Proposer as Proposer<Block>>::Transaction,
> + Send
Block,
Error = ConsensusError,
Transaction = <PF::Proposer as Proposer<Block>>::Transaction,
> + Send
+ Sync
+ 'static,
BS: BlockBackend<Block>,
Expand All @@ -120,7 +120,6 @@ where
para_id: ParaId,
proposer_factory: PF,
inherent_data_providers: InherentDataProviders,
overseer_handler: OverseerHandler,
block_import: BI,
block_status: Arc<BS>,
spawner: Arc<dyn SpawnNamed + Send + Sync>,
Expand All @@ -129,11 +128,7 @@ where
polkadot_client: Arc<PClient>,
polkadot_backend: Arc<PBackend2>,
) -> Self {
let wait_to_announce = Arc::new(Mutex::new(WaitToAnnounce::new(
spawner,
announce_block,
overseer_handler,
)));
let wait_to_announce = Arc::new(Mutex::new(WaitToAnnounce::new(spawner, announce_block)));

Self {
para_id,
Expand Down Expand Up @@ -347,7 +342,7 @@ where
mut self,
relay_parent: PHash,
validation_data: PersistedValidationData,
) -> Option<Collation> {
) -> Option<CollationResult> {
trace!(target: LOG_TARGET, "Producing candidate");

let last_head = match Block::Header::decode(&mut &validation_data.parent_head.0[..]) {
Expand Down Expand Up @@ -448,16 +443,21 @@ where
let collation = self.build_collation(b, block_hash, validation_data.relay_parent_number)?;
let pov_hash = collation.proof_of_validity.hash();

let (result_sender, signed_stmt_recv) = oneshot::channel();

self.wait_to_announce
.lock()
.wait_to_announce(block_hash, pov_hash);
.wait_to_announce(block_hash, pov_hash, signed_stmt_recv);

info!(
target: LOG_TARGET,
"Produced proof-of-validity candidate {:?} from block {:?}.", pov_hash, block_hash,
);

Some(collation)
Some(CollationResult {
collation,
result_sender: Some(result_sender),
})
}
}

Expand Down Expand Up @@ -524,7 +524,6 @@ where
para_id,
proposer_factory,
inherent_data_providers,
overseer_handler.clone(),
block_import,
block_status,
Arc::new(spawner),
Expand Down Expand Up @@ -707,7 +706,8 @@ mod tests {
validation_data.parent_head = header.encode().into();

let collation = block_on((config.collator)(relay_parent, &validation_data))
.expect("Collation is build");
.expect("Collation is build")
.collation;

let block_data = collation.proof_of_validity.block_data;

Expand Down
4 changes: 1 addition & 3 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "mas
# Polkadot deps
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-statement-table = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-overseer = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-node-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-node-subsystem = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" }

# other deps
codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] }
futures = { version = "0.3.1", features = ["compat"] }
futures-timer = "3.0.2"
log = "0.4.8"
tracing = "0.1.22"
parking_lot = "0.10.2"
derive_more = "0.99.2"

Expand Down
93 changes: 51 additions & 42 deletions client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
//! that use the relay chain provided consensus. See [`BlockAnnounceValidator`]
//! and [`WaitToAnnounce`] for more information about this implementation.
#[cfg(test)]
mod tests;
mod wait_on_relay_chain_block;

use sc_client_api::{Backend, BlockchainEvents};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
Expand All @@ -38,8 +34,6 @@ use sp_runtime::{
};

use polkadot_node_primitives::{SignedFullStatement, Statement};
use polkadot_node_subsystem::messages::StatementDistributionMessage;
use polkadot_overseer::OverseerHandler;
use polkadot_primitives::v1::{
Block as PBlock, CandidateReceipt, CompactStatement, Hash as PHash, Id as ParaId,
OccupiedCoreAssumption, ParachainHost, SignedStatement, SigningContext,
Expand All @@ -48,16 +42,19 @@ use polkadot_service::ClientHandle;

use codec::{Decode, Encode};
use futures::{
channel::{mpsc, oneshot},
channel::oneshot,
future::{ready, FutureExt},
pin_mut, select, Future, StreamExt,
pin_mut, select, Future,
};
use log::trace;

use std::{convert::TryFrom, fmt, marker::PhantomData, pin::Pin, sync::Arc};

use wait_on_relay_chain_block::WaitOnRelayChainBlock;

#[cfg(test)]
mod tests;
mod wait_on_relay_chain_block;

const LOG_TARGET: &str = "cumulus-network";

type BoxedError = Box<dyn std::error::Error + Send>;
Expand Down Expand Up @@ -90,15 +87,15 @@ impl BlockAnnounceData {
let candidate_hash = if let CompactStatement::Candidate(h) = self.statement.payload() {
h
} else {
log::debug!(
tracing::debug!(
target: LOG_TARGET,
"`CompactStatement` isn't the candidate variant!",
);
return Err(Validation::Failure { disconnect: true });
};

if *candidate_hash != self.receipt.hash() {
log::debug!(
tracing::debug!(
target: LOG_TARGET,
"Receipt candidate hash doesn't match candidate hash in statement",
);
Expand All @@ -108,7 +105,7 @@ impl BlockAnnounceData {
if polkadot_parachain::primitives::HeadData(encoded_header).hash()
!= self.receipt.descriptor.para_head
{
log::debug!(
tracing::debug!(
target: LOG_TARGET,
"Receipt para head hash doesn't match the hash of the header in the block announcement",
);
Expand All @@ -121,7 +118,10 @@ impl BlockAnnounceData {
/// Check the signature of the statement.
///
/// Returns an `Err(_)` if it failed.
fn check_signature<P>(&self, relay_chain_client: &Arc<P>) -> Result<Validation, BlockAnnounceError>
fn check_signature<P>(
&self,
relay_chain_client: &Arc<P>,
) -> Result<Validation, BlockAnnounceError>
where
P: ProvideRuntimeApi<PBlock> + Send + Sync + 'static,
P::Api: ParachainHost<PBlock>,
Expand Down Expand Up @@ -152,12 +152,12 @@ impl BlockAnnounceData {
let signer = match authorities.get(validator_index as usize) {
Some(r) => r,
None => {
log::debug!(
tracing::debug!(
target: LOG_TARGET,
"Block announcement justification signer is a validator index out of bound",
);

return Ok(Validation::Failure { disconnect: true })
return Ok(Validation::Failure { disconnect: true });
}
};

Expand All @@ -167,7 +167,7 @@ impl BlockAnnounceData {
.check_signature(&signing_context, &signer)
.is_err()
{
log::debug!(
tracing::debug!(
target: LOG_TARGET,
"Block announcement justification signature is invalid.",
);
Expand Down Expand Up @@ -301,7 +301,7 @@ where
let known_best_number = parent_head.number();

if block_number >= known_best_number {
trace!(
tracing::trace!(
target: "cumulus-network",
"validation failed because a justification is needed if the block at the top of the chain."
);
Expand Down Expand Up @@ -474,7 +474,6 @@ where
pub struct WaitToAnnounce<Block: BlockT> {
spawner: Arc<dyn SpawnNamed + Send + Sync>,
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
overseer_handler: OverseerHandler,
current_trigger: oneshot::Sender<()>,
}

Expand All @@ -483,24 +482,26 @@ impl<Block: BlockT> WaitToAnnounce<Block> {
pub fn new(
spawner: Arc<dyn SpawnNamed + Send + Sync>,
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
overseer_handler: OverseerHandler,
) -> WaitToAnnounce<Block> {
let (tx, _rx) = oneshot::channel();

WaitToAnnounce {
spawner,
announce_block,
overseer_handler,
current_trigger: tx,
}
}

/// Wait for a candidate message for the block, then announce the block. The candidate
/// message will be added as justification to the block announcement.
pub fn wait_to_announce(&mut self, block_hash: <Block as BlockT>::Hash, pov_hash: PHash) {
pub fn wait_to_announce(
&mut self,
block_hash: <Block as BlockT>::Hash,
pov_hash: PHash,
signed_stmt_recv: oneshot::Receiver<SignedFullStatement>,
) {
let (tx, rx) = oneshot::channel();
let announce_block = self.announce_block.clone();
let overseer_handler = self.overseer_handler.clone();

self.current_trigger = tx;

Expand All @@ -511,27 +512,27 @@ impl<Block: BlockT> WaitToAnnounce<Block> {
block_hash,
pov_hash,
announce_block,
overseer_handler,
signed_stmt_recv,
)
.fuse();
let t2 = rx.fuse();

pin_mut!(t1, t2);

trace!(
tracing::trace!(
target: "cumulus-network",
"waiting for announce block in a background task...",
);

select! {
_ = t1 => {
trace!(
tracing::trace!(
target: "cumulus-network",
"block announcement finished",
);
},
_ = t2 => {
trace!(
tracing::trace!(
target: "cumulus-network",
"previous task that waits for announce block has been canceled",
);
Expand All @@ -547,25 +548,33 @@ async fn wait_to_announce<Block: BlockT>(
block_hash: <Block as BlockT>::Hash,
pov_hash: PHash,
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
mut overseer_handler: OverseerHandler,
signed_stmt_recv: oneshot::Receiver<SignedFullStatement>,
) {
let (sender, mut receiver) = mpsc::channel(5);
overseer_handler
.send_msg(StatementDistributionMessage::RegisterStatementListener(
sender,
))
.await;

while let Some(statement) = receiver.next().await {
match statement.payload() {
Statement::Seconded(c) if &c.descriptor.pov_hash == &pov_hash => {
if let Ok(data) = BlockAnnounceData::try_from(statement) {
announce_block(block_hash, data.encode());
}
let statement = match signed_stmt_recv.await {
Ok(s) => s,
Err(_) => {
tracing::debug!(
target: "cumulus-network",
pov_hash = ?pov_hash,
block = ?block_hash,
"Wait to announce stopped, because sender was dropped.",
);
return;
}
};

break;
match statement.payload() {
Statement::Seconded(c) if &c.descriptor.pov_hash == &pov_hash => {
if let Ok(data) = BlockAnnounceData::try_from(statement) {
announce_block(block_hash, data.encode());
}
_ => {}
}
_ => tracing::debug!(
target: "cumulus-network",
statement = ?statement,
block = ?block_hash,
expected_pov_hash = ?pov_hash,
"Received invalid statement while waiting to announce block.",
),
}
}
2 changes: 1 addition & 1 deletion client/network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use polkadot_test_client::{
};
use sp_api::{ApiRef, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_consensus::{block_validation::BlockAnnounceValidator as _, BlockOrigin};
use sp_consensus::BlockOrigin;
use sp_core::H256;
use sp_keyring::Sr25519Keyring;
use sp_keystore::{testing::KeyStore, SyncCryptoStore, SyncCryptoStorePtr};
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-f
# Substrate dependencies
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", version = "2.0.0-rc5", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down
Loading

0 comments on commit ec08d11

Please sign in to comment.