mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Update Cumulus for Parachains V1 (#224)
* Start with something * Whatever * Update * MOARE * Make cumulus-network compile and tests work * Update more and fixes * More stuff * More fixes * Make collator build * Make test almost work * Remove contracts runtime * More test work * Make service compile * Fix test-service * Fix test client * More fixes * Fix collator test * Fix network tests (again) * Make everything compile, finally * Fix tests * Update to latest masters * Remove ignore * Switch to different branch in polkadot for now * Update reference * Make it compile with latest changes * Update collator/src/lib.rs Co-authored-by: Robert Habermeier <rphmeier@gmail.com> * Update to latest upstream * Update to latest master * Fix test Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
@@ -14,42 +14,34 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ansi_term::Color;
|
||||
use cumulus_network::DelayedBlockAnnounceValidator;
|
||||
use cumulus_network::build_block_announce_validator;
|
||||
use cumulus_service::{
|
||||
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
|
||||
};
|
||||
use parachain_runtime::RuntimeApi;
|
||||
use polkadot_primitives::v0::CollatorPair;
|
||||
use rococo_parachain_primitives::Block;
|
||||
use sc_executor::native_executor_instance;
|
||||
pub use sc_executor::NativeExecutor;
|
||||
use sc_informant::OutputFormat;
|
||||
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
|
||||
use sp_api::ConstructRuntimeApi;
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_trie::PrefixedMemoryDB;
|
||||
use std::sync::Arc;
|
||||
|
||||
// Native executor instance.
|
||||
native_executor_instance!(
|
||||
pub RuntimeExecutor,
|
||||
pub Executor,
|
||||
parachain_runtime::api::dispatch,
|
||||
parachain_runtime::native_version,
|
||||
);
|
||||
|
||||
// Native executor instance for the contracts runtime.
|
||||
native_executor_instance!(
|
||||
pub ContractsRuntimeExecutor,
|
||||
parachain_contracts_runtime::api::dispatch,
|
||||
parachain_contracts_runtime::native_version,
|
||||
);
|
||||
|
||||
/// Starts a `ServiceBuilder` for a full service.
|
||||
///
|
||||
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||
/// be able to perform chain operations.
|
||||
pub fn new_partial<RuntimeApi, Executor>(
|
||||
config: &mut Configuration,
|
||||
pub fn new_partial(
|
||||
config: &Configuration,
|
||||
) -> Result<
|
||||
PartialComponents<
|
||||
TFullClient<Block, RuntimeApi, Executor>,
|
||||
@@ -60,27 +52,10 @@ pub fn new_partial<RuntimeApi, Executor>(
|
||||
(),
|
||||
>,
|
||||
sc_service::Error,
|
||||
>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
Error = sp_blockchain::Error,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
{
|
||||
> {
|
||||
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
|
||||
|
||||
let (client, backend, keystore, task_manager) =
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
@@ -105,7 +80,7 @@ where
|
||||
backend,
|
||||
client,
|
||||
import_queue,
|
||||
keystore,
|
||||
keystore_container,
|
||||
task_manager,
|
||||
transaction_pool,
|
||||
inherent_data_providers,
|
||||
@@ -119,30 +94,15 @@ where
|
||||
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
|
||||
///
|
||||
/// This is the actual implementation that is abstract over the executor and the runtime api.
|
||||
fn start_node_impl<RuntimeApi, Executor, RB>(
|
||||
async fn start_node_impl<RB>(
|
||||
parachain_config: Configuration,
|
||||
collator_key: Arc<CollatorPair>,
|
||||
mut polkadot_config: polkadot_collator::Configuration,
|
||||
collator_key: CollatorPair,
|
||||
polkadot_config: Configuration,
|
||||
id: polkadot_primitives::v0::Id,
|
||||
validator: bool,
|
||||
rpc_ext_builder: RB,
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<TFullClient<Block, RuntimeApi, Executor>>)>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
Error = sp_blockchain::Error,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
RB: Fn(
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
|
||||
@@ -153,18 +113,12 @@ where
|
||||
return Err("Light client not supported!".into());
|
||||
}
|
||||
|
||||
let mut parachain_config = prepare_node_config(parachain_config);
|
||||
let parachain_config = prepare_node_config(parachain_config);
|
||||
|
||||
parachain_config.informant_output_format = OutputFormat {
|
||||
enable_color: true,
|
||||
prefix: format!("[{}] ", Color::Yellow.bold().paint("Parachain")),
|
||||
};
|
||||
polkadot_config.informant_output_format = OutputFormat {
|
||||
enable_color: true,
|
||||
prefix: format!("[{}] ", Color::Blue.bold().paint("Relaychain")),
|
||||
};
|
||||
let polkadot_full_node =
|
||||
cumulus_service::build_polkadot_full_node(polkadot_config, collator_key.public())?;
|
||||
|
||||
let params = new_partial::<RuntimeApi, Executor>(&mut parachain_config)?;
|
||||
let params = new_partial(¶chain_config)?;
|
||||
params
|
||||
.inherent_data_providers
|
||||
.register_provider(sp_timestamp::InherentDataProvider)
|
||||
@@ -172,11 +126,11 @@ where
|
||||
|
||||
let client = params.client.clone();
|
||||
let backend = params.backend.clone();
|
||||
let block_announce_validator = DelayedBlockAnnounceValidator::new();
|
||||
let block_announce_validator_builder = {
|
||||
let block_announce_validator = block_announce_validator.clone();
|
||||
move |_| Box::new(block_announce_validator) as Box<_>
|
||||
};
|
||||
let block_announce_validator = build_block_announce_validator(
|
||||
polkadot_full_node.client.clone(),
|
||||
id,
|
||||
Box::new(polkadot_full_node.network.clone()),
|
||||
);
|
||||
|
||||
let prometheus_registry = parachain_config.prometheus_registry().cloned();
|
||||
let transaction_pool = params.transaction_pool.clone();
|
||||
@@ -190,16 +144,13 @@ where
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
on_demand: None,
|
||||
block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)),
|
||||
block_announce_validator_builder: Some(Box::new(|_| block_announce_validator)),
|
||||
finality_proof_request_builder: None,
|
||||
finality_proof_provider: None,
|
||||
})?;
|
||||
|
||||
let rpc_extensions_builder = {
|
||||
let client = client.clone();
|
||||
|
||||
Box::new(move |_deny_unsafe| rpc_ext_builder(client.clone()))
|
||||
};
|
||||
let rpc_client = client.clone();
|
||||
let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone()));
|
||||
|
||||
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
on_demand: None,
|
||||
@@ -210,8 +161,8 @@ where
|
||||
task_manager: &mut task_manager,
|
||||
telemetry_connection_sinks: Default::default(),
|
||||
config: parachain_config,
|
||||
keystore: params.keystore,
|
||||
backend,
|
||||
keystore: params.keystore_container.sync_keystore(),
|
||||
backend: backend.clone(),
|
||||
network: network.clone(),
|
||||
network_status_sinks,
|
||||
system_rpc_tx,
|
||||
@@ -224,10 +175,12 @@ where
|
||||
|
||||
if validator {
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool,
|
||||
prometheus_registry.as_ref(),
|
||||
);
|
||||
let spawner = task_manager.spawn_handle();
|
||||
|
||||
let params = StartCollatorParams {
|
||||
para_id: id,
|
||||
@@ -237,22 +190,21 @@ where
|
||||
block_status: client.clone(),
|
||||
announce_block,
|
||||
client: client.clone(),
|
||||
block_announce_validator,
|
||||
task_manager: &mut task_manager,
|
||||
polkadot_config,
|
||||
collator_key,
|
||||
polkadot_full_node,
|
||||
spawner,
|
||||
backend,
|
||||
};
|
||||
|
||||
start_collator(params)?;
|
||||
start_collator(params).await?;
|
||||
} else {
|
||||
let params = StartFullNodeParams {
|
||||
client: client.clone(),
|
||||
announce_block,
|
||||
polkadot_config,
|
||||
collator_key,
|
||||
block_announce_validator,
|
||||
task_manager: &mut task_manager,
|
||||
para_id: id,
|
||||
polkadot_full_node,
|
||||
};
|
||||
|
||||
start_full_node(params)?;
|
||||
@@ -264,17 +216,14 @@ where
|
||||
}
|
||||
|
||||
/// Start a normal parachain node.
|
||||
pub fn start_node(
|
||||
pub async fn start_node(
|
||||
parachain_config: Configuration,
|
||||
collator_key: Arc<CollatorPair>,
|
||||
polkadot_config: polkadot_collator::Configuration,
|
||||
collator_key: CollatorPair,
|
||||
polkadot_config: Configuration,
|
||||
id: polkadot_primitives::v0::Id,
|
||||
validator: bool,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, parachain_runtime::RuntimeApi, RuntimeExecutor>>,
|
||||
)> {
|
||||
start_node_impl::<parachain_runtime::RuntimeApi, RuntimeExecutor, _>(
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<TFullClient<Block, RuntimeApi, Executor>>)> {
|
||||
start_node_impl(
|
||||
parachain_config,
|
||||
collator_key,
|
||||
polkadot_config,
|
||||
@@ -282,29 +231,5 @@ pub fn start_node(
|
||||
validator,
|
||||
|_| Default::default(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Start a contracts parachain node.
|
||||
pub fn start_contracts_node(
|
||||
parachain_config: Configuration,
|
||||
collator_key: Arc<CollatorPair>,
|
||||
polkadot_config: polkadot_collator::Configuration,
|
||||
id: polkadot_primitives::v0::Id,
|
||||
validator: bool,
|
||||
) -> sc_service::error::Result<TaskManager> {
|
||||
start_node_impl::<parachain_contracts_runtime::RuntimeApi, ContractsRuntimeExecutor, _>(
|
||||
parachain_config,
|
||||
collator_key,
|
||||
polkadot_config,
|
||||
id,
|
||||
validator,
|
||||
|client| {
|
||||
let mut io = jsonrpc_core::IoHandler::default();
|
||||
|
||||
use cumulus_pallet_contracts_rpc::{Contracts, ContractsApi};
|
||||
io.extend_with(ContractsApi::to_delegate(Contracts::new(client)));
|
||||
io
|
||||
},
|
||||
)
|
||||
.map(|r| r.0)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user