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

Implement additional require primitives for dynamic fees directly for pallet-xcm-bridge-hub #2261

Merged
merged 40 commits into from
Aug 25, 2023

Conversation

svyatonik
Copy link
Contributor

@svyatonik svyatonik commented Jul 13, 2023

related to #2434
alternative to #2233

The idea is to:

  • add backoff to inbound bridge queue (aka outbound XCMP queue between target BH and target chain) - if it has too many enqueued messages, we assume that the target chain is unable to process messages in a timely fashion and stop accepting message delivery transactions: e19c82a
  • add backoff mechanism to outbound bridge queue - if it has too many enqueued messages, we assume that the inbound bridge queue (at the bridged, target BH) contains too many messages (or if there's no relayer running) and stop accepting new messages to this queue by pausing inbound "end" of XCMP channel between sending chain and its sibling BH. It requires some parts of XCM bridge hub pallet (will be deployed at bridge hubs) #2213 and A way to dynamically (programmatically) suspend and resume inbound XCM channels at bridge hub #2406
  • XCMP queue has its own backoff mechanism and because of that, messages will eventually start piling up at the sending chain outbound XCMP queue "end". So it can estimate the number of messages in the whole bridge pipeline and start applying exponential fee or something like that

This PR requires corresponding changes to the relayer. It'll be done in a follow up/parallel PR.

===

Update: this ^^^ information is a bit obsolete, but overall it stays the same.Main things to notice in this PR:

  • I've introduced a separate BridgeId struct, so there's now both BridgeId and LaneId. Both are H256 and are matching now. The reason is that we shall use versioned XCM structs in BridgeId AND version may change at some point. Don't know what we'll do when it happens, but we must be prepared for that;
  • messages_xcm_extension.rs file is removed and required implementations are moved to the pallet-xcm-bridge-hub (HaulBlobExporter, MessageDispatch and so on);
  • there's now LocalXcmChannelManager, which is able to report channel status + suspend/resume the channel. I've removed bp-xcm-bridge-hub-router crate because of that.

// TODO: use following structures in the `pallet-message-queue` configuration

// TODO: it must be a part of `pallet-xcm-bridge-hub`
pub struct LocalInboundXcmChannelSuspender<Origin, Inner>(PhantomData<(Origin, Inner)>);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: in paritytech/cumulus#2157, the QueueChangeHandler of pallet_message_queue is not set (???) to the cumulus-pallet-xcmp-queue. Given that, our backpressure won't actually work - we are pausing dispatch here, but the transport channel will stay opened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svyatonik pushed a commit that referenced this pull request Jul 17, 2023
* add version checks on para ugprade

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove unneeded imports and errors

* fix test error path

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
@svyatonik svyatonik mentioned this pull request Jul 17, 2023
…orage format will likely change to be able to resume bridges from the on_iniitalize/on_idle"

This reverts commit bdd7ae1.
@svyatonik svyatonik changed the title Dynamic fees implementation that adds backoff for all intermediate bridge queues (main option) Implement additional require primitives for dynamic fees directly for pallet-xcm-bridge-hub Aug 1, 2023
@svyatonik
Copy link
Contributor Author

renamed, because most of the code required for dynamic fees is now in a separate PR: #2312

@@ -0,0 +1,131 @@
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be the copy of the similar primitives (LocalXcmQueueMessageProcessor and LocalXcmQueueSuspender) from #2294. The only difference is how we "compute" whether the inbound XCM queue should be suspended or not. In v1 PR it looks at the number of queued messages at the outbound lane. Here it should take into account all outbound lanes, opened by the same origin (a bit WIP)

@bkontur bkontur mentioned this pull request Aug 3, 2023
9 tasks
@svyatonik svyatonik marked this pull request as ready for review August 22, 2023 09:34
modules/xcm-bridge-hub/src/exporter.rs Outdated Show resolved Hide resolved
modules/xcm-bridge-hub/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +54 to +81
pub struct BridgeId(LaneId);

impl BridgeId {
/// Create bridge identifier from two universal locations.
///
/// - no more incoming XCM messages from the `owner` will be processed until further
/// `resume_inbound_channel` call;
/// The fact that we are using versioned locations here means that XCM version upgrades must
/// be coordinated at all involved chains (at source and target chains + at bridge hubs).
/// Otherwise messages may simply be dropped anywhere on its path to the target chain.
pub fn new(
universal_location1: &VersionedInteriorMultiLocation,
universal_location2: &VersionedInteriorMultiLocation,
) -> Self {
// a tricky helper struct that adds required `Ord` support for
// `VersionedInteriorMultiLocation`
#[derive(Eq, PartialEq, Ord, PartialOrd)]
struct EncodedVersionedInteriorMultiLocation(sp_std::vec::Vec<u8>);

impl Encode for EncodedVersionedInteriorMultiLocation {
fn encode(&self) -> sp_std::vec::Vec<u8> {
self.0.clone()
}
}

Self(LaneId::new(
EncodedVersionedInteriorMultiLocation(universal_location1.encode()),
EncodedVersionedInteriorMultiLocation(universal_location2.encode()),
))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've introduced a separate BridgeId struct, so there's now both BridgeId and LaneId. Both are H256 and are matching now. The reason is that we shall use versioned XCM structs in BridgeId AND version may change at some point. Don't know what we'll do when it happens, but we must be prepared for that;

Sounds like a complicated issue. But I'm not sure if introducing the BridgeId will help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - that's a very complicated issue. Like XCM version is upgraded for the whole chain. And since bridge hub is used by many other chains (including from other consensus) - we should coordinate that with all those chains. Or else we need e.g. to use different XCM version with different chains. I've seen there's a subscription for XCM version - i.e. you receive notification when XCM is upgraded on some other chain. Maybe we could use it here. But I do not know yet.

Why I'm adding BridgeId - because we e.g. may introduce storage map from BridgeId to LaneId. So even if BridgeId is changed, we may keep using the same LaneId. Also - those types are (will be) used in different communications - BridgeId will be used when communicating with sibling/parent chain and LaneId is used when communicating with the bridged bridge hub. So imo it makes sense to keep this difference at least because of that.

As for the XCM version support - I'll file an issue (probably for v3 :) ). It definitely needs some more thinking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - those types are (will be) used in different communications - BridgeId will be used when communicating with sibling/parent chain and LaneId is used when communicating with the bridged bridge hub. So imo it makes sense to keep this difference at least because of that.

Makes sense

As for the XCM version support - I'll file an issue (probably for v3 :) ). It definitely needs some more thinking.

Perfect. Better to track this in an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed #2500

* backport latest relevant dynamic fees changes from v1 to v2

* fix comment
@svyatonik svyatonik merged commit bd87488 into master Aug 25, 2023
@svyatonik svyatonik deleted the xcm-dynamic-fees-using-backoff-mechanism branch August 25, 2023 08:14
bkontur pushed a commit that referenced this pull request May 7, 2024
… pallet-xcm-bridge-hub (#2261)

* added backoff mechanism to inbound bridge queue

* impl backpressure in the XcmBlobHaulerAdapter

* leave TODOs

* BridgeMessageProcessor prototype

* another TODO

* Revert "also temporary (?) remove BridgesByLocalOrigin because the storage format will likely change to be able to resume bridges from the on_iniitalize/on_idle"

This reverts commit bdd7ae1.

* prototype for QueuePausedQuery

* implement ExportXcm and MessageDispatch for pallet-xcm-bridge-hub

* spelling

* flush

* small comments to myself

* more backports from dynamic-fees-v1

* use new pallet as exporter and dispatcher in Millau

* use new pallet as exporter and dispatcher in Rialto

* use new pallet as exporter and dispatcher in RialtoParachain

* flush

* fix remaining compilation issues

* warnings + fmt

* fix tests

* LocalXcmChannelManager

* change lane ids

* it works!

* remove bp-xcm-bridge-hub-router and use LocalXcmChannelManager everywhere

* removed commented code

* cleaning up

* cleaning up

* cleaning up

* - separated BridgeId and LaneId
- BridgeId now uses versioned universal locations
- added missing stuff to exporter.rs

* OnMessagesDelivered is back

* start using bp-xcm-bridge-hub as OnMessagesDelivered

* cleaning up

* spelling

* fix stupid issues

* Backport latest relevant dynamic fees changes from v1 to v2 (#2372)

* backport latest relevant dynamic fees changes from v1 to v2

* fix comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-Runtime PR-audit-needed A PR has to be audited before going live.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants