Skip to content

Commit c0dbd24

Browse files
svyatonikbkontur
authored andcommitted
introduce partial bp-xcm-bridge-hub - just LocalXcmChannelManager (#2265)
1 parent 807211c commit c0dbd24

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridges/primitives/xcm-bridge-hub/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ workspace = true
1515
# Substrate Dependencies
1616
sp-std = { path = "../../../substrate/primitives/std", default-features = false }
1717

18+
# Polkadot Dependencies
19+
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false }
20+
1821
[features]
1922
default = ["std"]
20-
std = ["sp-std/std"]
23+
std = [
24+
"sp-std/std",
25+
"xcm/std",
26+
]

bridges/primitives/xcm-bridge-hub/src/lib.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,64 @@
1616

1717
//! Primitives of the xcm-bridge-hub pallet.
1818
19-
#![warn(missing_docs)]
2019
#![cfg_attr(not(feature = "std"), no_std)]
2120

21+
use xcm::latest::prelude::*;
22+
2223
/// Encoded XCM blob. We expect the bridge messages pallet to use this blob type for both inbound
2324
/// and outbound payloads.
2425
pub type XcmAsPlainPayload = sp_std::vec::Vec<u8>;
26+
27+
/// A manager of XCM communication channels between the bridge hub and parent/sibling chains
28+
/// that have opened bridges at this bridge hub.
29+
///
30+
/// We use this interface to suspend and resume channels programmatically to implement backpressure
31+
/// mechanism for bridge queues.
32+
#[allow(clippy::result_unit_err)] // XCM uses `Result<(), ()>` everywhere
33+
pub trait LocalXcmChannelManager {
34+
// TODO: https://github.com/paritytech/parity-bridges-common/issues/2255
35+
// check following assumptions. They are important at least for following cases:
36+
// 1) we now close the associated outbound lane when misbehavior is reported. If we'll keep
37+
// handling inbound XCM messages after the `suspend_inbound_channel`, they will be dropped
38+
// 2) the sender will be able to enqueue message to othe lanes if we won't stop handling inbound
39+
// XCM immediately. He even may open additional bridges
40+
41+
/// Stop handling new incoming XCM messages from given bridge `owner` (parent/sibling chain).
42+
///
43+
/// We assume that the channel will be suspended immediately, but we don't mind if inbound
44+
/// messages will keep piling up here for some time. Once this is communicated to the
45+
/// `owner` chain (in any form), we expect it to stop sending messages to us and queue
46+
/// messages at that `owner` chain instead.
47+
///
48+
/// This method will be called if we detect a misbehavior in one of bridges, owned by
49+
/// the `owner`. We expect that:
50+
///
51+
/// - no more incoming XCM messages from the `owner` will be processed until further
52+
/// `resume_inbound_channel` call;
53+
///
54+
/// - soon after the call, the channel will switch to the state when incoming messages are
55+
/// piling up at the sending chain, not at the bridge hub.
56+
///
57+
/// This method shall not fail if the channel is already suspended.
58+
fn suspend_inbound_channel(owner: Location) -> Result<(), ()>;
59+
60+
/// Start handling incoming messages from from given bridge `owner` (parent/sibling chain)
61+
/// again.
62+
///
63+
/// This method is called when the `owner` tries to resume bridge operations after
64+
/// resolving "misbehavior" issues. The channel is assumed to be suspended by the previous
65+
/// `suspend_inbound_channel` call, however we don't check it anywhere.
66+
///
67+
/// This method shall not fail if the channel is already resumed.
68+
fn resume_inbound_channel(owner: Location) -> Result<(), ()>;
69+
}
70+
71+
impl LocalXcmChannelManager for () {
72+
fn suspend_inbound_channel(_owner: Location) -> Result<(), ()> {
73+
Ok(())
74+
}
75+
76+
fn resume_inbound_channel(_owner: Location) -> Result<(), ()> {
77+
Err(())
78+
}
79+
}

0 commit comments

Comments
 (0)