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

HRMP - set DefaultChannelSizeAndCapacityWithSystem with dynamic values according to the ActiveConfig #4332

Merged
merged 4 commits into from
May 1, 2024
Merged
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
15 changes: 14 additions & 1 deletion polkadot/runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use primitives::{
NodeFeatures, SessionIndex, LEGACY_MIN_BACKING_VOTES, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE,
MAX_POV_SIZE, ON_DEMAND_MAX_QUEUE_MAX_SIZE,
};
use sp_runtime::{traits::Zero, Perbill};
use sp_runtime::{traits::Zero, Perbill, Percent};
use sp_std::prelude::*;

#[cfg(test)]
Expand Down Expand Up @@ -1460,3 +1460,16 @@ impl<T: Config> Pallet<T> {
Ok(())
}
}

/// The implementation of `Get<(u32, u32)>` which reads `ActiveConfig` and returns `P` percent of
/// `hrmp_channel_max_message_size` / `hrmp_channel_max_capacity`.
pub struct ActiveConfigHrmpChannelSizeAndCapacityRatio<T, P>(sp_std::marker::PhantomData<(T, P)>);
impl<T: crate::hrmp::pallet::Config, P: Get<Percent>> Get<(u32, u32)>
for ActiveConfigHrmpChannelSizeAndCapacityRatio<T, P>
{
fn get() -> (u32, u32) {
let config = ActiveConfig::<T>::get();
let percent = P::get();
(percent * config.hrmp_channel_max_message_size, percent * config.hrmp_channel_max_capacity)
}
}
50 changes: 49 additions & 1 deletion polkadot/runtime/parachains/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::*;
use crate::{
configuration,
mock::{new_test_ext, Configuration, ParasShared, RuntimeOrigin, Test},
mock::{new_test_ext, Configuration, MockGenesisConfig, ParasShared, RuntimeOrigin, Test},
};
use bitvec::{bitvec, prelude::Lsb0};
use frame_support::{assert_err, assert_noop, assert_ok};
Expand Down Expand Up @@ -547,3 +547,51 @@ fn verify_externally_accessible() {
);
});
}

#[test]
fn active_config_hrmp_channel_size_and_capacity_ratio_works() {
frame_support::parameter_types! {
pub Ratio100: Percent = Percent::from_percent(100);
pub Ratio50: Percent = Percent::from_percent(50);
}

let mut genesis: MockGenesisConfig = Default::default();
genesis.configuration.config.hrmp_channel_max_message_size = 1024;
genesis.configuration.config.hrmp_channel_max_capacity = 100;

new_test_ext(genesis).execute_with(|| {
let active_config = configuration::ActiveConfig::<Test>::get();
assert_eq!(active_config.hrmp_channel_max_message_size, 1024);
assert_eq!(active_config.hrmp_channel_max_capacity, 100);

assert_eq!(
ActiveConfigHrmpChannelSizeAndCapacityRatio::<Test, Ratio100>::get(),
(1024, 100)
);
assert_eq!(ActiveConfigHrmpChannelSizeAndCapacityRatio::<Test, Ratio50>::get(), (512, 50));

// change ActiveConfig
assert_ok!(Configuration::set_hrmp_channel_max_message_size(
RuntimeOrigin::root(),
active_config.hrmp_channel_max_message_size * 4
));
assert_ok!(Configuration::set_hrmp_channel_max_capacity(
RuntimeOrigin::root(),
active_config.hrmp_channel_max_capacity * 4
));
on_new_session(1);
on_new_session(2);
let active_config = configuration::ActiveConfig::<Test>::get();
assert_eq!(active_config.hrmp_channel_max_message_size, 4096);
assert_eq!(active_config.hrmp_channel_max_capacity, 400);

assert_eq!(
ActiveConfigHrmpChannelSizeAndCapacityRatio::<Test, Ratio100>::get(),
(4096, 400)
);
assert_eq!(
ActiveConfigHrmpChannelSizeAndCapacityRatio::<Test, Ratio50>::get(),
(2048, 200)
);
})
}
8 changes: 6 additions & 2 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use runtime_common::{
use runtime_parachains::{
assigner_coretime as parachains_assigner_coretime,
assigner_on_demand as parachains_assigner_on_demand, configuration as parachains_configuration,
configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio,
coretime, disputes as parachains_disputes,
disputes::slashing as parachains_slashing,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
Expand Down Expand Up @@ -1033,15 +1034,18 @@ impl pallet_message_queue::Config for Runtime {
impl parachains_dmp::Config for Runtime {}

parameter_types! {
pub const DefaultChannelSizeAndCapacityWithSystem: (u32, u32) = (51200, 500);
pub const HrmpChannelSizeAndCapacityWithSystemRatio: Percent = Percent::from_percent(100);
}

impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type ChannelManager = EnsureRoot<AccountId>;
type Currency = Balances;
type DefaultChannelSizeAndCapacityWithSystem = DefaultChannelSizeAndCapacityWithSystem;
type DefaultChannelSizeAndCapacityWithSystem = ActiveConfigHrmpChannelSizeAndCapacityRatio<
Runtime,
HrmpChannelSizeAndCapacityWithSystemRatio,
>;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Runtime>;
}

Expand Down
Loading
Loading