mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Keep unpinned blocks for a while before announcing (#83)
* Initial commit Forked at:d4562c3a48Parent branch: origin/master * Change substrate and polkadot branch to cecton-cumulus-branch * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * update .editorconfig * should probably be --dev * formatting * Change substrate & polkadot branch to cecton-keep-unpinned-para-blocks * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * Update polkadot & substrate branches * WIP Forked at:d4562c3a48Parent branch: origin/master * Some fixes * Updated polkadot * WIP Forked at:d4562c3a48Parent branch: origin/master * WIP Forked at:d4562c3a48Parent branch: origin/master * Cargo.lock * WIP Forked at:e81bbaaefaParent branch: origin/master * WIP Forked at:e81bbaaefaParent branch: origin/master * Update substrate & polkadot branches * Clean-up * WIP Forked at:e81bbaaefaParent branch: origin/master * WIP Forked at:e81bbaaefaParent branch: origin/master * WIP Forked at:e81bbaaefaParent branch: origin/master * WIP Forked at:e81bbaaefaParent branch: origin/master * WIP Forked at:e81bbaaefaParent branch: origin/master * Use JustifiedBlockAnnounceValidator * debug * Revert "debug" This reverts commit 2404121b840984d6ffc1012ccec1e6a784fa236c. * Revert "Use JustifiedBlockAnnounceValidator" This reverts commit 33e2efef21a1553c294b2bc23fca8b08bf77be2b. * Revert branch to cumulus-branch * clean-up * clean-up * cleanup * cleanup * Update branches * debug * Cancel previous task when new one is created * Remove stream-cancel * Clean-up * cleanup * cleanup * Fix merge issue * Update polkadot_chainspec.json * Update network/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update network/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Use closure instead of NetworkService to announce_block * doc * WIP Forked at:e81bbaaefaParent branch: origin/master * Move disable announcement to its own function with doc * Change substrate and polkadot branch to cumulus-master Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -24,8 +24,9 @@ polkadot-validation = { git = "https://github.com/paritytech/polkadot", branch =
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-consensus = { path = "../consensus" }
|
||||
cumulus-runtime = { path = "../runtime" }
|
||||
cumulus-network = { path = "../network" }
|
||||
cumulus-primitives = { path = "../primitives" }
|
||||
cumulus-runtime = { path = "../runtime" }
|
||||
|
||||
# Other dependencies
|
||||
log = "0.4.8"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! Cumulus Collator implementation for Substrate.
|
||||
|
||||
use cumulus_network::WaitToAnnounce;
|
||||
use cumulus_primitives::{
|
||||
inherents::VALIDATION_FUNCTION_PARAMS_IDENTIFIER as VFP_IDENT,
|
||||
validation_function_params::ValidationFunctionParams,
|
||||
@@ -30,6 +31,7 @@ use sp_inherents::{InherentData, InherentDataProviders};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, HashFor};
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sc_client_api::{StateBackend, UsageProvider, Finalizer, BlockchainEvents};
|
||||
use sc_service::Configuration;
|
||||
|
||||
use polkadot_collator::{
|
||||
BuildParachainContext, InvalidHead, Network as CollatorNetwork, ParachainContext,
|
||||
@@ -44,7 +46,8 @@ use codec::{Decode, Encode};
|
||||
|
||||
use log::{error, trace};
|
||||
|
||||
use futures::{task::Spawn, Future, future, FutureExt};
|
||||
use futures::task::Spawn;
|
||||
use futures::prelude::*;
|
||||
|
||||
use std::{fmt::Debug, marker::PhantomData, sync::Arc, time::Duration, pin::Pin};
|
||||
|
||||
@@ -57,28 +60,39 @@ struct HeadData<Block: BlockT> {
|
||||
}
|
||||
|
||||
/// The implementation of the Cumulus `Collator`.
|
||||
pub struct Collator<Block, PF, BI> {
|
||||
pub struct Collator<Block: BlockT, PF, BI> {
|
||||
proposer_factory: Arc<Mutex<PF>>,
|
||||
_phantom: PhantomData<Block>,
|
||||
inherent_data_providers: InherentDataProviders,
|
||||
collator_network: Arc<dyn CollatorNetwork>,
|
||||
block_import: Arc<Mutex<BI>>,
|
||||
wait_to_announce: Arc<Mutex<WaitToAnnounce<Block>>>,
|
||||
}
|
||||
|
||||
impl<Block, PF, BI> Collator<Block, PF, BI> {
|
||||
impl<Block: BlockT, PF, BI> Collator<Block, PF, BI> {
|
||||
/// Create a new instance.
|
||||
fn new(
|
||||
proposer_factory: PF,
|
||||
inherent_data_providers: InherentDataProviders,
|
||||
collator_network: impl CollatorNetwork + Clone + 'static,
|
||||
block_import: BI,
|
||||
spawner: Arc<dyn Spawn + Send + Sync>,
|
||||
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
|
||||
) -> Self {
|
||||
let collator_network = Arc::new(collator_network);
|
||||
let wait_to_announce = Arc::new(Mutex::new(WaitToAnnounce::new(
|
||||
spawner,
|
||||
announce_block,
|
||||
collator_network.clone(),
|
||||
)));
|
||||
|
||||
Self {
|
||||
proposer_factory: Arc::new(Mutex::new(proposer_factory)),
|
||||
inherent_data_providers,
|
||||
_phantom: PhantomData,
|
||||
collator_network: Arc::new(collator_network),
|
||||
collator_network,
|
||||
block_import: Arc::new(Mutex::new(block_import)),
|
||||
wait_to_announce,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +129,7 @@ impl<Block, PF, BI> Collator<Block, PF, BI> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, PF, BI> Clone for Collator<Block, PF, BI> {
|
||||
impl<Block: BlockT, PF, BI> Clone for Collator<Block, PF, BI> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
proposer_factory: self.proposer_factory.clone(),
|
||||
@@ -123,6 +137,7 @@ impl<Block, PF, BI> Clone for Collator<Block, PF, BI> {
|
||||
_phantom: PhantomData,
|
||||
collator_network: self.collator_network.clone(),
|
||||
block_import: self.block_import.clone(),
|
||||
wait_to_announce: self.wait_to_announce.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +162,7 @@ where
|
||||
|
||||
fn produce_candidate(
|
||||
&mut self,
|
||||
_relay_chain_parent: PHash,
|
||||
relay_chain_parent: PHash,
|
||||
global_validation: GlobalValidationSchedule,
|
||||
local_validation: LocalValidationData,
|
||||
) -> Self::ProduceCandidate {
|
||||
@@ -169,6 +184,8 @@ where
|
||||
.lock()
|
||||
.init(&last_head.header);
|
||||
|
||||
let wait_to_announce = self.wait_to_announce.clone();
|
||||
|
||||
Box::pin(async move {
|
||||
let parent_state_root = *last_head.header.state_root();
|
||||
|
||||
@@ -245,8 +262,11 @@ where
|
||||
}
|
||||
|
||||
let block_data = BlockData(b.encode());
|
||||
let header = b.into_header();
|
||||
let encoded_header = header.encode();
|
||||
let hash = header.hash();
|
||||
let head_data = HeadData::<Block> {
|
||||
header: b.into_header(),
|
||||
header,
|
||||
};
|
||||
|
||||
let candidate = (
|
||||
@@ -254,6 +274,12 @@ where
|
||||
parachain::HeadData(head_data.encode()),
|
||||
);
|
||||
|
||||
wait_to_announce.lock().wait_to_announce(
|
||||
hash,
|
||||
relay_chain_parent,
|
||||
encoded_header,
|
||||
);
|
||||
|
||||
trace!(target: "cumulus-collator", "Produced candidate: {:?}", candidate);
|
||||
|
||||
Ok(candidate)
|
||||
@@ -268,6 +294,7 @@ pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Client> {
|
||||
block_import: BI,
|
||||
para_id: ParaId,
|
||||
client: Arc<Client>,
|
||||
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
|
||||
_marker: PhantomData<(Block, Backend)>,
|
||||
}
|
||||
|
||||
@@ -281,6 +308,7 @@ impl<Block: BlockT, PF, BI, Backend, Client>
|
||||
block_import: BI,
|
||||
para_id: ParaId,
|
||||
client: Arc<Client>,
|
||||
announce_block: Arc<dyn Fn(Block::Hash, Vec<u8>) + Send + Sync>,
|
||||
) -> Self {
|
||||
Self {
|
||||
proposer_factory,
|
||||
@@ -288,6 +316,7 @@ impl<Block: BlockT, PF, BI, Backend, Client>
|
||||
block_import,
|
||||
para_id,
|
||||
client,
|
||||
announce_block,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -313,7 +342,7 @@ where
|
||||
self,
|
||||
polkadot_client: Arc<PClient>,
|
||||
spawner: Spawner,
|
||||
network: impl CollatorNetwork + Clone + 'static,
|
||||
polkadot_network: impl CollatorNetwork + Clone + 'static,
|
||||
) -> Result<Self::ParachainContext, ()>
|
||||
where
|
||||
PClient: ProvideRuntimeApi<PBlock> + Send + Sync + BlockchainEvents<PBlock> + 'static,
|
||||
@@ -342,12 +371,24 @@ where
|
||||
Ok(Collator::new(
|
||||
self.proposer_factory,
|
||||
self.inherent_data_providers,
|
||||
network,
|
||||
polkadot_network,
|
||||
self.block_import,
|
||||
Arc::new(spawner),
|
||||
self.announce_block,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepare the collator's node condifugration
|
||||
///
|
||||
/// This function will disable the default announcement of Substrate for the parachain in favor
|
||||
/// of the one of Cumulus.
|
||||
pub fn prepare_collator_config(mut parachain_config: Configuration) -> Configuration {
|
||||
parachain_config.announce_block = false;
|
||||
|
||||
parachain_config
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -460,6 +501,7 @@ mod tests {
|
||||
let id = ParaId::from(100);
|
||||
let _ = env_logger::try_init();
|
||||
let spawner = futures::executor::ThreadPool::new().unwrap();
|
||||
let announce_block = |_, _| ();
|
||||
|
||||
let builder = CollatorBuilder::new(
|
||||
DummyFactory,
|
||||
@@ -467,6 +509,7 @@ mod tests {
|
||||
TestClientBuilder::new().build(),
|
||||
id,
|
||||
Arc::new(TestClientBuilder::new().build()),
|
||||
Arc::new(announce_block),
|
||||
);
|
||||
let context = builder
|
||||
.build(
|
||||
|
||||
Reference in New Issue
Block a user