use crate::{pallet, OutboundState};
use cumulus_primitives_core::ParaId;
use xcm::latest::prelude::*;
pub struct InAndOutXcmpChannelStatusProvider<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime: crate::Config> bp_xcm_bridge_hub_router::XcmChannelStatusProvider
for InAndOutXcmpChannelStatusProvider<Runtime>
{
fn is_congested(with: &Location) -> bool {
let sibling_para_id: ParaId = match with.unpack() {
(_, [Parachain(para_id)]) => (*para_id).into(),
_ => return false,
};
if pallet::Pallet::<Runtime>::is_inbound_channel_suspended(sibling_para_id) {
return true;
}
OutXcmpChannelStatusProvider::<Runtime>::is_congested(with)
}
}
pub struct OutXcmpChannelStatusProvider<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime: crate::Config> OutXcmpChannelStatusProvider<Runtime> {
fn is_congested(with: &Location) -> bool {
let sibling_para_id: ParaId = match with.unpack() {
(_, [Parachain(para_id)]) => (*para_id).into(),
_ => return false,
};
let Some((outbound_state, queued_pages)) =
pallet::Pallet::<Runtime>::outbound_channel_state(sibling_para_id)
else {
return false;
};
if outbound_state == OutboundState::Suspended {
return true;
}
const MAX_QUEUED_PAGES_BEFORE_DEACTIVATION: u16 = 4;
if queued_pages > MAX_QUEUED_PAGES_BEFORE_DEACTIVATION {
return true;
}
false
}
}
impl<Runtime: crate::Config> bp_xcm_bridge_hub_router::XcmChannelStatusProvider
for OutXcmpChannelStatusProvider<Runtime>
{
fn is_congested(with: &Location) -> bool {
Self::is_congested(with)
}
}
#[cfg(feature = "runtime-benchmarks")]
pub fn suspend_channel_for_benchmarks<T: crate::Config>(target: ParaId) {
pallet::Pallet::<T>::suspend_channel(target)
}