Update the minimal template to stable2412 (#21)

This synchronizes the template to the stable2412 branch.

---------

Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
Co-authored-by: iulianbarbu <14218860+iulianbarbu@users.noreply.github.com>
Co-authored-by: Iulian Barbu <iulian.barbu@parity.io>
This commit is contained in:
paritytech-polkadotsdk-templatebot[bot]
2025-02-20 15:29:47 +02:00
committed by GitHub
parent 3004222b11
commit a76e4bf0ed
18 changed files with 3430 additions and 2347 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ jobs:
uses: ./.github/actions/macos-dependencies uses: ./.github/actions/macos-dependencies
- name: Build the node individually in release mode - name: Build the node individually in release mode
run: cargo build --package minimal-template-node --release run: cargo build --package minimal-template-node --release --locked --all-features --all-targets
timeout-minutes: 90 timeout-minutes: 90
- name: Make sure the node is producing blocks - name: Make sure the node is producing blocks
+1 -1
View File
@@ -54,7 +54,7 @@ jobs:
rustup component add rust-src rustup component add rust-src
- name: Build the template - name: Build the template
run: cargo build --locked --release run: cargo build --locked --release --all-features --all-targets
timeout-minutes: 90 timeout-minutes: 90
- name: Upload the binaries - name: Upload the binaries
Generated
+3130 -2252
View File
File diff suppressed because it is too large Load Diff
+11 -6
View File
@@ -6,18 +6,23 @@ repository = "https://github.com/paritytech/polkadot-sdk-minimal-template.git"
edition = "2021" edition = "2021"
[workspace] [workspace]
members = ["node", "pallets/template", "runtime"] default-members = ["pallets/template", "runtime"]
members = [
"node",
"pallets/template",
"runtime",
]
resolver = "2" resolver = "2"
[workspace.dependencies] [workspace.dependencies]
minimal-template-runtime = { path = "./runtime", default-features = false } minimal-template-runtime = { path = "./runtime", default-features = false }
pallet-minimal-template = { path = "./pallets/template", default-features = false } pallet-minimal-template = { path = "./pallets/template", default-features = false }
clap = { version = "4.5.10" } clap = { version = "4.5.13" }
docify = { version = "0.2.8" } docify = { version = "0.2.9" }
futures = { version = "0.3.30" } futures = { version = "0.3.31" }
futures-timer = { version = "3.0.2" } futures-timer = { version = "3.0.2" }
jsonrpsee = { version = "0.24.3" } jsonrpsee = { version = "0.24.3" }
polkadot-sdk = { version = "0.7.0", default-features = false } polkadot-sdk = { version = "0.12.0", default-features = false }
serde_json = { version = "1.0.127", default-features = false } serde_json = { version = "1.0.132", default-features = false }
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" } codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false } scale-info = { version = "2.11.1", default-features = false }
+1 -1
View File
@@ -4,7 +4,7 @@ WORKDIR /polkadot
COPY . /polkadot COPY . /polkadot
RUN cargo fetch RUN cargo fetch
RUN cargo build --locked --release RUN cargo build --workspace --locked --release
FROM docker.io/parity/base-bin:latest FROM docker.io/parity/base-bin:latest
+151 -33
View File
@@ -11,91 +11,209 @@
</div> </div>
* 🤏 This template is a minimal (in terms of complexity and the number of components) ## Table of Contents
- [Intro](#intro)
- [Template Structure](#template-structure)
- [Getting Started](#getting-started)
- [Starting a Minimal Template Chain](#starting-a-minimal-template-chain)
- [Omni Node](#omni-node)
- [Minimal Template Node](#minimal-template-node)
- [Zombienet with Omni Node](#zombienet-with-omni-node)
- [Zombienet with Minimal Template Node](#zombienet-with-minimal-template-node)
- [Connect with the Polkadot-JS Apps Front-End](#connect-with-the-polkadot-js-apps-front-end)
- [Takeaways](#takeaways)
- [Contributing](#contributing)
- [Getting Help](#getting-help)
## Intro
- 🤏 This template is a minimal (in terms of complexity and the number of components)
template for building a blockchain node. template for building a blockchain node.
* 🔧 Its runtime is configured with a single custom pallet as a starting point, and a handful of ready-made pallets - 🔧 Its runtime is configured with a single custom pallet as a starting point, and a handful of ready-made pallets
such as a [Balances pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/index.html). such as a [Balances pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/index.html).
* 👤 The template has no consensus configured - it is best for experimenting with a single node network. - 👤 The template has no consensus configured - it is best for experimenting with a single node network.
## Template Structure ## Template Structure
A Polkadot SDK based project such as this one consists of: A Polkadot SDK based project such as this one consists of:
* 💿 a [Node](./node/README.md) - the binary application. - 🧮 the [Runtime](./runtime/README.md) - the core logic of the blockchain.
* 🧮 the [Runtime](./runtime/README.md) - the core logic of the blockchain. - 🎨 the [Pallets](./pallets/README.md) - from which the runtime is constructed.
* 🎨 the [Pallets](./pallets/README.md) - from which the runtime is constructed. - 💿 a [Node](./node/README.md) - the binary application (which is not part of the cargo default-members list and is not
compiled unless building the entire workspace).
## Getting Started ## Getting Started
* 🦀 The template is using the Rust language. - 🦀 The template is using the Rust language.
* 👉 Check the - 👉 Check the
[Rust installation instructions](https://www.rust-lang.org/tools/install) for your system. [Rust installation instructions](https://www.rust-lang.org/tools/install) for your system.
* 🛠️ Depending on your operating system and Rust version, there might be additional - 🛠️ Depending on your operating system and Rust version, there might be additional
packages required to compile this template - please take note of the Rust compiler output. packages required to compile this template - please take note of the Rust compiler output.
### Build Fetch minimal template code:
🔨 Use the following command to build the node without launching it:
```sh ```sh
cargo build --release git clone https://github.com/paritytech/polkadot-sdk-minimal-template.git minimal-template
cd minimal-template
``` ```
🐳 Alternatively, build the docker image: ## Starting a Minimal Template Chain
### Omni Node
[Omni Node](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/omni_node/index.html) can
be used to run the minimal template's runtime. `polkadot-omni-node` binary crate usage is described at a high-level
[on crates.io](https://crates.io/crates/polkadot-omni-node).
#### Install `polkadot-omni-node`
Please see installation section on [crates.io/omni-node](https://crates.io/crates/polkadot-omni-node).
#### Build `minimal-template-runtime`
```sh
cargo build -p minimal-template-runtime --release
```
#### Install `staging-chain-spec-builder`
Please see the installation section at [`crates.io/staging-chain-spec-builder`](https://crates.io/crates/staging-chain-spec-builder).
#### Use chain-spec-builder to generate the chain_spec.json file
```sh
chain-spec-builder create --relay-chain "dev" --para-id 1000 --runtime \
target/release/wbuild/minimal-template-runtime/minimal_template_runtime.wasm named-preset development
```
**Note**: the `relay-chain` and `para-id` flags are extra bits of information required to
configure the node for the case of representing a parachain that is connected to a relay chain.
They are not relevant to minimal template business logic, but they are mandatory information for
Omni Node, nonetheless.
#### Run Omni Node
Start Omni Node in development mode (sets up block production and finalization based on manual seal,
sealing a new block every 3 seconds), with a minimal template runtime chain spec.
```sh
polkadot-omni-node --chain <path/to/chain_spec.json> --dev
```
### Minimal Template Node
#### Build both node & runtime
```sh
cargo build --workspace --release
```
🐳 Alternatively, build the docker image which builds all the workspace members,
and has as entry point the node binary:
```sh ```sh
docker build . -t polkadot-sdk-minimal-template docker build . -t polkadot-sdk-minimal-template
``` ```
### Single-Node Development Chain #### Start the `minimal-template-node`
👤 The following command starts a single-node development chain: The `minimal-template-node` has dependency on the `minimal-template-runtime`. It will use
the `minimal_template_runtime::WASM_BINARY` constant (which holds the WASM blob as a byte
array) for chain spec building, while starting. This is in contrast to Omni Node which doesn't
depend on a specific runtime, but asks for the chain spec at startup.
```sh ```sh
./target/release/minimal-template-node --dev <target/release/path/to/minimal-template-node> --tmp --consensus manual-seal-3000
# or via docker
# docker version: docker run --rm polkadot-sdk-minimal-template
docker run --rm polkadot-sdk-minimal-template --dev
``` ```
Development chains: ### Zombienet with Omni Node
* 🧹 Do not persist the state. #### Install `zombienet`
* 💰 Are pre-configured with a genesis state that includes several pre-funded development accounts.
* 🧑‍⚖️ One development account (`ALICE`) is used as `sudo` accounts. We can install `zombienet` as described [here](https://paritytech.github.io/zombienet/install.html#installation),
and `zombienet-omni-node.toml` contains the network specification we want to start.
#### Update `zombienet-omni-node.toml` with a valid chain spec path
Before starting the network with zombienet we must update the network specification
with a valid chain spec path. If we need to generate one, we can look up at the previous
section for chain spec creation [here](#use-chain-spec-builder-to-generate-the-chain_specjson-file).
Then make the changes in the network specification like so:
```toml
# ...
chain = "dev"
chain_spec_path = "<TO BE UPDATED WITH A VALID PATH>"
default_args = ["--dev"]
# ..
```
#### Start the network
```sh
zombienet --provider native spawn zombienet-omni-node.toml
```
### Zombienet with `minimal-template-node`
For this one we just need to have `zombienet` installed and run:
```sh
zombienet --provider native spawn zombienet-multi-node.toml
```
### Connect with the Polkadot-JS Apps Front-End ### Connect with the Polkadot-JS Apps Front-End
* 🌐 You can interact with your local node using the - 🌐 You can interact with your local node using the
hosted version of the [Polkadot/Substrate hosted version of the [Polkadot/Substrate
Portal](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944). Portal](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944).
* 🪐 A hosted version is also - 🪐 A hosted version is also
available on [IPFS](https://dotapps.io/). available on [IPFS](https://dotapps.io/).
* 🧑‍🔧 You can also find the source code and instructions for hosting your own instance in the - 🧑‍🔧 You can also find the source code and instructions for hosting your own instance in the
[`polkadot-js/apps`](https://github.com/polkadot-js/apps) repository. [`polkadot-js/apps`](https://github.com/polkadot-js/apps) repository.
### Takeaways
Previously minimal template's development chains:
- ❌ Started in a multi-node setup will produce forks because minimal lacks consensus.
- 🧹 Do not persist the state.
- 💰 Are pre-configured with a genesis state that includes several pre-funded development accounts.
- 🧑‍⚖️ One development account (`ALICE`) is used as `sudo` accounts.
## Contributing ## Contributing
* 🔄 This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk). - 🔄 This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk).
* ➡️ Any pull requests should be directed to this [source](https://github.com/paritytech/polkadot-sdk/tree/master/templates/minimal). - ➡️ Any pull requests should be directed to this [source](https://github.com/paritytech/polkadot-sdk/tree/master/templates/minimal).
* 😇 Please refer to the monorepo's - 😇 Please refer to the monorepo's
[contribution guidelines](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md) and [contribution guidelines](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md) and
[Code of Conduct](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CODE_OF_CONDUCT.md). [Code of Conduct](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CODE_OF_CONDUCT.md).
## Getting Help ## Getting Help
* 🧑‍🏫 To learn about Polkadot in general, [Polkadot.network](https://polkadot.network/) website is a good starting point. - 🧑‍🏫 To learn about Polkadot in general, [Polkadot.network](https://polkadot.network/) website is a good starting point.
* 🧑‍🔧 For technical introduction, [here](https://github.com/paritytech/polkadot-sdk#-documentation) are - 🧑‍🔧 For technical introduction, [here](https://github.com/paritytech/polkadot-sdk#-documentation) are
the Polkadot SDK documentation resources. the Polkadot SDK documentation resources.
* 👥 Additionally, there are [GitHub issues](https://github.com/paritytech/polkadot-sdk/issues) and - 👥 Additionally, there are [GitHub issues](https://github.com/paritytech/polkadot-sdk/issues) and
[Substrate StackExchange](https://substrate.stackexchange.com/). [Substrate StackExchange](https://substrate.stackexchange.com/).
+1 -1
View File
@@ -20,4 +20,4 @@ It's a place to configure consensus-related topics. In favor of minimalism, this
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+3 -19
View File
@@ -15,13 +15,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use minimal_template_runtime::{BalancesConfig, SudoConfig, WASM_BINARY}; use minimal_template_runtime::WASM_BINARY;
use polkadot_sdk::{ use polkadot_sdk::{
sc_service::{ChainType, Properties}, sc_service::{ChainType, Properties},
sp_keyring::AccountKeyring,
*, *,
}; };
use serde_json::{json, Value};
/// This is a specialization of the general Substrate ChainSpec type. /// This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec; pub type ChainSpec = sc_service::GenericChainSpec;
@@ -33,26 +31,12 @@ fn props() -> Properties {
properties properties
} }
pub fn development_config() -> Result<ChainSpec, String> { pub fn development_chain_spec() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default()) Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default())
.with_name("Development") .with_name("Development")
.with_id("dev") .with_id("dev")
.with_chain_type(ChainType::Development) .with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis()) .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
.with_properties(props()) .with_properties(props())
.build()) .build())
} }
/// Configure initial storage state for FRAME pallets.
fn testnet_genesis() -> Value {
use minimal_template_runtime::interface::{Balance, MinimumBalance};
use polkadot_sdk::polkadot_sdk_frame::traits::Get;
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()) },
})
}
+3
View File
@@ -21,6 +21,7 @@ use polkadot_sdk::{sc_cli::RunCmd, *};
pub enum Consensus { pub enum Consensus {
ManualSeal(u64), ManualSeal(u64),
InstantSeal, InstantSeal,
None,
} }
impl std::str::FromStr for Consensus { impl std::str::FromStr for Consensus {
@@ -31,6 +32,8 @@ impl std::str::FromStr for Consensus {
Consensus::InstantSeal Consensus::InstantSeal
} else if let Some(block_time) = s.strip_prefix("manual-seal-") { } else if let Some(block_time) = s.strip_prefix("manual-seal-") {
Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?) Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?)
} else if s.to_lowercase() == "none" {
Consensus::None
} else { } else {
return Err("incorrect consensus identifier".into()); return Err("incorrect consensus identifier".into());
}) })
+1 -1
View File
@@ -49,7 +49,7 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> { fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id { Ok(match id {
"dev" => Box::new(chain_spec::development_config()?), "dev" => Box::new(chain_spec::development_chain_spec()?),
path => path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
}) })
+19 -16
View File
@@ -15,6 +15,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crate::cli::Consensus;
use futures::FutureExt; use futures::FutureExt;
use minimal_template_runtime::{interface::OpaqueBlock as Block, RuntimeApi}; use minimal_template_runtime::{interface::OpaqueBlock as Block, RuntimeApi};
use polkadot_sdk::{ use polkadot_sdk::{
@@ -28,8 +29,6 @@ use polkadot_sdk::{
}; };
use std::sync::Arc; use std::sync::Arc;
use crate::cli::Consensus;
type HostFunctions = sp_io::SubstrateHostFunctions; type HostFunctions = sp_io::SubstrateHostFunctions;
#[docify::export] #[docify::export]
@@ -45,7 +44,7 @@ pub type Service = sc_service::PartialComponents<
FullBackend, FullBackend,
FullSelectChain, FullSelectChain,
sc_consensus::DefaultImportQueue<Block>, sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, FullClient>, sc_transaction_pool::TransactionPoolHandle<Block, FullClient>,
Option<Telemetry>, Option<Telemetry>,
>; >;
@@ -78,12 +77,15 @@ pub fn new_partial(config: &Configuration) -> Result<Service, ServiceError> {
let select_chain = sc_consensus::LongestChain::new(backend.clone()); let select_chain = sc_consensus::LongestChain::new(backend.clone());
let transaction_pool = sc_transaction_pool::BasicPool::new_full( let transaction_pool = Arc::from(
config.transaction_pool.clone(), sc_transaction_pool::Builder::new(
config.role.is_authority().into(), task_manager.spawn_essential_handle(),
config.prometheus_registry(), client.clone(),
task_manager.spawn_essential_handle(), config.role.is_authority().into(),
client.clone(), )
.with_options(config.transaction_pool.clone())
.with_prometheus(config.prometheus_registry())
.build(),
); );
let import_queue = sc_consensus_manual_seal::import_queue( let import_queue = sc_consensus_manual_seal::import_queue(
@@ -135,11 +137,11 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) = let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams { sc_service::build_network(sc_service::BuildNetworkParams {
config: &config, config: &config,
net_config,
client: client.clone(), client: client.clone(),
transaction_pool: transaction_pool.clone(), transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(), spawn_handle: task_manager.spawn_handle(),
import_queue, import_queue,
net_config,
block_announce_validator_builder: None, block_announce_validator_builder: None,
warp_sync_config: None, warp_sync_config: None,
block_relay: None, block_relay: None,
@@ -147,9 +149,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
})?; })?;
if config.offchain_worker.enabled { if config.offchain_worker.enabled {
task_manager.spawn_handle().spawn( let offchain_workers =
"offchain-workers-runner",
"offchain-worker",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(), runtime_api_provider: client.clone(),
is_validator: config.role.is_authority(), is_validator: config.role.is_authority(),
@@ -161,9 +161,11 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
network_provider: Arc::new(network.clone()), network_provider: Arc::new(network.clone()),
enable_http_requests: true, enable_http_requests: true,
custom_extensions: |_| vec![], custom_extensions: |_| vec![],
}) })?;
.run(client.clone(), task_manager.spawn_handle()) task_manager.spawn_handle().spawn(
.boxed(), "offchain-workers-runner",
"offchain-worker",
offchain_workers.run(client.clone(), task_manager.spawn_handle()).boxed(),
); );
} }
@@ -259,6 +261,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
authorship_future, authorship_future,
); );
}, },
_ => {},
} }
network_starter.start_network(); network_starter.start_network();
+1 -1
View File
@@ -2,4 +2,4 @@
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+4
View File
@@ -5,6 +5,7 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
use frame::prelude::*;
use polkadot_sdk::polkadot_sdk_frame as frame; use polkadot_sdk::polkadot_sdk_frame as frame;
// Re-export all pallet parts, this is needed to properly import the pallet into the runtime. // Re-export all pallet parts, this is needed to properly import the pallet into the runtime.
@@ -19,4 +20,7 @@ pub mod pallet {
#[pallet::pallet] #[pallet::pallet]
pub struct Pallet<T>(_); pub struct Pallet<T>(_);
#[pallet::storage]
pub type Value<T> = StorageValue<Value = u32>;
} }
+3 -1
View File
@@ -12,7 +12,8 @@ publish = false
[dependencies] [dependencies]
codec = { workspace = true } codec = { workspace = true }
scale-info = { workspace = true } scale-info = { workspace = true }
polkadot-sdk = { workspace = true, features = ["experimental", "pallet-balances", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "runtime"] } polkadot-sdk = { workspace = true, features = ["pallet-balances", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "runtime"] }
serde_json = { workspace = true, default-features = false, features = ["alloc"] }
pallet-minimal-template.workspace = true pallet-minimal-template.workspace = true
[build-dependencies] [build-dependencies]
@@ -25,4 +26,5 @@ std = [
"pallet-minimal-template/std", "pallet-minimal-template/std",
"polkadot-sdk/std", "polkadot-sdk/std",
"scale-info/std", "scale-info/std",
"serde_json/std",
] ]
+1 -1
View File
@@ -12,4 +12,4 @@ responsible for validating blocks and executing the state changes they define.
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+60 -13
View File
@@ -25,28 +25,75 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
extern crate alloc; extern crate alloc;
use alloc::{vec, vec::Vec}; use alloc::vec::Vec;
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use polkadot_sdk::{ use polkadot_sdk::{
polkadot_sdk_frame::{ polkadot_sdk_frame::{
self as frame, self as frame,
prelude::*, deps::sp_genesis_builder,
runtime::{apis, prelude::*}, runtime::{apis, prelude::*},
}, },
*, *,
}; };
/// Provides getters for genesis configuration presets.
pub mod genesis_config_presets {
use super::*;
use crate::{
interface::{Balance, MinimumBalance},
sp_keyring::AccountKeyring,
BalancesConfig, RuntimeGenesisConfig, SudoConfig,
};
use alloc::{vec, vec::Vec};
use serde_json::Value;
/// Returns a development genesis config preset.
pub fn development_config_genesis() -> Value {
let endowment = <MinimumBalance as Get<Balance>>::get().max(1) * 1000;
let config = RuntimeGenesisConfig {
balances: BalancesConfig {
balances: AccountKeyring::iter()
.map(|a| (a.to_account_id(), endowment))
.collect::<Vec<_>>(),
},
sudo: SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) },
..Default::default()
};
serde_json::to_value(config).expect("Could not build genesis config.")
}
/// Get the set of the available genesis config presets.
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
let patch = match id.as_ref() {
sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
/// List of supported presets.
pub fn preset_names() -> Vec<PresetId> {
vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)]
}
}
/// The runtime version. /// The runtime version.
#[runtime_version] #[runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion { pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("minimal-template-runtime"), spec_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
impl_name: create_runtime_str!("minimal-template-runtime"), impl_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
authoring_version: 1, authoring_version: 1,
spec_version: 0, spec_version: 0,
impl_version: 1, impl_version: 1,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
state_version: 1, system_version: 1,
}; };
/// The version information used to identify this runtime when compiled natively. /// The version information used to identify this runtime when compiled natively.
@@ -55,8 +102,8 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
} }
/// The signed extensions that are added to the runtime. /// The transaction extensions that are added to the runtime.
type SignedExtra = ( type TxExtension = (
// Checks that the sender is not the zero address. // Checks that the sender is not the zero address.
frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckNonZeroSender<Runtime>,
// Checks that the runtime version is correct. // Checks that the runtime version is correct.
@@ -159,7 +206,7 @@ impl pallet_transaction_payment::Config for Runtime {
// Implements the types required for the template pallet. // Implements the types required for the template pallet.
impl pallet_minimal_template::Config for Runtime {} impl pallet_minimal_template::Config for Runtime {}
type Block = frame::runtime::types_common::BlockOf<Runtime, SignedExtra>; type Block = frame::runtime::types_common::BlockOf<Runtime, TxExtension>;
type Header = HeaderFor<Runtime>; type Header = HeaderFor<Runtime>;
type RuntimeExecutive = type RuntimeExecutive =
@@ -266,17 +313,17 @@ impl_runtime_apis! {
} }
} }
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime { impl apis::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result { fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config) build_state::<RuntimeGenesisConfig>(config)
} }
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> { fn get_preset(id: &Option<PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None) get_preset::<RuntimeGenesisConfig>(id, self::genesis_config_presets::get_preset)
} }
fn preset_names() -> Vec<sp_genesis_builder::PresetId> { fn preset_names() -> Vec<PresetId> {
vec![] self::genesis_config_presets::preset_names()
} }
} }
} }
+9
View File
@@ -0,0 +1,9 @@
[relaychain]
default_command = "polkadot-omni-node"
chain = "dev"
chain_spec_path = "<path/to/chain_spec.json>"
default_args = ["--dev"]
[[relaychain.nodes]]
name = "alice"
ws_port = 9944
+30
View File
@@ -0,0 +1,30 @@
# The setup bellow allows only one node to produce
# blocks and the rest will follow.
[relaychain]
chain = "dev"
default_command = "minimal-template-node"
[[relaychain.nodes]]
name = "alice"
args = ["--consensus manual-seal-3000"]
validator = true
ws_port = 9944
[[relaychain.nodes]]
name = "bob"
args = ["--consensus None"]
validator = true
ws_port = 9955
[[relaychain.nodes]]
name = "charlie"
args = ["--consensus None"]
validator = true
ws_port = 9966
[[relaychain.nodes]]
name = "dave"
args = ["--consensus None"]
validator = true
ws_port = 9977