Drop the `dist` `HashMap` in routing, replacing it with a `Vec`.
[rust-lightning] / lightning / src / routing / gossip.rs
index e5be0dfbfc6e29b8e19bb6f28c1b37603c4b2c1d..c820b4741bc5c2a35d902d339e07d0ff0e195cd6 100644 (file)
@@ -194,6 +194,7 @@ pub struct NetworkGraph<L: Deref> where L::Target: Logger {
 pub struct ReadOnlyNetworkGraph<'a> {
        channels: RwLockReadGuard<'a, IndexedMap<u64, ChannelInfo>>,
        nodes: RwLockReadGuard<'a, IndexedMap<NodeId, NodeInfo>>,
+       max_node_counter: u32,
 }
 
 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
@@ -1052,6 +1053,14 @@ impl<'a> DirectedChannelInfo<'a> {
        /// Refers to the `node_id` receiving the payment from the previous hop.
        #[inline]
        pub(super) fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
+
+       /// Returns the source node's counter
+       #[inline]
+       pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
+
+       /// Returns the target node's counter
+       #[inline]
+       pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
 }
 
 impl<'a> fmt::Debug for DirectedChannelInfo<'a> {
@@ -1483,6 +1492,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
                ReadOnlyNetworkGraph {
                        channels,
                        nodes,
+                       max_node_counter: (self.next_node_counter.load(Ordering::Acquire) as u32).saturating_sub(1),
                }
        }
 
@@ -2169,6 +2179,11 @@ impl ReadOnlyNetworkGraph<'_> {
                self.nodes.get(&NodeId::from_pubkey(&pubkey))
                        .and_then(|node| node.announcement_info.as_ref().map(|ann| ann.addresses().to_vec()))
        }
+
+       /// Gets the maximum possible node_counter for a node in this graph
+       pub(crate) fn max_node_counter(&self) -> u32 {
+               self.max_node_counter
+       }
 }
 
 #[cfg(test)]