Put cumulus-parachain-upgrade into the test parachain (#98)

This ensures that the crate compiles for `no_std`. Besides this, there
are some fixes to the crate code itself.
This commit is contained in:
Bastian Köcher
2020-05-15 16:10:22 +02:00
committed by GitHub
parent a29ac85f1d
commit d0507f4e17
8 changed files with 44 additions and 29 deletions
+3
View File
@@ -923,6 +923,7 @@ dependencies = [
"sp-inherents",
"sp-io",
"sp-runtime",
"sp-std",
"sp-version",
"substrate-test-runtime-client",
]
@@ -936,6 +937,7 @@ dependencies = [
"polkadot-parachain",
"polkadot-primitives",
"sp-inherents",
"sp-runtime",
"sp-std",
]
@@ -1023,6 +1025,7 @@ dependencies = [
name = "cumulus-test-parachain-runtime"
version = "0.1.0"
dependencies = [
"cumulus-parachain-upgrade",
"cumulus-runtime",
"frame-executive",
"frame-support",
+18 -16
View File
@@ -5,21 +5,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
description = "pallet to manage parachain upgrades"
[features]
default = ['std']
std = [
'serde',
'codec/std',
'frame-support/std',
'pallet-balances/std',
'cumulus-runtime/std',
'sp-core/std',
'sp-runtime/std',
'sp-io/std',
'system/std',
'cumulus-primitives/std',
]
[dependencies]
# Cumulus dependencies
cumulus-primitives = { path = "../primitives", default-features = false }
@@ -32,10 +17,10 @@ parachain = { package = "polkadot-parachain", git = "https://github.com/parityte
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
system = { package = "frame-system", git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
# Other Dependencies
@@ -45,3 +30,20 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
[dev-dependencies]
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
[features]
default = ['std']
std = [
'serde',
'codec/std',
'frame-support/std',
'pallet-balances/std',
'cumulus-runtime/std',
'sp-core/std',
'sp-runtime/std',
'sp-io/std',
'sp-std/std',
'system/std',
'cumulus-primitives/std',
]
+11 -10
View File
@@ -35,13 +35,12 @@ use cumulus_primitives::{
well_known_keys::{NEW_VALIDATION_CODE, VALIDATION_FUNCTION_PARAMS},
};
use frame_support::{
decl_error, decl_event, decl_module, decl_storage, ensure, storage, traits::Get,
weights::DispatchClass,
decl_error, decl_event, decl_module, decl_storage, ensure, storage, weights::DispatchClass,
};
use parachain::primitives::RelayChainBlockNumber;
use sp_core::storage::well_known_keys;
use sp_inherents::{InherentData, InherentIdentifier, ProvideInherent};
use sp_version::RuntimeVersion;
use sp_std::vec::Vec;
use system::ensure_none;
/// A ValidationFunction is a compiled WASM blob which, on execution, validates parachain blocks.
@@ -53,9 +52,6 @@ pub trait Trait: system::Trait {
/// The overarching event type.
type Event: From<Event> + Into<<Self as system::Trait>::Event>;
/// Get the chain's current version.
type Version: Get<RuntimeVersion>;
/// Something which can be notified when the validation function params are set.
///
/// Set this to `()` if not needed.
@@ -67,7 +63,8 @@ decl_storage! {
trait Store for Module<T: Trait> as ParachainUpgrade {
// we need to store the new validation function for the span between
// setting it and applying it.
PendingValidationFunction get(fn new_validation_function): Option<(RelayChainBlockNumber, ValidationFunction)>;
PendingValidationFunction get(fn new_validation_function):
Option<(RelayChainBlockNumber, ValidationFunction)>;
/// Were the VFPs updated this block?
DidUpdateVFPs: bool;
@@ -197,7 +194,10 @@ impl<T: Trait> ProvideInherent for Module<T> {
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
// If the inherent is not present, this returns None early. This in turn will
// cause the on_finalize assertion to fail.
let vfp: ValidationFunctionParams = data.get_data(&INHERENT_IDENTIFIER).ok().flatten()
let vfp: ValidationFunctionParams = data
.get_data(&INHERENT_IDENTIFIER)
.ok()
.flatten()
.expect("validation function params are always injected into inherent data; qed");
Some(Call::set_validation_function_parameters(vfp))
@@ -243,6 +243,7 @@ mod tests {
traits::{BlakeTwo256, Dispatchable, IdentityLookup},
Perbill,
};
use sp_version::RuntimeVersion;
use system::{InitKind, RawOrigin};
impl_outer_origin! {
@@ -306,7 +307,6 @@ mod tests {
}
impl Trait for Test {
type Event = TestEvent;
type Version = Version;
type OnValidationFunctionParams = ();
}
@@ -366,7 +366,8 @@ mod tests {
tests: Vec<BlockTest>,
pending_upgrade: Option<RelayChainBlockNumber>,
ran: bool,
vfp_maker: Option<Box<dyn Fn(&BlockTests, RelayChainBlockNumber) -> ValidationFunctionParams>>,
vfp_maker:
Option<Box<dyn Fn(&BlockTests, RelayChainBlockNumber) -> ValidationFunctionParams>>,
}
impl BlockTests {
+2
View File
@@ -8,6 +8,7 @@ edition = "2018"
# Substrate dependencies
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
# Polkadot dependencies
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
@@ -25,4 +26,5 @@ std = [
"polkadot-primitives/std",
"polkadot-parachain/std",
"sp-inherents/std",
"sp-runtime/std",
]
@@ -24,8 +24,7 @@ use polkadot_primitives::parachain::{GlobalValidationSchedule, LocalValidationDa
///
/// This struct is the subset of [`ValidationParams`](polkadot_parachain::ValidationParams)
/// which is of interest when upgrading parachain validation functions.
#[derive(PartialEq, Eq, Encode, Decode, Clone, Copy, Default)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(PartialEq, Eq, Encode, Decode, Clone, Copy, Default, sp_runtime::RuntimeDebug)]
pub struct ValidationFunctionParams {
/// The maximum code size permitted, in bytes.
pub max_code_size: u32,
@@ -25,7 +25,7 @@ use sp_trie::{delta_trie_root, read_trie_value, Layout, MemoryDB};
use hash_db::{HashDB, EMPTY_PREFIX};
use trie_db::{Trie, TrieDB, TrieDBIterator};
use trie_db::{TrieDB, TrieDBIterator};
use parachain::primitives::{HeadData, ValidationCode, ValidationParams, ValidationResult};
@@ -33,6 +33,7 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",
# Cumulus dependencies
cumulus-runtime = { path = "../../../runtime", default-features = false }
cumulus-parachain-upgrade = { path = "../../../parachain-upgrade", default-features = false }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.3" }
@@ -63,4 +64,5 @@ std = [
'pallet-sudo/std',
'pallet-transaction-payment/std',
'cumulus-runtime/std',
'cumulus-parachain-upgrade/std',
]
@@ -230,6 +230,11 @@ impl pallet_sudo::Trait for Runtime {
type Event = Event;
}
impl cumulus_parachain_upgrade::Trait for Runtime {
type Event = Event;
type OnValidationFunctionParams = ();
}
construct_runtime! {
pub enum Runtime where
Block = Block,
@@ -242,6 +247,7 @@ construct_runtime! {
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
}
}