referrerpolicy=no-referrer-when-downgrade

messages_relay/
message_lane.rs

1// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! One-way message lane types. Within single one-way lane we have three 'races' where we try to:
18//!
19//! 1) relay new messages from source to target node;
20//! 2) relay proof-of-delivery from target to source node.
21
22use crate::metrics::Labeled;
23use num_traits::{SaturatingAdd, Zero};
24use relay_utils::{BlockNumberBase, HeaderId};
25use sp_arithmetic::traits::AtLeast32BitUnsigned;
26use std::{fmt::Debug, ops::Sub};
27
28/// One-way message lane.
29pub trait MessageLane: 'static + Clone + Send + Sync {
30	/// Name of the messages source.
31	const SOURCE_NAME: &'static str;
32	/// Name of the messages target.
33	const TARGET_NAME: &'static str;
34
35	/// Lane identifier type.
36	type LaneId: Clone + Send + Sync + Labeled;
37
38	/// Messages proof.
39	type MessagesProof: Clone + Debug + Send + Sync;
40	/// Messages receiving proof.
41	type MessagesReceivingProof: Clone + Debug + Send + Sync;
42
43	/// The type of the source chain token balance, that is used to:
44	///
45	/// 1) pay transaction fees;
46	/// 2) pay message delivery and dispatch fee;
47	/// 3) pay relayer rewards.
48	type SourceChainBalance: AtLeast32BitUnsigned
49		+ Clone
50		+ Copy
51		+ Debug
52		+ PartialOrd
53		+ Sub<Output = Self::SourceChainBalance>
54		+ SaturatingAdd
55		+ Zero
56		+ Send
57		+ Sync;
58	/// Number of the source header.
59	type SourceHeaderNumber: BlockNumberBase;
60	/// Hash of the source header.
61	type SourceHeaderHash: Clone + Debug + Default + PartialEq + Send + Sync;
62
63	/// Number of the target header.
64	type TargetHeaderNumber: BlockNumberBase;
65	/// Hash of the target header.
66	type TargetHeaderHash: Clone + Debug + Default + PartialEq + Send + Sync;
67}
68
69/// Source header id within given one-way message lane.
70pub type SourceHeaderIdOf<P> =
71	HeaderId<<P as MessageLane>::SourceHeaderHash, <P as MessageLane>::SourceHeaderNumber>;
72
73/// Target header id within given one-way message lane.
74pub type TargetHeaderIdOf<P> =
75	HeaderId<<P as MessageLane>::TargetHeaderHash, <P as MessageLane>::TargetHeaderNumber>;