From 6cb5cb4c41e0d27ecd0d8c03d7fd25af38f954e1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 11 Sep 2023 12:34:42 +0200 Subject: [PATCH 01/15] rococo-runtime: RococoGenesisExt removed --- polkadot/node/service/src/chain_spec.rs | 72 +++---------------- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/rococo/build.rs | 20 ++++-- polkadot/runtime/rococo/constants/Cargo.toml | 3 + polkadot/runtime/rococo/constants/src/lib.rs | 4 +- .../functional/0002-parachains-disputes.toml | 2 +- .../0004-parachains-garbage-candidate.toml | 2 +- .../zombienet_tests/misc/0001-paritydb.toml | 2 +- 8 files changed, 33 insertions(+), 74 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 1e5aaa807b81..1da364496a86 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -134,7 +134,7 @@ pub type WestendChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the rococo runtime. #[cfg(feature = "rococo-native")] -pub type RococoChainSpec = service::GenericChainSpec; +pub type RococoChainSpec = service::GenericChainSpec; /// The `ChainSpec` parameterized for the `versi` runtime. /// @@ -146,30 +146,6 @@ pub type VersiChainSpec = RococoChainSpec; #[cfg(not(feature = "rococo-native"))] pub type RococoChainSpec = DummyChainSpec; -/// Extension for the Rococo genesis config to support a custom changes to the genesis state. -#[derive(serde::Serialize, serde::Deserialize)] -#[cfg(feature = "rococo-native")] -pub struct RococoGenesisExt { - /// The runtime genesis config. - runtime_genesis_config: rococo::RuntimeGenesisConfig, - /// The session length in blocks. - /// - /// If `None` is supplied, the default value is used. - session_length_in_blocks: Option, -} - -#[cfg(feature = "rococo-native")] -impl sp_runtime::BuildStorage for RococoGenesisExt { - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - if let Some(length) = self.session_length_in_blocks.as_ref() { - rococo_runtime_constants::time::EpochDurationInBlocks::set(length); - } - }); - self.runtime_genesis_config.assimilate_storage(storage) - } -} - pub fn polkadot_config() -> Result { PolkadotChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..]) } @@ -1128,10 +1104,7 @@ pub fn rococo_staging_testnet_config() -> Result { "Rococo Staging Testnet", "rococo_staging_testnet", ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: None, - }, + move || rococo_staging_testnet_config_genesis(wasm_binary), boot_nodes, Some( TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1165,10 +1138,7 @@ pub fn versi_staging_testnet_config() -> Result { "Versi Staging Testnet", "versi_staging_testnet", ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: Some(100), - }, + move || rococo_staging_testnet_config_genesis(wasm_binary), boot_nodes, Some( TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1718,11 +1688,7 @@ pub fn rococo_development_config() -> Result { "Development", "rococo_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -1741,11 +1707,7 @@ pub fn versi_development_config() -> Result { "Development", "versi_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some("versi"), @@ -1765,11 +1727,7 @@ pub fn wococo_development_config() -> Result { "Development", "wococo_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some(WOCOCO_DEV_PROTOCOL_ID), @@ -1888,11 +1846,7 @@ pub fn rococo_local_testnet_config() -> Result { "Rococo Local Testnet", "rococo_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_local_testnet_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -1927,11 +1881,7 @@ pub fn wococo_local_testnet_config() -> Result { "Wococo Local Testnet", "wococo_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || wococo_local_testnet_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -1966,11 +1916,7 @@ pub fn versi_local_testnet_config() -> Result { "Versi Local Testnet", "versi_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: versi_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || versi_local_testnet_genesis(wasm_binary), vec![], None, Some("versi"), diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index a181250cfa37..3a396b881100 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -284,6 +284,6 @@ try-runtime = [ ] # Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [] +fast-runtime = [ "rococo-runtime-constants/fast-runtime" ] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index e7134e0ef723..0055aabecdca 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -14,12 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +use std::env; use substrate_wasm_builder::WasmBuilder; +// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in +// prod_or_fast macro. +const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; + fn main() { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .build() + let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); + + if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() && env::var("CARGO_FEATURE_FAST_RUNTIME").is_ok() + { + builder = builder.enable_feature("fast-runtime") + }; + + builder.build(); + + println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); } diff --git a/polkadot/runtime/rococo/constants/Cargo.toml b/polkadot/runtime/rococo/constants/Cargo.toml index b1eb3f48f655..b15fcace0fde 100644 --- a/polkadot/runtime/rococo/constants/Cargo.toml +++ b/polkadot/runtime/rococo/constants/Cargo.toml @@ -25,3 +25,6 @@ std = [ "sp-runtime/std", "sp-weights/std", ] + +# Set timing constants (e.g. session period) to faster versions to speed up testing. +fast-runtime = [] diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 214e2f3fa980..3b2ff696f185 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -41,9 +41,9 @@ pub mod time { use runtime_common::prod_or_fast; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; - pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES); + frame_support::parameter_types! { - pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION; + pub storage EpochDurationInBlocks: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES, "ROCOCO_EPOCH_DURATION"); } // These time units are defined in number of blocks. diff --git a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml index a0a87d60d4e3..e6aeb8e245c2 100644 --- a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml +++ b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml @@ -1,7 +1,7 @@ [settings] timeout = 1000 -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtime.configuration.config] max_validators_per_core = 5 needed_approvals = 8 diff --git a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml index 7c4f5a9f1bca..ef27d7b92f02 100644 --- a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml +++ b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtime.configuration.config] max_validators_per_core = 1 needed_approvals = 2 diff --git a/polkadot/zombienet_tests/misc/0001-paritydb.toml b/polkadot/zombienet_tests/misc/0001-paritydb.toml index 38fa56898196..99dc9c66e26e 100644 --- a/polkadot/zombienet_tests/misc/0001-paritydb.toml +++ b/polkadot/zombienet_tests/misc/0001-paritydb.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtime.configuration.config] max_validators_per_core = 1 needed_approvals = 3 From a98cd78535d5d26c6adb1b36e191113d18220968 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:31:05 +0200 Subject: [PATCH 02/15] build.rs fixed, CARGO_FEATURE_FAST_RUNTIME not checked --- polkadot/runtime/rococo/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index 0055aabecdca..6cf732fa286e 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -24,8 +24,7 @@ const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; fn main() { let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); - if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() && env::var("CARGO_FEATURE_FAST_RUNTIME").is_ok() - { + if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() { builder = builder.enable_feature("fast-runtime") }; From f84cd5d1e25c7c9ccd420b7d8641ee2d7249df9e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:43:06 +0200 Subject: [PATCH 03/15] build fast-runtime helper script --- ...build-fast-rococo-and-update-chain-spec.sh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh new file mode 100755 index 000000000000..e78ac318f973 --- /dev/null +++ b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh @@ -0,0 +1,39 @@ +#!/bin/bash -eux + +CURRENT_DIR=$(pwd) + +#directory were polkadot-sdk is checked out +POLKADOT_SDK_DIR=/home/miszka/parity/10-genesis-config/polkadot-sdk-rococo + +# required epoch duration: +EPOCH_DURATION_IN_BLOCK=6 + +# polkadot command: +DOCKER_IMAGE=paritypr/polkadot-debug:1539-2085d3f0 +POLKADOT_CMD="docker run --rm -v $CURRENT_DIR:/dir -w /dir $DOCKER_IMAGE" +# POLKADOT_CMD=$POLKADOT_SDK_DIR/target/release/polkadot + +# path to built rococo runtime: +WASM_RUNTIME_BLOB_PATH=$POLKADOT_SDK_DIR/target/release/wbuild/rococo-runtime/rococo_runtime.compact.compressed.wasm + +# build rococo runtime with adjusted epoch diration +pushd $POLKADOT_SDK_DIR +ROCOCO_EPOCH_DURATION=$EPOCH_DURATION_IN_BLOCK cargo build --features fast-runtime --release -p rococo-runtime +popd + +# do hexdump of runtime: +hexdump -v -e '/1 "%02x"' $WASM_RUNTIME_BLOB_PATH > ./runtime.hex + +# get westend spec: +$POLKADOT_CMD build-spec --chain westend-staging > $CURRENT_DIR/wococo-source.json + +# replace runtime in chainspec with newly built runtime with overwritten epoch duration: +jq --rawfile code runtime.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/wococo-source.json + +# jq will write numbers in compact way with 1e+18, substrtate json parser dont support it. +sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json + +# generate raw +$POLKADOT_CMD build-spec --chain ./chainspec-nonraw.json --raw > $CURRENT_DIR/chainspec-raw.json + + From 6200cc3c02d2717c58a028b41c7e2275f49d0303 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:53:48 +0200 Subject: [PATCH 04/15] fixes --- polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh index e78ac318f973..b3f2e43a5f76 100755 --- a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh +++ b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh @@ -3,7 +3,7 @@ CURRENT_DIR=$(pwd) #directory were polkadot-sdk is checked out -POLKADOT_SDK_DIR=/home/miszka/parity/10-genesis-config/polkadot-sdk-rococo +POLKADOT_SDK_DIR=$(git rev-parse --show-toplevel) # required epoch duration: EPOCH_DURATION_IN_BLOCK=6 @@ -35,5 +35,3 @@ sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json # generate raw $POLKADOT_CMD build-spec --chain ./chainspec-nonraw.json --raw > $CURRENT_DIR/chainspec-raw.json - - From 5ca08c7fbea40df6c9e2a2f94b52b5c2abef99a8 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:54:27 +0200 Subject: [PATCH 05/15] fixes --- polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh index b3f2e43a5f76..fe7ee04bb036 100755 --- a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh +++ b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh @@ -6,7 +6,7 @@ CURRENT_DIR=$(pwd) POLKADOT_SDK_DIR=$(git rev-parse --show-toplevel) # required epoch duration: -EPOCH_DURATION_IN_BLOCK=6 +EPOCH_DURATION_IN_BLOCK=10 # polkadot command: DOCKER_IMAGE=paritypr/polkadot-debug:1539-2085d3f0 From 619c85c74445f3b5f8403ae7cf9b6a176f7957b2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:28:03 +0200 Subject: [PATCH 06/15] fix --- polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh index fe7ee04bb036..23b15511cc53 100755 --- a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh +++ b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh @@ -6,7 +6,7 @@ CURRENT_DIR=$(pwd) POLKADOT_SDK_DIR=$(git rev-parse --show-toplevel) # required epoch duration: -EPOCH_DURATION_IN_BLOCK=10 +EPOCH_DURATION_IN_BLOCKS=10 # polkadot command: DOCKER_IMAGE=paritypr/polkadot-debug:1539-2085d3f0 @@ -18,7 +18,7 @@ WASM_RUNTIME_BLOB_PATH=$POLKADOT_SDK_DIR/target/release/wbuild/rococo-runtime/ro # build rococo runtime with adjusted epoch diration pushd $POLKADOT_SDK_DIR -ROCOCO_EPOCH_DURATION=$EPOCH_DURATION_IN_BLOCK cargo build --features fast-runtime --release -p rococo-runtime +ROCOCO_EPOCH_DURATION=$EPOCH_DURATION_IN_BLOCKS cargo build --features fast-runtime --release -p rococo-runtime popd # do hexdump of runtime: From 657ae27ffd5cd853a7c83841d65ea10fd69af25c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Sep 2023 22:06:59 +0200 Subject: [PATCH 07/15] experiment: include runtimes into polkadot-debug docker image --- .gitlab/pipeline/build.yml | 5 +++++ .../dockerfiles/polkadot/polkadot_injected_debug.Dockerfile | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index c4dfc0dd0931..e9720d3f4dff 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -19,12 +19,17 @@ build-linux-stable: RUN_UI_TESTS: 1 script: - time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker + - time ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-10/ + - time ROCOCO_EPOCH_DURATION=100 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-100/ + - pwd + - ls -alR runtimes # pack artifacts - mkdir -p ./artifacts - VERSION="${CI_COMMIT_REF_NAME}" # will be tag or branch name - mv ./target/testnet/polkadot ./artifacts/. - mv ./target/testnet/polkadot-prepare-worker ./artifacts/. - mv ./target/testnet/polkadot-execute-worker ./artifacts/. + - mv ./runtimes/ ./artifacts/. - pushd artifacts - sha256sum polkadot | tee polkadot.sha256 - shasum -c polkadot.sha256 diff --git a/docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile b/docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile index 80ce82589873..09fc4f764d04 100644 --- a/docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile +++ b/docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile @@ -28,13 +28,16 @@ RUN apt-get update && \ find /var/lib/apt/lists/ -type f -not -name lock -delete; \ # add user and link ~/.local/share/polkadot to /data useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \ - mkdir -p /data /polkadot/.local/share && \ + mkdir -p /data /polkadot/.local/share /polkdot/runtimes && \ chown -R polkadot:polkadot /data && \ ln -s /data /polkadot/.local/share/polkadot # add polkadot binaries to docker image COPY ./artifacts/polkadot ./artifacts/polkadot-execute-worker ./artifacts/polkadot-prepare-worker /usr/local/bin +# add runtime binaries to docker image +COPY ./artifacts/runtimes /polkadot/runtimes/ + USER polkadot # check if executable works in this container From 2eddd9854de6eed9bb9c690ab8dc46eb478c8650 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Sep 2023 08:48:26 +0200 Subject: [PATCH 08/15] another updated chain-spec script --- .../update-chain-spec-with-fast-rococo.sh | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 polkadot/scripts/update-chain-spec-with-fast-rococo.sh diff --git a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh new file mode 100755 index 000000000000..8bbb66c15a8a --- /dev/null +++ b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh @@ -0,0 +1,63 @@ +#!/bin/bash -eu + +CURRENT_DIR=$(pwd) + +usage() { + echo "usage $0 docker-image epoch-duration [options]" + echo " -c chain-name - base chain-spec to be used [default: westend-staging)" + exit -1 +} + +if [ "$#" -lt 2 ]; then + usage +fi + +# docker image to be used +DOCKER_IMAGE=$1 +EPOCH_DURATION_IN_BLOCKS=$2 + +shift 2 + +CHAIN_NAME="westend-staging" + +while getopts "x" o; do + case "${o}" in + c) + CHAIN_NAME=${OPTARG} + ;; + *) + usage + ;; + esac +done + +if [ -z $DOCKER_IMAGE ]; then + usage +fi + +OUTPUT_ROOT_DIR=exported-runtimes/ + +# polkadot command: +POLKADOT_CMD="docker run --rm -v $CURRENT_DIR:/dir -w /dir $DOCKER_IMAGE" + +# extract rococo runtime with adjusted epoch diration from docker image +docker export $(docker create $DOCKER_IMAGE) | \ + tar --transform="s|polkadot/runtimes/|$OUTPUT_ROOT_DIR/|" -xf - polkadot/runtimes/rococo-runtime-$EPOCH_DURATION_IN_BLOCKS/rococo_runtime.wasm + +# path to extracted rococo runtime: +WASM_RUNTIME_BLOB_PATH=$OUTPUT_ROOT_DIR/rococo-runtime-$EPOCH_DURATION_IN_BLOCKS/rococo_runtime.wasm + +# do hexdump of runtime: +hexdump -v -e '/1 "%02x"' $WASM_RUNTIME_BLOB_PATH > $WASM_RUNTIME_BLOB_PATH.hex + +# get westend spec: +$POLKADOT_CMD build-spec --chain $CHAIN_NAME > $CURRENT_DIR/wococo-source.json + +# replace runtime in chainspec with newly built runtime with overwritten epoch duration: +jq --rawfile code $WASM_RUNTIME_BLOB_PATH.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/wococo-source.json + +# jq will write numbers in compact way with 1e+18, substrtate json parser dont support it. +sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json + +# generate raw +$POLKADOT_CMD build-spec --chain ./chainspec-nonraw.json --raw > $CURRENT_DIR/chainspec-raw.json From e87df131b061e16728c1333b91f109fe27451ce5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:41:51 +0200 Subject: [PATCH 09/15] fix + prod rococo-runtime (600) --- .gitlab/pipeline/build.yml | 1 + polkadot/scripts/update-chain-spec-with-fast-rococo.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index e9720d3f4dff..889535ab289d 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -21,6 +21,7 @@ build-linux-stable: - time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker - time ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-10/ - time ROCOCO_EPOCH_DURATION=100 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-100/ + - time ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/ - pwd - ls -alR runtimes # pack artifacts diff --git a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh index 8bbb66c15a8a..1515fa550e56 100755 --- a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh +++ b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh @@ -20,7 +20,7 @@ shift 2 CHAIN_NAME="westend-staging" -while getopts "x" o; do +while getopts "c:" o; do case "${o}" in c) CHAIN_NAME=${OPTARG} From 138db76ee2e9dbe0200ba7ac0785e5135c6f83ac Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:47:27 +0200 Subject: [PATCH 10/15] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- polkadot/runtime/rococo/build.rs | 4 ++++ polkadot/runtime/rococo/constants/src/lib.rs | 2 +- polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh | 2 +- polkadot/scripts/update-chain-spec-with-fast-rococo.sh | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index 6cf732fa286e..8b2e8e8a439b 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -21,6 +21,7 @@ use substrate_wasm_builder::WasmBuilder; // prod_or_fast macro. const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; +[cfg(feature = "std")] fn main() { let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); @@ -32,3 +33,6 @@ fn main() { println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); } + +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 3b2ff696f185..21fa6bb2f1f2 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -43,7 +43,7 @@ pub mod time { pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; frame_support::parameter_types! { - pub storage EpochDurationInBlocks: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES, "ROCOCO_EPOCH_DURATION"); + pub storage EpochDurationInBlocks: BlockNumber = option_env!("ROCOCO_EPOCH_DURATION").map(|s| s.parse().expect("`ROCOCO_EPOCH_DURATION` is not a valid `BlockNumber`")).unwrap_or(1 * MINUTES); } // These time units are defined in number of blocks. diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh index 23b15511cc53..18bff45d6dce 100755 --- a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh +++ b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eux +#!/usr/bin/env bash -eux CURRENT_DIR=$(pwd) diff --git a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh index 1515fa550e56..26df4b88eada 100755 --- a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh +++ b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu CURRENT_DIR=$(pwd) From d55ae688a8d0769966a125fde2f0dd6cc7f8e762 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:57:11 +0200 Subject: [PATCH 11/15] review comments applied + script removed --- polkadot/runtime/rococo/Cargo.toml | 3 +- polkadot/runtime/rococo/build.rs | 3 +- polkadot/runtime/rococo/constants/src/lib.rs | 5 ++- ...build-fast-rococo-and-update-chain-spec.sh | 37 ------------------- .../update-chain-spec-with-fast-rococo.sh | 7 +++- 5 files changed, 12 insertions(+), 43 deletions(-) delete mode 100755 polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 2359d80a5d67..64278a762d89 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -104,7 +104,7 @@ sp-tracing = { path = "../../../substrate/primitives/tracing", default-features tokio = { version = "1.24.2", features = ["macros"] } [build-dependencies] -substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder" } +substrate-wasm-builder = { path = "../../../substrate/utils/wasm-builder", optional = true } [features] default = [ "std" ] @@ -184,6 +184,7 @@ std = [ "sp-storage/std", "sp-tracing/std", "sp-version/std", + "substrate-wasm-builder", "tx-pool-api/std", "xcm-builder/std", "xcm-executor/std", diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index 8b2e8e8a439b..36352c5e883a 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -15,13 +15,14 @@ // along with Substrate. If not, see . use std::env; +#[cfg(feature = "std")] use substrate_wasm_builder::WasmBuilder; // note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in // prod_or_fast macro. const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; -[cfg(feature = "std")] +#[cfg(feature = "std")] fn main() { let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 21fa6bb2f1f2..2200f7ddefe1 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -38,12 +38,13 @@ pub mod currency { /// Time and blocks. pub mod time { use primitives::{BlockNumber, Moment}; - use runtime_common::prod_or_fast; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; frame_support::parameter_types! { - pub storage EpochDurationInBlocks: BlockNumber = option_env!("ROCOCO_EPOCH_DURATION").map(|s| s.parse().expect("`ROCOCO_EPOCH_DURATION` is not a valid `BlockNumber`")).unwrap_or(1 * MINUTES); + pub storage EpochDurationInBlocks: BlockNumber = option_env!("ROCOCO_EPOCH_DURATION") + .map(|s| s.parse().expect("`ROCOCO_EPOCH_DURATION` is not a valid `BlockNumber`")) + .unwrap_or(1 * MINUTES); } // These time units are defined in number of blocks. diff --git a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh b/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh deleted file mode 100755 index 18bff45d6dce..000000000000 --- a/polkadot/scripts/build-fast-rococo-and-update-chain-spec.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -eux - -CURRENT_DIR=$(pwd) - -#directory were polkadot-sdk is checked out -POLKADOT_SDK_DIR=$(git rev-parse --show-toplevel) - -# required epoch duration: -EPOCH_DURATION_IN_BLOCKS=10 - -# polkadot command: -DOCKER_IMAGE=paritypr/polkadot-debug:1539-2085d3f0 -POLKADOT_CMD="docker run --rm -v $CURRENT_DIR:/dir -w /dir $DOCKER_IMAGE" -# POLKADOT_CMD=$POLKADOT_SDK_DIR/target/release/polkadot - -# path to built rococo runtime: -WASM_RUNTIME_BLOB_PATH=$POLKADOT_SDK_DIR/target/release/wbuild/rococo-runtime/rococo_runtime.compact.compressed.wasm - -# build rococo runtime with adjusted epoch diration -pushd $POLKADOT_SDK_DIR -ROCOCO_EPOCH_DURATION=$EPOCH_DURATION_IN_BLOCKS cargo build --features fast-runtime --release -p rococo-runtime -popd - -# do hexdump of runtime: -hexdump -v -e '/1 "%02x"' $WASM_RUNTIME_BLOB_PATH > ./runtime.hex - -# get westend spec: -$POLKADOT_CMD build-spec --chain westend-staging > $CURRENT_DIR/wococo-source.json - -# replace runtime in chainspec with newly built runtime with overwritten epoch duration: -jq --rawfile code runtime.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/wococo-source.json - -# jq will write numbers in compact way with 1e+18, substrtate json parser dont support it. -sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json - -# generate raw -$POLKADOT_CMD build-spec --chain ./chainspec-nonraw.json --raw > $CURRENT_DIR/chainspec-raw.json diff --git a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh index 26df4b88eada..12904b85f5f0 100755 --- a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh +++ b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -eu +# Sample script showing how to update the chain-spec 'code' field with the pre-built rococo runtime blob with +# non-standard epoch duration. + CURRENT_DIR=$(pwd) usage() { @@ -51,10 +54,10 @@ WASM_RUNTIME_BLOB_PATH=$OUTPUT_ROOT_DIR/rococo-runtime-$EPOCH_DURATION_IN_BLOCKS hexdump -v -e '/1 "%02x"' $WASM_RUNTIME_BLOB_PATH > $WASM_RUNTIME_BLOB_PATH.hex # get westend spec: -$POLKADOT_CMD build-spec --chain $CHAIN_NAME > $CURRENT_DIR/wococo-source.json +$POLKADOT_CMD build-spec --chain $CHAIN_NAME > $CURRENT_DIR/chainspec-source.json # replace runtime in chainspec with newly built runtime with overwritten epoch duration: -jq --rawfile code $WASM_RUNTIME_BLOB_PATH.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/wococo-source.json +jq --rawfile code $WASM_RUNTIME_BLOB_PATH.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/chainspec-source.json # jq will write numbers in compact way with 1e+18, substrtate json parser dont support it. sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json From f2fd3ae6126a24186b66b82272fb9183c7ce2542 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:20:04 +0200 Subject: [PATCH 12/15] fixes + readme improved --- .gitlab/pipeline/build.yml | 2 +- polkadot/runtime/rococo/README.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index d993e6202bb1..029c0f6a3cdd 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -21,7 +21,7 @@ build-linux-stable: - time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker - time ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-10/ - time ROCOCO_EPOCH_DURATION=100 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-100/ - - time ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/ + - time ROCOCO_EPOCH_DURATION=600 ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/ - pwd - ls -alR runtimes # pack artifacts diff --git a/polkadot/runtime/rococo/README.md b/polkadot/runtime/rococo/README.md index 465afd25549b..502359a2acbc 100644 --- a/polkadot/runtime/rococo/README.md +++ b/polkadot/runtime/rococo/README.md @@ -2,6 +2,13 @@ Rococo is a testnet runtime with no stability guarantees. +## How to build `rococo` runtime +`EpochDurationInBlocks` parameter is configurable via `ROCOCO_EPOCH_DURATION` environment variable. To build wasm +runtime blob with customized epoch duration run following command shall be exectuted: +```bash +ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime /path/to/output/directory/ +``` + ## How to run `rococo-local` The [Cumulus Tutorial](https://docs.substrate.io/tutorials/v3/cumulus/start-relay/) details building, starting, and From e240385c5a0859176a669b77bd31e47506eaa684 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:46:04 +0200 Subject: [PATCH 13/15] fast-rutnime removed from rococo-constants --- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/rococo/README.md | 2 +- polkadot/runtime/rococo/build.rs | 13 +++++-------- polkadot/runtime/rococo/constants/Cargo.toml | 3 --- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 64278a762d89..64bd8c6b2b50 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -285,6 +285,6 @@ try-runtime = [ ] # Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [ "rococo-runtime-constants/fast-runtime" ] +fast-runtime = [ ] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] diff --git a/polkadot/runtime/rococo/README.md b/polkadot/runtime/rococo/README.md index 502359a2acbc..5b2c296f0ced 100644 --- a/polkadot/runtime/rococo/README.md +++ b/polkadot/runtime/rococo/README.md @@ -4,7 +4,7 @@ Rococo is a testnet runtime with no stability guarantees. ## How to build `rococo` runtime `EpochDurationInBlocks` parameter is configurable via `ROCOCO_EPOCH_DURATION` environment variable. To build wasm -runtime blob with customized epoch duration run following command shall be exectuted: +runtime blob with customized epoch duration the following command shall be exectuted: ```bash ROCOCO_EPOCH_DURATION=10 ./polkadot/scripts/build-only-wasm.sh rococo-runtime /path/to/output/directory/ ``` diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index 36352c5e883a..88a872507490 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use std::env; #[cfg(feature = "std")] use substrate_wasm_builder::WasmBuilder; @@ -24,13 +23,11 @@ const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; #[cfg(feature = "std")] fn main() { - let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); - - if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() { - builder = builder.enable_feature("fast-runtime") - }; - - builder.build(); + WasmBuilder::new() + .with_current_project() + .import_memory() + .export_heap_base() + .build(); println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); } diff --git a/polkadot/runtime/rococo/constants/Cargo.toml b/polkadot/runtime/rococo/constants/Cargo.toml index b15fcace0fde..b1eb3f48f655 100644 --- a/polkadot/runtime/rococo/constants/Cargo.toml +++ b/polkadot/runtime/rococo/constants/Cargo.toml @@ -25,6 +25,3 @@ std = [ "sp-runtime/std", "sp-weights/std", ] - -# Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [] From c4e26b2ef242699f3b3b0b31821a9c7ac6a6d331 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:05:43 +0200 Subject: [PATCH 14/15] fixes --- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/rococo/build.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 64bd8c6b2b50..80f8339a9976 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -285,6 +285,6 @@ try-runtime = [ ] # Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [ ] +fast-runtime = [] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index 88a872507490..ed32d33105b7 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -14,16 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -#[cfg(feature = "std")] -use substrate_wasm_builder::WasmBuilder; - -// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in -// prod_or_fast macro. -const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; - #[cfg(feature = "std")] fn main() { - WasmBuilder::new() + // note: needs to be synced with rococo-runtime-constants::time hard-coded string literal + const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; + + substrate_wasm_builder::WasmBuilder::new() .with_current_project() .import_memory() .export_heap_base() From 43257373908a53c1755a69f82410830235c36807 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:55:35 +0200 Subject: [PATCH 15/15] update-chain-spec-with-fast-rococo.sh removed This script will leave in different repository. --- .../update-chain-spec-with-fast-rococo.sh | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100755 polkadot/scripts/update-chain-spec-with-fast-rococo.sh diff --git a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh b/polkadot/scripts/update-chain-spec-with-fast-rococo.sh deleted file mode 100755 index 12904b85f5f0..000000000000 --- a/polkadot/scripts/update-chain-spec-with-fast-rococo.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash -eu - -# Sample script showing how to update the chain-spec 'code' field with the pre-built rococo runtime blob with -# non-standard epoch duration. - -CURRENT_DIR=$(pwd) - -usage() { - echo "usage $0 docker-image epoch-duration [options]" - echo " -c chain-name - base chain-spec to be used [default: westend-staging)" - exit -1 -} - -if [ "$#" -lt 2 ]; then - usage -fi - -# docker image to be used -DOCKER_IMAGE=$1 -EPOCH_DURATION_IN_BLOCKS=$2 - -shift 2 - -CHAIN_NAME="westend-staging" - -while getopts "c:" o; do - case "${o}" in - c) - CHAIN_NAME=${OPTARG} - ;; - *) - usage - ;; - esac -done - -if [ -z $DOCKER_IMAGE ]; then - usage -fi - -OUTPUT_ROOT_DIR=exported-runtimes/ - -# polkadot command: -POLKADOT_CMD="docker run --rm -v $CURRENT_DIR:/dir -w /dir $DOCKER_IMAGE" - -# extract rococo runtime with adjusted epoch diration from docker image -docker export $(docker create $DOCKER_IMAGE) | \ - tar --transform="s|polkadot/runtimes/|$OUTPUT_ROOT_DIR/|" -xf - polkadot/runtimes/rococo-runtime-$EPOCH_DURATION_IN_BLOCKS/rococo_runtime.wasm - -# path to extracted rococo runtime: -WASM_RUNTIME_BLOB_PATH=$OUTPUT_ROOT_DIR/rococo-runtime-$EPOCH_DURATION_IN_BLOCKS/rococo_runtime.wasm - -# do hexdump of runtime: -hexdump -v -e '/1 "%02x"' $WASM_RUNTIME_BLOB_PATH > $WASM_RUNTIME_BLOB_PATH.hex - -# get westend spec: -$POLKADOT_CMD build-spec --chain $CHAIN_NAME > $CURRENT_DIR/chainspec-source.json - -# replace runtime in chainspec with newly built runtime with overwritten epoch duration: -jq --rawfile code $WASM_RUNTIME_BLOB_PATH.hex '.genesis.runtime.system.code = "0x" + $code' > $CURRENT_DIR/chainspec-nonraw.json < $CURRENT_DIR/chainspec-source.json - -# jq will write numbers in compact way with 1e+18, substrtate json parser dont support it. -sed 's/1e+18/1000000000000000000/' -i $CURRENT_DIR/chainspec-nonraw.json - -# generate raw -$POLKADOT_CMD build-spec --chain ./chainspec-nonraw.json --raw > $CURRENT_DIR/chainspec-raw.json