Skip to content

Commit

Permalink
[create-pull-request] automated change
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma authored and github-actions[bot] committed Dec 23, 2024
1 parent 3004222 commit 430dd05
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 18,674 deletions.
18,564 changes: 0 additions & 18,564 deletions Cargo.lock

This file was deleted.

17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ repository = "https://github.com/paritytech/polkadot-sdk-minimal-template.git"
edition = "2021"

[workspace]
members = ["node", "pallets/template", "runtime"]
"default-members" = ["pallets/template", "runtime"]
members = [
"node",
"pallets/template",
"runtime",
]
resolver = "2"

[workspace.dependencies]
minimal-template-runtime = { path = "./runtime", default-features = false }
pallet-minimal-template = { path = "./pallets/template", default-features = false }
clap = { version = "4.5.10" }
docify = { version = "0.2.8" }
futures = { version = "0.3.30" }
clap = { version = "4.5.13" }
docify = { version = "0.2.9" }
futures = { version = "0.3.31" }
futures-timer = { version = "3.0.2" }
jsonrpsee = { version = "0.24.3" }
polkadot-sdk = { version = "0.7.0", default-features = false }
serde_json = { version = "1.0.127", default-features = false }
polkadot-sdk = { version = "0.1.0", default-features = false }
serde_json = { version = "1.0.132", default-features = false }
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false }
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /polkadot
COPY . /polkadot

RUN cargo fetch
RUN cargo build --locked --release
RUN cargo build --workspace --locked --release

FROM docker.io/parity/base-bin:latest

Expand Down
180 changes: 149 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,91 +11,209 @@
</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.

* 🔧 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).

* 👤 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

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 [Pallets](./pallets/README.md) - from which the runtime is constructed.
- 🧮 the [Runtime](./runtime/README.md) - the core logic of the blockchain.
- 🎨 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

* 🦀 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.

* 🛠️ 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.

### Build
Fetch minimal template code:

```sh
git clone https://github.com/paritytech/polkadot-sdk-minimal-template.git minimal-template

cd minimal-template
```

## 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

🔨 Use the following command to build the node without launching it:
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
cargo build --release
polkadot-omni-node --chain <path/to/chain_spec.json> --dev
```

🐳 Alternatively, build the docker image:
### 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
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
./target/release/minimal-template-node --dev
<target/release/path/to/minimal-template-node> --tmp --consensus manual-seal-3000
# or via docker
docker run --rm polkadot-sdk-minimal-template
```

### Zombienet with Omni Node

#### Install `zombienet`

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.

# docker version:
docker run --rm polkadot-sdk-minimal-template --dev
#### 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
```

Development chains:
### Zombienet with `minimal-template-node`

* 🧹 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.
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

* 🌐 You can interact with your local node using the
- 🌐 You can interact with your local node using the
hosted version of the [Polkadot/Substrate
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/).

* 🧑‍🔧 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.

### 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

* 🔄 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
[Code of Conduct](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CODE_OF_CONDUCT.md).

## 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.

* 👥 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/).
5 changes: 3 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "minimal-template-node"
description = "A minimal Substrate-based Substrate node, ready for hacking."
version = "0.1.0"
version = "0.0.0"
license = "Unlicense"
authors.workspace = true
homepage.workspace = true
Expand All @@ -20,8 +20,9 @@ futures = { features = ["thread-pool"], workspace = true }
futures-timer = { workspace = true }
jsonrpsee = { features = ["server"], workspace = true }
serde_json = { workspace = true, default-features = true }

polkadot-sdk = { workspace = true, features = ["experimental", "node"] }
minimal-template-runtime.workspace = true
minimal-template-runtime = { workspace = true }

[build-dependencies]
polkadot-sdk = { workspace = true, features = ["substrate-build-script-utils"] }
Expand Down
5 changes: 0 additions & 5 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@
initial (genesis) state.
- [`service.rs`](./src/service.rs): This file defines the node implementation.
It's a place to configure consensus-related topics. In favor of minimalism, this template has no consensus configured.


## Release

Polkadot SDK stable2409
22 changes: 3 additions & 19 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use minimal_template_runtime::{BalancesConfig, SudoConfig, WASM_BINARY};
use minimal_template_runtime::WASM_BINARY;
use polkadot_sdk::{
sc_service::{ChainType, Properties},
sp_keyring::AccountKeyring,
*,
};
use serde_json::{json, Value};

/// This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec;
Expand All @@ -33,26 +31,12 @@ fn props() -> 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())
.with_name("Development")
.with_id("dev")
.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())
.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 changes: 3 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use polkadot_sdk::{sc_cli::RunCmd, *};
pub enum Consensus {
ManualSeal(u64),
InstantSeal,
None,
}

impl std::str::FromStr for Consensus {
Expand All @@ -31,6 +32,8 @@ impl std::str::FromStr for Consensus {
Consensus::InstantSeal
} else if let Some(block_time) = s.strip_prefix("manual-seal-") {
Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?)
} else if s.to_lowercase() == "none" {
Consensus::None
} else {
return Err("incorrect consensus identifier".into());
})
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl SubstrateCli for Cli {

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()?),
"dev" => Box::new(chain_spec::development_chain_spec()?),
path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
Expand Down
Loading

0 comments on commit 430dd05

Please sign in to comment.