Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Glutton script chain spec generator #2638

Merged
merged 8 commits into from
May 29, 2023
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
4 changes: 2 additions & 2 deletions polkadot-parachain/src/chain_spec/glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec {
// Name
format!("Glutton {}", para_id).as_str(),
// ID
format!("glutton_kusama_{}", para_id).as_str(),
format!("glutton-kusama-{}", para_id).as_str(),
ChainType::Live,
move || glutton_genesis(para_id),
Vec::new(),
None,
// Protocol ID
Some(format!("glutton_kusama_{}", para_id).as_str()),
Some(format!("glutton-kusama-{}", para_id).as_str()),
None,
Some(properties),
Extensions { relay_chain: "kusama".into(), para_id: para_id.into() },
Expand Down
86 changes: 86 additions & 0 deletions scripts/create_glutton_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

# Example usage to:
#
# - Use the `polkadot-parachain` binary;
# - Use `rococo` as the parent Relay Chain;
# - Generate `ParaId`s from 1,300 to 1,370, inclusive;
# - Set the Sudo key to `G7Z5mTmTQsjEGBVqVGDZyR9m7RoHNZJk6JeykyfKQ3vmBiR`;
# - Set `compute`, `storage`, and `trash_data_count` set to 50%, 50%, and 5,120, respectively;
# - And save the results in `output-dir`.
#
# ./scripts/create_glutton_spec.sh ./target/release/polkadot-parachain rococo 1300 1370 G7Z5mTmTQsjEGBVqVGDZyR9m7RoHNZJk6JeykyfKQ3vmBiR 500000000 500000000 5120 output-dir

usage() {
echo Usage:
echo "$0 <binary path> <relay chain> <from parachain id> <to parachain id> <sudo key> <compute> <storage> <trash_data_count> <output dir>"
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
exit 1
}

set -e

if ! command -v jq >/dev/null 2>&1; then
echo "'jq' is not installed, please install. Exiting..."
exit 1
fi

binary_path=$1
relay_chain=$2
from_para_id=$3
to_para_id=$4
sudo=$5
compute=$6
storage=$7
trash_data_count=$8
output_dir=$9

[ -z "$binary_path" ] && usage
[ -z "$relay_chain" ] && usage
[ -z "$from_para_id" ] && usage
[ -z "$to_para_id" ] && usage
[ -z "$sudo" ] && usage
[ -z "$compute" ] && usage
[ -z "$storage" ] && usage
[ -z "$trash_data_count" ] && usage
[ -z "$output_dir" ] && usage


for (( para_id=$from_para_id; para_id<=$to_para_id; para_id++ )); do
echo "Building chain specs for parachain $para_id"

# create dir to store parachain generated files
output_para_dir="$output_dir/glutton-$relay_chain-$para_id"
if [ ! -d "$output_para_dir" ]; then
mkdir $output_para_dir
fi

# build the chain spec we'll manipulate
$binary_path build-spec --disable-default-bootnode --chain "glutton-kusama-genesis-$para_id" > "$output_para_dir/plain-glutton-$relay_chain-$para_id-spec.json"

id="glutton-$relay_chain-$para_id"
protocol_id="glutton-$relay_chain-$para_id"

# replace the runtime in the spec with the given runtime and set some values to production
cat "$output_para_dir/plain-glutton-$relay_chain-$para_id-spec.json" \
| jq --arg id $id '.id = $id' \
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
| jq --arg protocol_id $protocol_id '.protocolId = $protocol_id' \
| jq --arg relay_chain $relay_chain '.relay_chain = $relay_chain' \
| jq --argjson para_id $para_id '.para_id = $para_id' \
| jq --arg sudo $sudo '.genesis.runtime.sudo.key = $sudo' \
| jq --argjson para_id $para_id '.genesis.runtime.parachainInfo.parachainId = $para_id' \
| jq --argjson compute $compute '.genesis.runtime.glutton.compute = $compute' \
| jq --argjson storage $storage '.genesis.runtime.glutton.storage = $storage' \
| jq --argjson trash_data_count $trash_data_count '.genesis.runtime.glutton.trashDataCount = $trash_data_count' \
> $output_para_dir/glutton-$relay_chain-$para_id-spec.json

# build a raw spec
$binary_path build-spec --disable-default-bootnode --chain "$output_para_dir/glutton-$relay_chain-$para_id-spec.json" --raw > "$output_para_dir/glutton-$relay_chain-$para_id-raw-spec.json"

# build genesis data
$binary_path export-genesis-state --chain "$output_para_dir/glutton-$relay_chain-$para_id-raw-spec.json" > "$output_para_dir/glutton-$relay_chain-$para_id-head-data"

# build genesis wasm
$binary_path export-genesis-wasm --chain "$output_para_dir/glutton-$relay_chain-$para_id-raw-spec.json" > "$output_para_dir/glutton-$relay_chain-$para_id-validation-code"

rm "$output_para_dir/plain-glutton-$relay_chain-$para_id-spec.json"
done