|
| 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 |
0 commit comments