mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 03:31:05 +00:00
Companion for Polkadot#7451 (#2807)
* Companion for Polkadot#7451 https://github.com/paritytech/polkadot/pull/7451 * Update Substrate & Polkadot * FMT * Fix integration tests * Bring back `polkadot-native` feature for now * 🤦
This commit is contained in:
Generated
+454
-340
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,6 @@ sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "maste
|
|||||||
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|
||||||
# Polkadot
|
# Polkadot
|
||||||
polkadot-client = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
|
||||||
polkadot-test-client = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
polkadot-test-client = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
||||||
|
|
||||||
# Cumulus
|
# Cumulus
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
|
|||||||
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|
||||||
# Polkadot
|
# Polkadot
|
||||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, features = ["cli"] }
|
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, features = ["cli", "polkadot-native"] }
|
||||||
polkadot-client = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
|
||||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
||||||
|
|
||||||
# Cumulus
|
# Cumulus
|
||||||
|
|||||||
@@ -27,14 +27,13 @@ use cumulus_primitives_core::{
|
|||||||
};
|
};
|
||||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
||||||
use futures::{FutureExt, Stream, StreamExt};
|
use futures::{FutureExt, Stream, StreamExt};
|
||||||
use polkadot_client::{ClientHandle, ExecuteWithClient, FullBackend};
|
|
||||||
use polkadot_service::{
|
use polkadot_service::{
|
||||||
AuxStore, BabeApi, CollatorPair, Configuration, Handle, NewFull, TaskManager,
|
CollatorPair, Configuration, FullBackend, FullClient, Handle, NewFull, TaskManager,
|
||||||
};
|
};
|
||||||
use sc_cli::SubstrateCli;
|
use sc_cli::SubstrateCli;
|
||||||
use sc_client_api::{
|
use sc_client_api::{
|
||||||
blockchain::BlockStatus, Backend, BlockchainEvents, HeaderBackend, ImportNotifications,
|
blockchain::BlockStatus, Backend, BlockchainEvents, HeaderBackend, ImportNotifications,
|
||||||
StorageProof, UsageProvider,
|
StorageProof,
|
||||||
};
|
};
|
||||||
use sc_telemetry::TelemetryWorkerHandle;
|
use sc_telemetry::TelemetryWorkerHandle;
|
||||||
use sp_api::ProvideRuntimeApi;
|
use sp_api::ProvideRuntimeApi;
|
||||||
@@ -46,17 +45,18 @@ use sp_state_machine::{Backend as StateBackend, StorageValue};
|
|||||||
const TIMEOUT_IN_SECONDS: u64 = 6;
|
const TIMEOUT_IN_SECONDS: u64 = 6;
|
||||||
|
|
||||||
/// Provides an implementation of the [`RelayChainInterface`] using a local in-process relay chain node.
|
/// Provides an implementation of the [`RelayChainInterface`] using a local in-process relay chain node.
|
||||||
pub struct RelayChainInProcessInterface<Client> {
|
#[derive(Clone)]
|
||||||
full_client: Arc<Client>,
|
pub struct RelayChainInProcessInterface {
|
||||||
|
full_client: Arc<FullClient>,
|
||||||
backend: Arc<FullBackend>,
|
backend: Arc<FullBackend>,
|
||||||
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
|
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
|
||||||
overseer_handle: Handle,
|
overseer_handle: Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Client> RelayChainInProcessInterface<Client> {
|
impl RelayChainInProcessInterface {
|
||||||
/// Create a new instance of [`RelayChainInProcessInterface`]
|
/// Create a new instance of [`RelayChainInProcessInterface`]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
full_client: Arc<Client>,
|
full_client: Arc<FullClient>,
|
||||||
backend: Arc<FullBackend>,
|
backend: Arc<FullBackend>,
|
||||||
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
|
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
|
||||||
overseer_handle: Handle,
|
overseer_handle: Handle,
|
||||||
@@ -65,29 +65,8 @@ impl<Client> RelayChainInProcessInterface<Client> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Clone for RelayChainInProcessInterface<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self {
|
|
||||||
full_client: self.full_client.clone(),
|
|
||||||
backend: self.backend.clone(),
|
|
||||||
sync_oracle: self.sync_oracle.clone(),
|
|
||||||
overseer_handle: self.overseer_handle.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<Client> RelayChainInterface for RelayChainInProcessInterface<Client>
|
impl RelayChainInterface for RelayChainInProcessInterface {
|
||||||
where
|
|
||||||
Client: ProvideRuntimeApi<PBlock>
|
|
||||||
+ HeaderBackend<PBlock>
|
|
||||||
+ BlockchainEvents<PBlock>
|
|
||||||
+ AuxStore
|
|
||||||
+ UsageProvider<PBlock>
|
|
||||||
+ Sync
|
|
||||||
+ Send,
|
|
||||||
Client::Api: ParachainHost<PBlock> + BabeApi<PBlock>,
|
|
||||||
{
|
|
||||||
async fn retrieve_dmq_contents(
|
async fn retrieve_dmq_contents(
|
||||||
&self,
|
&self,
|
||||||
para_id: ParaId,
|
para_id: ParaId,
|
||||||
@@ -269,14 +248,11 @@ pub enum BlockCheckStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to check if a block is in chain.
|
// Helper function to check if a block is in chain.
|
||||||
pub fn check_block_in_chain<Client>(
|
pub fn check_block_in_chain(
|
||||||
backend: Arc<FullBackend>,
|
backend: Arc<FullBackend>,
|
||||||
client: Arc<Client>,
|
client: Arc<FullClient>,
|
||||||
hash: PHash,
|
hash: PHash,
|
||||||
) -> RelayChainResult<BlockCheckStatus>
|
) -> RelayChainResult<BlockCheckStatus> {
|
||||||
where
|
|
||||||
Client: BlockchainEvents<PBlock>,
|
|
||||||
{
|
|
||||||
let _lock = backend.get_import_lock().read();
|
let _lock = backend.get_import_lock().read();
|
||||||
|
|
||||||
if backend.blockchain().status(hash)? == BlockStatus::InChain {
|
if backend.blockchain().status(hash)? == BlockStatus::InChain {
|
||||||
@@ -288,49 +264,6 @@ where
|
|||||||
Ok(BlockCheckStatus::Unknown(listener))
|
Ok(BlockCheckStatus::Unknown(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builder for a concrete relay chain interface, created from a full node. Builds
|
|
||||||
/// a [`RelayChainInProcessInterface`] to access relay chain data necessary for parachain operation.
|
|
||||||
///
|
|
||||||
/// The builder takes a [`polkadot_client::Client`]
|
|
||||||
/// that wraps a concrete instance. By using [`polkadot_client::ExecuteWithClient`]
|
|
||||||
/// the builder gets access to this concrete instance and instantiates a [`RelayChainInProcessInterface`] with it.
|
|
||||||
struct RelayChainInProcessInterfaceBuilder {
|
|
||||||
polkadot_client: polkadot_client::Client,
|
|
||||||
backend: Arc<FullBackend>,
|
|
||||||
sync_oracle: Arc<dyn SyncOracle + Send + Sync>,
|
|
||||||
overseer_handle: Handle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelayChainInProcessInterfaceBuilder {
|
|
||||||
pub fn build(self) -> Arc<dyn RelayChainInterface> {
|
|
||||||
self.polkadot_client.clone().execute_with(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExecuteWithClient for RelayChainInProcessInterfaceBuilder {
|
|
||||||
type Output = Arc<dyn RelayChainInterface>;
|
|
||||||
|
|
||||||
fn execute_with_client<Client, Api, Backend>(self, client: Arc<Client>) -> Self::Output
|
|
||||||
where
|
|
||||||
Client: ProvideRuntimeApi<PBlock>
|
|
||||||
+ HeaderBackend<PBlock>
|
|
||||||
+ BlockchainEvents<PBlock>
|
|
||||||
+ AuxStore
|
|
||||||
+ UsageProvider<PBlock>
|
|
||||||
+ 'static
|
|
||||||
+ Sync
|
|
||||||
+ Send,
|
|
||||||
Client::Api: ParachainHost<PBlock> + BabeApi<PBlock>,
|
|
||||||
{
|
|
||||||
Arc::new(RelayChainInProcessInterface::new(
|
|
||||||
client,
|
|
||||||
self.backend,
|
|
||||||
self.sync_oracle,
|
|
||||||
self.overseer_handle,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build the Polkadot full node using the given `config`.
|
/// Build the Polkadot full node using the given `config`.
|
||||||
#[sc_tracing::logging::prefix_logs_with("Relaychain")]
|
#[sc_tracing::logging::prefix_logs_with("Relaychain")]
|
||||||
fn build_polkadot_full_node(
|
fn build_polkadot_full_node(
|
||||||
@@ -338,7 +271,7 @@ fn build_polkadot_full_node(
|
|||||||
parachain_config: &Configuration,
|
parachain_config: &Configuration,
|
||||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||||
hwbench: Option<sc_sysinfo::HwBench>,
|
hwbench: Option<sc_sysinfo::HwBench>,
|
||||||
) -> Result<(NewFull<polkadot_client::Client>, Option<CollatorPair>), polkadot_service::Error> {
|
) -> Result<(NewFull, Option<CollatorPair>), polkadot_service::Error> {
|
||||||
let (is_collator, maybe_collator_key) = if parachain_config.role.is_authority() {
|
let (is_collator, maybe_collator_key) = if parachain_config.role.is_authority() {
|
||||||
let collator_key = CollatorPair::generate().0;
|
let collator_key = CollatorPair::generate().0;
|
||||||
(polkadot_service::IsCollator::Yes(collator_key.clone()), Some(collator_key))
|
(polkadot_service::IsCollator::Yes(collator_key.clone()), Some(collator_key))
|
||||||
@@ -385,18 +318,18 @@ pub fn build_inprocess_relay_chain(
|
|||||||
)
|
)
|
||||||
.map_err(|e| RelayChainError::Application(Box::new(e) as Box<_>))?;
|
.map_err(|e| RelayChainError::Application(Box::new(e) as Box<_>))?;
|
||||||
|
|
||||||
let relay_chain_interface_builder = RelayChainInProcessInterfaceBuilder {
|
let relay_chain_interface = Arc::new(RelayChainInProcessInterface::new(
|
||||||
polkadot_client: full_node.client.clone(),
|
full_node.client,
|
||||||
backend: full_node.backend.clone(),
|
full_node.backend,
|
||||||
sync_oracle: full_node.sync_service.clone(),
|
full_node.sync_service,
|
||||||
overseer_handle: full_node.overseer_handle.clone().ok_or(RelayChainError::GenericError(
|
full_node.overseer_handle.clone().ok_or(RelayChainError::GenericError(
|
||||||
"Overseer not running in full node.".to_string(),
|
"Overseer not running in full node.".to_string(),
|
||||||
))?,
|
))?,
|
||||||
};
|
));
|
||||||
|
|
||||||
task_manager.add_child(full_node.task_manager);
|
task_manager.add_child(full_node.task_manager);
|
||||||
|
|
||||||
Ok((relay_chain_interface_builder.build(), collator_key))
|
Ok((relay_chain_interface, collator_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -427,8 +360,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_client_backend_and_block(
|
fn build_client_backend_and_block() -> (Arc<Client>, PBlock, RelayChainInProcessInterface) {
|
||||||
) -> (Arc<Client>, PBlock, RelayChainInProcessInterface<Client>) {
|
|
||||||
let builder =
|
let builder =
|
||||||
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible);
|
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible);
|
||||||
let backend = builder.backend();
|
let backend = builder.backend();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ async fn polkadot_argument_parsing() {
|
|||||||
|
|
||||||
let args = &[
|
let args = &[
|
||||||
"--",
|
"--",
|
||||||
"--dev",
|
"--chain=rococo-local",
|
||||||
"--bootnodes",
|
"--bootnodes",
|
||||||
"/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy",
|
"/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy",
|
||||||
"--bootnodes",
|
"--bootnodes",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ async fn interrupt_polkadot_mdns_issue_test() {
|
|||||||
|
|
||||||
let base_dir = tempdir().expect("could not create a temp dir");
|
let base_dir = tempdir().expect("could not create a temp dir");
|
||||||
|
|
||||||
let args = &["--", "--dev"];
|
let args = &["--", "--chain=rococo-local"];
|
||||||
|
|
||||||
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
||||||
common::run_node_for_a_while(base_dir.path(), args, SIGTERM).await;
|
common::run_node_for_a_while(base_dir.path(), args, SIGTERM).await;
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ async fn purge_chain_works() {
|
|||||||
let base_dir = tempdir().expect("could not create a temp dir");
|
let base_dir = tempdir().expect("could not create a temp dir");
|
||||||
let base_dir_path = format!("{}/polkadot", base_dir.path().display());
|
let base_dir_path = format!("{}/polkadot", base_dir.path().display());
|
||||||
|
|
||||||
let args = &["--", "--dev", "-d", &base_dir_path];
|
let args = &["--", "-d", &base_dir_path, "--chain=rococo-local"];
|
||||||
|
|
||||||
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
||||||
|
|
||||||
assert!(base_dir.path().join("chains/local_testnet/db/full").exists());
|
assert!(base_dir.path().join("chains/local_testnet/db/full").exists());
|
||||||
assert!(base_dir.path().join("polkadot/chains/dev/db/full").exists());
|
assert!(base_dir.path().join("polkadot/chains/rococo_local_testnet/db/full").exists());
|
||||||
|
|
||||||
let status = Command::new(cargo_bin("polkadot-parachain"))
|
let status = Command::new(cargo_bin("polkadot-parachain"))
|
||||||
.args(["purge-chain", "-d"])
|
.args(["purge-chain", "-d"])
|
||||||
@@ -48,6 +48,6 @@ async fn purge_chain_works() {
|
|||||||
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
||||||
assert!(base_dir.path().join("chains/local_testnet").exists());
|
assert!(base_dir.path().join("chains/local_testnet").exists());
|
||||||
assert!(!base_dir.path().join("chains/local_testnet/db/full").exists());
|
assert!(!base_dir.path().join("chains/local_testnet/db/full").exists());
|
||||||
// assert!(base_path.path().join("polkadot/chains/dev").exists());
|
assert!(base_dir.path().join("polkadot/chains/rococo_local_testnet").exists());
|
||||||
// assert!(!base_path.path().join("polkadot/chains/dev/db").exists());
|
assert!(!base_dir.path().join("polkadot/chains/rococo_local_testnet/db/full").exists());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ async fn running_the_node_works_and_can_be_interrupted() {
|
|||||||
|
|
||||||
let base_dir = tempdir().expect("could not create a temp dir");
|
let base_dir = tempdir().expect("could not create a temp dir");
|
||||||
|
|
||||||
let args = &["--", "--dev"];
|
let args = &["--", "--chain=rococo-local"];
|
||||||
|
|
||||||
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
common::run_node_for_a_while(base_dir.path(), args, SIGINT).await;
|
||||||
common::run_node_for_a_while(base_dir.path(), args, SIGTERM).await;
|
common::run_node_for_a_while(base_dir.path(), args, SIGTERM).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user