mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-04-27 16:17:56 +00:00
* #188 added RPC node to enable interaction
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//! substrate service.
|
||||
|
||||
// std
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use std::{path::Path, sync::Arc, time::Duration};
|
||||
|
||||
use cumulus_client_cli::CollatorOptions;
|
||||
// Cumulus Imports
|
||||
@@ -22,7 +22,7 @@ use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
|
||||
// Local Runtime Types
|
||||
use parachain_template_runtime::{
|
||||
opaque::{Block, Hash},
|
||||
RuntimeApi,
|
||||
RuntimeApi, TransactionConverter,
|
||||
};
|
||||
use sc_client_api::Backend;
|
||||
use sc_consensus::ImportQueue;
|
||||
@@ -34,9 +34,15 @@ use sc_network_sync::SyncingService;
|
||||
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
|
||||
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
|
||||
use sp_core::U256;
|
||||
use sp_keystore::KeystorePtr;
|
||||
use substrate_prometheus_endpoint::Registry;
|
||||
|
||||
use crate::eth::{
|
||||
db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration,
|
||||
FrontierBackend, FrontierPartialComponents,
|
||||
};
|
||||
|
||||
/// Native executor type.
|
||||
pub struct ParachainNativeExecutor;
|
||||
|
||||
@@ -66,6 +72,7 @@ type ParachainBlockImport = TParachainBlockImport<Block, Arc<ParachainClient>, P
|
||||
/// builder in order to be able to perform chain operations.
|
||||
pub fn new_partial(
|
||||
config: &Configuration,
|
||||
eth_config: &EthConfiguration,
|
||||
) -> Result<
|
||||
PartialComponents<
|
||||
ParachainClient,
|
||||
@@ -73,7 +80,13 @@ pub fn new_partial(
|
||||
(),
|
||||
sc_consensus::DefaultImportQueue<Block>,
|
||||
sc_transaction_pool::FullPool<Block, ParachainClient>,
|
||||
(ParachainBlockImport, Option<Telemetry>, Option<TelemetryWorkerHandle>),
|
||||
(
|
||||
ParachainBlockImport,
|
||||
Option<Telemetry>,
|
||||
Option<TelemetryWorkerHandle>,
|
||||
FrontierBackend,
|
||||
Arc<fc_rpc::OverrideHandle<Block>>,
|
||||
),
|
||||
>,
|
||||
sc_service::Error,
|
||||
> {
|
||||
@@ -135,6 +148,37 @@ pub fn new_partial(
|
||||
&task_manager,
|
||||
)?;
|
||||
|
||||
let overrides = crate::rpc::overrides_handle(client.clone());
|
||||
|
||||
let frontier_backend = match eth_config.frontier_backend_type {
|
||||
BackendType::KeyValue => FrontierBackend::KeyValue(fc_db::kv::Backend::open(
|
||||
Arc::clone(&client),
|
||||
&config.database,
|
||||
&db_config_dir(config),
|
||||
)?),
|
||||
BackendType::Sql => {
|
||||
let db_path = db_config_dir(config).join("sql");
|
||||
std::fs::create_dir_all(&db_path).expect("failed creating sql db directory");
|
||||
let backend = futures::executor::block_on(fc_db::sql::Backend::new(
|
||||
fc_db::sql::BackendConfig::Sqlite(fc_db::sql::SqliteBackendConfig {
|
||||
path: Path::new("sqlite:///")
|
||||
.join(db_path)
|
||||
.join("frontier.db3")
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
create_if_missing: true,
|
||||
thread_count: eth_config.frontier_sql_backend_thread_count,
|
||||
cache_size: eth_config.frontier_sql_backend_cache_size,
|
||||
}),
|
||||
eth_config.frontier_sql_backend_pool_size,
|
||||
std::num::NonZeroU32::new(eth_config.frontier_sql_backend_num_ops_timeout),
|
||||
overrides.clone(),
|
||||
))
|
||||
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));
|
||||
FrontierBackend::Sql(backend)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(PartialComponents {
|
||||
backend,
|
||||
client,
|
||||
@@ -143,7 +187,7 @@ pub fn new_partial(
|
||||
task_manager,
|
||||
transaction_pool,
|
||||
select_chain: (),
|
||||
other: (block_import, telemetry, telemetry_worker_handle),
|
||||
other: (block_import, telemetry, telemetry_worker_handle, frontier_backend, overrides),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -157,13 +201,19 @@ async fn start_node_impl(
|
||||
parachain_config: Configuration,
|
||||
polkadot_config: Configuration,
|
||||
collator_options: CollatorOptions,
|
||||
eth_config: &EthConfiguration,
|
||||
para_id: ParaId,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
|
||||
let parachain_config = prepare_node_config(parachain_config);
|
||||
|
||||
let params = new_partial(¶chain_config)?;
|
||||
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;
|
||||
let params = new_partial(¶chain_config, eth_config)?;
|
||||
|
||||
let FrontierPartialComponents { filter_pool, fee_history_cache, fee_history_cache_limit } =
|
||||
new_frontier_partial(eth_config)?;
|
||||
|
||||
let (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, overrides) =
|
||||
params.other;
|
||||
let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);
|
||||
|
||||
let client = params.client.clone();
|
||||
@@ -185,6 +235,7 @@ async fn start_node_impl(
|
||||
let prometheus_registry = parachain_config.prometheus_registry().cloned();
|
||||
let transaction_pool = params.transaction_pool.clone();
|
||||
let import_queue_service = params.import_queue.service();
|
||||
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
|
||||
build_network(BuildNetworkParams {
|
||||
@@ -223,18 +274,81 @@ async fn start_node_impl(
|
||||
);
|
||||
}
|
||||
|
||||
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
|
||||
fc_mapping_sync::EthereumBlockNotification<Block>,
|
||||
> = Default::default();
|
||||
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);
|
||||
|
||||
let rpc_builder = {
|
||||
let client = client.clone();
|
||||
let transaction_pool = transaction_pool.clone();
|
||||
let target_gas_price = eth_config.target_gas_price;
|
||||
let enable_dev_signer = eth_config.enable_dev_signer;
|
||||
let pending_create_inherent_data_providers = move |_, ()| async move {
|
||||
let current = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();
|
||||
let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into());
|
||||
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
|
||||
*timestamp,
|
||||
slot_duration,
|
||||
);
|
||||
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
|
||||
Ok((slot, timestamp, dynamic_fee))
|
||||
};
|
||||
let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(
|
||||
task_manager.spawn_handle(),
|
||||
overrides.clone(),
|
||||
eth_config.eth_log_block_cache,
|
||||
eth_config.eth_statuses_cache,
|
||||
prometheus_registry.clone(),
|
||||
));
|
||||
let execute_gas_limit_multiplier = eth_config.execute_gas_limit_multiplier;
|
||||
let max_past_logs = eth_config.max_past_logs;
|
||||
let network = network.clone();
|
||||
let sync_service = sync_service.clone();
|
||||
let frontier_backend = frontier_backend.clone();
|
||||
let filter_pool = filter_pool.clone();
|
||||
let overrides = overrides.clone();
|
||||
let fee_history_cache = fee_history_cache.clone();
|
||||
let pubsub_notification_sinks = pubsub_notification_sinks.clone();
|
||||
|
||||
Box::new(move |deny_unsafe, _| {
|
||||
Box::new(move |deny_unsafe, subscription_task_executor| {
|
||||
let eth = crate::rpc::EthDeps {
|
||||
client: client.clone(),
|
||||
pool: transaction_pool.clone(),
|
||||
graph: transaction_pool.pool().clone(),
|
||||
converter: Some(TransactionConverter),
|
||||
is_authority: validator,
|
||||
enable_dev_signer,
|
||||
network: network.clone(),
|
||||
sync: sync_service.clone(),
|
||||
frontier_backend: match frontier_backend.clone() {
|
||||
fc_db::Backend::KeyValue(b) => Arc::new(b),
|
||||
fc_db::Backend::Sql(b) => Arc::new(b),
|
||||
},
|
||||
overrides: overrides.clone(),
|
||||
block_data_cache: block_data_cache.clone(),
|
||||
filter_pool: filter_pool.clone(),
|
||||
max_past_logs,
|
||||
fee_history_cache: fee_history_cache.clone(),
|
||||
fee_history_cache_limit,
|
||||
execute_gas_limit_multiplier,
|
||||
forced_parent_hashes: None,
|
||||
pending_create_inherent_data_providers,
|
||||
};
|
||||
let deps = crate::rpc::FullDeps {
|
||||
client: client.clone(),
|
||||
pool: transaction_pool.clone(),
|
||||
deny_unsafe,
|
||||
eth,
|
||||
};
|
||||
|
||||
crate::rpc::create_full(deps).map_err(Into::into)
|
||||
crate::rpc::create_full(
|
||||
deps,
|
||||
subscription_task_executor,
|
||||
pubsub_notification_sinks.clone(),
|
||||
)
|
||||
.map_err(Into::into)
|
||||
})
|
||||
};
|
||||
|
||||
@@ -245,9 +359,6 @@ async fn start_node_impl(
|
||||
task_manager: &mut task_manager,
|
||||
config: parachain_config,
|
||||
keystore: params.keystore_container.keystore(),
|
||||
#[cfg(not(feature = "async-backing"))]
|
||||
backend,
|
||||
#[cfg(feature = "async-backing")]
|
||||
backend: backend.clone(),
|
||||
network: network.clone(),
|
||||
sync_service: sync_service.clone(),
|
||||
@@ -311,6 +422,20 @@ async fn start_node_impl(
|
||||
sync_service: sync_service.clone(),
|
||||
})?;
|
||||
|
||||
spawn_frontier_tasks(
|
||||
&task_manager,
|
||||
client.clone(),
|
||||
backend.clone(),
|
||||
frontier_backend,
|
||||
filter_pool,
|
||||
overrides,
|
||||
fee_history_cache,
|
||||
fee_history_cache_limit,
|
||||
sync_service.clone(),
|
||||
pubsub_notification_sinks,
|
||||
)
|
||||
.await;
|
||||
|
||||
if validator {
|
||||
start_consensus(
|
||||
client.clone(),
|
||||
@@ -464,8 +589,17 @@ pub async fn start_parachain_node(
|
||||
parachain_config: Configuration,
|
||||
polkadot_config: Configuration,
|
||||
collator_options: CollatorOptions,
|
||||
eth_config: &EthConfiguration,
|
||||
para_id: ParaId,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
|
||||
start_node_impl(parachain_config, polkadot_config, collator_options, para_id, hwbench).await
|
||||
start_node_impl(
|
||||
parachain_config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
eth_config,
|
||||
para_id,
|
||||
hwbench,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user