Bring back runtime upgrade test (#525)

This brings back the runtime upgrade test and also updates Substrate &
Polkadot.
This commit is contained in:
Bastian Köcher
2021-07-06 16:21:19 +02:00
committed by GitHub
parent a6bd34545e
commit 9b85b5117e
11 changed files with 362 additions and 329 deletions
+315 -255
View File
File diff suppressed because it is too large Load Diff
@@ -7,7 +7,7 @@ description = "Kusama variant of Statemint parachain runtime"
[dependencies]
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.14", default-features = false }
parachain-info = { path = "../pallets/parachain-info", default-features = false }
smallvec = "1.6.1"
@@ -49,7 +49,6 @@ pallet-uniques = { git = "https://github.com/paritytech/substrate", default-feat
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
node-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
max-encoded-len = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
# Cumulus dependencies
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }
@@ -39,11 +39,11 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use constants::{currency::*, fee::WeightToFee};
use frame_support::{
construct_runtime, match_type, parameter_types,
traits::{All, Filter, InstanceFilter, MaxEncodedLen},
traits::{All, Filter, InstanceFilter},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight},
DispatchClass, IdentityFee, Weight,
@@ -365,12 +365,9 @@ impl InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
Call::Balances(..)
| Call::Assets(..)
| Call::Uniques(..)
),
ProxyType::NonTransfer => {
!matches!(c, Call::Balances(..) | Call::Assets(..) | Call::Uniques(..))
}
ProxyType::CancelProxy => matches!(
c,
Call::Proxy(pallet_proxy::Call::reject_announcement(..))
@@ -7,7 +7,7 @@ description = "Statemint parachain runtime"
[dependencies]
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.14", default-features = false }
parachain-info = { path = "../pallets/parachain-info", default-features = false }
smallvec = "1.6.1"
@@ -48,7 +48,6 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
node-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
max-encoded-len = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
# Cumulus dependencies
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }
@@ -39,11 +39,11 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use constants::{currency::*, fee::WeightToFee};
use frame_support::{
construct_runtime, match_type, parameter_types,
traits::{All, InstanceFilter, MaxEncodedLen},
traits::{All, InstanceFilter},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight},
DispatchClass, IdentityFee, Weight,
@@ -327,11 +327,7 @@ impl InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
Call::Balances(..)
| Call::Assets(..)
),
ProxyType::NonTransfer => !matches!(c, Call::Balances(..) | Call::Assets(..)),
ProxyType::CancelProxy => matches!(
c,
Call::Proxy(pallet_proxy::Call::reject_announcement(..))
@@ -7,7 +7,7 @@ description = "Westend variant of Statemint parachain runtime"
[dependencies]
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.14", default-features = false }
parachain-info = { path = "../pallets/parachain-info", default-features = false }
smallvec = "1.6.1"
@@ -48,7 +48,6 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
node-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
max-encoded-len = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
# Cumulus dependencies
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }
@@ -39,11 +39,11 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use constants::{currency::*, fee::WeightToFee};
use frame_support::{
construct_runtime, match_type, parameter_types,
traits::{All, InstanceFilter, MaxEncodedLen},
traits::{All, InstanceFilter},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight},
DispatchClass, IdentityFee, Weight,
@@ -313,7 +313,7 @@ pub enum ProxyType {
AssetOwner,
/// Asset manager. Can execute calls related to asset management.
AssetManager,
// Collator selection proxy. Can execute calls related to collator selection mechanism.
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
Collator,
}
impl Default for ProxyType {
@@ -325,11 +325,7 @@ impl InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
Call::Balances(..)
| Call::Assets(..)
),
ProxyType::NonTransfer => !matches!(c, Call::Balances(..) | Call::Assets(..)),
ProxyType::CancelProxy => matches!(
c,
Call::Proxy(pallet_proxy::Call::reject_announcement(..))
-20
View File
@@ -253,15 +253,6 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
parameter_types! {
pub storage ParachainId: cumulus_primitives_core::ParaId = 100.into();
pub storage UpgradeDetection: bool = false;
}
pub struct UpgradeDetectionOnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for UpgradeDetectionOnRuntimeUpgrade {
fn on_runtime_upgrade() -> u64 {
UpgradeDetection::set(&true);
0
}
}
construct_runtime! {
@@ -326,7 +317,6 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
UpgradeDetectionOnRuntimeUpgrade,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
@@ -336,10 +326,6 @@ decl_runtime_apis! {
/// Returns the last timestamp of a runtime.
fn get_last_timestamp() -> u64;
}
pub trait GetUpgradeDetection {
/// Returns `true` if the runtime has been upgraded at least once.
fn has_upgraded() -> bool;
}
}
impl_runtime_apis! {
@@ -417,12 +403,6 @@ impl_runtime_apis! {
}
}
impl crate::GetUpgradeDetection<Block> for Runtime {
fn has_upgraded() -> bool {
UpgradeDetection::get()
}
}
impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info()
+2
View File
@@ -70,6 +70,8 @@ polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch
# Substrate dependencies
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
# Cumulus
cumulus-test-runtime-upgrade = { path = "../runtime-upgrade" }
+1 -1
View File
@@ -669,7 +669,7 @@ impl TestNode {
/// Register a parachain at this relay chain.
pub async fn schedule_upgrade(&self, validation: Vec<u8>) -> Result<(), RpcTransactionError> {
let call = frame_system::Call::set_code_without_checks(validation);
let call = frame_system::Call::set_code(validation);
self.send_extrinsic(
runtime::SudoCall::sudo_unchecked_weight(Box::new(call.into()), 1_000),
+29 -24
View File
@@ -16,16 +16,12 @@
use cumulus_primitives_core::ParaId;
use cumulus_test_service::{initial_head_data, run_relay_chain_validator_node, Keyring::*};
use futures::join;
use futures::{join, StreamExt};
use sc_service::TaskExecutor;
use sc_client_api::client::BlockchainEvents;
use futures::StreamExt;
use sp_api::ProvideRuntimeApi;
use cumulus_test_runtime::GetUpgradeDetection;
use sp_runtime::generic::BlockId;
use sc_client_api::BlockchainEvents;
#[substrate_test_utils::test]
#[ignore]
async fn test_runtime_upgrade(task_executor: TaskExecutor) {
let mut builder = sc_cli::LoggerBuilder::new("runtime=debug");
builder.with_colors(false);
@@ -60,35 +56,44 @@ async fn test_runtime_upgrade(task_executor: TaskExecutor) {
.build()
.await;
// run cumulus dave (a parachain full node) and wait for it to sync some blocks
// run cumulus dave (a parachain full node)
let dave = cumulus_test_service::TestNodeBuilder::new(para_id, task_executor.clone(), Dave)
.connect_to_parachain_node(&charlie)
.connect_to_relay_chain_nodes(vec![&alice, &bob])
.build()
.await;
let mut import_notification_stream = charlie.client.import_notification_stream();
// Wait for 2 blocks to be produced
charlie.wait_for_blocks(2).await;
while let Some(notification) = import_notification_stream.next().await {
if notification.is_new_best {
let res = charlie.client.runtime_api()
.has_upgraded(&BlockId::Hash(notification.hash));
if matches!(res, Ok(false)) {
break;
}
}
}
let mut expected_runtime_version = charlie
.client
.runtime_version_at(&BlockId::number(0))
.expect("Runtime version exists");
expected_runtime_version.spec_version += 1;
// Replace the runtime version in the WASM blob to make it look like a new runtime.
let wasm = sp_maybe_compressed_blob::decompress(
cumulus_test_runtime_upgrade::WASM_BINARY.unwrap(),
sp_maybe_compressed_blob::CODE_BLOB_BOMB_LIMIT,
)
.expect("Decompressing the WASM blob works");
let wasm = sp_version::embed::embed_runtime_version(&wasm, expected_runtime_version.clone())
.expect("Embedding the runtime version works");
// schedule runtime upgrade
charlie.schedule_upgrade(cumulus_test_runtime_upgrade::WASM_BINARY.unwrap().to_vec())
.await
.unwrap();
charlie.schedule_upgrade(wasm).await.unwrap();
while let Some(notification) = import_notification_stream.next().await {
let mut import_stream = dave.client.import_notification_stream();
while let Some(notification) = import_stream.next().await {
if notification.is_new_best {
let res = charlie.client.runtime_api()
.has_upgraded(&BlockId::Hash(notification.hash));
if res.unwrap_or(false) {
let runtime_version = dave
.client
.runtime_version_at(&BlockId::Hash(notification.hash))
.expect("Runtime version exists");
if expected_runtime_version == runtime_version {
break;
}
}