git.delta.rocks / unique-network / refs/commits / 5189324f5050

difftreelog

Adjust node and rpc to work with different runtimes

Daniel Shiposha2022-03-14parent: #ea9e87e.patch.diff
in: master

7 files changed

modifiedCargo.lockdiffbeforeafterboth
11942 "opal-runtime",11942 "opal-runtime",
11943 "pallet-ethereum",11943 "pallet-ethereum",
11944 "pallet-transaction-payment-rpc",11944 "pallet-transaction-payment-rpc",
11945 "pallet-transaction-payment-rpc-runtime-api",
11945 "parity-scale-codec",11946 "parity-scale-codec",
11946 "parking_lot 0.11.2",11947 "parking_lot 0.11.2",
11947 "polkadot-cli",11948 "polkadot-cli",
11988 "substrate-prometheus-endpoint",11989 "substrate-prometheus-endpoint",
11989 "unique-rpc",11990 "unique-rpc",
11990 "unique-runtime",11991 "unique-runtime",
11992 "unique-runtime-common",
11991 "up-data-structs",11993 "up-data-structs",
11994 "up-rpc",
11992]11995]
1199311996
11994[[package]]11997[[package]]
12003 "futures 0.3.21",12006 "futures 0.3.21",
12004 "jsonrpc-core",12007 "jsonrpc-core",
12005 "jsonrpc-pubsub",12008 "jsonrpc-pubsub",
12006 "opal-runtime",12009 "pallet-common",
12007 "pallet-ethereum",12010 "pallet-ethereum",
12008 "pallet-transaction-payment-rpc",12011 "pallet-transaction-payment-rpc",
12009 "pallet-transaction-payment-rpc-runtime-api",12012 "pallet-transaction-payment-rpc-runtime-api",
12010 "pallet-unique",12013 "pallet-unique",
12011 "quartz-runtime",
12012 "sc-client-api",12014 "sc-client-api",
12013 "sc-consensus-aura",12015 "sc-consensus-aura",
12014 "sc-consensus-epochs",12016 "sc-consensus-epochs",
12020 "sc-rpc-api",12022 "sc-rpc-api",
12021 "sc-service",12023 "sc-service",
12022 "sc-transaction-pool",12024 "sc-transaction-pool",
12025 "serde",
12023 "sp-api",12026 "sp-api",
12024 "sp-block-builder",12027 "sp-block-builder",
12025 "sp-blockchain",12028 "sp-blockchain",
12034 "substrate-frame-rpc-system",12037 "substrate-frame-rpc-system",
12035 "tokio 0.2.25",12038 "tokio 0.2.25",
12036 "uc-rpc",12039 "uc-rpc",
12037 "unique-runtime",12040 "unique-runtime-common",
12038 "up-rpc",12041 "up-rpc",
12039]12042]
1204012043
12118name = "unique-runtime-common"12121name = "unique-runtime-common"
12119version = "0.1.0"12122version = "0.1.0"
12120dependencies = [12123dependencies = [
12124 "fp-rpc",
12121 "frame-support",12125 "frame-support",
12122 "frame-system",12126 "frame-system",
12127 "pallet-common",
12123 "parity-scale-codec",12128 "parity-scale-codec",
12124 "scale-info",12129 "scale-info",
12130 "sp-consensus-aura",
12125 "sp-core",12131 "sp-core",
12126 "sp-runtime",12132 "sp-runtime",
12127]12133]
modifiednode/cli/Cargo.tomldiffbeforeafterboth
238################################################################################238################################################################################
239# Local dependencies239# Local dependencies
240
241[dependencies.unique-runtime-common]
242default-features = false
243path = "../../runtime/common"
240244
241[dependencies.unique-runtime]245[dependencies.unique-runtime]
242path = '../../runtime/unique'246path = '../../runtime/unique'
254path = "../../primitives/data-structs"258path = "../../primitives/data-structs"
255default-features = false259default-features = false
260
261[dependencies.up-rpc]
262path = "../../primitives/rpc"
263
264[dependencies.pallet-transaction-payment-rpc-runtime-api]
265git = 'https://github.com/paritytech/substrate.git'
266branch = 'polkadot-v0.9.17'
256267
257################################################################################268################################################################################
258# Package269# Package
295unique-rpc = { default-features = false, path = "../rpc" }306unique-rpc = { default-features = false, path = "../rpc" }
296307
297[features]308[features]
298default = ["unique-runtime"]309default = ["unique-runtime", "quartz-runtime", "opal-runtime"]
299runtime-benchmarks = [310runtime-benchmarks = [
300 'unique-runtime/runtime-benchmarks',311 'unique-runtime/runtime-benchmarks',
301 'polkadot-service/runtime-benchmarks',312 'polkadot-service/runtime-benchmarks',
modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
24use serde::{Deserialize, Serialize};24use serde::{Deserialize, Serialize};
25use serde_json::map::Map;25use serde_json::map::Map;
26
27#[cfg(feature = "unique-runtime")]
28use unique_runtime as runtime;
29
30#[cfg(feature = "quartz-runtime")]
31use quartz_runtime as runtime;
32
33#[cfg(feature = "opal-runtime")]
34use opal_runtime as runtime;
3526
36use runtime::{*, opaque::*};27use unique_runtime_common::types::*;
3728
38/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.29/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
39pub type ChainSpec = sc_service::GenericChainSpec<runtime::GenesisConfig, Extensions>;30pub type ChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;
31
32pub trait RuntimeIdentification {
33 fn is_unique(&self) -> bool;
34
35 fn is_quartz(&self) -> bool;
36
37 fn is_opal(&self) -> bool;
38}
39
40impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {
41 fn is_unique(&self) -> bool {
42 self.id().starts_with("unique")
43 }
44
45 fn is_quartz(&self) -> bool {
46 self.id().starts_with("quartz")
47 }
48
49 fn is_opal(&self) -> bool {
50 self.id().starts_with("opal")
51 }
52}
4053
41/// Helper function to generate a crypto pair from seed54/// Helper function to generate a crypto pair from seed
42pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {55pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
225 initial_authorities: Vec<AuraId>,238 initial_authorities: Vec<AuraId>,
226 endowed_accounts: Vec<AccountId>,239 endowed_accounts: Vec<AccountId>,
227 id: ParaId,240 id: ParaId,
228) -> GenesisConfig {241) -> unique_runtime::GenesisConfig {
242 use unique_runtime::*;
243
229 GenesisConfig {244 GenesisConfig {
230 system: runtime::SystemConfig {245 system: SystemConfig {
231 code: runtime::WASM_BINARY246 code: WASM_BINARY
232 .expect("WASM binary was not build, please build it!")247 .expect("WASM binary was not build, please build it!")
233 .to_vec(),248 .to_vec(),
234 },249 },
245 key: Some(root_key),260 key: Some(root_key),
246 },261 },
247 vesting: VestingConfig { vesting: vec![] },262 vesting: VestingConfig { vesting: vec![] },
248 parachain_info: runtime::ParachainInfoConfig { parachain_id: id },263 parachain_info: ParachainInfoConfig { parachain_id: id },
249 parachain_system: Default::default(),264 parachain_system: Default::default(),
250 aura: runtime::AuraConfig {265 aura: AuraConfig {
251 authorities: initial_authorities,266 authorities: initial_authorities,
252 },267 },
253 aura_ext: Default::default(),268 aura_ext: Default::default(),
modifiednode/cli/src/command.rsdiffbeforeafterboth
33// limitations under the License.33// limitations under the License.
3434
35use crate::{35use crate::{
36 chain_spec,36 chain_spec::{self, RuntimeIdentification},
37 cli::{Cli, RelayChainCli, Subcommand},37 cli::{Cli, RelayChainCli, Subcommand},
38 service::{new_partial, ParachainRuntimeExecutor},38 service::new_partial,
39};39};
40
41#[cfg(feature = "unique-runtime")]
42use crate::service::UniqueRuntimeExecutor;
43
44#[cfg(feature = "quartz-runtime")]
45use crate::service::QuartzRuntimeExecutor;
46
47#[cfg(feature = "opal-runtime")]
48use crate::service::OpalRuntimeExecutor;
49
40use codec::Encode;50use codec::Encode;
41use cumulus_primitives_core::ParaId;51use cumulus_primitives_core::ParaId;
53use sp_runtime::traits::Block as BlockT;63use sp_runtime::traits::Block as BlockT;
54use std::{io::Write, net::SocketAddr};64use std::{io::Write, net::SocketAddr};
5565
56#[cfg(feature = "unique-runtime")]
57use unique_runtime as runtime;66use unique_runtime_common::types::Block;
5867
59#[cfg(feature = "quartz-runtime")]68macro_rules! no_runtime_err {
60use quartz_runtime as runtime;69 ($chain_spec:expr) => {
61
62#[cfg(feature = "opal-runtime")]70 format!("No runtime valid runtime was found, chain id: {}",
71 $chain_spec.id())
63use opal_runtime as runtime;72 };
6473}
65use runtime::Block;
6674
67fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {75fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
68 Ok(match id {76 Ok(match id {
79impl SubstrateCli for Cli {87impl SubstrateCli for Cli {
80 // TODO use args88 // TODO use args
81 fn impl_name() -> String {89 fn impl_name() -> String {
82 format!("{} Node", runtime::RUNTIME_NAME)90 "Unique Node".into()
83 }91 }
8492
85 fn impl_version() -> String {93 fn impl_version() -> String {
88 // TODO use args96 // TODO use args
89 fn description() -> String {97 fn description() -> String {
90 format!(98 format!(
91 "{} Node\n\nThe command-line arguments provided first will be \99 "Unique Node\n\nThe command-line arguments provided first will be \
92 passed to the parachain node, while the arguments provided after -- will be passed \100 passed to the parachain node, while the arguments provided after -- will be passed \
93 to the relaychain node.\n\n\101 to the relaychain node.\n\n\
94 {} [parachain-args] -- [relaychain-args]",102 {} [parachain-args] -- [relaychain-args]",
95 runtime::RUNTIME_NAME,
96 Self::executable_name()103 Self::executable_name()
97 )104 )
98 }105 }
114 load_spec(id)121 load_spec(id)
115 }122 }
116123
117 fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {124 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
125 #[cfg(feature = "unique-runtime")]
126 if chain_spec.is_unique() {
127 return &unique_runtime::VERSION;
128 }
129
130 #[cfg(feature = "quartz-runtime")]
131 if chain_spec.is_quartz() {
132 return &quartz_runtime::VERSION;
133 }
134
135 #[cfg(feature = "opal-runtime")]
136 if chain_spec.is_opal() {
118 &runtime::VERSION137 return &opal_runtime::VERSION;
138 }
139
140 panic!("{}", no_runtime_err!(chain_spec));
119 }141 }
120}142}
121143
122impl SubstrateCli for RelayChainCli {144impl SubstrateCli for RelayChainCli {
123 // TODO use args145 // TODO use args
124 fn impl_name() -> String {146 fn impl_name() -> String {
125 format!("{} Node", runtime::RUNTIME_NAME)147 "Unique Node".into()
126 }148 }
127149
128 fn impl_version() -> String {150 fn impl_version() -> String {
129 env!("SUBSTRATE_CLI_IMPL_VERSION").into()151 env!("SUBSTRATE_CLI_IMPL_VERSION").into()
130 }152 }
131 // TODO use args153 // TODO use args
132 fn description() -> String {154 fn description() -> String {
155 "Unique Node\n\nThe command-line arguments provided first will be \
156 passed to the parachain node, while the arguments provided after -- will be passed \
157 to the relaychain node.\n\n\
158 parachain-collator [parachain-args] -- [relaychain-args]"
133 format!(159 .into()
134 "{} Node\n\nThe command-line arguments provided first will be \
135 passed to the parachain node, while the arguments provided after -- will be passed \
136 to the relaychain node.\n\n\
137 parachain-collator [parachain-args] -- [relaychain-args]",
138 runtime::RUNTIME_NAME
139 )
140 }160 }
141161
174 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{194 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
175 let runner = $cli.create_runner($cmd)?;195 let runner = $cli.create_runner($cmd)?;
196
197 #[cfg(feature = "unique-runtime")]
176 runner.async_run(|$config| {198 if runner.config().chain_spec.is_unique() {
199 return runner.async_run(|$config| {
177 let $components = new_partial::<200 let $components = new_partial::<
178 _201 unique_runtime::RuntimeApi, UniqueRuntimeExecutor, _
179 >(202 >(
180 &$config,203 &$config,
181 crate::service::parachain_build_import_queue,204 crate::service::parachain_build_import_queue,
182 )?;205 )?;
183 let task_manager = $components.task_manager;206 let task_manager = $components.task_manager;
184 { $( $code )* }.map(|v| (v, task_manager))207 { $( $code )* }.map(|v| (v, task_manager))
185 })208 });
209 }
210
211 #[cfg(feature = "quartz-runtime")]
212 if runner.config().chain_spec.is_quartz() {
213 return runner.async_run(|$config| {
214 let $components = new_partial::<
215 quartz_runtime::RuntimeApi, QuartzRuntimeExecutor, _
216 >(
217 &$config,
218 crate::service::parachain_build_import_queue,
219 )?;
220 let task_manager = $components.task_manager;
221 { $( $code )* }.map(|v| (v, task_manager))
222 });
223 }
224
225 #[cfg(feature = "opal-runtime")]
226 if runner.config().chain_spec.is_opal() {
227 return runner.async_run(|$config| {
228 let $components = new_partial::<
229 opal_runtime::RuntimeApi, OpalRuntimeExecutor, _
230 >(
231 &$config,
232 crate::service::parachain_build_import_queue,
233 )?;
234 let task_manager = $components.task_manager;
235 { $( $code )* }.map(|v| (v, task_manager))
236 });
237 }
238
239 Err(no_runtime_err!(runner.config().chain_spec).into())
186 }}240 }}
187}241}
188242
287 if cfg!(feature = "runtime-benchmarks") {341 if cfg!(feature = "runtime-benchmarks") {
288 let runner = cli.create_runner(cmd)?;342 let runner = cli.create_runner(cmd)?;
289
290 runner.sync_run(|config| cmd.run::<Block, ParachainRuntimeExecutor>(config))343 runner.sync_run(|config| {
344 #[cfg(feature = "unique-runtime")]
345 if config.chain_spec.is_unique() {
346 return cmd.run::<Block, UniqueRuntimeExecutor>(config);
347 }
348
349 #[cfg(feature = "quartz-runtime")]
350 if config.chain_spec.is_quartz() {
351 return cmd.run::<Block, QuartzRuntimeExecutor>(config);
352 }
353
354 #[cfg(feature = "opal-runtime")]
355 if config.chain_spec.is_opal() {
356 return cmd.run::<Block, OpalRuntimeExecutor>(config);
357 }
358
359 Err(no_runtime_err!(config.chain_spec).into())
360 })
291 } else {361 } else {
292 Err("Benchmarking wasn't enabled when building the node. \362 Err("Benchmarking wasn't enabled when building the node. \
293 You can enable it with `--features runtime-benchmarks`."363 You can enable it with `--features runtime-benchmarks`."
341 }411 }
342 );412 );
343413
414 #[cfg(feature = "unique-runtime")]
415 if config.chain_spec.is_unique() {
416 return crate::service::start_node::<
417 unique_runtime::Runtime,
418 unique_runtime::RuntimeApi,
419 UniqueRuntimeExecutor,
420 >(config, polkadot_config, id)
421 .await
422 .map(|r| r.0)
423 .map_err(Into::into);
424 }
425
426 #[cfg(feature = "quartz-runtime")]
427 if config.chain_spec.is_quartz() {
428 return crate::service::start_node::<
429 quartz_runtime::Runtime,
430 quartz_runtime::RuntimeApi,
431 QuartzRuntimeExecutor,
432 >(config, polkadot_config, id)
433 .await
434 .map(|r| r.0)
435 .map_err(Into::into);
436 }
437
438 #[cfg(feature = "opal-runtime")]
439 if config.chain_spec.is_opal() {
344 crate::service::start_node(config, polkadot_config, id)440 return crate::service::start_node::<
441 opal_runtime::Runtime,
442 opal_runtime::RuntimeApi,
443 OpalRuntimeExecutor,
444 >(config, polkadot_config, id)
445 .await
446 .map(|r| r.0)
345 .await447 .map_err(Into::into);
346 .map(|r| r.0)448 }
347 .map_err(Into::into)449
450 Err(no_runtime_err!(config.chain_spec).into())
348 })451 })
349 }452 }
350 }453 }
modifiednode/cli/src/service.rsdiffbeforeafterboth
25use futures::StreamExt;25use futures::StreamExt;
2626
27use unique_rpc::overrides_handle;27use unique_rpc::overrides_handle;
28// Local Runtime Types
29#[cfg(feature = "unique-runtime")]
30use unique_runtime as runtime;
31
32#[cfg(feature = "quartz-runtime")]
33use quartz_runtime as runtime;
34
35#[cfg(feature = "opal-runtime")]
36use opal_runtime as runtime;
3728
38use runtime::RuntimeApi;29use serde::{Serialize, Deserialize};
3930
40// Cumulus Imports31// Cumulus Imports
41use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};32use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
71pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;62pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
72type Hash = sp_core::H256;63type Hash = sp_core::H256;
64
65use unique_runtime_common::types::{AuraId, RuntimeInstance, AccountId, Balance, Index};
7366
74/// Native executor instance.67/// Native executor instance.
75pub struct ParachainRuntimeExecutor;68pub struct UniqueRuntimeExecutor;
69pub struct QuartzRuntimeExecutor;
70pub struct OpalRuntimeExecutor;
7671
77impl NativeExecutionDispatch for ParachainRuntimeExecutor {72impl NativeExecutionDispatch for UniqueRuntimeExecutor {
78 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;73 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
7974
80 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {75 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
81 runtime::api::dispatch(method, data)76 unique_runtime::api::dispatch(method, data)
82 }77 }
8378
84 fn native_version() -> sc_executor::NativeVersion {79 fn native_version() -> sc_executor::NativeVersion {
85 runtime::native_version()80 unique_runtime::native_version()
86 }81 }
87}82}
83
84impl NativeExecutionDispatch for QuartzRuntimeExecutor {
85 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
86
87 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
88 unique_runtime::api::dispatch(method, data)
89 }
90
91 fn native_version() -> sc_executor::NativeVersion {
92 unique_runtime::native_version()
93 }
94}
95
96impl NativeExecutionDispatch for OpalRuntimeExecutor {
97 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
98
99 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
100 unique_runtime::api::dispatch(method, data)
101 }
102
103 fn native_version() -> sc_executor::NativeVersion {
104 unique_runtime::native_version()
105 }
106}
88107
89pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {108pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {
90 let config_dir = config109 let config_dir = config
106 )?))125 )?))
107}126}
108
109type ExecutorDispatch = ParachainRuntimeExecutor;
110127
111type FullClient =128type FullClient<RuntimeApi, ExecutorDispatch> =
112 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;129 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
113type FullBackend = sc_service::TFullBackend<Block>;130type FullBackend = sc_service::TFullBackend<Block>;
114type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;131type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
118/// Use this macro if you don't actually need the full service, but just the builder in order to135/// Use this macro if you don't actually need the full service, but just the builder in order to
119/// be able to perform chain operations.136/// be able to perform chain operations.
120#[allow(clippy::type_complexity)]137#[allow(clippy::type_complexity)]
121pub fn new_partial<BIQ>(138pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(
122 config: &Configuration,139 config: &Configuration,
123 build_import_queue: BIQ,140 build_import_queue: BIQ,
124) -> Result<141) -> Result<
125 PartialComponents<142 PartialComponents<
126 FullClient,143 FullClient<RuntimeApi, ExecutorDispatch>,
127 FullBackend,144 FullBackend,
128 FullSelectChain,145 FullSelectChain,
129 sc_consensus::DefaultImportQueue<Block, FullClient>,146 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
130 sc_transaction_pool::FullPool<Block, FullClient>,147 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
131 (148 (
132 Option<Telemetry>,149 Option<Telemetry>,
133 Option<FilterPool>,150 Option<FilterPool>,
140>157>
141where158where
142 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,159 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
160 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
161 + Send
162 + Sync
163 + 'static,
164 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
143 ExecutorDispatch: NativeExecutionDispatch + 'static,165 ExecutorDispatch: NativeExecutionDispatch + 'static,
144 BIQ: FnOnce(166 BIQ: FnOnce(
145 Arc<FullClient>,167 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
146 &Configuration,168 &Configuration,
147 Option<TelemetryHandle>,169 Option<TelemetryHandle>,
148 &TaskManager,170 &TaskManager,
149 ) -> Result<sc_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error>,171 ) -> Result<
172 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
173 sc_service::Error,
174 >,
150{175{
151 let _telemetry = config176 let _telemetry = config
240///265///
241/// This is the actual implementation that is abstract over the executor and the runtime api.266/// This is the actual implementation that is abstract over the executor and the runtime api.
242#[sc_tracing::logging::prefix_logs_with("Parachain")]267#[sc_tracing::logging::prefix_logs_with("Parachain")]
243async fn start_node_impl<BIQ, BIC>(268async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(
244 parachain_config: Configuration,269 parachain_config: Configuration,
245 polkadot_config: Configuration,270 polkadot_config: Configuration,
246 id: ParaId,271 id: ParaId,
247 build_import_queue: BIQ,272 build_import_queue: BIQ,
248 build_consensus: BIC,273 build_consensus: BIC,
249) -> sc_service::error::Result<(TaskManager, Arc<FullClient>)>274) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>
250where275where
251 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,276 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
277 Runtime: RuntimeInstance + Send + Sync + 'static,
278 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,
279 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,
280 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
281 + Send
282 + Sync
283 + 'static,
284 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
285 + fp_rpc::EthereumRuntimeRPCApi<Block>
286 + sp_session::SessionKeys<Block>
287 + sp_block_builder::BlockBuilder<Block>
288 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
289 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>
290 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>
291 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
292 + sp_api::Metadata<Block>
293 + sp_offchain::OffchainWorkerApi<Block>
294 + cumulus_primitives_core::CollectCollationInfo<Block>,
252 ExecutorDispatch: NativeExecutionDispatch + 'static,295 ExecutorDispatch: NativeExecutionDispatch + 'static,
253 BIQ: FnOnce(296 BIQ: FnOnce(
254 Arc<FullClient>,297 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
255 &Configuration,298 &Configuration,
256 Option<TelemetryHandle>,299 Option<TelemetryHandle>,
257 &TaskManager,300 &TaskManager,
258 ) -> Result<sc_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error>,301 ) -> Result<
302 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
303 sc_service::Error,
304 >,
259 BIC: FnOnce(305 BIC: FnOnce(
260 Arc<FullClient>,306 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
261 Option<&Registry>,307 Option<&Registry>,
262 Option<TelemetryHandle>,308 Option<TelemetryHandle>,
263 &TaskManager,309 &TaskManager,
264 Arc<dyn RelayChainInterface>,310 Arc<dyn RelayChainInterface>,
265 Arc<sc_transaction_pool::FullPool<Block, FullClient>>,311 Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,
266 Arc<NetworkService<Block, Hash>>,312 Arc<NetworkService<Block, Hash>>,
267 SyncCryptoStorePtr,313 SyncCryptoStorePtr,
268 bool,314 bool,
275 let parachain_config = prepare_node_config(parachain_config);321 let parachain_config = prepare_node_config(parachain_config);
276322
277 let params = new_partial::<BIQ>(&parachain_config, build_import_queue)?;323 let params =
324 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;
278 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =325 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =
279 params.other;326 params.other;
280327
320367
321 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(368 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(
322 task_manager.spawn_handle(),369 task_manager.spawn_handle(),
323 overrides_handle(client.clone()),370 overrides_handle::<_, _, Runtime>(client.clone()),
324 50,371 50,
325 50,372 50,
326 ));373 ));
347 };394 };
348395
349 Ok(unique_rpc::create_full::<_, _, _, _, RuntimeApi, _>(396 Ok(
397 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(
350 full_deps,398 full_deps,
351 subscription_executor.clone(),399 subscription_executor.clone(),
352 ))400 ),
401 )
353 });402 });
354403
436}485}
437486
438/// Build the import queue for the the parachain runtime.487/// Build the import queue for the the parachain runtime.
439pub fn parachain_build_import_queue(488pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(
440 client: Arc<FullClient>,489 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
441 config: &Configuration,490 config: &Configuration,
442 telemetry: Option<TelemetryHandle>,491 telemetry: Option<TelemetryHandle>,
443 task_manager: &TaskManager,492 task_manager: &TaskManager,
444) -> Result<sc_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error> {493) -> Result<
494 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
495 sc_service::Error,
496>
497where
498 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
499 + Send
500 + Sync
501 + 'static,
502 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
503 + sp_block_builder::BlockBuilder<Block>
504 + sp_consensus_aura::AuraApi<Block, AuraId>
505 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
506 ExecutorDispatch: NativeExecutionDispatch + 'static,
507{
445 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;508 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
446509
475}538}
476539
477/// Start a normal parachain node.540/// Start a normal parachain node.
478pub async fn start_node(541pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(
479 parachain_config: Configuration,542 parachain_config: Configuration,
480 polkadot_config: Configuration,543 polkadot_config: Configuration,
481 id: ParaId,544 id: ParaId,
482) -> sc_service::error::Result<(TaskManager, Arc<FullClient>)> {545) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>
546where
547 Runtime: RuntimeInstance + Send + Sync + 'static,
548 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,
549 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,
550 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
551 + Send
552 + Sync
553 + 'static,
554 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
555 + fp_rpc::EthereumRuntimeRPCApi<Block>
556 + sp_session::SessionKeys<Block>
557 + sp_block_builder::BlockBuilder<Block>
558 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
559 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>
560 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>
561 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
562 + sp_api::Metadata<Block>
563 + sp_offchain::OffchainWorkerApi<Block>
564 + cumulus_primitives_core::CollectCollationInfo<Block>
565 + sp_consensus_aura::AuraApi<Block, AuraId>,
566 ExecutorDispatch: NativeExecutionDispatch + 'static,
567{
483 start_node_impl::<_, _>(568 start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(
484 parachain_config,569 parachain_config,
485 polkadot_config,570 polkadot_config,
486 id,571 id,
modifiednode/rpc/Cargo.tomldiffbeforeafterboth
48fc-db = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.17" }48fc-db = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.17" }
49fc-mapping-sync = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.17" }49fc-mapping-sync = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.17" }
5050
51pallet-unique = { path = "../../pallets/unique" }51pallet-common = { default-features = false, path = "../../pallets/common" }
52uc-rpc = { path = "../../client/rpc" }
53up-rpc = { path = "../../primitives/rpc" }52unique-runtime-common = { default-features = false, path = "../../runtime/common" }
54unique-runtime = { path = "../../runtime/unique", optional = true }53pallet-unique = { path = "../../pallets/unique" }
55quartz-runtime = { path = "../../runtime/quartz", optional = true }54uc-rpc = { path = "../../client/rpc" }
56opal-runtime = { path = "../../runtime/opal", optional = true }55up-rpc = { path = "../../primitives/rpc" }
56
57[dependencies.serde]
58features = ['derive']
59version = '1.0.130'
5760
58[features]61[features]
59default = ["unique-runtime"]62default = []
60std = []63std = []
6164
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
40use sc_service::TransactionPool;40use sc_service::TransactionPool;
41use std::{collections::BTreeMap, marker::PhantomData, sync::Arc};41use std::{collections::BTreeMap, marker::PhantomData, sync::Arc};
42
43#[cfg(feature = "unique-runtime")]
44use unique_runtime as runtime;
45
46#[cfg(feature = "quartz-runtime")]
47use quartz_runtime as runtime;
48
49#[cfg(feature = "opal-runtime")]
50use opal_runtime as runtime;
5142
52use runtime::opaque::{Hash, AccountId, CrossAccountId, Index, Block, BlockNumber, Balance};43use unique_runtime_common::types::{
44 Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance,
45};
5346
54/// Public io handler for exporting into other modules47/// Public io handler for exporting into other modules
100 pub block_data_cache: Arc<EthBlockDataCache<Block>>,93 pub block_data_cache: Arc<EthBlockDataCache<Block>>,
101}94}
10295
103struct AccountCodes<C, B> {96struct AccountCodes<C, B, R> {
104 client: Arc<C>,97 client: Arc<C>,
105 _marker: PhantomData<B>,98 _blk_marker: PhantomData<B>,
99 _runtime_marker: PhantomData<R>,
106}100}
107101
108impl<C, Block> AccountCodes<C, Block>102impl<C, Block, R> AccountCodes<C, Block, R>
109where103where
110 Block: sp_api::BlockT,104 Block: sp_api::BlockT,
111 C: ProvideRuntimeApi<Block>,105 C: ProvideRuntimeApi<Block>,
106 R: RuntimeInstance,
112{107{
113 fn new(client: Arc<C>) -> Self {108 fn new(client: Arc<C>) -> Self {
114 Self {109 Self {
115 client,110 client,
116 _marker: PhantomData,111 _blk_marker: PhantomData,
112 _runtime_marker: PhantomData,
117 }113 }
118 }114 }
119}115}
120116
121impl<C, Block> fc_rpc::AccountCodeProvider<Block> for AccountCodes<C, Block>117impl<C, Block, Runtime> fc_rpc::AccountCodeProvider<Block> for AccountCodes<C, Block, Runtime>
122where118where
123 Block: sp_api::BlockT,119 Block: sp_api::BlockT,
124 C: ProvideRuntimeApi<Block>,120 C: ProvideRuntimeApi<Block>,
125 C::Api: up_rpc::UniqueApi<Block, CrossAccountId, AccountId>,121 C::Api: up_rpc::UniqueApi<Block, <Runtime as RuntimeInstance>::CrossAccountId, AccountId>,
122 Runtime: RuntimeInstance,
126{123{
127 fn code(&self, block: &sp_api::BlockId<Block>, account: sp_core::H160) -> Option<Vec<u8>> {124 fn code(&self, block: &sp_api::BlockId<Block>, account: sp_core::H160) -> Option<Vec<u8>> {
128 use up_rpc::UniqueApi;125 use up_rpc::UniqueApi;
134 }131 }
135}132}
136133
137pub fn overrides_handle<C, BE>(client: Arc<C>) -> Arc<OverrideHandle<Block>>134pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>
138where135where
139 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,136 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,
140 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,137 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
141 C: Send + Sync + 'static,138 C: Send + Sync + 'static,
142 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,139 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
143 C::Api: up_rpc::UniqueApi<Block, CrossAccountId, AccountId>,140 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,
144 BE: Backend<Block> + 'static,141 BE: Backend<Block> + 'static,
145 BE::State: StateBackend<BlakeTwo256>,142 BE::State: StateBackend<BlakeTwo256>,
143 R: RuntimeInstance + Send + Sync + 'static,
146{144{
147 let mut overrides_map = BTreeMap::new();145 let mut overrides_map = BTreeMap::new();
148 overrides_map.insert(146 overrides_map.insert(
149 EthereumStorageSchema::V1,147 EthereumStorageSchema::V1,
150 Box::new(SchemaV1Override::new_with_code_provider(148 Box::new(SchemaV1Override::new_with_code_provider(
151 client.clone(),149 client.clone(),
152 Arc::new(AccountCodes::<C, Block>::new(client.clone())),150 Arc::new(AccountCodes::<C, Block, R>::new(client.clone())),
153 )) as Box<dyn StorageOverride<_> + Send + Sync>,151 )) as Box<dyn StorageOverride<_> + Send + Sync>,
154 );152 );
155 overrides_map.insert(153 overrides_map.insert(
170}168}
171169
172/// Instantiate all Full RPC extensions.170/// Instantiate all Full RPC extensions.
173pub fn create_full<C, P, SC, CA, A, B>(171pub fn create_full<C, P, SC, CA, R, A, B>(
174 deps: FullDeps<C, P, SC, CA>,172 deps: FullDeps<C, P, SC, CA>,
175 subscription_task_executor: SubscriptionTaskExecutor,173 subscription_task_executor: SubscriptionTaskExecutor,
176) -> jsonrpc_core::IoHandler<sc_rpc_api::Metadata>174) -> jsonrpc_core::IoHandler<sc_rpc_api::Metadata>
184 // C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,182 // C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,
185 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,183 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
186 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,184 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
187 C::Api: up_rpc::UniqueApi<Block, CrossAccountId, AccountId>,185 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,
188 B: sc_client_api::Backend<Block> + Send + Sync + 'static,186 B: sc_client_api::Backend<Block> + Send + Sync + 'static,
189 B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,187 B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
190 P: TransactionPool<Block = Block> + 'static,188 P: TransactionPool<Block = Block> + 'static,
191 CA: ChainApi<Block = Block> + 'static,189 CA: ChainApi<Block = Block> + 'static,
190 R: RuntimeInstance + Send + Sync + 'static,
191 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,
192 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,
192{193{
193 use fc_rpc::{194 use fc_rpc::{
194 EthApi, EthApiServer, EthDevSigner, EthFilterApi, EthFilterApiServer, EthPubSubApi,195 EthApi, EthApiServer, EthDevSigner, EthFilterApi, EthFilterApiServer, EthPubSubApi,
235 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);236 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
236 }237 }
237238
238 let overrides = overrides_handle(client.clone());239 let overrides = overrides_handle::<_, _, R>(client.clone());
239240
240 io.extend_with(EthApiServer::to_delegate(EthApi::new(241 io.extend_with(EthApiServer::to_delegate(EthApi::new(
241 client.clone(),242 client.clone(),
242 pool.clone(),243 pool.clone(),
243 graph,244 graph,
244 runtime::TransactionConverter,245 <R as RuntimeInstance>::get_transaction_converter(),
245 network.clone(),246 network.clone(),
246 signers,247 signers,
247 overrides.clone(),248 overrides.clone(),