Skip to content

Commit 8ce97b0

Browse files
authored
Bulletin - prepare chain spec script for genesis (#47)
* Setup some dummy chain spec for production run * Run bulletin-polkadot-local * Run local validator for bulletin-polkadot * Nits
1 parent d89da8d commit 8ce97b0

File tree

10 files changed

+268
-11
lines changed

10 files changed

+268
-11
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ Controls the validator set. Currently set in genesis and validators can be added
4949
#### polkadot-bulletin-chain/pallets/transaction-storage
5050
Stores arbitrary data on IPFS via the `store` extrinsic, provided that either the signer or the preimage of the data are pre-authorized. Stored data can be retrieved from IPFS or directly from the node via the transaction index or hash.
5151

52+
## Polkadot Bulletin production/live runtime
53+
54+
### Initial genesis chain spec
55+
56+
[bulletin-polkadot-genesis.json](./node/chain-specs/bulletin-polkadot.json)
57+
58+
```
59+
cargo build --release -p polkadot-bulletin-chain
60+
61+
./target/release/polkadot-bulletin-chain build-spec --chain bulletin-polkadot
62+
or
63+
./target/release/polkadot-bulletin-chain build-spec --chain bulletin-polkadot --raw
64+
```
65+
66+
### Run local chain
67+
```
68+
cargo build --release -p polkadot-bulletin-chain
69+
70+
POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain zombienet -p native spawn ./zombienet/bulletin-polkadot-local.toml
71+
```
72+
73+
### Run a production chain (but only with Alice validator)
74+
You can override the Alice validator keys here: [adjust\_bp\_spec.sh](./zombienet/adjust_bp_spec.sh) (you should see finalized blocks in the logs).
75+
76+
```
77+
cargo build --release -p polkadot-bulletin-chain
78+
79+
POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain ENV_PATH=<path-to-zombienet-dir-in-bulletin-repo> zombienet -p native spawn ./zombienet/bulletin-polkadot.toml
80+
```
81+
82+
### Run a production chain
83+
84+
```
85+
cargo build --release -p polkadot-bulletin-chain
86+
./target/release/polkadot-bulletin-chain --chain bulletin-polkadot
87+
```
88+
5289
### Fresh benchmarks
5390

5491
Run on the dedicated machine from the root directory:

node/chain-specs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!/*.json

node/chain-specs/bulletin-polkadot.json

Lines changed: 61 additions & 0 deletions
Large diffs are not rendered by default.

node/src/chain_spec.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn rococo_local_testnet_config() -> Result<ChainSpec, String> {
3333
.build())
3434
}
3535

36-
pub fn polkadot_development_config() -> Result<ChainSpec, String> {
36+
pub fn bulletin_polkadot_development_config() -> Result<ChainSpec, String> {
3737
Ok(ChainSpec::builder(
3838
bulletin_polkadot_runtime::WASM_BINARY
3939
.ok_or_else(|| "bulletin_polkadot_runtime::WASM_BINARY not available".to_string())?,
@@ -47,7 +47,7 @@ pub fn polkadot_development_config() -> Result<ChainSpec, String> {
4747
.build())
4848
}
4949

50-
pub fn polkadot_local_testnet_config() -> Result<ChainSpec, String> {
50+
pub fn bulletin_polkadot_local_testnet_config() -> Result<ChainSpec, String> {
5151
Ok(ChainSpec::builder(
5252
bulletin_polkadot_runtime::WASM_BINARY
5353
.ok_or_else(|| "bulletin_polkadot_runtime::WASM_BINARY not available".to_string())?,
@@ -60,3 +60,8 @@ pub fn polkadot_local_testnet_config() -> Result<ChainSpec, String> {
6060
.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
6161
.build())
6262
}
63+
64+
/// Production/live Bulletin Polkadot chain configuration.
65+
pub fn bulletin_polkadot_config() -> Result<ChainSpec, String> {
66+
ChainSpec::from_json_bytes(&include_bytes!("../chain-specs/bulletin-polkadot.json")[..])
67+
}

node/src/command.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ impl SubstrateCli for Cli {
4848
Ok(match id {
4949
"dev" | "rococo-dev" => Box::new(chain_spec::rococo_development_config()?),
5050
"local" | "rococo-local" => Box::new(chain_spec::rococo_local_testnet_config()?),
51-
"polkadot-dev" => Box::new(chain_spec::polkadot_development_config()?),
52-
"polkadot-local" => Box::new(chain_spec::polkadot_local_testnet_config()?),
51+
"polkadot-dev" | "bulletin-polkadot-dev" => Box::new(chain_spec::bulletin_polkadot_development_config()?),
52+
"polkadot-local" | "bulletin-polkadot-local" => Box::new(chain_spec::bulletin_polkadot_local_testnet_config()?),
53+
"bulletin-polkadot" => Box::new(chain_spec::bulletin_polkadot_config()?),
5354
"" => return Err(
54-
"No chain_id or path specified! Either provide a path to the chain spec or specify chain_id: Rococo (dev, local, rococo-dev, rococo-local) or Polkadot (polkadot-dev, polkadot-local)"
55+
"No chain_id or path specified! Either provide a path to the chain spec or specify chain_id: \
56+
Polkadot Live (bulletin-polkadot) \
57+
or Polkadot Dev/Local (bulletin-polkadot-dev, bulletin-polkadot-local) \
58+
or Rococo (dev, local, rococo-dev, rococo-local)"
5559
.into(),
5660
),
5761
path =>

runtimes/bulletin-polkadot/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
117117
spec_name: alloc::borrow::Cow::Borrowed("polkadot-bulletin-chain"),
118118
impl_name: alloc::borrow::Cow::Borrowed("polkadot-bulletin-chain"),
119119
authoring_version: 0,
120-
// The version of the runtime specification. A full node will not attempt to use its native
121-
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
122-
// `spec_version`, and `authoring_version` are the same between Wasm and native.
123-
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
124-
// the compatible custom types.
125-
spec_version: 100,
120+
spec_version: 1_000_000,
126121
impl_version: 1,
127122
apis: RUNTIME_API_VERSIONS,
128123
transaction_version: 1,
@@ -185,6 +180,8 @@ parameter_types! {
185180
// This is double the "normal" Relay Chain block length limit.
186181
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
187182
::max_with_normal_ratio(10 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
183+
// Let's use substrate one: https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
184+
// (Note: Possibly we can add new one.)
188185
pub const SS58Prefix: u8 = 42;
189186

190187
pub const MaxAuthorities: u32 = 100; // TODO
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
usage() {
4+
echo Usage:
5+
echo "$1 <srtool compressed runtime path>"
6+
echo "e.g.: ./scripts/create_bulletin_polkadot_spec.sh ./target/production/wbuild/bulletin-polkadot-runtime/bulletin_polkadot_runtime.compact.compressed.wasm"
7+
exit 1
8+
}
9+
10+
if [ -z "$1" ]; then
11+
usage
12+
fi
13+
14+
set -e
15+
16+
rt_path=$1
17+
18+
echo "Generating chain spec for runtime: $rt_path"
19+
20+
# Ensure polkadot-bulletin-chain binary
21+
binary="./target/release/polkadot-bulletin-chain"
22+
if [ -f "$binary" ]; then
23+
echo "File $binary exists (no need to compile)."
24+
else
25+
echo "File $binary does not exist. Compiling..."
26+
cargo build --profile production
27+
fi
28+
ls -lrt $binary
29+
30+
# build the chain spec we'll manipulate
31+
$binary build-spec --chain bulletin-polkadot-local > chain-spec-plain.json
32+
33+
# convert runtime to hex
34+
cat $rt_path | od -A n -v -t x1 | tr -d ' \n' > rt-hex.txt
35+
36+
# TODO: provide bootNodes:
37+
# "/dns/bulletin-polkadot-node-todo.w3f.node.io/tcp/443/wss/p2p/12D3KooWCF1eA2Gap69zgXD7Df3e9DqDUsGoByocggTGejoHjK23"
38+
39+
# TODO: provide sessionKeys
40+
# TODO: provide validatorSet.initialValidators
41+
# TODO: provide relayerSet.initialRelayers
42+
# TODO: replace 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3 (//Bob)
43+
44+
# TODO: provide bridgePolkadotGrandpa.initData (set some people-chain live header)
45+
46+
# replace the runtime in the spec with the given runtime and set some values to production
47+
# Boot nodes, invulnerables, and session keys from https://github.com/paritytech/devops/issues/2847
48+
#
49+
# Note: This is a testnet runtime. Each invulnerable's Aura key is also used as its AccountId. This
50+
# is not recommended in value-bearing networks.
51+
cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesis.code = ("0x" + $code)' \
52+
| jq '.name = "Polkadot Bulletin"' \
53+
| jq '.id = "bulletin-polkadot"' \
54+
| jq '.chainType = "Live"' \
55+
| jq '.bootNodes = [
56+
"/ip4/127.0.0.1/tcp/33333/ws/p2p/5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
57+
]' \
58+
| jq '.genesis.runtimeGenesis.patch.session.keys = [
59+
[
60+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
61+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
62+
{
63+
"babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
64+
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
65+
}
66+
]
67+
]' \
68+
| jq '.genesis.runtimeGenesis.patch.validatorSet.initialValidators = [
69+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
70+
]' \
71+
| jq '.genesis.runtimeGenesis.patch.relayerSet.initialRelayers = [
72+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
73+
]' \
74+
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotGrandpa.owner)' \
75+
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotParachains.owner)' \
76+
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotMessages.owner)' \
77+
> edited-chain-spec-plain.json
78+
79+
# build a raw spec
80+
$binary build-spec --chain edited-chain-spec-plain.json --raw > chain-spec-raw.json
81+
cp edited-chain-spec-plain.json bulletin-polkadot-spec.json
82+
cp chain-spec-raw.json ./node/chain-specs/bulletin-polkadot.json
83+
cp chain-spec-raw.json bulletin-polkadot-spec-raw.json
84+
85+
# build genesis data
86+
$binary export-genesis-state --chain chain-spec-raw.json > bulletin-polkadot-genesis-head-data
87+
88+
# build genesis wasm
89+
$binary export-genesis-wasm --chain chain-spec-raw.json > bulletin-polkadot-wasm

zombienet/adjust_bp_spec.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Add Alice(`5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`) as pre-defined validator
4+
# We do this only if there is a `.genesis.runtimeGenesis.patch` object.
5+
# Otherwise we're working with the raw chain spec.
6+
$POLKADOT_BULLETIN_BINARY_PATH build-spec --chain bulletin-polkadot-local \
7+
| jq '.name = "Polkadot Bulletin (Alice/Bob patched)"' \
8+
| jq '.id = "bulletin-polkadot"' \
9+
| jq '.chainType = "Live"' \
10+
| jq '.bootNodes = [
11+
"/ip4/127.0.0.1/tcp/33333/ws/p2p/5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
12+
]' \
13+
| jq '.genesis.runtimeGenesis.patch.session.keys = [
14+
[
15+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
16+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
17+
{
18+
"babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
19+
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
20+
}
21+
]
22+
]' \
23+
| jq '.genesis.runtimeGenesis.patch.validatorSet.initialValidators = [
24+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
25+
]' \
26+
| jq '.genesis.runtimeGenesis.patch.relayerSet.initialRelayers = [
27+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
28+
]'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://www.npmjs.com/package/@zombienet/cli
2+
# To run the network, execute the following command:
3+
# POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain zombienet -p native spawn ./zombienet/bulletin-polkadot-local.toml
4+
5+
[relaychain]
6+
chain = "bulletin-polkadot-local"
7+
default_command = "{{POLKADOT_BULLETIN_BINARY_PATH}}"
8+
9+
[[relaychain.nodes]]
10+
name = "alice"
11+
rpc_port = 12345
12+
validator = true
13+
args = [ "--ipfs-server", "-lruntime=trace"]
14+
15+
[[relaychain.nodes]]
16+
name = "bob"
17+
rpc_port = 12346
18+
validator = true
19+
args = ["-lruntime=trace"]

zombienet/bulletin-polkadot.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# https://www.npmjs.com/package/@zombienet/cli
2+
# To run the network, execute the following command:
3+
# POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain ENV_PATH=<zombienet-dir> zombienet -p native spawn ./zombienet/bulletin-polkadot.toml
4+
5+
[relaychain]
6+
chain = "bulletin-polkadot"
7+
default_command = "{{POLKADOT_BULLETIN_BINARY_PATH}}"
8+
chain_spec_command = "{{ENV_PATH}}/adjust_bp_spec.sh {% raw %} {{chainName}} {% endraw %}"
9+
10+
[[relaychain.nodes]]
11+
name = "alice"
12+
rpc_port = 12345
13+
p2p_port = 33333
14+
validator = true
15+
args = [ "--ipfs-server", "-lruntime=trace"]
16+

0 commit comments

Comments
 (0)