|
16 | 16 |
|
17 | 17 | //! Primitives of the xcm-bridge-hub pallet. |
18 | 18 |
|
19 | | -#![warn(missing_docs)] |
20 | 19 | #![cfg_attr(not(feature = "std"), no_std)] |
21 | 20 |
|
| 21 | +use xcm::latest::prelude::*; |
| 22 | + |
22 | 23 | /// Encoded XCM blob. We expect the bridge messages pallet to use this blob type for both inbound |
23 | 24 | /// and outbound payloads. |
24 | 25 | 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