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

Add westend chain-spec and some chain-spec utilities #19

Merged
merged 18 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ build/
# Chopsticks
/chopsticks/*.db.sqlite*

# genesis state and chain-spec dumps
/chain_dumps

# Before adding new lines, see the comment at the top.
10 changes: 10 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,13 @@ fn testnet_genesis(
"sudo": { "key": Some(root) }
})
}

pub fn bajun_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../resources/bajun/bajun-raw.json")[..])
}

pub fn bajun_westend_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(
&include_bytes!("../../resources/bajun/westend/bajun-westend.json")[..],
)
}
12 changes: 12 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ use sp_runtime::traits::AccountIdConversion;

use crate::{
chain_spec,
chain_spec::{bajun_config, bajun_westend_config},
cli::{Cli, RelayChainCli, Subcommand},
service::new_partial,
};

fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Ok(match id {
// live configs
"bajun" => Box::new(bajun_config()?),
// "bajun-westend" => Box::new(bajun_westend_config()?),
clangenb marked this conversation as resolved.
Show resolved Hide resolved

// initialize new genesis configs
// Todo: add helper functions to chain-spec to recreate configs for
// bajun and bajun-westend. so that we don't have to copy paste custom
// genesis keys.

// on the spot configs
"dev" => Box::new(chain_spec::development_config()),
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),

path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Expand Down
28 changes: 28 additions & 0 deletions scripts/dump_wasm_state_and_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Helper script to generate the wasm, state and chain-spec/ -raw.json for a given chain-spec.
#
# Usage: ./scripts/dump_wasm_state_and_spec.sh <chain-spec> <collator-binary> <dump-dir>
#
# Example: ./scripts/dump_wasm_state_and_spec.sh template-rococo collator ./dump_dir
#
# chain-spec is mandatory, the rest is optional.


CHAIN_SPEC=$1
COLLATOR=${2:-./target/release/bajun-node}
DUMP_DIR=${3:-./chain_dumps}

mkdir -p ${DUMP_DIR}

echo "dumping spec for: $CHAIN_SPEC"
echo "collator: ${COLLATOR}"
echo "dump_dir: ${DUMP_DIR}"
echo ""

$COLLATOR build-spec --chain ${CHAIN_SPEC} >$DUMP_DIR/${CHAIN_SPEC}.json
$COLLATOR build-spec --chain ${CHAIN_SPEC} --raw >$DUMP_DIR/${CHAIN_SPEC}-raw-unsorted.json
jq --sort-keys . $DUMP_DIR/${CHAIN_SPEC}-raw-unsorted.json > $DUMP_DIR/${CHAIN_SPEC}-raw.json

$COLLATOR export-genesis-state --chain $DUMP_DIR/${CHAIN_SPEC}-raw.json >$DUMP_DIR/${CHAIN_SPEC}.state
$COLLATOR export-genesis-wasm --chain $DUMP_DIR/${CHAIN_SPEC}-raw.json >$DUMP_DIR/${CHAIN_SPEC}.wasm
Loading