Add a new `NodeCounters` utility to track counters when routing
[rust-lightning] / lightning / src / routing / gossip.rs
index 335876572a008ab0ab348f7e02d69851f1a6899e..f7fbff677b98b34d6040e08bd67a5bda21eac47c 100644 (file)
@@ -204,6 +204,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
@@ -1505,6 +1506,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),
                }
        }
 
@@ -2194,6 +2196,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)]