Commit d675fe2a authored by Cecile Tonglet's avatar Cecile Tonglet
Browse files

Adapting code

parent 8ea2ad73
Pipeline #84410 failed with stage
in 11 minutes and 39 seconds
......@@ -3767,7 +3767,6 @@ dependencies = [
"parity-util-mem 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-cli 0.7.28",
"polkadot-service 0.7.28",
"vergen 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -3810,6 +3809,7 @@ dependencies = [
"sc-client-api 2.0.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sc-client-db 0.8.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sc-executor 0.8.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sc-service 0.8.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sp-api 2.0.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sp-core 2.0.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
"sp-runtime 2.0.0-alpha.4 (git+https://github.com/paritytech/substrate?branch=cecton-the-revenge-of-the-cli)",
......
......@@ -15,9 +15,6 @@ futures = "0.3.4"
service = { package = "polkadot-service", path = "service" }
parity-util-mem = { version = "*", default-features = false, features = ["jemalloc-global"] }
[build-dependencies]
vergen = "3.0.4"
[dev-dependencies]
assert_cmd = "0.12"
nix = "0.17"
......
......@@ -14,13 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
extern crate vergen;
use vergen::{ConstantsFlags, generate_cargo_keys};
const ERROR_MSG: &'static str = "Failed to generate metadata files";
fn main() {
generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
println!("cargo:rerun-if-changed=.git/HEAD");
}
......@@ -2,7 +2,7 @@
name = "polkadot-cli"
version = "0.7.28"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Polkadot node implementation in Rust."
description = "Polkadot Relay-chain Client Node"
edition = "2018"
[package.metadata.wasm-pack.profile.release]
......@@ -24,6 +24,7 @@ sc-client = { git = "https://github.com/paritytech/substrate", branch = "cecton-
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli" }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli" }
service = { package = "polkadot-service", path = "../service", default-features = false }
tokio = { version = "0.2.13", features = ["rt-threaded"], optional = true }
......@@ -34,6 +35,9 @@ wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.7", optional = true }
browser-utils = { package = "substrate-browser-utils", git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli", optional = true }
[build-dependencies]
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cecton-the-revenge-of-the-cli" }
[features]
default = [ "wasmtime", "rocksdb", "cli" ]
wasmtime = [ "sc-cli/wasmtime" ]
......
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot 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.
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
fn main() {
sc_cli::generate_cargo_keys();
}
......@@ -76,13 +76,3 @@ impl ChainSpec {
}
}
}
/// Load the `ChainSpec` for the given `id`.
/// `force_kusama` treats chain specs coming from a file as kusama specs.
pub fn load_spec(id: &str, force_kusama: bool) -> Result<Box<dyn service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => spec.load()?,
None if force_kusama => Box::new(service::KusamaChainSpec::from_json_file(std::path::PathBuf::from(id))?),
None => Box::new(service::PolkadotChainSpec::from_json_file(std::path::PathBuf::from(id))?),
})
}
......@@ -18,18 +18,30 @@ use log::info;
use sp_runtime::traits::BlakeTwo256;
use service::{IsKusama, Block, self, RuntimeApiCollection, TFullClient};
use sp_api::ConstructRuntimeApi;
use sc_cli::{spec_factory, SubstrateCLI};
use sc_executor::NativeExecutionDispatch;
use crate::chain_spec::load_spec;
use crate::cli::{Cli, Subcommand};
use sc_cli::VersionInfo;
use crate::ChainSpec;
#[spec_factory(
impl_name = "parity-polkadot",
support_url = "https://github.com/paritytech/polkadot/issues/new",
copyright_start_year = 2017,
executable_name = "polkadot",
)]
fn spec_factory(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => spec.load()?,
//None if force_kusama => Box::new(service::KusamaChainSpec::from_json_file(std::path::PathBuf::from(id))?), // TODO
None => Box::new(service::PolkadotChainSpec::from_json_file(std::path::PathBuf::from(id))?),
})
}
/// Parses polkadot specific CLI arguments and run the service.
pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
let opt = sc_cli::from_args::<Cli>(&version);
pub fn run() -> sc_cli::Result<()> {
let opt = Cli::from_args();
let mut config = service::Configuration::from_version(&version);
config.impl_name = "parity-polkadot";
let force_kusama = opt.run.force_kusama;
// let force_kusama = opt.run.force_kusama; // TODO
let grandpa_pause = if opt.grandpa_pause.is_empty() {
None
......@@ -40,6 +52,7 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
};
match opt.subcommand {
/*
None => {
opt.run.base.init(&version)?;
opt.run.base.update_config(
......@@ -80,56 +93,60 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
>(config, opt.authority_discovery_enabled, grandpa_pause)
}
},
Some(Subcommand::Base(cmd)) => {
cmd.init(&version)?;
cmd.update_config(
&mut config,
|id| load_spec(id, force_kusama),
&version
)?;
let is_kusama = config.expect_chain_spec().is_kusama();
*/
Some(Subcommand::Base(subcommand)) => {
let runtime = Cli::create_runtime(&subcommand)?;
let is_kusama = runtime.config().chain_spec.is_kusama();
if is_kusama {
cmd.run(config, service::new_chain_ops::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
service::kusama_runtime::UncheckedExtrinsic,
>)
runtime.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
service::kusama_runtime::UncheckedExtrinsic,
>(config)
)
} else {
cmd.run(config, service::new_chain_ops::<
service::polkadot_runtime::RuntimeApi,
service::PolkadotExecutor,
service::polkadot_runtime::UncheckedExtrinsic,
>)
runtime.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::polkadot_runtime::RuntimeApi,
service::PolkadotExecutor,
service::polkadot_runtime::UncheckedExtrinsic,
>(config)
)
}
},
Some(Subcommand::ValidationWorker(args)) => {
Some(Subcommand::ValidationWorker(cmd)) => {
sc_cli::init_logger("");
if cfg!(feature = "browser") {
Err(sc_cli::Error::Input("Cannot run validation worker in browser".into()))
} else {
#[cfg(not(feature = "browser"))]
service::run_validation_worker(&args.mem_id)?;
service::run_validation_worker(&cmd.mem_id)?;
Ok(())
}
},
Some(Subcommand::Benchmark(cmd)) => {
cmd.init(&version)?;
cmd.update_config(&mut config, |id| load_spec(id, force_kusama), &version)?;
let is_kusama = config.expect_chain_spec().is_kusama();
let runtime = Cli::create_runtime(&cmd)?;
let is_kusama = runtime.config().chain_spec.is_kusama();
if is_kusama {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
runtime.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
})
} else {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
runtime.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
})
}
},
_ => todo!(),
}
}
fn run_service_until_exit<R, D, E>(
config: service::Configuration,
fn run_node<R, D, E>(
runtime: sc_cli::Runtime<Cli>,
authority_discovery_enabled: bool,
grandpa_pause: Option<(u32, u32)>,
) -> sc_cli::Result<()>
......@@ -151,26 +168,18 @@ where
TLightClient<R, D>
>,
{
match config.roles {
service::Roles::LIGHT =>
sc_cli::run_service_until_exit(
config,
|config| service::new_light::<R, D, E>(config),
),
_ =>
sc_cli::run_service_until_exit(
config,
|config| service::new_full::<R, D, E>(
config,
None,
None,
authority_discovery_enabled,
6000,
grandpa_pause,
)
.map(|(s, _)| s),
),
}
runtime.run_node(
|config| service::new_light::<R, D, E>(config),
|config| service::new_full::<R, D, E>(
config,
None,
None,
authority_discovery_enabled,
6000,
grandpa_pause,
).map(|(s, _)| s),
)
//
}
// We can't simply use `service::TLightClient` due to a
......
......@@ -41,4 +41,4 @@ pub use command::*;
pub use chain_spec::*;
#[cfg(feature = "cli")]
pub use sc_cli::{VersionInfo, Error, Result};
pub use sc_cli::{Error, Result};
......@@ -18,19 +18,6 @@
#![warn(missing_docs)]
use cli::VersionInfo;
fn main() -> Result<(), cli::Error> {
let version = VersionInfo {
name: "Parity Polkadot",
commit: env!("VERGEN_SHA_SHORT"),
version: env!("CARGO_PKG_VERSION"),
executable_name: "polkadot",
author: "Parity Team <admin@parity.io>",
description: "Polkadot Relay-chain Client Node",
support_url: "https://github.com/paritytech/polkadot/issues/new",
copyright_start_year: 2017,
};
cli::run(version)
fn main() -> cli::Result<()> {
cli::run()
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment