lnp/router/gossip/
util.rs

1// LNP/BP Core Library implementing LNPBP specifications & standards
2// Written in 2019 by
3//     Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
4//
5// To the extent possible under law, the author(s) have dedicated all
6// copyright and related and neighboring rights to this software to
7// the public domain worldwide. This software is distributed without
8// any warranty.
9//
10// You should have received a copy of the MIT License
11// along with this software.
12// If not, see <https://opensource.org/licenses/MIT>.
13
14use amplify::Slice32;
15use internet2::addr::NodeId;
16use p2p::bolt::{ChannelFeatures, ChannelId, ShortChannelId};
17
18#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
19#[derive(StrictEncode, StrictDecode)]
20pub struct DirectionalInfo {
21    /// Time stamp
22    pub timestamp: u32,
23
24    /// message flags
25    // TODO: Introduce a dedicated data type
26    pub message_flags: u8,
27
28    /// channel flags
29    // TODO: Introduce a dedicated data type
30    pub channel_flags: u8,
31
32    /// CLTV expiry delta
33    pub cltv_expiry_delta: u16,
34
35    /// minimum HTLC in msat
36    pub htlc_minimum_msat: u64,
37
38    /// base fee in msat
39    pub fee_base_msat: u32,
40
41    /// fee proportional millionth
42    pub fee_proportional_millionths: u32,
43
44    /// Used only if `option_channel_htlc_max` in `message_flags` is set
45    pub htlc_maximum_msat: u64,
46}
47
48/// Information about channel used for route construction and re-broadcasting
49/// gossip messages.
50#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug, Display)]
51#[derive(StrictEncode, StrictDecode)]
52#[display("{short_channel_id}")]
53pub struct GossipChannelInfo {
54    /// Node identities constituting channel
55    pub nodes: (NodeId, NodeId),
56
57    /// Chainhash
58    pub chain_hash: Slice32,
59
60    /// Short Channel Id
61    pub short_channel_id: ShortChannelId,
62
63    /// Information about each channel direction.
64    ///
65    /// The first tuple field corresponds to the direction from the first
66    /// node id (see [`GossipChannelInfo::nodes`]) to the second one – and the
67    /// second tuple field to the opposite direction.
68    pub directions: (Option<DirectionalInfo>, Option<DirectionalInfo>),
69
70    /// The channel capacity, known only for local channels - or if it can be
71    /// deduced from on-chain data, if they are available
72    pub capacity_sats: Option<u64>,
73
74    /// Channel features
75    pub features: ChannelFeatures,
76}
77
78/// Information about channel used for route construction and re-broadcasting
79/// gossip messages.
80#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug, Display)]
81#[derive(StrictEncode, StrictDecode)]
82#[display("{channel_id}@{remote_node}")]
83pub struct LocalChannelInfo {
84    /// Other node identity
85    pub remote_node: NodeId,
86
87    /// Full channel id
88    pub channel_id: ChannelId,
89
90    /// Short Channel Id
91    pub short_channel_id: ShortChannelId,
92
93    /// Chainhash
94    pub chain_hash: Slice32,
95
96    pub inbound_capacity_msat: u64,
97
98    pub outbound_capacity_msat: u64,
99
100    /// CLTV expiry delta
101    pub cltv_expiry: u16,
102
103    /// minimum HTLC in msat
104    pub htlc_minimum_msat: u64,
105
106    /// maximum HTLC in msat
107    pub htlc_maximum_msat: u64,
108}