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

Commit f33ecdb

Browse files
pepyakinapopiakshawntabriziKiChjang
authored
UMP: Support Overweight messages (#3575)
* Introduce new config: ump_max_individual_weight * Implement overweight msg stashing * Test * Add migration module. Also introduces a test for migration * Integrate ExecuteOverweightOrigin to runtimes * Fix more stuff * Add `yeet` into dictionary * Use suggested `Error` variant names * typo * Use 20ms as the maximum individual message weight * Update the test value * rustfmt * Clean up * Remove deprecated field from host config * Remove missed _hrmp_open_request_ttl * Apply typo fix suggestion Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Rename `migration::migrate_to_latest` * Restore `_hrmp_open_request_ttl` in `v0::HostConfiguration` * Apply suggestion for a rustdoc * Apply the suggestion * Test v0 config with the raw production data fetched from Kusama * Update runtime/parachains/src/ump.rs Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Expose migration functions * Fix spellcheck Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
1 parent 560e965 commit f33ecdb

File tree

11 files changed

+572
-35
lines changed

11 files changed

+572
-35
lines changed

node/service/src/chain_spec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ fn default_parachains_host_configuration(
185185
ump_service_total_weight: 4 * 1_000_000_000,
186186
max_upward_message_size: 1024 * 1024,
187187
max_upward_message_num_per_candidate: 5,
188-
_hrmp_open_request_ttl: 5,
189188
hrmp_sender_deposit: 0,
190189
hrmp_recipient_deposit: 0,
191190
hrmp_channel_max_capacity: 8,

runtime/kusama/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ impl parachains_ump::Config for Runtime {
11181118
type Event = Event;
11191119
type UmpSink = crate::parachains_ump::XcmSink<XcmExecutor<XcmConfig>, Runtime>;
11201120
type FirstMessageFactorPercent = FirstMessageFactorPercent;
1121+
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
11211122
}
11221123

11231124
impl parachains_dmp::Config for Runtime {}

runtime/parachains/src/configuration.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! Configuration can change only at session boundaries and is buffered until then.
2020
2121
use crate::shared;
22-
use frame_support::pallet_prelude::*;
22+
use frame_support::{pallet_prelude::*, weights::constants::WEIGHT_PER_MILLIS};
2323
use frame_system::pallet_prelude::*;
2424
use parity_scale_codec::{Decode, Encode};
2525
use primitives::v1::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_POV_SIZE};
@@ -28,6 +28,10 @@ use sp_std::prelude::*;
2828

2929
pub use pallet::*;
3030

31+
pub mod migration;
32+
33+
const LOG_TARGET: &str = "runtime::configuration";
34+
3135
/// All configuration of the runtime with respect to parachains and parathreads.
3236
#[derive(Clone, Encode, Decode, PartialEq, sp_core::RuntimeDebug)]
3337
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
@@ -91,10 +95,6 @@ pub struct HostConfiguration<BlockNumber> {
9195
pub hrmp_max_parachain_outbound_channels: u32,
9296
/// The maximum number of outbound HRMP channels a parathread is allowed to open.
9397
pub hrmp_max_parathread_outbound_channels: u32,
94-
/// NOTE: this field is deprecated. Channel open requests became non-expiring. Changing this value
95-
/// doesn't have any effect. This field doesn't have a `deprecated` attribute because that would
96-
/// trigger warnings coming from macros.
97-
pub _hrmp_open_request_ttl: u32,
9898
/// The deposit that the sender should provide for opening an HRMP channel.
9999
pub hrmp_sender_deposit: Balance,
100100
/// The deposit that the recipient should provide for accepting opening an HRMP channel.
@@ -170,6 +170,9 @@ pub struct HostConfiguration<BlockNumber> {
170170
pub needed_approvals: u32,
171171
/// The number of samples to do of the `RelayVRFModulo` approval assignment criterion.
172172
pub relay_vrf_modulo_samples: u32,
173+
/// The maximum amount of weight any individual upward message may consume. Messages above this
174+
/// weight go into the overweight queue and may only be serviced explicitly.
175+
pub ump_max_individual_weight: Weight,
173176
}
174177

175178
impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber> {
@@ -204,7 +207,6 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
204207
ump_service_total_weight: Default::default(),
205208
max_upward_message_size: Default::default(),
206209
max_upward_message_num_per_candidate: Default::default(),
207-
_hrmp_open_request_ttl: Default::default(),
208210
hrmp_sender_deposit: Default::default(),
209211
hrmp_recipient_deposit: Default::default(),
210212
hrmp_channel_max_capacity: Default::default(),
@@ -215,6 +217,7 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
215217
hrmp_max_parachain_outbound_channels: Default::default(),
216218
hrmp_max_parathread_outbound_channels: Default::default(),
217219
hrmp_max_message_num_per_candidate: Default::default(),
220+
ump_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
218221
}
219222
}
220223
}
@@ -261,6 +264,7 @@ pub mod pallet {
261264

262265
#[pallet::pallet]
263266
#[pallet::generate_store(pub(super) trait Store)]
267+
#[pallet::storage_version(migration::STORAGE_VERSION)]
264268
pub struct Pallet<T>(_);
265269

266270
#[pallet::config]
@@ -764,10 +768,24 @@ pub mod pallet {
764768
});
765769
Ok(())
766770
}
771+
772+
/// Sets the maximum amount of weight any individual upward message may consume.
773+
#[pallet::weight((1_000, DispatchClass::Operational))]
774+
pub fn set_ump_max_individual_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
775+
ensure_root(origin)?;
776+
Self::update_config_member(|config| {
777+
sp_std::mem::replace(&mut config.ump_max_individual_weight, new) != new
778+
});
779+
Ok(())
780+
}
767781
}
768782

769783
#[pallet::hooks]
770784
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
785+
fn on_runtime_upgrade() -> Weight {
786+
migration::migrate_to_latest::<T>()
787+
}
788+
771789
fn integrity_test() {
772790
assert_eq!(
773791
&ActiveConfig::<T>::hashed_key(),
@@ -888,7 +906,6 @@ mod tests {
888906
ump_service_total_weight: 20000,
889907
max_upward_message_size: 448,
890908
max_upward_message_num_per_candidate: 5,
891-
_hrmp_open_request_ttl: 0,
892909
hrmp_sender_deposit: 22,
893910
hrmp_recipient_deposit: 4905,
894911
hrmp_channel_max_capacity: 3921,
@@ -899,6 +916,7 @@ mod tests {
899916
hrmp_max_parachain_outbound_channels: 100,
900917
hrmp_max_parathread_outbound_channels: 200,
901918
hrmp_max_message_num_per_candidate: 20,
919+
ump_max_individual_weight: 909,
902920
};
903921

904922
assert!(<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY).is_none());
@@ -1060,6 +1078,11 @@ mod tests {
10601078
new_config.hrmp_max_message_num_per_candidate,
10611079
)
10621080
.unwrap();
1081+
Configuration::set_ump_max_individual_weight(
1082+
Origin::root(),
1083+
new_config.ump_max_individual_weight,
1084+
)
1085+
.unwrap();
10631086

10641087
assert_eq!(
10651088
<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY),

0 commit comments

Comments
 (0)