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

Add force_open_hrmp_channel Call #6155

Merged
merged 6 commits into from
Oct 17, 2022
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: 15 additions & 0 deletions runtime/kusama/src/weights/runtime_parachains_hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,19 @@ impl<T: frame_system::Config> runtime_parachains::hrmp::WeightInfo for WeightInf
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64)))
}
// Storage: Paras ParaLifecycles (r:2 w:0)
// Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1)
// Storage: Hrmp HrmpChannels (r:1 w:0)
// Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1)
// Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1)
// Storage: Dmp DownwardMessageQueueHeads (r:2 w:2)
// Storage: Dmp DownwardMessageQueues (r:2 w:2)
// Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1)
fn force_open_hrmp_channel() -> Weight {
Weight::from_ref_time(104_771_000 as u64)
.saturating_add(T::DbWeight::get().reads(13 as u64))
.saturating_add(T::DbWeight::get().writes(8 as u64))
}
}
33 changes: 33 additions & 0 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub trait WeightInfo {
fn force_process_hrmp_close(c: u32) -> Weight;
fn hrmp_cancel_open_request(c: u32) -> Weight;
fn clean_open_channel_requests(c: u32) -> Weight;
fn force_open_hrmp_channel() -> Weight;
}

/// A weight info that is only suitable for testing.
Expand Down Expand Up @@ -88,6 +89,9 @@ impl WeightInfo for TestWeightInfo {
fn clean_open_channel_requests(_: u32) -> Weight {
Weight::MAX
}
fn force_open_hrmp_channel() -> Weight {
Weight::MAX
}
}

/// A description of a request to open an HRMP channel.
Expand Down Expand Up @@ -269,6 +273,9 @@ pub mod pallet {
OpenChannelAccepted(ParaId, ParaId),
/// HRMP channel closed. `[by_parachain, channel_id]`
ChannelClosed(ParaId, HrmpChannelId),
/// An HRMP channel was opened via Root origin.
/// `[sender, recipient, proposed_max_capacity, proposed_max_message_size]`
HrmpChannelForceOpened(ParaId, ParaId, u32, u32),
}

#[pallet::error]
Expand Down Expand Up @@ -577,6 +584,32 @@ pub mod pallet {
Self::deposit_event(Event::OpenChannelCanceled(origin, channel_id));
Ok(())
}

/// Open a channel from a `sender` to a `recipient` `ParaId` using the Root origin. Although
/// opened by Root, the `max_capacity` and `max_message_size` are still subject to the Relay
/// Chain's configured limits.
///
/// Expected use is when one of the `ParaId`s involved in the channel is governed by the
/// Relay Chain, e.g. a common good parachain.
#[pallet::weight(<T as Config>::WeightInfo::force_open_hrmp_channel())]
pub fn force_open_hrmp_channel(
origin: OriginFor<T>,
sender: ParaId,
recipient: ParaId,
max_capacity: u32,
max_message_size: u32,
) -> DispatchResult {
ensure_root(origin)?;
Self::init_open_channel(sender, recipient, max_capacity, max_message_size)?;
Self::accept_open_channel(recipient, sender)?;
Self::deposit_event(Event::HrmpChannelForceOpened(
sender,
recipient,
max_capacity,
max_message_size,
));
Ok(())
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions runtime/parachains/src/hrmp/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,32 @@ frame_benchmarking::benchmarks! {
} verify {
assert_eq!(HrmpOpenChannelRequestsList::<T>::decode_len().unwrap_or_default() as u32, 0);
}

force_open_hrmp_channel {
let sender_id: ParaId = 1u32.into();
let recipient_id: ParaId = 2u32.into();

// make sure para is registered, and has enough balance.
let sender_deposit: BalanceOf<T> =
Configuration::<T>::config().hrmp_sender_deposit.unique_saturated_into();
let recipient_deposit: BalanceOf<T> =
Configuration::<T>::config().hrmp_recipient_deposit.unique_saturated_into();
register_parachain_with_balance::<T>(sender_id, sender_deposit);
register_parachain_with_balance::<T>(recipient_id, recipient_deposit);

let capacity = Configuration::<T>::config().hrmp_channel_max_capacity;
let message_size = Configuration::<T>::config().hrmp_channel_max_message_size;

// make sure this channel doesn't exist
let channel_id = HrmpChannelId { sender: sender_id, recipient: recipient_id };
assert!(HrmpOpenChannelRequests::<T>::get(&channel_id).is_none());
assert!(HrmpChannels::<T>::get(&channel_id).is_none());
}: _(frame_system::Origin::<T>::Root, sender_id, recipient_id, capacity, message_size)
verify {
assert_last_event::<T>(
Event::<T>::HrmpChannelForceOpened(sender_id, recipient_id, capacity, message_size).into()
);
}
}

frame_benchmarking::impl_benchmark_test_suite!(
Expand Down
30 changes: 29 additions & 1 deletion runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::*;
use crate::mock::{
new_test_ext, Configuration, Hrmp, MockGenesisConfig, Paras, ParasShared,
RuntimeEvent as MockEvent, System, Test,
RuntimeEvent as MockEvent, RuntimeOrigin, System, Test,
};
use frame_support::{assert_noop, assert_ok, traits::Currency as _};
use primitives::v2::BlockNumber;
Expand Down Expand Up @@ -194,6 +194,34 @@ fn open_channel_works() {
});
}

#[test]
fn force_open_channel_works() {
let para_a = 1.into();
let para_b = 3.into();

new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| {
// We need both A & B to be registered and live parachains.
register_parachain(para_a);
register_parachain(para_b);

run_to_block(5, Some(vec![4, 5]));
Hrmp::force_open_hrmp_channel(RuntimeOrigin::root(), para_a, para_b, 2, 8).unwrap();
Hrmp::assert_storage_consistency_exhaustive();
assert!(System::events().iter().any(|record| record.event ==
MockEvent::Hrmp(Event::HrmpChannelForceOpened(para_a, para_b, 2, 8))));

// Advance to a block 6, but without session change. That means that the channel has
// not been created yet.
run_to_block(6, None);
assert!(!channel_exists(para_a, para_b));
Hrmp::assert_storage_consistency_exhaustive();

// Now let the session change happen and thus open the channel.
run_to_block(8, Some(vec![8]));
assert!(channel_exists(para_a, para_b));
});
}

#[test]
fn close_channel_works() {
let para_a = 5.into();
Expand Down
1 change: 1 addition & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ mod benches {
[runtime_common::paras_registrar, Registrar]
[runtime_parachains::configuration, Configuration]
[runtime_parachains::disputes, ParasDisputes]
[runtime_parachains::hrmp, Hrmp]
[runtime_parachains::initializer, Initializer]
[runtime_parachains::paras, Paras]
[runtime_parachains::paras_inherent, ParaInherent]
Expand Down
15 changes: 15 additions & 0 deletions runtime/polkadot/src/weights/runtime_parachains_hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,19 @@ impl<T: frame_system::Config> runtime_parachains::hrmp::WeightInfo for WeightInf
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64)))
}
// Storage: Paras ParaLifecycles (r:2 w:0)
// Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1)
// Storage: Hrmp HrmpChannels (r:1 w:0)
// Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1)
// Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1)
// Storage: Dmp DownwardMessageQueueHeads (r:2 w:2)
// Storage: Dmp DownwardMessageQueues (r:2 w:2)
// Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1)
fn force_open_hrmp_channel() -> Weight {
Weight::from_ref_time(104_771_000 as u64)
.saturating_add(T::DbWeight::get().reads(13 as u64))
.saturating_add(T::DbWeight::get().writes(8 as u64))
}
}
15 changes: 15 additions & 0 deletions runtime/rococo/src/weights/runtime_parachains_hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,19 @@ impl<T: frame_system::Config> runtime_parachains::hrmp::WeightInfo for WeightInf
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64)))
}
// Storage: Paras ParaLifecycles (r:2 w:0)
// Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1)
// Storage: Hrmp HrmpChannels (r:1 w:0)
// Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1)
// Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1)
// Storage: Dmp DownwardMessageQueueHeads (r:2 w:2)
// Storage: Dmp DownwardMessageQueues (r:2 w:2)
// Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1)
fn force_open_hrmp_channel() -> Weight {
Weight::from_ref_time(104_771_000 as u64)
.saturating_add(T::DbWeight::get().reads(13 as u64))
.saturating_add(T::DbWeight::get().writes(8 as u64))
}
}
15 changes: 15 additions & 0 deletions runtime/westend/src/weights/runtime_parachains_hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,19 @@ impl<T: frame_system::Config> runtime_parachains::hrmp::WeightInfo for WeightInf
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64)))
}
// Storage: Paras ParaLifecycles (r:2 w:0)
// Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1)
// Storage: Hrmp HrmpChannels (r:1 w:0)
// Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1)
// Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1)
// Storage: Dmp DownwardMessageQueueHeads (r:2 w:2)
// Storage: Dmp DownwardMessageQueues (r:2 w:2)
// Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0)
// Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1)
fn force_open_hrmp_channel() -> Weight {
Weight::from_ref_time(104_771_000 as u64)
.saturating_add(T::DbWeight::get().reads(13 as u64))
.saturating_add(T::DbWeight::get().writes(8 as u64))
}
}