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

Use docify export for parachain template hardcoded configuration and embed it in its README #6333 #7093

Merged
merged 42 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dd6429e
initial docify readme with some content #6333
seemantaggarwal Jan 8, 2025
5386289
further improvement for docify, still buggy, mid level commit
seemantaggarwal Jan 9, 2025
75dbca0
reverting to one less experimental stage
seemantaggarwal Jan 9, 2025
2e4f52b
keeping remote and local up to date
seemantaggarwal Jan 9, 2025
8cda7b3
further improvements in using docify
seemantaggarwal Jan 9, 2025
45bce73
removing function call for export call
seemantaggarwal Jan 9, 2025
65f93a4
fixing docify imports
seemantaggarwal Jan 9, 2025
318d589
addressing comments from iulian
seemantaggarwal Jan 11, 2025
219baa4
further trials in docify
seemantaggarwal Jan 11, 2025
757878d
mid level commit
seemantaggarwal Jan 12, 2025
f7122d8
fixing build errors
seemantaggarwal Jan 13, 2025
1e46e4f
creating and toml and lib.rs for parachain directory
seemantaggarwal Jan 13, 2025
96f915e
Patch from iulian barbu
seemantaggarwal Jan 13, 2025
f7f73c0
code cleanup
seemantaggarwal Jan 13, 2025
5cebc72
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 14, 2025
6af63fc
cargo fmt and taplo format
seemantaggarwal Jan 14, 2025
3494678
modifying sync-template-
seemantaggarwal Jan 14, 2025
7d15c09
fixing the path to src/lib.rs for readme generation script
seemantaggarwal Jan 14, 2025
a21b946
exclude template/parachain from check-workspace
seemantaggarwal Jan 14, 2025
7a26f92
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 14, 2025
f507fc9
fixing indentation in check-workspace.py
seemantaggarwal Jan 14, 2025
e02af52
modifying check workspace to account for excluding template/parachain
seemantaggarwal Jan 14, 2025
bb0856f
fixing cargo.lock
seemantaggarwal Jan 14, 2025
4585d1e
applying patch to update crate changes
seemantaggarwal Jan 14, 2025
9e9ec48
add pr doc and run taplo format
seemantaggarwal Jan 14, 2025
15a4e4b
modifying generate-prdoc to ignore double crate changes
seemantaggarwal Jan 14, 2025
1ac4ae2
change to pass check-prdoc
seemantaggarwal Jan 14, 2025
2663c34
change to pass check-prdoc
seemantaggarwal Jan 15, 2025
f8384f2
reverting changes in generate-pr-doc
seemantaggarwal Jan 15, 2025
b4b603a
code cleanup
seemantaggarwal Jan 15, 2025
2b8db82
reverting taplo format for cumulus crate
seemantaggarwal Jan 15, 2025
db9347d
comment address
seemantaggarwal Jan 15, 2025
e89d0c2
addressing comments
seemantaggarwal Jan 15, 2025
8c6bb70
fixing spacing
seemantaggarwal Jan 15, 2025
aa12866
reverting node changes
seemantaggarwal Jan 15, 2025
30d9ad9
fix markdown lint
seemantaggarwal Jan 15, 2025
bae8b3a
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 15, 2025
29b9737
modifying prdoc and removing docker command
seemantaggarwal Jan 16, 2025
d39f0bd
Update prdoc/pr_7093.prdoc
seemantaggarwal Jan 16, 2025
4d068dd
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 16, 2025
3f1d6ab
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 17, 2025
8b9c1d5
Merge branch 'master' into docify-parachain-readme
seemantaggarwal Jan 18, 2025
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
250 changes: 250 additions & 0 deletions templates/parachain/README.docify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<div align="center">

# Polkadot SDK's Parachain Template

<img height="70px" alt="Polkadot SDK Logo" src="https://github.com/paritytech/polkadot-sdk/raw/master/docs/images/Polkadot_Logo_Horizontal_Pink_White.png#gh-dark-mode-only"/>
<img height="70px" alt="Polkadot SDK Logo" src="https://github.com/paritytech/polkadot-sdk/raw/master/docs/images/Polkadot_Logo_Horizontal_Pink_Black.png#gh-light-mode-only"/>

> This is a template for creating a [parachain](https://wiki.polkadot.network/docs/learn-parachains) based on Polkadot SDK.
>
> This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk).

</div>

## Table of Contents

- [Intro](#intro)

- [Template Structure](#template-structure)

- [Getting Started](#getting-started)

- [Starting a Development Chain](#starting-a-development-chain)

- [Omni Node](#omni-node-prerequisites)
- [Zombienet setup with Omni Node](#zombienet-setup-with-omni-node)
- [Parachain Template Node](#parachain-template-node)
- [Connect with the Polkadot-JS Apps Front-End](#connect-with-the-polkadot-js-apps-front-end)
- [Takeaways](#takeaways)

- [Runtime development](#runtime-development)
- [Contributing](#contributing)
- [Getting Help](#getting-help)

## Intro

- ⏫ This template provides a starting point to build a [parachain](https://wiki.polkadot.network/docs/learn-parachains).

- ☁️ It is based on the
[Cumulus](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/polkadot_sdk/cumulus/index.html) framework.

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

- 👉 Learn more about parachains [here](https://wiki.polkadot.network/docs/learn-parachains)

## Template Structure

A Polkadot SDK based project such as this one consists of:

- 🧮 the [Runtime](./runtime/README.md) - the core logic of the parachain.
- 🎨 the [Pallets](./pallets/README.md) - from which the runtime is constructed.
- 💿 a [Node](./node/README.md) - the binary application, not part of the project default-members list and not compiled unless
building the project with `--workspace` flag, which builds all workspace members, and is an alternative to
[Omni Node](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/omni_node/index.html).

## Getting Started

- 🦀 The template is using the Rust language.

- 👉 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
packages required to compile this template - please take note of the Rust compiler output.

Fetch parachain template code:

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

cd parachain-template
```

## Starting a Development Chain
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved

### Omni Node Prerequisites

[Omni Node](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/omni_node/index.html) can
be used to run the parachain 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 the installation section at [`crates.io/omni-node`](https://crates.io/crates/polkadot-omni-node).

#### Build `parachain-template-runtime`

```sh
cargo build --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 "rococo-local" --para-id <!-- docify::embed!("runtime/src/genesis_config_cmd_list_presets.rs", get_parachain_id)--> --runtime \
target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm named-preset development
```

**Note**: the `relay-chain` and `para-id` flags are mandatory information required by
Omni Node, and for parachain template case the value for `para-id` must be set to `{{PARACHAIN_ID}}`, since this
is also the value injected through [ParachainInfo](https://docs.rs/staging-parachain-info/0.17.0/staging_parachain_info/)
pallet into the `parachain-template-runtime`'s storage. The `relay-chain` value is set in accordance
with the relay chain ID where this instantiation of parachain-template will connect to.

#### Run Omni Node

Start Omni Node with the generated chain spec. We'll start it in development mode (without a relay chain config), producing
and finalizing blocks based on manual seal, configured below to seal a block with each second.

```bash
polkadot-omni-node --chain <path/to/chain_spec.json> --dev --dev-block-time {{PARACHAIN_ID}}
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved
```

However, such a setup is not close to what would run in production, and for that we need to setup a local
relay chain network that will help with the block finalization. In this guide we'll setup a local relay chain
as well. We'll not do it manually, by starting one node at a time, but we'll use [zombienet](https://paritytech.github.io/zombienet/intro.html).

Follow through the next section for more details on how to do it.

### Zombienet setup with Omni Node

Assuming we continue from the last step of the previous section, we have a chain spec and we need to setup a relay chain.
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.

#### Relay chain prerequisites

Download the `polkadot` (and the accompanying `polkadot-prepare-worker` and `polkadot-execute-worker`) binaries from
[Polkadot SDK releases](https://github.com/paritytech/polkadot-sdk/releases). Then expose them on `PATH` like so:

```sh
export PATH="$PATH:<path/to/binaries>"
```

#### Update `zombienet-omni-node.toml` with a valid chain spec path

```toml
# ...
[[parachains]]
id = {{PARACHAIN_ID}}
chain_spec_path = "<TO BE UPDATED WITH A VALID PATH>"
# ...
```

#### Start the network

```sh
zombienet --provider native spawn zombienet-omni-node.toml
```

### Parachain Template Node

As mentioned in the `Template Structure` section, the `node` crate is optionally compiled and it is an alternative
to `Omni Node`. Similarly, it requires setting up a relay chain, and we'll use `zombienet` once more.

#### Install the `parachain-template-node`

```sh
cargo install --path node
```

#### Setup and start the network

For setup, please consider the instructions for `zombienet` installation [here](https://paritytech.github.io/zombienet/install.html#installation)
and [relay chain prerequisites](#relay-chain-prerequisites).

We're left just with starting the network:

```sh
zombienet --provider native spawn zombienet.toml
```

### Connect with the Polkadot-JS Apps Front-End

- 🌐 You can interact with your local node using the
hosted version of the Polkadot/Substrate Portal:
[relay chain](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944)
and [parachain](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9988).

- 🪐 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
[`polkadot-js/apps`](https://github.com/polkadot-js/apps) repository.

### Takeaways

Development parachains:

- 🔗 Connect to relay chains, and we showcased how to connect to a local one.
- 🧹 Do not persist the state.
- 💰 Are preconfigured with a genesis state that includes several prefunded development accounts.
- 🧑‍⚖️ Development accounts are used as validators, collators, and `sudo` accounts.

## Runtime development

We recommend using [`chopsticks`](https://github.com/AcalaNetwork/chopsticks) when the focus is more on the runtime
development and `OmniNode` is enough as is.

### Install chopsticks

To use `chopsticks`, please install the latest version according to the installation [guide](https://github.com/AcalaNetwork/chopsticks?tab=readme-ov-file#install).

### Build a raw chain spec

Build the `parachain-template-runtime` as mentioned before in this guide and use `chain-spec-builder`
again but this time by passing `--raw-storage` flag:

```sh
chain-spec-builder create --raw-storage --relay-chain "rococo-local" --para-id {{PARACHAIN_ID}} --runtime \
target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm named-preset development
```

### Start `chopsticks` with the chain spec

```sh
npx @acala-network/chopsticks@latest --chain-spec <path/to/chain_spec.json>
```

### Alternatives

`OmniNode` can be still used for runtime development if using the `--dev` flag, while `parachain-template-node` doesn't
support it at this moment. It can still be used to test a runtime in a full setup where it is started alongside a
relay chain network (see [Parachain Template node](#parachain-template-node) setup).

## Contributing

- 🔄 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/parachain).

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

- 🧑‍🔧 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
[Substrate StackExchange](https://substrate.stackexchange.com/).


18 changes: 18 additions & 0 deletions templates/parachain/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
use std::process::Command;

#[cfg(all(feature = "std", feature = "metadata-hash"))]
#[docify::export(template_enable_metadata_hash)]
fn main() {
println!("cargo:rerun-if-changed=../../parachain/runtime/src/genesis_config_presets.rs");
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("UNIT", 12)
.build();
let docify_command = Command::new("cargo build")
.args(&["build"])
.current_dir("../../")
.output()
.expect("Failed to execute docify");

// Print the output of the docify command for debugging
println!("docify output: {:?}", docify_command);

println!("cargo:rerun-if-changed=../../parachain/runtime/src/genesis_config_presets.rs");

if !docify_command.status.success() {
eprintln!("Failed to run docify: {:?}", docify_command);
std::process::exit(1);
}
}

#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
Expand Down
14 changes: 13 additions & 1 deletion templates/parachain/runtime/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use alloc::{vec, vec::Vec};

use polkadot_sdk::{staging_xcm as xcm, *};

#[doc::include_str!("../../README.md")]
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "generate-readme")]

iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved
docify::compile_markdown!("../..","../..");
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved

use docify::{export, export_content};

use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use parachains_common::AuraId;
Expand All @@ -17,14 +24,19 @@ use sp_keyring::Sr25519Keyring;
/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
/// Parachain id used for genesis config presets of parachain template.
pub const PARACHAIN_ID: u32 = 1000;
#[export]
pub const PARACHAIN_ID: u32 = 2000;
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn template_session_keys(keys: AuraId) -> SessionKeys {
SessionKeys { aura: keys }
}
#[docify::export(name = "get_parachain_id")]
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved
pub fn get_parachain_id() -> u32 {
PARACHAIN_ID
}
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved

fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
Expand Down
Loading