mirror of
https://github.com/pezkuwichain/pez-minimal-template.git
synced 2026-04-22 05:38:00 +00:00
Update template triggered by workflow_dispatch
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
[package]
|
||||
name = "minimal-template-node"
|
||||
description = "A miniaml Substrate-based Substrate node, ready for hacking. (polkadot v1.9.0)"
|
||||
version = "0.1.0"
|
||||
license = "MIT-0"
|
||||
authors.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
edition.workspace = true
|
||||
publish = false
|
||||
build = "build.rs"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.1", features = ["derive"] }
|
||||
futures = { version = "0.3.21", features = ["thread-pool"] }
|
||||
futures-timer = "3.0.1"
|
||||
jsonrpsee = { version = "0.22", features = ["server"] }
|
||||
serde_json = { workspace = true, default-features = true }
|
||||
sc-cli = { version = "0.39.0" }
|
||||
sc-executor = { version = "0.35.0" }
|
||||
sc-network = { version = "0.37.0" }
|
||||
sc-service = { version = "0.38.0" }
|
||||
sc-telemetry = { version = "17.0.0" }
|
||||
sc-transaction-pool = { version = "31.0.0" }
|
||||
sc-transaction-pool-api = { version = "31.0.0" }
|
||||
sc-consensus = { version = "0.36.0" }
|
||||
sc-consensus-manual-seal = { version = "0.38.0" }
|
||||
sc-rpc-api = { version = "0.36.0" }
|
||||
sc-basic-authorship = { version = "0.37.0" }
|
||||
sc-offchain = { version = "32.0.0" }
|
||||
sc-client-api = { version = "31.0.0" }
|
||||
sp-timestamp = { version = "29.0.0" }
|
||||
sp-keyring = { version = "34.0.0" }
|
||||
sp-api = { version = "29.0.0" }
|
||||
sp-blockchain = { version = "31.0.0" }
|
||||
sp-block-builder = { version = "29.0.0" }
|
||||
sp-io = { version = "33.0.0" }
|
||||
sp-runtime = { version = "34.0.0" }
|
||||
substrate-frame-rpc-system = { version = "31.0.0" }
|
||||
|
||||
# Once the native runtime is gone, there should be little to no dependency on FRAME here, and
|
||||
# certainly no dependency on the runtime.
|
||||
frame = { version = "0.1.1", package = "polkadot-sdk-frame", features = ["experimental", "runtime"] }
|
||||
runtime = { package = "minimal-template-runtime", path = "../runtime", version = "0.1.0" }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-build-script-utils = { version = "11.0.0" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@@ -0,0 +1,23 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
|
||||
|
||||
fn main() {
|
||||
generate_cargo_keys();
|
||||
rerun_if_git_head_changed();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use runtime::{BalancesConfig, SudoConfig, WASM_BINARY};
|
||||
use sc_service::{ChainType, Properties};
|
||||
use serde_json::{json, Value};
|
||||
use sp_keyring::AccountKeyring;
|
||||
|
||||
/// This is a specialization of the general Substrate ChainSpec type.
|
||||
pub type ChainSpec = sc_service::GenericChainSpec<()>;
|
||||
|
||||
fn props() -> Properties {
|
||||
let mut properties = Properties::new();
|
||||
properties.insert("tokenDecimals".to_string(), 0.into());
|
||||
properties.insert("tokenSymbol".to_string(), "MINI".into());
|
||||
properties
|
||||
}
|
||||
|
||||
pub fn development_config() -> Result<ChainSpec, String> {
|
||||
Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default())
|
||||
.with_name("Development")
|
||||
.with_id("dev")
|
||||
.with_chain_type(ChainType::Development)
|
||||
.with_genesis_config_patch(testnet_genesis())
|
||||
.with_properties(props())
|
||||
.build())
|
||||
}
|
||||
|
||||
/// Configure initial storage state for FRAME pallets.
|
||||
fn testnet_genesis() -> Value {
|
||||
use frame::traits::Get;
|
||||
use runtime::interface::{Balance, MinimumBalance};
|
||||
let endowment = <MinimumBalance as Get<Balance>>::get().max(1) * 1000;
|
||||
let balances = AccountKeyring::iter()
|
||||
.map(|a| (a.to_account_id(), endowment))
|
||||
.collect::<Vec<_>>();
|
||||
json!({
|
||||
"balances": BalancesConfig { balances },
|
||||
"sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) },
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sc_cli::RunCmd;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Consensus {
|
||||
ManualSeal(u64),
|
||||
InstantSeal,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Consensus {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(if s == "instant-seal" {
|
||||
Consensus::InstantSeal
|
||||
} else if let Some(block_time) = s.strip_prefix("manual-seal-") {
|
||||
Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?)
|
||||
} else {
|
||||
return Err("incorrect consensus identifier".into())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub subcommand: Option<Subcommand>,
|
||||
|
||||
#[clap(long, default_value = "manual-seal-3000")]
|
||||
pub consensus: Consensus,
|
||||
|
||||
#[clap(flatten)]
|
||||
pub run: RunCmd,
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
pub enum Subcommand {
|
||||
/// Key management cli utilities
|
||||
#[command(subcommand)]
|
||||
Key(sc_cli::KeySubcommand),
|
||||
|
||||
/// Build a chain specification.
|
||||
BuildSpec(sc_cli::BuildSpecCmd),
|
||||
|
||||
/// Validate blocks.
|
||||
CheckBlock(sc_cli::CheckBlockCmd),
|
||||
|
||||
/// Export blocks.
|
||||
ExportBlocks(sc_cli::ExportBlocksCmd),
|
||||
|
||||
/// Export the state of a given block into a chain spec.
|
||||
ExportState(sc_cli::ExportStateCmd),
|
||||
|
||||
/// Import blocks.
|
||||
ImportBlocks(sc_cli::ImportBlocksCmd),
|
||||
|
||||
/// Remove the whole chain.
|
||||
PurgeChain(sc_cli::PurgeChainCmd),
|
||||
|
||||
/// Revert the chain to a previous state.
|
||||
Revert(sc_cli::RevertCmd),
|
||||
|
||||
/// Db meta columns information.
|
||||
ChainInfo(sc_cli::ChainInfoCmd),
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, Subcommand},
|
||||
service,
|
||||
};
|
||||
use sc_cli::SubstrateCli;
|
||||
use sc_service::PartialComponents;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use try_runtime_cli::block_building_info::timestamp_with_aura_info;
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> String {
|
||||
"Substrate Node".into()
|
||||
}
|
||||
|
||||
fn impl_version() -> String {
|
||||
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
env!("CARGO_PKG_DESCRIPTION").into()
|
||||
}
|
||||
|
||||
fn author() -> String {
|
||||
env!("CARGO_PKG_AUTHORS").into()
|
||||
}
|
||||
|
||||
fn support_url() -> String {
|
||||
"support.anonymous.an".into()
|
||||
}
|
||||
|
||||
fn copyright_start_year() -> i32 {
|
||||
2017
|
||||
}
|
||||
|
||||
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
Ok(match id {
|
||||
"dev" => Box::new(chain_spec::development_config()?),
|
||||
path =>
|
||||
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse and run command line arguments
|
||||
pub fn run() -> sc_cli::Result<()> {
|
||||
let cli = Cli::from_args();
|
||||
|
||||
match &cli.subcommand {
|
||||
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
|
||||
Some(Subcommand::BuildSpec(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
|
||||
},
|
||||
Some(Subcommand::CheckBlock(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, import_queue, .. } =
|
||||
service::new_partial(&config)?;
|
||||
Ok((cmd.run(client, import_queue), task_manager))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::ExportBlocks(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
||||
Ok((cmd.run(client, config.database), task_manager))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::ExportState(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
||||
Ok((cmd.run(client, config.chain_spec), task_manager))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::ImportBlocks(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, import_queue, .. } =
|
||||
service::new_partial(&config)?;
|
||||
Ok((cmd.run(client, import_queue), task_manager))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::PurgeChain(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.sync_run(|config| cmd.run(config.database))
|
||||
},
|
||||
Some(Subcommand::Revert(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, backend, .. } =
|
||||
service::new_partial(&config)?;
|
||||
Ok((cmd.run(client, backend, None), task_manager))
|
||||
})
|
||||
},
|
||||
Some(Subcommand::ChainInfo(cmd)) => {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
runner.sync_run(|config| cmd.run::<runtime::interface::OpaqueBlock>(&config))
|
||||
},
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run)?;
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
service::new_full(config, cli.consensus).map_err(sc_cli::Error::Service)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// This file is part of Polkadot Sdk.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod chain_spec;
|
||||
pub(crate) mod cli;
|
||||
pub mod rpc;
|
||||
pub mod service;
|
||||
@@ -0,0 +1,29 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Substrate Node Template CLI library.
|
||||
#![warn(missing_docs)]
|
||||
|
||||
mod chain_spec;
|
||||
mod cli;
|
||||
mod command;
|
||||
mod rpc;
|
||||
mod service;
|
||||
|
||||
fn main() -> sc_cli::Result<()> {
|
||||
command::run()
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! A collection of node-specific RPC methods.
|
||||
//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
|
||||
//! used by Substrate nodes. This file extends those RPC definitions with
|
||||
//! capabilities that are specific to this project's runtime configuration.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use jsonrpsee::RpcModule;
|
||||
use runtime::interface::{AccountId, Nonce, OpaqueBlock};
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
|
||||
use std::sync::Arc;
|
||||
use substrate_frame_rpc_system::{System, SystemApiServer};
|
||||
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
|
||||
/// Full client dependencies.
|
||||
pub struct FullDeps<C, P> {
|
||||
/// The client instance to use.
|
||||
pub client: Arc<C>,
|
||||
/// Transaction pool instance.
|
||||
pub pool: Arc<P>,
|
||||
/// Whether to deny unsafe calls
|
||||
pub deny_unsafe: DenyUnsafe,
|
||||
}
|
||||
|
||||
/// Instantiate all full RPC extensions.
|
||||
pub fn create_full<C, P>(
|
||||
deps: FullDeps<C, P>,
|
||||
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
C: Send
|
||||
+ Sync
|
||||
+ 'static
|
||||
+ sp_api::ProvideRuntimeApi<OpaqueBlock>
|
||||
+ HeaderBackend<OpaqueBlock>
|
||||
+ HeaderMetadata<OpaqueBlock, Error = BlockChainError>
|
||||
+ 'static,
|
||||
C::Api: sp_block_builder::BlockBuilder<OpaqueBlock>,
|
||||
C::Api: substrate_frame_rpc_system::AccountNonceApi<OpaqueBlock, AccountId, Nonce>,
|
||||
P: TransactionPool + 'static,
|
||||
{
|
||||
let mut module = RpcModule::new(());
|
||||
let FullDeps { client, pool, deny_unsafe } = deps;
|
||||
|
||||
module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
|
||||
|
||||
Ok(module)
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use futures::FutureExt;
|
||||
use runtime::{self, interface::OpaqueBlock as Block, RuntimeApi};
|
||||
use sc_client_api::backend::Backend;
|
||||
use sc_executor::WasmExecutor;
|
||||
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cli::Consensus;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type HostFunctions =
|
||||
(sp_io::SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions);
|
||||
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
type HostFunctions = sp_io::SubstrateHostFunctions;
|
||||
|
||||
pub(crate) type FullClient =
|
||||
sc_service::TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>;
|
||||
type FullBackend = sc_service::TFullBackend<Block>;
|
||||
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
|
||||
/// Assembly of PartialComponents (enough to run chain ops subcommands)
|
||||
pub type Service = sc_service::PartialComponents<
|
||||
FullClient,
|
||||
FullBackend,
|
||||
FullSelectChain,
|
||||
sc_consensus::DefaultImportQueue<Block>,
|
||||
sc_transaction_pool::FullPool<Block, FullClient>,
|
||||
Option<Telemetry>,
|
||||
>;
|
||||
|
||||
pub fn new_partial(config: &Configuration) -> Result<Service, ServiceError> {
|
||||
let telemetry = config
|
||||
.telemetry_endpoints
|
||||
.clone()
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
|
||||
let worker = TelemetryWorker::new(16)?;
|
||||
let telemetry = worker.handle().new_telemetry(endpoints);
|
||||
Ok((worker, telemetry))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let executor = sc_service::new_wasm_executor(&config);
|
||||
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
||||
config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
executor,
|
||||
)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
let telemetry = telemetry.map(|(worker, telemetry)| {
|
||||
task_manager.spawn_handle().spawn("telemetry", None, worker.run());
|
||||
telemetry
|
||||
});
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||
config.transaction_pool.clone(),
|
||||
config.role.is_authority().into(),
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_essential_handle(),
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let import_queue = sc_consensus_manual_seal::import_queue(
|
||||
Box::new(client.clone()),
|
||||
&task_manager.spawn_essential_handle(),
|
||||
config.prometheus_registry(),
|
||||
);
|
||||
|
||||
Ok(sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
other: (telemetry),
|
||||
})
|
||||
}
|
||||
|
||||
/// Builds a new service for a full client.
|
||||
pub fn new_full(config: Configuration, consensus: Consensus) -> Result<TaskManager, ServiceError> {
|
||||
let sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
mut task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
other: mut telemetry,
|
||||
} = new_partial(&config)?;
|
||||
|
||||
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: &config,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
net_config,
|
||||
block_announce_validator_builder: None,
|
||||
warp_sync_params: None,
|
||||
block_relay: None,
|
||||
})?;
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
task_manager.spawn_handle().spawn(
|
||||
"offchain-workers-runner",
|
||||
"offchain-worker",
|
||||
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
|
||||
runtime_api_provider: client.clone(),
|
||||
is_validator: config.role.is_authority(),
|
||||
keystore: Some(keystore_container.keystore()),
|
||||
offchain_db: backend.offchain_storage(),
|
||||
transaction_pool: Some(OffchainTransactionPoolFactory::new(
|
||||
transaction_pool.clone(),
|
||||
)),
|
||||
network_provider: network.clone(),
|
||||
enable_http_requests: true,
|
||||
custom_extensions: |_| vec![],
|
||||
})
|
||||
.run(client.clone(), task_manager.spawn_handle())
|
||||
.boxed(),
|
||||
);
|
||||
}
|
||||
|
||||
let rpc_extensions_builder = {
|
||||
let client = client.clone();
|
||||
let pool = transaction_pool.clone();
|
||||
|
||||
Box::new(move |deny_unsafe, _| {
|
||||
let deps =
|
||||
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };
|
||||
crate::rpc::create_full(deps).map_err(Into::into)
|
||||
})
|
||||
};
|
||||
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
|
||||
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
network,
|
||||
client: client.clone(),
|
||||
keystore: keystore_container.keystore(),
|
||||
task_manager: &mut task_manager,
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
rpc_builder: rpc_extensions_builder,
|
||||
backend,
|
||||
system_rpc_tx,
|
||||
tx_handler_controller,
|
||||
sync_service,
|
||||
config,
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
let proposer = sc_basic_authorship::ProposerFactory::new(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool.clone(),
|
||||
prometheus_registry.as_ref(),
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
);
|
||||
|
||||
match consensus {
|
||||
Consensus::InstantSeal => {
|
||||
let params = sc_consensus_manual_seal::InstantSealParams {
|
||||
block_import: client.clone(),
|
||||
env: proposer,
|
||||
client,
|
||||
pool: transaction_pool,
|
||||
select_chain,
|
||||
consensus_data_provider: None,
|
||||
create_inherent_data_providers: move |_, ()| async move {
|
||||
Ok(sp_timestamp::InherentDataProvider::from_system_time())
|
||||
},
|
||||
};
|
||||
|
||||
let authorship_future = sc_consensus_manual_seal::run_instant_seal(params);
|
||||
|
||||
task_manager.spawn_essential_handle().spawn_blocking(
|
||||
"instant-seal",
|
||||
None,
|
||||
authorship_future,
|
||||
);
|
||||
},
|
||||
Consensus::ManualSeal(block_time) => {
|
||||
let (mut sink, commands_stream) = futures::channel::mpsc::channel(1024);
|
||||
task_manager.spawn_handle().spawn("block_authoring", None, async move {
|
||||
loop {
|
||||
futures_timer::Delay::new(std::time::Duration::from_millis(block_time)).await;
|
||||
sink.try_send(sc_consensus_manual_seal::EngineCommand::SealNewBlock {
|
||||
create_empty: true,
|
||||
finalize: true,
|
||||
parent_hash: None,
|
||||
sender: None,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
let params = sc_consensus_manual_seal::ManualSealParams {
|
||||
block_import: client.clone(),
|
||||
env: proposer,
|
||||
client,
|
||||
pool: transaction_pool,
|
||||
select_chain,
|
||||
commands_stream: Box::pin(commands_stream),
|
||||
consensus_data_provider: None,
|
||||
create_inherent_data_providers: move |_, ()| async move {
|
||||
Ok(sp_timestamp::InherentDataProvider::from_system_time())
|
||||
},
|
||||
};
|
||||
let authorship_future = sc_consensus_manual_seal::run_manual_seal(params);
|
||||
|
||||
task_manager.spawn_essential_handle().spawn_blocking(
|
||||
"manual-seal",
|
||||
None,
|
||||
authorship_future,
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
network_starter.start_network();
|
||||
Ok(task_manager)
|
||||
}
|
||||
Reference in New Issue
Block a user