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

Zombienet upgrade test #5794

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ build-linux-stable:
- mv ./target/testnet/polkadot-prepare-worker ./artifacts/.
- mv ./target/testnet/polkadot-execute-worker ./artifacts/.
- mv ./runtimes/ ./artifacts/.
- mv ./target/testnet/wbuild/rococo-runtime/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm ./artifacts/.
- pushd artifacts
- sha256sum polkadot | tee polkadot.sha256
- shasum -c polkadot.sha256
Expand Down
22 changes: 22 additions & 0 deletions .gitlab/pipeline/zombienet/polkadot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
LOCAL_SDK_TEST: "/builds/parity/mirrors/polkadot-sdk/polkadot/zombienet-sdk-tests"
FF_DISABLE_UMASK_FOR_DOCKER_EXECUTOR: 1
RUN_IN_CONTAINER: "1"
RUN_IN_CI: "1"
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: always
Expand Down Expand Up @@ -357,3 +358,24 @@ zombienet-polkadot-coretime-revenue:
- unset NEXTEST_FAILURE_OUTPUT
- unset NEXTEST_SUCCESS_OUTPUT
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- smoke::coretime_revenue::coretime_revenue_test

zombienet-polkadot-smoke-runtime-upgrade:
extends:
- .zombienet-polkadot-common
needs:
- job: build-linux-stable
artifacts: true
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export ZOMBIE_WASM_INCREMENTED_PATH="$(pwd)/artifacts/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm"
script:
# we want to use `--no-capture` in zombienet tests.
- unset NEXTEST_FAILURE_OUTPUT
- unset NEXTEST_SUCCESS_OUTPUT
# retries is handle by gitlab
- export NEXTEST_RETRIES=0
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- smoke::runtime_upgrade::runtime_upgrade_test

26 changes: 14 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions polkadot/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,6 @@ runtime-metrics = [
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller, like logging for example.
on-chain-release-build = ["metadata-hash"]

# Produce a runtime with the spec_version incremented to use in upgrade tests.
increment-spec-version = []
13 changes: 13 additions & 0 deletions polkadot/runtime/rococo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ fn main() {
.set_file_name("fast_runtime_binary.rs")
.enable_feature("fast-runtime")
.build();

substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_feature("increment-spec-version")
.enable_feature("fast-runtime")
.set_file_name("wasm_binary_spec_version_incremented.rs")
.build();
}

#[cfg(all(feature = "metadata-hash", feature = "std"))]
Expand All @@ -35,6 +41,13 @@ fn main() {
.enable_feature("fast-runtime")
.enable_metadata_hash("ROC", 12)
.build();

substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_feature("increment-spec-version")
.enable_feature("fast-runtime")
.enable_metadata_hash("ROC", 12)
.set_file_name("wasm_binary_spec_version_incremented.rs")
.build();
}

#[cfg(not(feature = "std"))]
Expand Down
26 changes: 26 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,19 @@ pub mod fast_runtime_binary {
include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
}

// The only difference between the two declarations below is the `spec_version`. With the
// `increment-spec-version` feature enabled `spec_version` should be greater than the one of without
// the `increment-spec-version` feature.
//
// The duplication here is unfortunate necessity.
//
// runtime_version macro is dumb. It accepts a const item declaration, passes it through and
// also emits runtime version custom section. It parses the expressions to extract the version
// details. Since macro kicks in early, it operates on AST. Thus you cannot use constants.
// Macros are expanded top to bottom, meaning we also cannot use `cfg` here.

/// Runtime version (Rococo).
#[cfg(not(feature = "increment-spec-version"))]
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("rococo"),
Expand All @@ -177,6 +189,20 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
system_version: 1,
};

/// Runtime version (Rococo).
#[cfg(feature = "increment-spec-version")]
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("rococo"),
impl_name: create_runtime_str!("parity-rococo-v2.0"),
authoring_version: 0,
spec_version: 1_016_000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract out:

CONST SPEC_VERSION: 1_015_000 and then here I would use SPEC_VERSION + 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can extract out, I will leave this way.

 error: only numeric literals (e.g. `10`) are supported here
     --> polkadot-sdk/polkadot/runtime/rococo/src/lib.rs:187:16
      |
  187 |     spec_version: SPEC_VERSION,

Thx!

impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
system_version: 1,
};

/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
Expand Down
5 changes: 3 additions & 2 deletions polkadot/zombienet-sdk-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ subxt = { version = "0.37", features = ["substrate-compat"] }
subxt-signer = { version = "0.37" }
tokio = { version = "1.36.0", features = ["rt-multi-thread"] }
anyhow = "1.0.81"
zombienet-sdk = "0.2.6"
zombienet-sdk = "0.2.12"
serde = "1.0.197"
serde_json = "1.0.114"
parity-scale-codec = { version = "3.6.9", features = ["derive"] }

[features]
zombie-metadata = []
zombienet = []
zombie-metadata = ["zombienet"]

[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = true }
Expand Down
3 changes: 3 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/smoke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

#[cfg(feature = "zombie-metadata")]
mod coretime_revenue;

#[cfg(feature = "zombienet")]
mod runtime_upgrade;
75 changes: 75 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/smoke/runtime_upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use std::env;
use zombienet_sdk::{tx_helper::RuntimeUpgradeOptions, NetworkConfigBuilder};

const BEST_BLOCK_METRIC: &str = "block_height{status=\"best\"}";

#[tokio::test(flavor = "multi_thread")]
async fn runtime_upgrade_test() -> Result<(), anyhow::Error> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

let images = zombienet_sdk::environment::get_images_from_env();
let config = NetworkConfigBuilder::new()
.with_relaychain(|r| {
r.with_chain("rococo-local")
.with_default_command("polkadot")
.with_default_image(images.polkadot.as_str())
.with_node(|node| {
node.with_name("latest-release")
// used for getting the chain-spec
.with_image("parity/polkadot:latest")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow use the exact runtime-image that roco chain is currently using, or at least the last stable release version, since the upgrades happened all at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parity/polkadot:latest this tag should point to the latest release (stable).
image

Thx!

})
.with_node(|node| node.with_name("bob"))
})
.build()
.map_err(|e| {
let errs = e.into_iter().map(|e| e.to_string()).collect::<Vec<_>>().join(" ");
anyhow!("config errs: {errs}")
})?;

let spawn_fn = zombienet_sdk::environment::get_spawn_fn();
let network = spawn_fn(config).await?;

// wait 10 blocks
let latest_release = network.get_node("latest-release")?;
assert!(latest_release.wait_metric(BEST_BLOCK_METRIC, |b| b > 10_f64).await.is_ok());

// get current runtime spec
let client = network.get_node("latest-release")?.client::<subxt::PolkadotConfig>().await?;
let current_runtime = client.backend().current_runtime_version().await?;

// get current best
latest_release.wait_metric(BEST_BLOCK_METRIC, |x| x > 10_f64).await?;
let best_block = latest_release.reports(BEST_BLOCK_METRIC).await?;

// upgrade runtime
let wasm = env::var("ZOMBIE_WASM_INCREMENTED_PATH").unwrap_or_else(|_| {
let root_workspace_dir = env!("CARGO_WORKSPACE_ROOT_DIR");
format!("{root_workspace_dir}/target/testnet/wbuild/rococo-runtime/wasm_binary_spec_version_incremented.rs.compact.compressed.wasm")
});

network
.relaychain()
.runtime_upgrade(RuntimeUpgradeOptions::new(wasm.as_str().into()))
.await?;

// wait 10 more blocks
latest_release
.wait_metric(BEST_BLOCK_METRIC, |x| x > best_block + 10_f64)
.await?;

let incremented_runtime = client.backend().current_runtime_version().await?;

assert_eq!(
incremented_runtime.spec_version,
current_runtime.spec_version + 1000,
"version should be incremented"
);

Ok(())
}
Loading