Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dev-omni-node #5117

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ members = [
"substrate/bin/node/testing",
"substrate/bin/utils/chain-spec-builder",
"substrate/bin/utils/subkey",
"substrate/bin/utils/dev-omni-node",
"substrate/client/allocator",
"substrate/client/api",
"substrate/client/authority-discovery",
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/rococo/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn get_authority_keys_from_seed_no_beefy(
}

fn testnet_accounts() -> Vec<AccountId> {
// TODO: just use sp_keyring::AccountKeyring::iter()??
Vec::from([
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand Down Expand Up @@ -532,8 +533,8 @@ fn wococo_local_testnet_genesis() -> serde_json::Value {
/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<alloc::vec::Vec<u8>> {
let patch = match id.try_into() {
Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => rococo_development_config_genesis(),
Ok("local_testnet") => rococo_local_testnet_genesis(),
Ok("development") => rococo_development_config_genesis(),
Ok("staging_testnet") => rococo_staging_testnet_config_genesis(),
Ok("wococo_local_testnet") => wococo_local_testnet_genesis(),
Ok("versi_local_testnet") => versi_local_testnet_genesis(),
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2572,8 +2572,8 @@ sp_api::impl_runtime_apis! {

fn preset_names() -> Vec<PresetId> {
vec![
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
PresetId::from("local_testnet"),
PresetId::from("development"),
PresetId::from("staging_testnet"),
PresetId::from("wococo_local_testnet"),
PresetId::from("versi_local_testnet"),
Expand Down
23 changes: 23 additions & 0 deletions substrate/bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ impl SubstrateCli for Cli {
};
Ok(spec)
}

fn load_spec_from_runtime(
&self,
runtime: &[u8],
maybe_preset: Option<&str>,
) -> std::result::Result<Box<dyn sc_cli::ChainSpec>, String> {
use sc_service::{ChainType, Properties};
let mut properties = Properties::new();
properties.insert("tokenDecimals".to_string(), 12.into());
properties.insert("tokenSymbol".to_string(), "SUB-DEV".into());

let mut builder = chain_spec::ChainSpec::builder(runtime, Default::default())
.with_name("Development")
.with_id("dev")
.with_chain_type(ChainType::Development)
.with_properties(properties);

if let Some(preset) = maybe_preset {
builder = builder.with_genesis_config_preset_name(preset);
}

Ok(Box::new(builder.build()))
}
}

/// Parse command line arguments into service configuration.
Expand Down
73 changes: 73 additions & 0 deletions substrate/bin/utils/dev-omni-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[package]
name = "dev-omni-node"
description = "A minimal omni node capable of running runtimes without any consensus."
version = "1.0.0"
authors.workspace = true
edition.workspace = true
repository.workspace = true
publish = true
build = "build.rs"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
homepage = "https://paritytech.github.io/polkadot-sdk"


[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
clap = { features = ["derive"], workspace = true }
futures = { features = ["thread-pool"], workspace = true }
futures-timer = { workspace = true }
jsonrpsee = { features = ["server"], workspace = true }
serde_json = { workspace = true, default-features = true }
log = { worksapce = true }
docify = { workspace = true }

sc-cli = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-network = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
sc-transaction-pool = { workspace = true, default-features = true }
sc-transaction-pool-api = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true }
sc-rpc-api = { workspace = true, default-features = true }
sc-basic-authorship = { workspace = true, default-features = true }
sc-offchain = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-chain-spec = { workspace = true, default-features = true }

sp-timestamp = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-block-builder = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-transaction-pool = { workspace = true, default-features = true }
sp-session = { workspace = true, default-features = true }
sp-offchain = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-inherents = { workspace = true, default-features = true }
sp-consensus-aura = { workspace = true, default-features = true }
sp-consensus-grandpa = { workspace = true, default-features = true }
sp-weights = { workspace = true, default-features = true }
sp-version = { workspace = true, default-features = true }

# frame and pallets
pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true, default-features = true }

substrate-frame-rpc-system = { workspace = true, default-features = true }
frame-system-rpc-runtime-api = { workspace = true, default-features = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = true }

[dev-dependencies]
assert_cmd = "2.0.14"
nix = { version = "0.28.0", features = ["signal"] }


[features]
default = []
23 changes: 23 additions & 0 deletions substrate/bin/utils/dev-omni-node/build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
103 changes: 103 additions & 0 deletions substrate/bin/utils/dev-omni-node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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.

//! The CLI parameters of the dev omni-node.

use sc_cli::RunCmd;

/// The consensus algorithm to use.
#[derive(Debug, Clone)]
pub enum Consensus {
/// Manual seal, with the block time in milliseconds.
///
/// Should be provided as `manual-seal-3000` for a 3 seconds block time.
ManualSeal(u64),
/// Instant seal.
///
/// Authors a new block as soon as a transaction is received.
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())
})
}
}

/// You typically run this node with:
///
/// * Either of `--chain runtime.wasm` or `--chain spec.json`.
/// * `--tmp` to use a temporary database.
///
/// This binary goes hand in hand with:
///
/// * a `.wasm` file. You typically get this from your runtime template.
/// * `chain-spec-builder` to generate chain-spec. You might possibly edit this chain-spec manually,
/// or alter your runtime's `sp_genesis_builder` impl with specific presets.
///
/// * `frame-omni-bencher` to create benchmarking.
#[derive(Debug, clap::Parser)]
pub struct Cli {
/// The subcommand to use.
#[command(subcommand)]
pub subcommand: Option<Subcommand>,

/// The block authoring (aka. consensus) engine to use.
#[clap(long, default_value = "manual-seal-1000")]
pub consensus: Consensus,

/// The main run command
#[clap(flatten)]
pub run: RunCmd,
}

/// Possible sub-commands.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Key management cli utilities
#[command(subcommand)]
Key(sc_cli::KeySubcommand),

/// 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),
}
Loading
Loading