Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit da4c3ba

Browse files
committed
Merge remote-tracking branch 'origin/master' into rococo-v1
2 parents 6ed9632 + 2180cf4 commit da4c3ba

File tree

14 files changed

+672
-308
lines changed

14 files changed

+672
-308
lines changed

Cargo.lock

Lines changed: 312 additions & 294 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"rococo-parachains/runtime",
1919
"rococo-parachains/shell-runtime",
2020
"test/runtime",
21+
"test/runtime-upgrade",
2122
"test/client",
2223
"test/service",
2324
"test/relay-sproof-builder",

client/consensus/relay-chain/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ where
196196
Default::default(),
197197
//TODO: Fix this.
198198
Duration::from_millis(500),
199+
// Set the block limit to 50% of the maximum PoV size.
200+
//
201+
// TODO: If we got benchmarking that includes that encapsulates the proof size,
202+
// we should be able to use the maximum pov size.
203+
Some((validation_data.max_pov_size / 2) as usize),
199204
)
200205
.await
201206
.map_err(|e| tracing::error!(target: LOG_TARGET, error = ?e, "Proposing failed."))

pallets/parachain-system/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,15 @@ decl_module! {
258258
}
259259

260260
#[weight = 1_000_000]
261-
fn enact_authorized_upgrade(origin, code: Vec<u8>) {
261+
fn enact_authorized_upgrade(_origin, code: Vec<u8>) -> DispatchResultWithPostInfo {
262262
// No ensure origin on purpose. We validate by checking the code vs hash in storage.
263263
let required_hash = AuthorizedUpgrade::<T>::get()
264264
.ok_or(Error::<T>::NothingAuthorized)?;
265265
let actual_hash = T::Hashing::hash(&code[..]);
266266
ensure!(actual_hash == required_hash, Error::<T>::Unauthorized);
267267
Self::set_code_impl(code)?;
268268
AuthorizedUpgrade::<T>::kill();
269+
Ok(Pays::No.into())
269270
}
270271

271272
fn on_finalize() {
@@ -336,9 +337,14 @@ decl_module! {
336337
maximum_channels,
337338
);
338339

339-
// Note conversion to the OutboundHrmpMessage isn't needed since the data that
340+
// Note conversion to the `OutboundHrmpMessage` isn't needed since the data that
340341
// `take_outbound_messages` returns encodes equivalently.
341-
// If the following code breaks, then we'll need to revisit that assumption.
342+
//
343+
// The following code is a smoke test to check that the `OutboundHrmpMessage` type
344+
// doesn't accidentally change (e.g. by having a field added to it). If the following
345+
// line breaks, then we'll need to revisit the assumption that the result of
346+
// `take_outbound_messages` can be placed into `HRMP_OUTBOUND_MESSAGES` directly without
347+
// a decode/encode round-trip.
342348
let _ = OutboundHrmpMessage { recipient: ParaId::from(0), data: vec![] };
343349

344350
storage::unhashed::put(well_known_keys::HRMP_OUTBOUND_MESSAGES, &outbound_messages);
@@ -777,6 +783,10 @@ impl<T: Config> ProvideInherent for Module<T> {
777783

778784
Some(Call::set_validation_data(data))
779785
}
786+
787+
fn is_inherent(call: &Self::Call) -> bool {
788+
matches!(call, Call::set_validation_data(_))
789+
}
780790
}
781791

782792
decl_event! {

pallets/xcmp-queue/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,31 @@ impl<T: Config> Module<T> {
406406

407407
/// Service the incoming XCMP message queue attempting to execute up to `max_weight` execution
408408
/// weight of messages.
409+
///
410+
/// Channels are first shuffled and then processed in this random one page at a time, order over
411+
/// and over until either `max_weight` is exhausted or no channel has messages that can be
412+
/// processed any more.
413+
///
414+
/// There are two obvious "modes" that we could apportion `max_weight`: one would be to attempt
415+
/// to spend it all on the first channel's first page, then use the leftover (if any) for the
416+
/// second channel's first page and so on until finally we cycle back and the process messages
417+
/// on the first channel's second page &c. The other mode would be to apportion only `1/N` of
418+
/// `max_weight` for the first page (where `N` could be, perhaps, the number of channels to
419+
/// service, using the remainder plus the next `1/N` for the next channel's page &c.
420+
///
421+
/// Both modes have good qualities, the first ensures that a channel with a large message (over
422+
/// `1/N` does not get indefinitely blocked if other channels have continuous, light traffic.
423+
/// The second is fairer, and ensures that channels with continuous light messages don't suffer
424+
/// high latency.
425+
///
426+
/// The following code is a hybrid solution; we have a concept of `weight_available` which
427+
/// incrementally approaches `max_weight` as more channels are attempted to be processed. We use
428+
/// the parameter `weight_restrict_decay` to control the speed with which `weight_available`
429+
/// approaches `max_weight`, with `0` being strictly equivalent to the first aforementioned
430+
/// mode, and `N` approximating the second. A reasonable parameter may be `1`, which makes
431+
/// half of the `max_weight` available for the first page, then a quarter plus the remainder
432+
/// for the second &c. though empirical and or practical factors may give rise to adjusting it
433+
/// further.
409434
fn service_xcmp_queue(max_weight: Weight) -> Weight {
410435
let mut status = InboundXcmpStatus::get(); // <- sorted.
411436
if status.len() == 0 {
@@ -441,7 +466,7 @@ impl<T: Config> Module<T> {
441466
// first round. For the second round we unlock all weight. If we come close enough
442467
// on the first round to unlocking everything, then we do so.
443468
if shuffle_index < status.len() {
444-
weight_available += (max_weight - weight_available) / weight_restrict_decay;
469+
weight_available += (max_weight - weight_available) / (weight_restrict_decay + 1);
445470
if weight_available + threshold_weight > max_weight {
446471
weight_available = max_weight;
447472
}

test/runtime-upgrade/Cargo.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[package]
2+
name = "cumulus-test-runtime-upgrade"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
9+
serde = { version = "1.0.101", optional = true, features = ["derive"] }
10+
11+
# Substrate dependencies
12+
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
13+
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
14+
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
15+
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
16+
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
17+
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
18+
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
19+
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
20+
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
21+
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
22+
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
23+
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
24+
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
25+
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
26+
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
27+
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
28+
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
29+
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
30+
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
31+
32+
# Cumulus dependencies
33+
cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false }
34+
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
35+
36+
# Polkadot dependencies
37+
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "rococo-v1" }
38+
39+
[build-dependencies]
40+
substrate-wasm-builder = "3.0.0"
41+
42+
[features]
43+
default = [ "std", "upgrade" ]
44+
std = [
45+
"codec/std",
46+
"cumulus-pallet-parachain-system/std",
47+
"cumulus-primitives-core/std",
48+
"frame-executive/std",
49+
"frame-support/std",
50+
"frame-system/std",
51+
"pallet-balances/std",
52+
"pallet-randomness-collective-flip/std",
53+
"pallet-sudo/std",
54+
"pallet-timestamp/std",
55+
"pallet-transaction-payment/std",
56+
"serde",
57+
"sp-api/std",
58+
"sp-block-builder/std",
59+
"sp-core/std",
60+
"sp-inherents/std",
61+
"sp-io/std",
62+
"sp-offchain/std",
63+
"sp-runtime/std",
64+
"sp-session/std",
65+
"sp-std/std",
66+
"sp-transaction-pool/std",
67+
"sp-version/std",
68+
]
69+
upgrade = []

test/runtime-upgrade/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../runtime/build.rs

test/runtime-upgrade/src

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../runtime/src

test/runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ std = [
6666
"sp-transaction-pool/std",
6767
"sp-version/std",
6868
]
69+
upgrade = []

test/runtime/src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub use frame_support::{
4747
};
4848
use frame_system::limits::{BlockLength, BlockWeights};
4949
pub use pallet_balances::Call as BalancesCall;
50+
pub use pallet_sudo::Call as SudoCall;
5051
pub use pallet_timestamp::Call as TimestampCall;
5152
#[cfg(any(feature = "std", test))]
5253
pub use sp_runtime::BuildStorage;
@@ -58,12 +59,17 @@ impl_opaque_keys! {
5859
pub struct SessionKeys {}
5960
}
6061

62+
const SPEC_VERSION: u32 = 3;
63+
6164
/// This runtime version.
6265
pub const VERSION: RuntimeVersion = RuntimeVersion {
6366
spec_name: create_runtime_str!("cumulus-test-parachain"),
6467
impl_name: create_runtime_str!("cumulus-test-parachain"),
6568
authoring_version: 1,
66-
spec_version: 3,
69+
#[cfg(feature = "upgrade")]
70+
spec_version: SPEC_VERSION + 1,
71+
#[cfg(not(feature = "upgrade"))]
72+
spec_version: SPEC_VERSION,
6773
impl_version: 1,
6874
apis: RUNTIME_API_VERSIONS,
6975
transaction_version: 1,
@@ -220,6 +226,15 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
220226

221227
parameter_types! {
222228
pub storage ParachainId: cumulus_primitives_core::ParaId = 100.into();
229+
pub storage UpgradeDetection: bool = false;
230+
}
231+
232+
pub struct UpgradeDetectionOnRuntimeUpgrade;
233+
impl frame_support::traits::OnRuntimeUpgrade for UpgradeDetectionOnRuntimeUpgrade {
234+
fn on_runtime_upgrade() -> u64 {
235+
UpgradeDetection::set(&true);
236+
0
237+
}
223238
}
224239

225240
construct_runtime! {
@@ -284,6 +299,7 @@ pub type Executive = frame_executive::Executive<
284299
frame_system::ChainContext<Runtime>,
285300
Runtime,
286301
AllPallets,
302+
UpgradeDetectionOnRuntimeUpgrade,
287303
>;
288304
/// The payload being signed in transactions.
289305
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
@@ -293,6 +309,10 @@ decl_runtime_apis! {
293309
/// Returns the last timestamp of a runtime.
294310
fn get_last_timestamp() -> u64;
295311
}
312+
pub trait GetUpgradeDetection {
313+
/// Returns `true` if the runtime has been upgraded at least once.
314+
fn has_upgraded() -> bool;
315+
}
296316
}
297317

298318
impl_runtime_apis! {
@@ -372,6 +392,12 @@ impl_runtime_apis! {
372392
Timestamp::now()
373393
}
374394
}
395+
396+
impl crate::GetUpgradeDetection<Block> for Runtime {
397+
fn has_upgraded() -> bool {
398+
UpgradeDetection::get()
399+
}
400+
}
375401
}
376402

377403
cumulus_pallet_parachain_system::register_validate_block!(Runtime, Executive);

0 commit comments

Comments
 (0)