Unverified Commit 17e40d13 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Add ParasSudoWrapper to test-runtime and bring back register_parachain to test-service (#1811)

* Make register/deregister parachain dispatchables

This makes `register_parachain` and `deregister_parachain` of
`Registrar` dispatchables.

Besides that it brings back the functionality of the test node to
register a parachain.

* Fix tests

* PR review comments
parent 702fc938
Pipeline #110873 passed with stages
in 24 minutes and 54 seconds
......@@ -5572,6 +5572,7 @@ dependencies = [
"polkadot-primitives",
"polkadot-rpc",
"polkadot-runtime-common",
"polkadot-runtime-parachains",
"polkadot-service",
"polkadot-test-runtime",
"rand 0.7.3",
......
......@@ -19,6 +19,7 @@ polkadot-rpc = { path = "../../rpc" }
polkadot-runtime-common = { path = "../../runtime/common" }
polkadot-service = { path = "../service" }
polkadot-test-runtime = { path = "../../runtime/test-runtime" }
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
# Substrate dependencies
authority-discovery = { package = "sc-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master" }
......
......@@ -23,12 +23,13 @@ mod chain_spec;
pub use chain_spec::*;
use futures::future::Future;
use polkadot_overseer::OverseerHandler;
use polkadot_primitives::v1::Block;
use polkadot_primitives::v1::{Block, Id as ParaId, HeadData, ValidationCode};
use polkadot_runtime_common::BlockHashCount;
use polkadot_service::{
new_full, NewFull, FullClient, AbstractClient, ClientHandle, ExecuteWithClient,
};
use polkadot_test_runtime::{Runtime, SignedExtra, SignedPayload, VERSION};
use polkadot_test_runtime::{Runtime, SignedExtra, SignedPayload, VERSION, ParasSudoWrapperCall};
use polkadot_runtime_parachains::paras::ParaGenesisArgs;
use sc_chain_spec::ChainSpec;
use sc_client_api::{execution_extensions::ExecutionStrategies, BlockchainEvents};
use sc_executor::native_executor_instance;
......@@ -82,9 +83,13 @@ impl ClientHandle for TestClient {
}
}
/// Create a Polkadot `Configuration`. By default an in-memory socket will be used, therefore you need to provide boot
/// nodes if you want the future node to be connected to other nodes. The `storage_update_func` can be used to make
/// adjustements to the runtime before the node starts.
/// Create a Polkadot `Configuration`.
///
/// By default an in-memory socket will be used, therefore you need to provide boot
/// nodes if you want the future node to be connected to other nodes.
///
/// The `storage_update_func` function will be executed in an externalities provided environment
/// and can be used to make adjustements to the runtime genesis storage.
pub fn node_config(
storage_update_func: impl Fn(),
task_executor: TaskExecutor,
......@@ -178,9 +183,13 @@ pub fn node_config(
}
}
/// Run a Polkadot test node using the Polkadot test runtime. The node will be using an in-memory socket, therefore you
/// need to provide boot nodes if you want it to be connected to other nodes. The `storage_update_func` can be used to
/// make adjustements to the runtime before the node starts.
/// Run a Polkadot test node using the Polkadot test runtime.
///
/// The node will be using an in-memory socket, therefore you need to provide boot nodes if you
/// want it to be connected to other nodes.
///
/// The `storage_update_func` function will be executed in an externalities provided environment
/// and can be used to make adjustements to the runtime genesis storage.
pub fn run_test_node(
task_executor: TaskExecutor,
key: Sr25519Keyring,
......@@ -230,9 +239,10 @@ where
/// Send a transaction through RPCHandlers to call a function.
pub async fn call_function(
&self,
function: polkadot_test_runtime::Call,
function: impl Into<polkadot_test_runtime::Call>,
caller: Sr25519Keyring,
) -> Result<RpcTransactionOutput, RpcTransactionError> {
let function = function.into();
let current_block_hash = self.client.info().best_hash;
let current_block = self.client.info().best_number.saturated_into();
let genesis_block = self.client.hash(0).unwrap().unwrap();
......@@ -274,6 +284,25 @@ where
self.rpc_handlers.send_transaction(extrinsic.into()).await
}
/// Register a parachain at this relay chain.
pub async fn register_parachain(
&self,
id: ParaId,
validation_code: ValidationCode,
genesis_head: HeadData,
) -> Result<(), RpcTransactionError> {
let call = ParasSudoWrapperCall::sudo_schedule_para_initialize(
id,
ParaGenesisArgs {
genesis_head,
validation_code,
parachain: true,
},
);
self.call_function(call, Sr25519Keyring::Alice).await.map(drop)
}
}
impl<S, C> PolkadotTestNode<S, C>
......
......@@ -176,7 +176,6 @@ pub struct ParaGenesisArgs {
pub parachain: bool,
}
decl_storage! {
trait Store for Module<T: Trait> as Paras {
/// All parachains. Ordered ascending by ParaId. Parathreads are not included.
......
......@@ -63,8 +63,7 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use pallet_session::historical as session_historical;
use frame_system::EnsureRoot;
use runtime_common::paras_sudo_wrapper as paras_sudo_wrapper;
use runtime_common::paras_registrar;
use runtime_common::{paras_sudo_wrapper, paras_registrar};
use runtime_parachains::origin as parachains_origin;
use runtime_parachains::configuration as parachains_configuration;
......@@ -740,9 +739,9 @@ impl pallet_authorship::Trait for Runtime {
type EventHandler = (Staking, ImOnline);
}
impl parachains_origin::Trait for Runtime { }
impl parachains_origin::Trait for Runtime {}
impl parachains_configuration::Trait for Runtime { }
impl parachains_configuration::Trait for Runtime {}
impl parachains_inclusion::Trait for Runtime {
type Event = Event;
......@@ -752,17 +751,17 @@ impl parachains_paras::Trait for Runtime {
type Origin = Origin;
}
impl parachains_router::Trait for Runtime { }
impl parachains_router::Trait for Runtime {}
impl parachains_inclusion_inherent::Trait for Runtime { }
impl parachains_inclusion_inherent::Trait for Runtime {}
impl parachains_scheduler::Trait for Runtime { }
impl parachains_scheduler::Trait for Runtime {}
impl parachains_initializer::Trait for Runtime {
type Randomness = Babe;
}
impl paras_sudo_wrapper::Trait for Runtime { }
impl paras_sudo_wrapper::Trait for Runtime {}
impl paras_registrar::Trait for Runtime {
type Currency = Balances;
......
......@@ -37,7 +37,7 @@ use primitives::v1::{
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
};
use runtime_common::{
claims, SlowAdjustingFeeUpdate,
claims, SlowAdjustingFeeUpdate, paras_sudo_wrapper,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, ParachainSessionKeyPlaceholder,
};
......@@ -74,6 +74,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
pub use paras_sudo_wrapper::Call as ParasSudoWrapperCall;
/// Constant values used within the runtime.
pub mod constants;
......@@ -448,6 +449,8 @@ impl router::Trait for Runtime {}
impl scheduler::Trait for Runtime {}
impl paras_sudo_wrapper::Trait for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
......@@ -487,8 +490,8 @@ construct_runtime! {
Initializer: initializer::{Module, Call, Storage},
Paras: paras::{Module, Call, Storage, Origin},
Scheduler: scheduler::{Module, Call, Storage},
ParasSudoWrapper: paras_sudo_wrapper::{Module, Call},
// Sudo. Last module.
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment