Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,43 @@ Controls the validator set. Currently set in genesis and validators can be added
#### polkadot-bulletin-chain/pallets/transaction-storage
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.

## Polkadot Bulletin production/live runtime

### Initial genesis chain spec

[bulletin-polkadot-genesis.json](./node/chain-specs/bulletin-polkadot.json)

```
cargo build --release -p polkadot-bulletin-chain

./target/release/polkadot-bulletin-chain build-spec --chain bulletin-polkadot
or
./target/release/polkadot-bulletin-chain build-spec --chain bulletin-polkadot --raw
```

### Run local chain
```
cargo build --release -p polkadot-bulletin-chain

POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain zombienet -p native spawn ./zombienet/bulletin-polkadot-local.toml
```

### Run a production chain (but only with Alice validator)
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).

```
cargo build --release -p polkadot-bulletin-chain

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

### Run a production chain

```
cargo build --release -p polkadot-bulletin-chain
./target/release/polkadot-bulletin-chain --chain bulletin-polkadot
```

### Fresh benchmarks

Run on the dedicated machine from the root directory:
Expand Down
1 change: 1 addition & 0 deletions node/chain-specs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!/*.json
61 changes: 61 additions & 0 deletions node/chain-specs/bulletin-polkadot.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn rococo_local_testnet_config() -> Result<ChainSpec, String> {
.build())
}

pub fn polkadot_development_config() -> Result<ChainSpec, String> {
pub fn bulletin_polkadot_development_config() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder(
bulletin_polkadot_runtime::WASM_BINARY
.ok_or_else(|| "bulletin_polkadot_runtime::WASM_BINARY not available".to_string())?,
Expand All @@ -47,7 +47,7 @@ pub fn polkadot_development_config() -> Result<ChainSpec, String> {
.build())
}

pub fn polkadot_local_testnet_config() -> Result<ChainSpec, String> {
pub fn bulletin_polkadot_local_testnet_config() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder(
bulletin_polkadot_runtime::WASM_BINARY
.ok_or_else(|| "bulletin_polkadot_runtime::WASM_BINARY not available".to_string())?,
Expand All @@ -60,3 +60,8 @@ pub fn polkadot_local_testnet_config() -> Result<ChainSpec, String> {
.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
.build())
}

/// Production/live Bulletin Polkadot chain configuration.
pub fn bulletin_polkadot_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../chain-specs/bulletin-polkadot.json")[..])
}
10 changes: 7 additions & 3 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ impl SubstrateCli for Cli {
Ok(match id {
"dev" | "rococo-dev" => Box::new(chain_spec::rococo_development_config()?),
"local" | "rococo-local" => Box::new(chain_spec::rococo_local_testnet_config()?),
"polkadot-dev" => Box::new(chain_spec::polkadot_development_config()?),
"polkadot-local" => Box::new(chain_spec::polkadot_local_testnet_config()?),
"polkadot-dev" | "bulletin-polkadot-dev" => Box::new(chain_spec::bulletin_polkadot_development_config()?),
"polkadot-local" | "bulletin-polkadot-local" => Box::new(chain_spec::bulletin_polkadot_local_testnet_config()?),
"bulletin-polkadot" => Box::new(chain_spec::bulletin_polkadot_config()?),
"" => return Err(
"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)"
"No chain_id or path specified! Either provide a path to the chain spec or specify chain_id: \
Polkadot Live (bulletin-polkadot) \
or Polkadot Dev/Local (bulletin-polkadot-dev, bulletin-polkadot-local) \
or Rococo (dev, local, rococo-dev, rococo-local)"
.into(),
),
path =>
Expand Down
9 changes: 3 additions & 6 deletions runtimes/bulletin-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: alloc::borrow::Cow::Borrowed("polkadot-bulletin-chain"),
impl_name: alloc::borrow::Cow::Borrowed("polkadot-bulletin-chain"),
authoring_version: 0,
// The version of the runtime specification. A full node will not attempt to use its native
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 100,
spec_version: 1_000_000,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -185,6 +180,8 @@ parameter_types! {
// This is double the "normal" Relay Chain block length limit.
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(10 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
// Let's use substrate one: https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
// (Note: Possibly we can add new one.)
pub const SS58Prefix: u8 = 42;

pub const MaxAuthorities: u32 = 100; // TODO
Expand Down
89 changes: 89 additions & 0 deletions scripts/create_bulletin_polkadot_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

usage() {
echo Usage:
echo "$1 <srtool compressed runtime path>"
echo "e.g.: ./scripts/create_bulletin_polkadot_spec.sh ./target/production/wbuild/bulletin-polkadot-runtime/bulletin_polkadot_runtime.compact.compressed.wasm"
exit 1
}

if [ -z "$1" ]; then
usage
fi

set -e

rt_path=$1

echo "Generating chain spec for runtime: $rt_path"

# Ensure polkadot-bulletin-chain binary
binary="./target/release/polkadot-bulletin-chain"
if [ -f "$binary" ]; then
echo "File $binary exists (no need to compile)."
else
echo "File $binary does not exist. Compiling..."
cargo build --profile production
fi
ls -lrt $binary

# build the chain spec we'll manipulate
$binary build-spec --chain bulletin-polkadot-local > chain-spec-plain.json

# convert runtime to hex
cat $rt_path | od -A n -v -t x1 | tr -d ' \n' > rt-hex.txt

# TODO: provide bootNodes:
# "/dns/bulletin-polkadot-node-todo.w3f.node.io/tcp/443/wss/p2p/12D3KooWCF1eA2Gap69zgXD7Df3e9DqDUsGoByocggTGejoHjK23"

# TODO: provide sessionKeys
# TODO: provide validatorSet.initialValidators
# TODO: provide relayerSet.initialRelayers
# TODO: replace 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3 (//Bob)

# TODO: provide bridgePolkadotGrandpa.initData (set some people-chain live header)

# replace the runtime in the spec with the given runtime and set some values to production
# Boot nodes, invulnerables, and session keys from https://github.com/paritytech/devops/issues/2847
#
# Note: This is a testnet runtime. Each invulnerable's Aura key is also used as its AccountId. This
# is not recommended in value-bearing networks.
cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesis.code = ("0x" + $code)' \
| jq '.name = "Polkadot Bulletin"' \
| jq '.id = "bulletin-polkadot"' \
| jq '.chainType = "Live"' \
| jq '.bootNodes = [
"/ip4/127.0.0.1/tcp/33333/ws/p2p/5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]' \
| jq '.genesis.runtimeGenesis.patch.session.keys = [
[
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
{
"babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
]
]' \
| jq '.genesis.runtimeGenesis.patch.validatorSet.initialValidators = [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]' \
| jq '.genesis.runtimeGenesis.patch.relayerSet.initialRelayers = [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]' \
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotGrandpa.owner)' \
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotParachains.owner)' \
| jq 'del(.genesis.runtimeGenesis.patch.bridgePolkadotMessages.owner)' \
> edited-chain-spec-plain.json

# build a raw spec
$binary build-spec --chain edited-chain-spec-plain.json --raw > chain-spec-raw.json
cp edited-chain-spec-plain.json bulletin-polkadot-spec.json
cp chain-spec-raw.json ./node/chain-specs/bulletin-polkadot.json
cp chain-spec-raw.json bulletin-polkadot-spec-raw.json

# build genesis data
$binary export-genesis-state --chain chain-spec-raw.json > bulletin-polkadot-genesis-head-data

# build genesis wasm
$binary export-genesis-wasm --chain chain-spec-raw.json > bulletin-polkadot-wasm
28 changes: 28 additions & 0 deletions zombienet/adjust_bp_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Add Alice(`5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`) as pre-defined validator
# We do this only if there is a `.genesis.runtimeGenesis.patch` object.
# Otherwise we're working with the raw chain spec.
$POLKADOT_BULLETIN_BINARY_PATH build-spec --chain bulletin-polkadot-local \
| jq '.name = "Polkadot Bulletin (Alice/Bob patched)"' \
| jq '.id = "bulletin-polkadot"' \
| jq '.chainType = "Live"' \
| jq '.bootNodes = [
"/ip4/127.0.0.1/tcp/33333/ws/p2p/5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]' \
| jq '.genesis.runtimeGenesis.patch.session.keys = [
[
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
{
"babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
]
]' \
| jq '.genesis.runtimeGenesis.patch.validatorSet.initialValidators = [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]' \
| jq '.genesis.runtimeGenesis.patch.relayerSet.initialRelayers = [
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
]'
19 changes: 19 additions & 0 deletions zombienet/bulletin-polkadot-local.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://www.npmjs.com/package/@zombienet/cli
# To run the network, execute the following command:
# POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain zombienet -p native spawn ./zombienet/bulletin-polkadot-local.toml

[relaychain]
chain = "bulletin-polkadot-local"
default_command = "{{POLKADOT_BULLETIN_BINARY_PATH}}"

[[relaychain.nodes]]
name = "alice"
rpc_port = 12345
validator = true
args = [ "--ipfs-server", "-lruntime=trace"]

[[relaychain.nodes]]
name = "bob"
rpc_port = 12346
validator = true
args = ["-lruntime=trace"]
16 changes: 16 additions & 0 deletions zombienet/bulletin-polkadot.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://www.npmjs.com/package/@zombienet/cli
# To run the network, execute the following command:
# POLKADOT_BULLETIN_BINARY_PATH=./target/release/polkadot-bulletin-chain ENV_PATH=<zombienet-dir> zombienet -p native spawn ./zombienet/bulletin-polkadot.toml

[relaychain]
chain = "bulletin-polkadot"
default_command = "{{POLKADOT_BULLETIN_BINARY_PATH}}"
chain_spec_command = "{{ENV_PATH}}/adjust_bp_spec.sh {% raw %} {{chainName}} {% endraw %}"

[[relaychain.nodes]]
name = "alice"
rpc_port = 12345
p2p_port = 33333
validator = true
args = [ "--ipfs-server", "-lruntime=trace"]