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

Coretime Guides Rework (Omninode Considerations) #5946

Merged
merged 18 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
14 changes: 8 additions & 6 deletions docs/build/build-guides-coretime-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Polkadot. These guides are **not** production ready due to the moving nature of

## Using the Polkadot SDK

At first glance, the Polkadot SDK can be rather overwhelming, and in a way it is - it packs a lot of
tech into one place. The Polkadot SDK used to be overarching **three** repositories:
The Polkadot SDK used to be overarching **three** repositories:
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved

- [**Polkadot**](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/polkadot_sdk/index.html#polkadot) -
Which for a time, included both the client implementation and runtime, until the runtime was moved
Expand All @@ -38,9 +37,9 @@ tech into one place. The Polkadot SDK used to be overarching **three** repositor

:::info What is a task?

You might see the term "task" referenced quite a bit, but in most cases, it refers to a process
utilizing Polkadot's compute. This could be a parachain or any other computational process, provided
that it adheres to the Polkadot protocol.
You might see the term "task" referenced in place of "parachain". In most cases, it refers to a
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
process utilizing the relay chain's compute. This could be a parachain or any other computational
process, provided that it adheres to the Polkadot protocol.
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved

The full definition can be found [here](../learn/learn-agile-coretime.md#task).

Expand Down Expand Up @@ -106,7 +105,10 @@ PC-->DEP
### Install dependencies

Make sure you have everything you need for your target system
[here.](./build-guides-install-deps.md)
[here.](./build-guides-install-deps.md).

Be sure you also install the `polkadot-parachain` and `chain-spec-builder` binaries, as they will be
used to start and run your chain!
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved

### Deployment Example - Adder Collator

Expand Down
25 changes: 25 additions & 0 deletions docs/build/build-guides-install-deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,28 @@ active toolchain
nightly-x86_64-unknown-linux-gnu (overridden by +toolchain on the command line)
rustc 1.63.0-nightly (e7144
```

## Install `polkadot-parachain` and `chain-spec-builder`

The `polkadot-parachain` can be used a universal collator instance for running most of the
parachains (an
["omninode beta"](https://forum.polkadot.network/t/polkadot-parachain-omni-node-gathering-ideas-and-feedback/7823)).
It can be installed as follows:

> You can change `--tag` to the specific release of your choice

```sh
cargo install --git https://github.com/paritytech/polkadot-sdk --tag polkadot-v1.13.0 --force polkadot-parachain-bin
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
```

The `chain-spec-builder` is how you will generate chain specifications from different presets. Each
preset represents different type of your network, such as development, testnet, and live networks.
It requires a `wasm` runtime bundle to generate the chain specification from.

It can be installed as follows:

> Note that chain-spec-builder only works with select Polkadot SDK versions (`<v1.13.0`)

```sh
cargo install staging-chain-spec-builder
```
159 changes: 83 additions & 76 deletions docs/build/build-guides-template-basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ We can now move on to working with the template. Some essential prerequisites ar

:::info Install dependencies

Visit [the dependencies' installation](./build-guides-install-deps.md) page before starting.
Visit [the dependencies installation](./build-guides-install-deps.md) page before starting.

:::

We need to clone the Polkadot SDK. This guide uses release
[`polkadot-v1.10.0`](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.10.0),
[`polkadot-v1.13.0`](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.13.0),
which can be cloned using the appropriate release tag:

```shell
git clone [email protected]:paritytech/polkadot-sdk.git --branch polkadot-v1.10.0 --single-branch
git clone [email protected]:paritytech/polkadot-sdk.git --branch polkadot-v1.13.0 --single-branch
```

Now, navigate to `polkadot-sdk/templates/parachain`:
Expand Down Expand Up @@ -97,13 +97,68 @@ FRAME and Substrate. All you need to know is the following:
When we compile our template, we can extract the runtime code as a `.wasm` blob, which is one of the
key artifacts for our core.

Build the node using the following:

```shell
cargo build -p parachain-template-node --release
```

For the sake of this example, we won't go into adding or modifying any pallets. However, this is
definitey a next step after you get used to deploying your parachain on Rococo!
definitely a next step after you get used to deploying your parachain on Rococo!

### Generating the Chain Specification

> Ensure you have
> the[ `chain-spec-builder`](./build-guides-install-deps.md#install-polkadot-parachain-and-chain-spec-builder)
> installed before following along!

By now, your `./target` folder should look something akin to:

```sh
./target/release/wbuild/parachain-template-runtime
├── Cargo.lock
├── Cargo.toml
├── parachain_template_runtime.compact.compressed.wasm
├── parachain_template_runtime.compact.wasm
├── parachain_template_runtime.wasm
├── src
└── target
```

We'll be using `parachain_template_runtime.wasm` in conjunction with `chain-spec-builder` to build
our chain specification, which we can then use to generate our genesis code and WASM bundle.

Although you may want to create a preset, we can use the default one and customize it as we need to
directly:

```sh
chain-spec-builder create -v -r ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm default
```

### Configuring Parachain's Chain Spec
You should now see `chain_spec.json` generated, with the message `Genesis config verification: OK`.

Before we generate the binary for our parachain's node, we have a bit of prep to do to our node
inside `node/src/chain_spec.rs`. Namely, there are a few main factors to check off our list:
Next, you'll need to modify a few things in your chain spec:

```json
"name": "CHAIN_NAME_HERE",
"id": "live",
"chainType": "Live",
"bootNodes": [],
"telemetryEndpoints": null,
"protocolId": "chain-live",
"relay_chain": "paseo",
"para_id": PARA_ID_HERE,
```

You will also need to replace the following with your ParaID:

```json
"parachainInfo": {
"parachainId": PARA_ID_HERE
},
```

Use this checklist to ensure all the necessary fields are in place:

1. **Make** sure that `relay_chain` is set to the target relay chain (`rococo`, in our case)
2. **Make** sure that `para_id` (right below `relay_chain`) is set to your reserved ParaId
Expand All @@ -120,79 +175,27 @@ Feel free to copy the configuration below and use it to ensure everything is in
deployment. This function should replace the `local_testnet_config` function within
`node/src/chain_spec.rs`:

> **:warning: WARNING! :warning:** Make sure you replace the ParaId with the one you reserved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesssss, happy to see all of this goes away now 😇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still some cleanup to do on my end, I mostly need to back around to the PR to allow for an easier way to generate parachain specs - although, it's just really modifying a JSON after generating it ATM, which isn't terrible, so I may push it with that extra manual step. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, I think editing a JSON file is well within the capabilities of anyone. It is not amazing devEx tho, but we can improve that next.

> earlier!

```rust
pub fn local_testnet_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "SOME".into());
properties.insert("tokenDecimals".into(), (12).into());
properties.insert("ss58Format".into(), (42).into());

#[allow(deprecated)]
ChainSpec::builder(
runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo".into(),
// You MUST set this to the correct network!
para_id: YOUR_PARA_ID_HERE,
}
)
.with_name("SomeChain")
.with_id("some_chain")
.with_chain_type(ChainType::Live)
.with_genesis_config_patch(
testnet_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash")
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
(YOUR_PARA_ID_HERE).into()
)
)
.with_protocol_id("template-local")
.with_properties(properties)
.build()
}
```

Once this is in place, you are ready to compile your parachain node.

For more information on chain specifications in general,
[check out the reference document from the Polkadot SDK.](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/chain_spec_genesis/index.html)

### Generating the Runtime and Genesis

Be sure first to build the node using the following (assuming you're within
`polkadot-sdk/templates/parachain`):
With our chain specification successfully generated, we can move to generating the genesis state and
runtime.

```shell
cargo build -p parachain-template-node --release
```
Generate the genesis as follows:
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved

```shell
../../target/release/parachain-template-node export-genesis-state genesis
polkadot-parachain export-genesis-head --chain chain_spec.json genesis
```

Although you can use the WebAssembly within `wbuild`, for ease of access you can also regenerate
your WebAssembly blob with the following:

```shell
../../target/release/parachain-template-node export-genesis-wasm genesis-wasm
polkadot-parachain export-genesis-wasm --chain chain_spec.json genesis-wasm
```

Within `polkadot-sdk/templates/parachain`, you should now have two files:
Expand All @@ -202,16 +205,20 @@ Within `polkadot-sdk/templates/parachain`, you should now have two files:

## Running Your Collator

It would help if you now started syncing your collator. Keep in mind that you will need to sync
Rococo first - this could take some time (12 hours to a day - depending on your download speed), so
best to get started ASAP. In order to avoid storing the full state of the relay chain, be sure to
run with the appropriate pruning flags (`blocks-pruning` and `state-pruning`):
> Make sure you have the
> [`polkadot-parachain`](./build-guides-install-deps.md#installing-the-omninode) binary installed!

You should start syncing your collator. Keep in mind that you will need to sync Rococo first - this
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
could take some time depending on your download speed, so it is best to start this process ASAP. In
order to avoid storing the full state of the relay chain, be sure to run with the appropriate
pruning flags (`blocks-pruning` and `state-pruning`):

```shell
./../target/release/parachain-template-node --collator \
polkadot-parachain --collator \
--alice \
--chain chain_spec.json \
--force-authoring \
--base-path <your-base-path-here> \
--base-path <your-base-path-here> \
-- \
--chain=rococo \
--sync fast-unsafe \
Expand Down
Loading