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

Bridges V2 - dynamic lanes #4427

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
introduce partial bp-xcm-bridge-hub - just LocalXcmChannelManager (#2265
)
  • Loading branch information
svyatonik authored and bkontur committed Jul 1, 2024
commit dbc8b49a1b71002d2514459d33d1f2ef9904d57d
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion bridges/primitives/xcm-bridge-hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ workspace = true
# Substrate Dependencies
sp-std = { workspace = true }

# Polkadot Dependencies
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false }

[features]
default = ["std"]
std = ["sp-std/std"]
std = [
"sp-std/std",
"xcm/std",
]
57 changes: 56 additions & 1 deletion bridges/primitives/xcm-bridge-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,64 @@

//! Primitives of the xcm-bridge-hub pallet.

#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]

use xcm::latest::prelude::*;

/// Encoded XCM blob. We expect the bridge messages pallet to use this blob type for both inbound
/// and outbound payloads.
pub type XcmAsPlainPayload = sp_std::vec::Vec<u8>;

/// A manager of XCM communication channels between the bridge hub and parent/sibling chains
/// that have opened bridges at this bridge hub.
///
/// We use this interface to suspend and resume channels programmatically to implement backpressure
/// mechanism for bridge queues.
#[allow(clippy::result_unit_err)] // XCM uses `Result<(), ()>` everywhere
pub trait LocalXcmChannelManager {
// TODO: https://github.com/paritytech/parity-bridges-common/issues/2255
// check following assumptions. They are important at least for following cases:
// 1) we now close the associated outbound lane when misbehavior is reported. If we'll keep
// handling inbound XCM messages after the `suspend_inbound_channel`, they will be dropped
// 2) the sender will be able to enqueue message to othe lanes if we won't stop handling inbound
// XCM immediately. He even may open additional bridges

/// Stop handling new incoming XCM messages from given bridge `owner` (parent/sibling chain).
///
/// We assume that the channel will be suspended immediately, but we don't mind if inbound
/// messages will keep piling up here for some time. Once this is communicated to the
/// `owner` chain (in any form), we expect it to stop sending messages to us and queue
/// messages at that `owner` chain instead.
///
/// This method will be called if we detect a misbehavior in one of bridges, owned by
/// the `owner`. We expect that:
///
/// - no more incoming XCM messages from the `owner` will be processed until further
/// `resume_inbound_channel` call;
///
/// - soon after the call, the channel will switch to the state when incoming messages are
/// piling up at the sending chain, not at the bridge hub.
///
/// This method shall not fail if the channel is already suspended.
fn suspend_inbound_channel(owner: Location) -> Result<(), ()>;

/// Start handling incoming messages from from given bridge `owner` (parent/sibling chain)
/// again.
///
/// This method is called when the `owner` tries to resume bridge operations after
/// resolving "misbehavior" issues. The channel is assumed to be suspended by the previous
/// `suspend_inbound_channel` call, however we don't check it anywhere.
///
/// This method shall not fail if the channel is already resumed.
fn resume_inbound_channel(owner: Location) -> Result<(), ()>;
}

impl LocalXcmChannelManager for () {
fn suspend_inbound_channel(_owner: Location) -> Result<(), ()> {
Ok(())
}

fn resume_inbound_channel(_owner: Location) -> Result<(), ()> {
Err(())
}
}