Introduce rpc client for relay chain full node (#963)

* Initial network interface preparations

* Implement get_storage_by_key

* Implement `validators` and `session_index_for_child`

* Implement persisted_validation_data and candidate_pending_availability

* Fix method name for persisted_validation_data and add encoded params

* Implement `retrieve_dmq_contents` and `retrieve_all_inbound_hrmp_channel_contents`

* Implement `prove_read`

* Introduce separate RPC client, expose JsonRpSee errors

* Simplify closure in call_remote_runtime_function

* Implement import stream, upgrade JsonRpSee

* Implement finality stream

* Remove unused method from interface

* Implement `is_major_syncing`

* Implement `wait_on_block`

* Fix tests

* Unify error handling `ApiError`

* Replace WaitError with RelayChainError

* Wrap BlockChainError in RelayChainError

* Unify error handling in relay chain intefaces

* Fix return type of proof method

* Improve error handling of new methods

* Improve error handling and move logging outside of interface

* Clean up

* Remove unwanted changes, clean up

* Remove unused import

* Add format for StatemachineError and remove nused From trait

* Use 'thiserror' crate to simplify error handling

* Expose error for overseer, further simplify error handling

* Reintroduce network interface

* Implement cli option

* Adjust call_state method to use hashes

* Disable PoV recovery when RPC is used

* Add integration test for network full node

* Use Hash instead of BlockId to ensure compatibility with RPC interface

* Fix cargo check warnings

* Implement retries

* Remove `expect` statements from code

* Update jsonrpsee to 0.8.0 and make collator keys optional

* Make cli arguments conflicting

* Remove unused `block_status` method

* Add clippy fixes

* Cargo fmt

* Validate relay chain rpc url

* Clean up dependencies and add one more integration test

* Clean up

* Clean up dependencies of relay-chain-network

* Use hash instead of blockid for rpc methods

* Fix tests

* Update client/cli/src/lib.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Improve error message of cli validation

* Add rpc client constructor

* Do not use debug formatting for errors

* Improve logging for remote runtime methods

* Only retry on transport problems

* Use PHash by value, rename test

* Improve tracing, return error  on relay-chain-interface build

* Fix naming, use generics instead of deserializing manually

* Rename RelayChainLocal and RelayChainNetwork

* lock

* Format

* Use impl trait for encodable runtime payload

* Only instantiate full node in tests when we need it

* Upgrade scale-codec to 3.0.0

* Improve expect log

Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
Sebastian Kunert
2022-03-01 12:37:51 +01:00
committed by GitHub
parent 58e02c8497
commit 234c42c2df
34 changed files with 1109 additions and 271 deletions
+3 -1
View File
@@ -79,7 +79,9 @@ cumulus-client-network = { path = "../client/network" }
cumulus-primitives-core = { path = "../primitives/core" }
cumulus-primitives-parachain-inherent = { path = "../primitives/parachain-inherent" }
cumulus-relay-chain-interface = { path = "../client/relay-chain-interface" }
cumulus-relay-chain-local = { path = "../client/relay-chain-local" }
cumulus-relay-chain-inprocess-interface = { path = "../client/relay-chain-inprocess-interface" }
cumulus-relay-chain-rpc-interface = { path = "../client/relay-chain-rpc-interface" }
# Polkadot dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
+1 -1
View File
@@ -109,7 +109,7 @@ pub struct Cli {
pub run: cumulus_client_cli::RunCmd,
/// Relay chain arguments
#[clap(raw = true)]
#[clap(raw = true, conflicts_with = "relay-chain-rpc-url")]
pub relaychain_args: Vec<String>,
}
+24 -13
View File
@@ -493,6 +493,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options();
runner.run_node_until_exit(|config| async move {
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
@@ -534,7 +535,7 @@ pub fn run() -> Result<()> {
statemint_runtime::RuntimeApi,
StatemintRuntimeExecutor,
StatemintAuraId,
>(config, polkadot_config, id)
>(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
@@ -543,7 +544,7 @@ pub fn run() -> Result<()> {
statemine_runtime::RuntimeApi,
StatemineRuntimeExecutor,
AuraId,
>(config, polkadot_config, id)
>(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
@@ -552,7 +553,7 @@ pub fn run() -> Result<()> {
westmint_runtime::RuntimeApi,
WestmintRuntimeExecutor,
AuraId,
>(config, polkadot_config, id)
>(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
@@ -560,7 +561,7 @@ pub fn run() -> Result<()> {
crate::service::start_shell_node::<
shell_runtime::RuntimeApi,
ShellRuntimeExecutor,
>(config, polkadot_config, id)
>(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
@@ -568,20 +569,30 @@ pub fn run() -> Result<()> {
crate::service::start_shell_node::<
seedling_runtime::RuntimeApi,
SeedlingRuntimeExecutor,
>(config, polkadot_config, id)
>(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_canvas_kusama() {
crate::service::start_canvas_kusama_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
crate::service::start_canvas_kusama_node(
config,
polkadot_config,
collator_options,
id,
)
.await
.map(|r| r.0)
.map_err(Into::into)
} else {
crate::service::start_rococo_parachain_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
crate::service::start_rococo_parachain_node(
config,
polkadot_config,
collator_options,
id,
)
.await
.map(|r| r.0)
.map_err(Into::into)
}
})
},
+76 -25
View File
@@ -15,6 +15,7 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use codec::Codec;
use cumulus_client_cli::CollatorOptions;
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
use cumulus_client_consensus_common::{
ParachainBlockImport, ParachainCandidate, ParachainConsensus,
@@ -27,9 +28,11 @@ use cumulus_primitives_core::{
relay_chain::v1::{Hash as PHash, PersistedValidationData},
ParaId,
};
use cumulus_relay_chain_interface::RelayChainInterface;
use cumulus_relay_chain_local::build_relay_chain_interface;
use polkadot_service::NativeExecutionDispatch;
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;
use polkadot_service::{CollatorPair, NativeExecutionDispatch};
use sp_core::Pair;
use crate::rpc;
pub use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index as Nonce};
@@ -48,7 +51,6 @@ use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerH
use sp_api::{ApiExt, ConstructRuntimeApi};
use sp_consensus::CacheKeyId;
use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_keystore::SyncCryptoStorePtr;
use sp_runtime::{
app_crypto::AppKey,
@@ -277,6 +279,26 @@ where
Ok(params)
}
async fn build_relay_chain_interface(
polkadot_config: Configuration,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
task_manager: &mut TaskManager,
collator_options: CollatorOptions,
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
match collator_options.relay_chain_rpc_url {
Some(relay_chain_url) =>
Ok((Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>, None)),
None => {
let relay_chain_local = build_inprocess_relay_chain(
polkadot_config,
telemetry_worker_handle,
task_manager,
)?;
Ok((relay_chain_local.0, Some(relay_chain_local.1)))
},
}
}
/// Start a shell 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 for shell nodes.
@@ -284,6 +306,7 @@ where
async fn start_shell_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
rpc_ext_builder: RB,
build_import_queue: BIQ,
@@ -356,12 +379,17 @@ where
let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) =
build_relay_chain_interface(polkadot_config, telemetry_worker_handle, &mut task_manager)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
telemetry_worker_handle,
&mut task_manager,
collator_options.clone(),
)
.await
.map_err(|e| match e {
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
s => s.to_string().into(),
})?;
let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);
@@ -431,7 +459,7 @@ where
spawner,
parachain_consensus,
import_queue,
collator_key,
collator_key: collator_key.expect("Command line arguments do not allow this. qed"),
relay_chain_slot_duration,
};
@@ -445,6 +473,7 @@ where
relay_chain_interface,
relay_chain_slot_duration,
import_queue,
collator_options,
};
start_full_node(params)?;
@@ -462,6 +491,7 @@ where
async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
_rpc_ext_builder: RB,
build_import_queue: BIQ,
@@ -535,12 +565,17 @@ where
let backend = params.backend.clone();
let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) =
build_relay_chain_interface(polkadot_config, telemetry_worker_handle, &mut task_manager)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
telemetry_worker_handle,
&mut task_manager,
collator_options.clone(),
)
.await
.map_err(|e| match e {
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
s => s.to_string().into(),
})?;
let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);
@@ -622,7 +657,7 @@ where
spawner,
parachain_consensus,
import_queue,
collator_key,
collator_key: collator_key.expect("Command line arguments do not allow this. qed"),
relay_chain_slot_duration,
};
@@ -636,6 +671,7 @@ where
relay_chain_interface,
relay_chain_slot_duration,
import_queue,
collator_options,
};
start_full_node(params)?;
@@ -705,6 +741,7 @@ pub fn rococo_parachain_build_import_queue(
pub async fn start_rococo_parachain_node(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
) -> sc_service::error::Result<(
TaskManager,
@@ -719,6 +756,7 @@ pub async fn start_rococo_parachain_node(
start_node_impl::<rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor, _, _, _>(
parachain_config,
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
rococo_parachain_build_import_queue,
@@ -842,6 +880,7 @@ where
pub async fn start_shell_node<RuntimeApi, Executor>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
) -> sc_service::error::Result<(
TaskManager,
@@ -867,6 +906,7 @@ where
start_shell_node_impl::<RuntimeApi, Executor, _, _, _>(
parachain_config,
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
shell_build_import_queue,
@@ -1112,6 +1152,7 @@ where
pub async fn start_statemint_node<RuntimeApi, Executor, AuraId: AppKey>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
) -> sc_service::error::Result<(
TaskManager,
@@ -1142,6 +1183,7 @@ where
start_node_impl::<RuntimeApi, Executor, _, _, _>(
parachain_config,
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
statemint_build_import_queue::<_, _, AuraId>,
@@ -1277,6 +1319,7 @@ where
async fn start_canvas_kusama_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
_rpc_ext_builder: RB,
build_import_queue: BIQ,
@@ -1351,12 +1394,17 @@ where
let backend = params.backend.clone();
let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) =
build_relay_chain_interface(polkadot_config, telemetry_worker_handle, &mut task_manager)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
telemetry_worker_handle,
&mut task_manager,
collator_options.clone(),
)
.await
.map_err(|e| match e {
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
s => s.to_string().into(),
})?;
let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);
@@ -1438,7 +1486,7 @@ where
spawner,
parachain_consensus,
import_queue,
collator_key,
collator_key: collator_key.expect("Command line arguments do not allow this. qed"),
relay_chain_slot_duration,
};
@@ -1452,6 +1500,7 @@ where
relay_chain_interface,
relay_chain_slot_duration,
import_queue,
collator_options,
};
start_full_node(params)?;
@@ -1521,6 +1570,7 @@ pub fn canvas_kusama_build_import_queue(
pub async fn start_canvas_kusama_node(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
) -> sc_service::error::Result<(
TaskManager,
@@ -1541,6 +1591,7 @@ pub async fn start_canvas_kusama_node(
>(
parachain_config,
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
canvas_kusama_build_import_queue,