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

Commit

Permalink
BHK + BH-Westend release backport (#2083)
Browse files Browse the repository at this point in the history
* Runtime code according to the released runtime bridge-hub-kusama_runtime-v9360.compact.compressed.wasm

* Add chains spec for westend with generated by `./scripts/create_bridge_hub_westend_spec.sh ~/Downloads/upload/bridge-hub-kusama_runtime-v9360.compact.compressed.wasm 1002`

* fmt
  • Loading branch information
bkontur authored Jan 13, 2023
1 parent e949f21 commit aae4731
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 3 deletions.
2 changes: 1 addition & 1 deletion parachains/chain-specs/bridge-hub-kusama.json

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions parachains/chain-specs/bridge-hub-westend.json

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion polkadot-parachain/src/chain_spec/bridge_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub enum BridgeHubRuntimeType {
KusamaLocal,
// used by benchmarks
KusamaDevelopment,

// used with kusama runtime
Westend,
}

impl FromStr for BridgeHubRuntimeType {
Expand All @@ -45,6 +48,7 @@ impl FromStr for BridgeHubRuntimeType {
kusama::BRIDGE_HUB_KUSAMA => Ok(BridgeHubRuntimeType::Kusama),
kusama::BRIDGE_HUB_KUSAMA_LOCAL => Ok(BridgeHubRuntimeType::KusamaLocal),
kusama::BRIDGE_HUB_KUSAMA_DEVELOPMENT => Ok(BridgeHubRuntimeType::KusamaDevelopment),
westend::BRIDGE_HUB_WESTEND => Ok(BridgeHubRuntimeType::Westend),
rococo::BRIDGE_HUB_ROCOCO => Ok(BridgeHubRuntimeType::Rococo),
rococo::BRIDGE_HUB_ROCOCO_LOCAL => Ok(BridgeHubRuntimeType::RococoLocal),
rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT => Ok(BridgeHubRuntimeType::RococoDevelopment),
Expand All @@ -64,6 +68,8 @@ impl BridgeHubRuntimeType {
BridgeHubRuntimeType::KusamaLocal |
BridgeHubRuntimeType::KusamaDevelopment =>
Ok(Box::new(kusama::BridgeHubChainSpec::from_json_file(path)?)),
BridgeHubRuntimeType::Westend =>
Ok(Box::new(westend::BridgeHubChainSpec::from_json_file(path)?)),
BridgeHubRuntimeType::Rococo |
BridgeHubRuntimeType::RococoLocal |
BridgeHubRuntimeType::RococoDevelopment =>
Expand Down Expand Up @@ -91,6 +97,10 @@ impl BridgeHubRuntimeType {
"kusama-dev",
ParaId::new(1003),
))),
BridgeHubRuntimeType::Westend =>
Ok(Box::new(westend::BridgeHubChainSpec::from_json_bytes(
&include_bytes!("../../../parachains/chain-specs/bridge-hub-westend.json")[..],
)?)),
BridgeHubRuntimeType::Rococo => Ok(Box::new(rococo::live_config(
rococo::BRIDGE_HUB_ROCOCO,
"Rococo BridgeHub",
Expand Down Expand Up @@ -132,6 +142,7 @@ impl BridgeHubRuntimeType {
BridgeHubRuntimeType::Kusama |
BridgeHubRuntimeType::KusamaLocal |
BridgeHubRuntimeType::KusamaDevelopment => &bridge_hub_kusama_runtime::VERSION,
BridgeHubRuntimeType::Westend => &bridge_hub_kusama_runtime::VERSION,
BridgeHubRuntimeType::Rococo |
BridgeHubRuntimeType::RococoLocal |
BridgeHubRuntimeType::RococoDevelopment |
Expand Down Expand Up @@ -373,7 +384,7 @@ pub mod wococo {
}
}

/// Sub-module for Kusama setup (reuses stuff from Rococo)
/// Sub-module for Kusama setup
pub mod kusama {
use super::{BridgeHubBalance, ParaId};
use crate::chain_spec::{
Expand Down Expand Up @@ -495,3 +506,12 @@ pub mod kusama {
}
}
}

/// Sub-module for Westend setup (uses Kusama runtime)
pub mod westend {
use crate::chain_spec::bridge_hubs::kusama;

pub(crate) const BRIDGE_HUB_WESTEND: &str = "bridge-hub-westend";
pub type BridgeHubChainSpec = kusama::BridgeHubChainSpec;
pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi;
}
18 changes: 18 additions & 0 deletions polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Westend => {
runner.async_run(|$config| {
let $components = new_partial::<chain_spec::bridge_hubs::westend::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;

let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment => {
Expand Down Expand Up @@ -871,6 +882,13 @@ pub fn run() -> Result<()> {
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0),
chain_spec::bridge_hubs::BridgeHubRuntimeType::Westend =>
crate::service::start_generic_aura_node::<
chain_spec::bridge_hubs::westend::RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0),
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment =>
Expand Down
4 changes: 3 additions & 1 deletion scripts/create_bridge_hub_kusama_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ usage() {
echo Usage:
echo "$1 <srtool compressed runtime path>"
echo "$2 <para_id>"
echo "e.g.: ./scripts/create_bridge_hub_kusama_spec.sh ./target/release/wbuild/bridge-hub-kusama-runtime/bridge_hub_kusama_runtime.compact.compressed.wasm 1003"
echo "e.g.: ./scripts/create_bridge_hub_kusama_spec.sh ./target/release/wbuild/bridge-hub-kusama-runtime/bridge_hub_kusama_runtime.compact.compressed.wasm 1002"
exit 1
}

Expand Down Expand Up @@ -97,7 +97,9 @@ cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtime.syste

# build a raw spec
$binary build-spec --chain edited-chain-spec-plain.json --raw > chain-spec-raw.json
cp edited-chain-spec-plain.json bridge-hub-kusama-spec.json
cp chain-spec-raw.json ./parachains/chain-specs/bridge-hub-kusama.json
cp chain-spec-raw.json bridge-hub-kusama-spec-raw.json

# build genesis data
$binary export-genesis-state --chain chain-spec-raw.json > bridge-hub-kusama-genesis-head-data
Expand Down
101 changes: 101 additions & 0 deletions scripts/create_bridge_hub_westend_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

usage() {
echo Usage:
echo "$1 <srtool compressed runtime path>"
echo "$2 <para_id>"
echo "e.g.: ./scripts/create_bridge_hub_westend_spec.sh ./target/release/wbuild/bridge-hub-kusama-runtime/bridge_hub_kusama_runtime.compact.compressed.wasm 1002"
exit 1
}

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

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

set -e

rt_path=$1
para_id=$2

echo "Generating chain spec for runtime: $rt_path and para_id: $para_id"

binary="./target/release/polkadot-parachain"

# build the chain spec we'll manipulate
$binary build-spec --chain bridge-hub-kusama-dev > chain-spec-plain.json

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

# replace the runtime in the spec with the given runtime and set some values to production
cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtime.system.code = ("0x" + $code)' \
| jq '.name = "Westend BridgeHub"' \
| jq '.id = "bridge-hub-westend"' \
| jq '.chainType = "Live"' \
| jq '.bootNodes = [
"/dns/westend-bridge-hub-collator-node-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKyEuqkkWvFSrwZWKWBAsHgLV3HGfHj7yH3LNJLAVhmxY",
"/dns/westend-bridge-hub-collator-node-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWBpvudthz61XC4oP2YYFFJdhWohBeQ1ffn1BMSGWhapjd",
"/dns/westend-bridge-hub-collator-node-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPXqdRRthjKAMPFtaXUK7yBxsvh83QsmzXzALA3inoJfo",
"/dns/westend-bridge-hub-collator-node-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWAp2YpVaiNBy7rozEHJGocDpaLFt3VFZsGMBEYh4BoEz7"
]' \
| jq '.relay_chain = "westend"' \
| jq '.properties = {
"tokenDecimals": 12,
"tokenSymbol": "WND"
}' \
| jq --argjson para_id $para_id '.para_id = $para_id' \
| jq --argjson para_id $para_id '.genesis.runtime.parachainInfo.parachainId = $para_id' \
| jq '.genesis.runtime.balances.balances = []' \
| jq '.genesis.runtime.collatorSelection.invulnerables = [
"5GN5qBbUkxigdLhTajWqAG66MRD2v5WjUFqkuGVSRCyhMCg6",
"5GRCPWstCyp3u9T2c3oGqj83rniQffJR5Q2LpGsL9m19oQ8T",
"5GR2p9FpJFPpDuZPk1Lt9VZJ76aLPfKVA6qBE4FRted2oT6D",
"5FH8VBgdXijT1vM6pj1aFGw49J2fQDZKM1BFQtVV1zjmA7mM"
]' \
| jq '.genesis.runtime.session.keys = [
[
"5GN5qBbUkxigdLhTajWqAG66MRD2v5WjUFqkuGVSRCyhMCg6",
"5GN5qBbUkxigdLhTajWqAG66MRD2v5WjUFqkuGVSRCyhMCg6",
{
"aura": "5GN5qBbUkxigdLhTajWqAG66MRD2v5WjUFqkuGVSRCyhMCg6"
}
],
[
"5GRCPWstCyp3u9T2c3oGqj83rniQffJR5Q2LpGsL9m19oQ8T",
"5GRCPWstCyp3u9T2c3oGqj83rniQffJR5Q2LpGsL9m19oQ8T",
{
"aura": "5GRCPWstCyp3u9T2c3oGqj83rniQffJR5Q2LpGsL9m19oQ8T"
}
],
[
"5GR2p9FpJFPpDuZPk1Lt9VZJ76aLPfKVA6qBE4FRted2oT6D",
"5GR2p9FpJFPpDuZPk1Lt9VZJ76aLPfKVA6qBE4FRted2oT6D",
{
"aura": "5GR2p9FpJFPpDuZPk1Lt9VZJ76aLPfKVA6qBE4FRted2oT6D"
}
],
[
"5FH8VBgdXijT1vM6pj1aFGw49J2fQDZKM1BFQtVV1zjmA7mM",
"5FH8VBgdXijT1vM6pj1aFGw49J2fQDZKM1BFQtVV1zjmA7mM",
{
"aura": "5FH8VBgdXijT1vM6pj1aFGw49J2fQDZKM1BFQtVV1zjmA7mM"
}
]
]' \
> 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 bridge-hub-westend-spec.json
cp chain-spec-raw.json ./parachains/chain-specs/bridge-hub-westend.json
cp chain-spec-raw.json bridge-hub-westend-spec-raw.json

# build genesis data
$binary export-genesis-state --chain chain-spec-raw.json > bridge-hub-westend-genesis-head-data

# build genesis wasm
$binary export-genesis-wasm --chain chain-spec-raw.json > bridge-hub-westend-wasm

0 comments on commit aae4731

Please sign in to comment.