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

rococo-runtime: RococoGenesisExt removed #1490

Merged
merged 17 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 6 additions & 0 deletions .gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ 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/
- time ./polkadot/scripts/build-only-wasm.sh rococo-runtime $(pwd)/runtimes/rococo-runtime-600/
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 9 additions & 63 deletions polkadot/node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub type WestendChainSpec = GenericChainSpec;

/// The `ChainSpec` parameterized for the rococo runtime.
#[cfg(feature = "rococo-native")]
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
pub type RococoChainSpec = service::GenericChainSpec<rococo::RuntimeGenesisConfig, Extensions>;

/// The `ChainSpec` parameterized for the `versi` runtime.
///
Expand All @@ -96,30 +96,6 @@ pub type VersiChainSpec = RococoChainSpec;
#[cfg(not(feature = "rococo-native"))]
pub type RococoChainSpec = GenericChainSpec;

/// 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<u32>,
}

#[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<GenericChainSpec, String> {
GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
}
Expand Down Expand Up @@ -787,10 +763,7 @@ pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
"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)])
Expand Down Expand Up @@ -824,10 +797,7 @@ pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
"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)])
Expand Down Expand Up @@ -1144,11 +1114,7 @@ pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
"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),
Expand All @@ -1167,11 +1133,7 @@ pub fn versi_development_config() -> Result<RococoChainSpec, String> {
"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"),
Expand All @@ -1191,11 +1153,7 @@ pub fn wococo_development_config() -> Result<RococoChainSpec, String> {
"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),
Expand Down Expand Up @@ -1253,11 +1211,7 @@ pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"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),
Expand Down Expand Up @@ -1292,11 +1246,7 @@ pub fn wococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"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),
Expand Down Expand Up @@ -1331,11 +1281,7 @@ pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
"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"),
Expand Down
5 changes: 3 additions & 2 deletions polkadot/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -284,6 +285,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" ]
24 changes: 19 additions & 5 deletions polkadot/runtime/rococo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

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")]
fn main() {
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
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() {
builder = builder.enable_feature("fast-runtime")
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
};

builder.build();

println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV);
}
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(not(feature = "std"))]
fn main() {}
3 changes: 3 additions & 0 deletions polkadot/runtime/rococo/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
7 changes: 4 additions & 3 deletions polkadot/runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 = 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.
Expand Down
66 changes: 66 additions & 0 deletions polkadot/scripts/update-chain-spec-with-fast-rococo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash -eu
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

# 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
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion polkadot/zombienet_tests/misc/0001-paritydb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down