This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 380
Transfer asset via bridge pallet xcm with dynamic fees and back-pressure #2997
Open
bkontur
wants to merge
31
commits into
bko-transfer-asset-via-bridge-pallet-xcm
Choose a base branch
from
bko-transfer-asset-via-bridge-pallet-xcm-with-dynamic-fees
base: bko-transfer-asset-via-bridge-pallet-xcm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
429d6b0
Squashed 'bridges/' changes from edf33a2c85..8f86ec78b7
bkontur 6544a5c
Merge commit '429d6b09cab2379e1a118bc4d59dc8f935c5ae2d' into bko-tran…
bkontur 18b425a
[dynfees] Rococo/Wococo does not need congestion and dynamic fees (fo…
bkontur a399514
Adding paid xcm bridge hub router
bkontur e5a03a3
[dynfees] Implemented `XcmChannelStatusProvider` for `XcmpQueue`
bkontur 025f109
Allow to change `XcmBridgeHubRouterByteFee` by governance
bkontur d48d27e
Adding paid xcm bridge hub router to AssetHubPolkadot
bkontur 8b92cd7
Extended script for local run BHK/P
bkontur 43cda64
Docs nits
bkontur e86d89e
Added XcmBridgeHubRouterCall::report_bridge_status encodings for AHK/P
bkontur 130646c
Added `test_report_bridge_status_call_compatibility` for encodings
bkontur c82f585
Allowed `xcm::Transact(pallet_xcm_bridge_hub_router::Call::report_bri…
bkontur 05d504a
Added const for `XcmBridgeHubRouterTransactCallMaxWeight`
bkontur 356969d
Added constant for base fee (with sanity check)
bkontur 0a54659
Introduced base delivery fee constants
bkontur 824a480
Congestion messages as Optional to turn on/off `supports_congestion_d…
bkontur 6363103
Fix for BHRo/Wo
bkontur 7fd6d26
Benchmarks for router
bkontur 0f45881
Benchmarks setup for router
bkontur 4bfd8d2
Fix origin for benchmarks
bkontur 22a644e
More fix
bkontur 08642bd
Fix for benchmarks
bkontur c624475
Fix for benchmarks - need hrmp opened
bkontur 9b045f9
Removed WeightInfo TODO
bkontur 5d7b413
Merge remote-tracking branch 'origin/bko-transfer-asset-via-bridge-pa…
bkontur 7c87577
Fmt
bkontur 969a48f
Merge remote-tracking branch 'origin/bko-transfer-asset-via-bridge-pa…
bkontur 7dd0ea9
Merge remote-tracking branch 'origin/bko-transfer-asset-via-bridge-pa…
bkontur 3f7c7f7
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
a5f04fe
Apply git patch from job: https://gitlab.parity.io/parity/mirrors/cum…
bkontur cbcfb6f
Apply suggestions from code review
acatangiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::pallet; | ||
use cumulus_primitives_core::ParaId; | ||
use frame_support::pallet_prelude::Get; | ||
|
||
/// Adapter implementation for `bp_xcm_bridge_hub_router::XcmChannelStatusProvider` which checks | ||
/// both `OutboundXcmpStatus` and `InboundXcmpStatus` for defined `ParaId` if any of those is | ||
/// suspended. | ||
pub struct InboundAndOutboundXcmpChannelCongestionStatusProvider<SiblingBridgeHubParaId, Runtime>( | ||
sp_std::marker::PhantomData<(SiblingBridgeHubParaId, Runtime)>, | ||
); | ||
impl<SiblingBridgeHubParaId: Get<ParaId>, Runtime: crate::Config> | ||
bp_xcm_bridge_hub_router::XcmChannelStatusProvider | ||
for InboundAndOutboundXcmpChannelCongestionStatusProvider<SiblingBridgeHubParaId, Runtime> | ||
{ | ||
fn is_congested() -> bool { | ||
// if the outbound channel with recipient is suspended, it means that one of further | ||
// bridge queues (e.g. bridge queue between two bridge hubs) is overloaded, so we shall | ||
// take larger fee for our outbound messages | ||
let sibling_bridge_hub_id: ParaId = SiblingBridgeHubParaId::get(); | ||
let outbound_channels = pallet::OutboundXcmpStatus::<Runtime>::get(); | ||
let outbound_channel = | ||
outbound_channels.iter().find(|c| c.recipient == sibling_bridge_hub_id); | ||
let is_outbound_channel_suspended = | ||
outbound_channel.map(|c| c.is_suspended()).unwrap_or(false); | ||
if is_outbound_channel_suspended { | ||
return true | ||
} | ||
|
||
// if the inbound channel with recipient is suspended, it means that we are unable to | ||
// receive congestion reports from the bridge hub. So we assume the bridge pipeline is | ||
// congested too | ||
let inbound_channels = pallet::InboundXcmpStatus::<Runtime>::get(); | ||
let inbound_channel = inbound_channels.iter().find(|c| c.sender == sibling_bridge_hub_id); | ||
let is_inbound_channel_suspended = | ||
inbound_channel.map(|c| c.is_suspended()).unwrap_or(false); | ||
if is_inbound_channel_suspended { | ||
return true | ||
} | ||
|
||
// TODO: https://github.com/paritytech/cumulus/pull/2342 - once this PR is merged, we may | ||
// remove the following code | ||
// | ||
// if the outbound channel has at least `N` pages enqueued, let's assume it is congested. | ||
// Normally, the chain with a few opened HRMP channels, will "send" pages at every block. | ||
// Having `N` pages means that for last `N` blocks we either have not sent any messages, | ||
// or have sent signals. | ||
const MAX_OUTBOUND_PAGES_BEFORE_CONGESTION: u16 = 4; | ||
let is_outbound_channel_congested = outbound_channel.map(|c| c.queued_pages()).unwrap_or(0); | ||
is_outbound_channel_congested > MAX_OUTBOUND_PAGES_BEFORE_CONGESTION | ||
} | ||
} | ||
|
||
/// Adapter implementation for `bp_xcm_bridge_hub_router::XcmChannelStatusProvider` which checks | ||
/// only `OutboundXcmpStatus` for defined `SiblingParaId` if is suspended. | ||
pub struct OutboundXcmpChannelCongestionStatusProvider<SiblingBridgeHubParaId, Runtime>( | ||
sp_std::marker::PhantomData<(SiblingBridgeHubParaId, Runtime)>, | ||
); | ||
impl<SiblingParaId: Get<ParaId>, Runtime: crate::Config> | ||
bp_xcm_bridge_hub_router::XcmChannelStatusProvider | ||
for OutboundXcmpChannelCongestionStatusProvider<SiblingParaId, Runtime> | ||
{ | ||
fn is_congested() -> bool { | ||
// let's find the channel with the sibling parachain | ||
let sibling_para_id: cumulus_primitives_core::ParaId = SiblingParaId::get(); | ||
let outbound_channels = pallet::OutboundXcmpStatus::<Runtime>::get(); | ||
let channel_with_sibling_parachain = | ||
outbound_channels.iter().find(|c| c.recipient == sibling_para_id); | ||
|
||
// no channel => it is empty, so not congested | ||
let channel_with_sibling_parachain = match channel_with_sibling_parachain { | ||
Some(channel_with_sibling_parachain) => channel_with_sibling_parachain, | ||
None => return false, | ||
}; | ||
|
||
// suspended channel => it is congested | ||
if channel_with_sibling_parachain.is_suspended() { | ||
return true | ||
} | ||
|
||
// TODO: the following restriction is arguable, we may live without that, assuming that | ||
// there can't be more than some `N` messages queued at the bridge queue (at the source BH) | ||
// AND before accepting next (or next-after-next) delivery transaction, we'll receive the | ||
// suspension signal from the target parachain and stop accepting delivery transactions | ||
|
||
// it takes some time for target parachain to suspend inbound channel with the target BH and | ||
// during that we will keep accepting new message delivery transactions. Let's also reject | ||
// new deliveries if there are too many "pages" (concatenated XCM messages) in the target BH | ||
// -> target parachain queue. | ||
const MAX_QUEUED_PAGES_BEFORE_DEACTIVATION: u16 = 4; | ||
if channel_with_sibling_parachain.queued_pages() > MAX_QUEUED_PAGES_BEFORE_DEACTIVATION { | ||
return true | ||
} | ||
|
||
true | ||
} | ||
} | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub fn suspend_channel_for_benchmarks<T: crate::Config>(target: ParaId) { | ||
pallet::Pallet::<T>::suspend_channel(target) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.