Skip to content

Commit

Permalink
Update from bkontur running command 'fmt'
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 14, 2024
1 parent ecf3499 commit f643ec7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
19 changes: 9 additions & 10 deletions bridges/modules/xcm-bridge-hub-router/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use frame_support::{ensure, pallet_prelude::PhantomData, traits::Get};
use xcm::prelude::*;
use xcm_builder::{ensure_is_remote, ExporterFor};

/// Implementation of [`bp_xcm_bridge_hub::LocalXcmChannelManager`] which tracks and updates `is_congested` for a given
/// `BridgeId`. This implementation is useful for managing congestion and dynamic fees with the
/// local `ExportXcm` implementation.
/// Implementation of [`bp_xcm_bridge_hub::LocalXcmChannelManager`] which tracks and updates
/// `is_congested` for a given `BridgeId`. This implementation is useful for managing congestion and
/// dynamic fees with the local `ExportXcm` implementation.
impl<T: Config<I>, I: 'static> bp_xcm_bridge_hub::LocalXcmChannelManager<BridgeIdOf<T, I>>
for Pallet<T, I>
{
Expand Down Expand Up @@ -72,8 +72,8 @@ impl<T: Config<I>, I: 'static> bp_xcm_bridge_hub::LocalXcmChannelManager<BridgeI
/// Adapter implementation for [`ExporterFor`] that allows exporting message size fee and/or dynamic
/// fees based on the `BridgeId` resolved by the `T::BridgeIdResolver` resolver, if and only if the
/// `E` exporter supports bridging. This adapter acts as an [`ExporterFor`], for example, for the
/// [`xcm_builder::SovereignPaidRemoteExporter`], enabling it to compute message and/or dynamic fees using a fee
/// factor.
/// [`xcm_builder::SovereignPaidRemoteExporter`], enabling it to compute message and/or dynamic fees
/// using a fee factor.
pub struct ViaRemoteBridgeHubExporter<T, I, E, BNF, BHLF>(PhantomData<(T, I, E, BNF, BHLF)>);
impl<T: Config<I>, I: 'static, E, BridgedNetworkIdFilter, BridgeHubLocationFilter> ExporterFor
for ViaRemoteBridgeHubExporter<T, I, E, BridgedNetworkIdFilter, BridgeHubLocationFilter>
Expand Down Expand Up @@ -195,7 +195,8 @@ where
/// Adapter implementation for [`SendXcm`] that allows adding a message size fee and/or dynamic fees
/// based on the `BridgeId` resolved by the `T::BridgeIdResolver` resolver, if and only if `E`
/// supports routing. This adapter can be used, for example, as a wrapper over
/// [`xcm_builder::UnpaidLocalExporter`], enabling it to compute message and/or dynamic fees using a fee factor.
/// [`xcm_builder::UnpaidLocalExporter`], enabling it to compute message and/or dynamic fees using a
/// fee factor.
pub struct ViaLocalBridgeHubExporter<T, I, E>(PhantomData<(T, I, E)>);
impl<T: Config<I>, I: 'static, E: SendXcm> SendXcm for ViaLocalBridgeHubExporter<T, I, E> {
type Ticket = E::Ticket;
Expand All @@ -222,10 +223,8 @@ impl<T: Config<I>, I: 'static, E: SendXcm> SendXcm for ViaLocalBridgeHubExporter
if let Some(bridge_state) = Bridges::<T, I>::get(bridge_id) {
let mut dynamic_fees = sp_std::vec::Vec::with_capacity(fees.len());
for fee in fees.into_inner() {
dynamic_fees.push(Pallet::<T, I>::calculate_dynamic_fee(
&bridge_state,
fee,
));
dynamic_fees
.push(Pallet::<T, I>::calculate_dynamic_fee(&bridge_state, fee));
}
fees = Assets::from(dynamic_fees);
}
Expand Down
23 changes: 13 additions & 10 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ pub const LOG_TARGET: &str = "runtime::bridge-xcm-router";
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::weights::WeightMeter;
use frame_support::{pallet_prelude::*, weights::WeightMeter};
use frame_system::pallet_prelude::*;

/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
Expand Down Expand Up @@ -195,15 +194,21 @@ pub mod pallet {
// If no longer congested, we can start decreasing the fee factor.
if !bridge_state.is_congested {
let previous_factor = bridge_state.delivery_fee_factor;
let new_factor = previous_factor / EXPONENTIAL_FEE_BASE;
let new_factor = previous_factor / EXPONENTIAL_FEE_BASE;
if new_factor >= MINIMAL_DELIVERY_FEE_FACTOR {
bridge_state.delivery_fee_factor = new_factor;
if meter.try_consume(T::WeightInfo::on_idle_when_bridge_state_updated()).is_err() {
if meter
.try_consume(T::WeightInfo::on_idle_when_bridge_state_updated())
.is_err()
{
break;
}
bridges_to_update.push((bridge_id, previous_factor, bridge_state));
} else {
if meter.try_consume(T::WeightInfo::on_idle_when_bridge_state_removed()).is_err() {
if meter
.try_consume(T::WeightInfo::on_idle_when_bridge_state_removed())
.is_err()
{
break;
}
bridges_to_remove.push((bridge_id, previous_factor));
Expand Down Expand Up @@ -333,10 +338,7 @@ pub mod pallet {
/// factor specified in the `bridge_state`. If the asset is fungible, the
/// `delivery_fee_factor` is applied to the asset’s amount, potentially altering its
/// value.
pub(crate) fn calculate_dynamic_fee(
bridge_state: &BridgeState,
mut asset: Asset,
) -> Asset {
pub(crate) fn calculate_dynamic_fee(bridge_state: &BridgeState, mut asset: Asset) -> Asset {
if let Fungibility::Fungible(ref mut amount) = asset.fun {
*amount = bridge_state.delivery_fee_factor.saturating_mul_int(*amount);
}
Expand Down Expand Up @@ -554,7 +556,8 @@ mod tests {
let mut last_delivery_fee_factor = initial_fee_factor;
while let Some(bridge_state) = get_bridge_state_for::<TestRuntime, ()>(&dest) {
last_delivery_fee_factor = bridge_state.delivery_fee_factor;
remaining_weight = XcmBridgeHubRouter::on_idle(One::one(), remaining_weight.clone());
remaining_weight =
XcmBridgeHubRouter::on_idle(One::one(), remaining_weight.clone());

// avoid infinite loops (decreasing is expected)
if let Some(bridge_state) = get_bridge_state_for::<TestRuntime, ()>(&dest) {
Expand Down
10 changes: 5 additions & 5 deletions bridges/modules/xcm-bridge-hub/src/congestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ impl<
/// Manages the local XCM channels by sending XCM messages with the `report_bridge_status` extrinsic
/// to the `local_origin`. The `XcmProvider` type converts the encoded call to `XCM`, which is then
/// sent by `XcmSender` to the `local_origin`. This is useful, for example, when a router with
/// [`xcm::prelude::ExportMessage`] is deployed on a different chain, and we want to control congestion by sending
/// XCMs.
/// [`xcm::prelude::ExportMessage`] is deployed on a different chain, and we want to control
/// congestion by sending XCMs.
pub struct ReportBridgeStatusXcmChannelManager<T, I, XcmProvider, XcmSender>(
PhantomData<(T, I, XcmProvider, XcmSender)>,
);
Expand Down Expand Up @@ -209,9 +209,9 @@ impl<T: Config<I>, I: 'static, XcmProvider: Convert<Vec<u8>, Xcm<()>>, XcmSender
}

/// Adapter that ties together the [`DispatchBlob`] trait with the [`DispatchChannelStatusProvider`]
/// trait. The idea is that [`DispatchBlob`] triggers message dispatch/delivery on the receiver side,
/// while [`DispatchChannelStatusProvider`] provides a status check to ensure the dispatch channel is
/// active (not congested).
/// trait. The idea is that [`DispatchBlob`] triggers message dispatch/delivery on the receiver
/// side, while [`DispatchChannelStatusProvider`] provides a status check to ensure the dispatch
/// channel is active (not congested).
pub struct BlobDispatcherWithChannelStatus<ChannelDispatch, ChannelStatus>(
PhantomData<(ChannelDispatch, ChannelStatus)>,
);
Expand Down

0 comments on commit f643ec7

Please sign in to comment.