Skip to content

Commit

Permalink
Start minimal relay node if relay_chain_rpc_url is set (#2042)
Browse files Browse the repository at this point in the history
* feat: start minimal relay node is relay_chain_rpc_url is set

* editorconfig
  • Loading branch information
librelois authored Jan 20, 2023
1 parent 1fa2a1e commit e41cc12
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 16 deletions.
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use cli_opt::{EthApi, RpcConfig};
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::BenchmarkCmd;
use log::info;
use log::{info, warn};
use parity_scale_codec::Encode;
#[cfg(feature = "westend-native")]
use polkadot_service::WestendChainSpec;
Expand Down Expand Up @@ -812,6 +812,22 @@ pub fn run() -> Result<()> {
info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
info!(
"Is collating: {}",
if config.role.is_authority() {
"yes"
} else {
"no"
}
);

if rpc_config.relay_chain_rpc_url.is_some() && cli.relaychain_args.len() > 0 {
warn!(
"Detected relay chain node arguments together with \
--relay-chain-rpc-url. This command starts a minimal Polkadot node that only \
uses a network-related subset of all relay chain CLI options."
);
}

match &config.chain_spec {
#[cfg(feature = "moonriver-native")]
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ cumulus-primitives-core = { git = "https://github.com/purestake/cumulus", branch
cumulus-primitives-parachain-inherent = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
cumulus-relay-chain-inprocess-interface = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
cumulus-relay-chain-interface = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
cumulus-relay-chain-minimal-node = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
cumulus-relay-chain-rpc-interface = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
cumulus-test-relay-sproof-builder = { git = "https://github.com/purestake/cumulus", branch = "moonbeam-polkadot-v0.9.32" }
nimbus-consensus = { git = "https://github.com/purestake/nimbus", branch = "moonbeam-polkadot-v0.9.32" }
Expand Down
65 changes: 50 additions & 15 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@
//! Full Service: A complete parachain node including the pool, rpc, network, embedded relay chain
//! Dev Service: A leaner service without the relay chain backing.

pub mod rpc;

use cli_opt::{EthApi as EthApiCmd, RpcConfig};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_consensus_common::ParachainConsensus;
use cumulus_client_network::BlockAnnounceValidator;
use cumulus_client_service::{
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
};
use cumulus_primitives_core::relay_chain::v2::CollatorPair;
use cumulus_primitives_core::ParaId;
use cumulus_primitives_parachain_inherent::{
MockValidationDataInherentDataProvider, MockXcmConfig,
};
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;
use fc_consensus::FrontierBlockImport;
use fc_db::DatabaseSource;
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
Expand All @@ -34,19 +50,6 @@ pub use moonbase_runtime;
pub use moonbeam_runtime;
#[cfg(feature = "moonriver-native")]
pub use moonriver_runtime;
use std::{collections::BTreeMap, sync::Mutex, time::Duration};
pub mod rpc;
use cumulus_client_consensus_common::ParachainConsensus;
use cumulus_client_network::BlockAnnounceValidator;
use cumulus_client_service::{
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
};
use cumulus_primitives_core::ParaId;
use cumulus_primitives_parachain_inherent::{
MockValidationDataInherentDataProvider, MockXcmConfig,
};
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface};
use nimbus_consensus::NimbusManualSealConsensusDataProvider;
use nimbus_consensus::{BuildNimbusConsensusParams, NimbusConsensus};
use nimbus_primitives::NimbusId;
Expand All @@ -63,6 +66,7 @@ use sp_api::ConstructRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_keystore::SyncCryptoStorePtr;
use std::sync::Arc;
use std::{collections::BTreeMap, sync::Mutex, time::Duration};
use substrate_prometheus_endpoint::Registry;

pub use client::*;
Expand Down Expand Up @@ -494,6 +498,31 @@ where
})
}

async fn build_relay_chain_interface(
polkadot_config: Configuration,
parachain_config: &Configuration,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
task_manager: &mut TaskManager,
collator_options: CollatorOptions,
hwbench: Option<sc_sysinfo::HwBench>,
) -> RelayChainResult<(
Arc<(dyn RelayChainInterface + 'static)>,
Option<CollatorPair>,
)> {
match collator_options.relay_chain_rpc_url {
Some(relay_chain_url) => {
build_minimal_relay_chain_node(polkadot_config, task_manager, relay_chain_url).await
}
None => build_inprocess_relay_chain(
polkadot_config,
parachain_config,
telemetry_worker_handle,
task_manager,
hwbench,
),
}
}

/// 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.
Expand Down Expand Up @@ -531,6 +560,10 @@ where
{
let mut parachain_config = prepare_node_config(parachain_config);

let collator_options = CollatorOptions {
relay_chain_rpc_url: rpc_config.relay_chain_rpc_url.clone(),
};

let params = new_partial(&mut parachain_config, false)?;
let (
_block_import,
Expand All @@ -545,13 +578,15 @@ where
let backend = params.backend.clone();
let mut task_manager = params.task_manager;

let (relay_chain_interface, collator_key) = build_inprocess_relay_chain(
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
&parachain_config,
telemetry_worker_handle,
&mut task_manager,
None,
collator_options.clone(),
hwbench.clone(),
)
.await
.map_err(|e| match e {
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
s => s.to_string().into(),
Expand Down

0 comments on commit e41cc12

Please sign in to comment.