Lines
0 %
Functions
Branches
100 %
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.
// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>.
use {
crate::cli::RelayChainCli,
parity_scale_codec::Encode,
sc_chain_spec::construct_genesis_block,
sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, SharedParams, SubstrateCli,
},
sc_service::config::{BasePath, PrometheusConfig},
sp_runtime::{
traits::{Block as BlockT, Get, Hash as HashT, Header as HeaderT},
StateVersion,
std::result::Result as StdResult,
};
/// Generate the genesis block from a given ChainSpec.
pub fn generate_genesis_block<Block: BlockT>(
chain_spec: &dyn ChainSpec,
genesis_state_version: StateVersion,
) -> StdResult<Block, String> {
let storage = chain_spec.build_storage()?;
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
genesis_state_version,
);
(sk.clone(), state_root.encode())
});
storage.top.clone().into_iter().chain(child_roots).collect(),
Ok(construct_genesis_block(state_root, genesis_state_version))
}
impl<N: Get<&'static str>> DefaultConfigurationValues for RelayChainCli<N> {
fn p2p_listen_port() -> u16 {
30334
fn rpc_listen_port() -> u16 {
9945
fn prometheus_listen_port() -> u16 {
9616
impl<N: Get<&'static str>> CliConfiguration<Self> for RelayChainCli<N> {
fn shared_params(&self) -> &SharedParams {
self.base.base.shared_params()
fn import_params(&self) -> Option<&ImportParams> {
self.base.base.import_params()
fn network_params(&self) -> Option<&NetworkParams> {
self.base.base.network_params()
fn keystore_params(&self) -> Option<&KeystoreParams> {
self.base.base.keystore_params()
fn base_path(&self) -> Result<Option<BasePath>> {
Ok(self
.shared_params()
.base_path()?
.or_else(|| Some(self.base_path.clone().into())))
fn rpc_addr(&self, default_listen_port: u16) -> Result<Option<Vec<sc_cli::RpcEndpoint>>> {
self.base.base.rpc_addr(default_listen_port)
fn prometheus_config(
&self,
default_listen_port: u16,
chain_spec: &Box<dyn ChainSpec>,
) -> Result<Option<PrometheusConfig>> {
self.base
.base
.prometheus_config(default_listen_port, chain_spec)
fn init<F>(&self, _support_url: &String, _impl_version: &String, _logger_hook: F) -> Result<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder),
{
unreachable!("PolkadotCli is never initialized; qed");
fn chain_id(&self, is_dev: bool) -> Result<String> {
let chain_id = self.base.base.chain_id(is_dev)?;
Ok(if chain_id.is_empty() {
self.chain_id.clone().unwrap_or_default()
} else {
chain_id
})
fn role(&self, is_dev: bool) -> Result<sc_service::Role> {
self.base.base.role(is_dev)
fn transaction_pool(&self, is_dev: bool) -> Result<sc_service::config::TransactionPoolOptions> {
self.base.base.transaction_pool(is_dev)
fn trie_cache_maximum_size(&self) -> Result<Option<usize>> {
self.base.base.trie_cache_maximum_size()
fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {
self.base.base.rpc_methods()
fn rpc_max_connections(&self) -> Result<u32> {
self.base.base.rpc_max_connections()
fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {
self.base.base.rpc_cors(is_dev)
fn default_heap_pages(&self) -> Result<Option<u64>> {
self.base.base.default_heap_pages()
fn force_authoring(&self) -> Result<bool> {
self.base.base.force_authoring()
fn disable_grandpa(&self) -> Result<bool> {
self.base.base.disable_grandpa()
fn max_runtime_instances(&self) -> Result<Option<usize>> {
self.base.base.max_runtime_instances()
fn announce_block(&self) -> Result<bool> {
self.base.base.announce_block()
fn telemetry_endpoints(
) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {
self.base.base.telemetry_endpoints(chain_spec)
fn node_name(&self) -> Result<String> {
self.base.base.node_name()
impl<N: Get<&'static str>> SubstrateCli for RelayChainCli<N> {
fn impl_version() -> String {
option_env!("SUBSTRATE_CLI_IMPL_VERSION")
.unwrap_or("Unknown version")
.into()
fn author() -> String {
option_env!("CARGO_PKG_AUTHORS")
.unwrap_or("Unknown authors")
fn support_url() -> String {
"https://github.com/paritytech/cumulus/issues/new".into()
fn copyright_start_year() -> i32 {
2020
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
polkadot_cli::Cli::from_iter([Self::executable_name()].iter()).load_spec(id)
fn impl_name() -> String {
format!("Container Chain {} Node", N::get())
fn description() -> String {
format!(
"Container Chain {} Node\n\nThe command-line arguments provided first will be \
passed to the parachain node, while the arguments provided after -- will be passed \
to the relay chain node.\n\n\
{} <parachain-args> -- <relay-chain-args>",
N::get(),
RelayChainCli::<N>::executable_name()
)