Skip to content

Commit 5b3ca02

Browse files
committed
Avoid references to primitives and add NetWorkGraph::new()
non-mut references to primitives are only excess overhead, so there's not much reason to ever have them. As a nice bonus, it also is one less thing to worry about when generating C bindings
1 parent e839712 commit 5b3ca02

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
125125
let _ = self.network_graph.write().unwrap().update_channel(msg, Some(&self.secp_ctx));
126126
},
127127
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => {
128-
self.network_graph.write().unwrap().close_channel_from_update(short_channel_id, &is_permanent);
128+
self.network_graph.write().unwrap().close_channel_from_update(*short_channel_id, *is_permanent);
129129
},
130130
&msgs::HTLCFailChannelUpdate::NodeFailure { ref node_id, ref is_permanent } => {
131-
self.network_graph.write().unwrap().fail_node(node_id, &is_permanent);
131+
self.network_graph.write().unwrap().fail_node(node_id, *is_permanent);
132132
},
133133
}
134134
}
@@ -505,6 +505,14 @@ impl NetworkGraph {
505505
None
506506
}
507507

508+
/// Creates a new, empty, network graph.
509+
pub fn new() -> NetworkGraph {
510+
Self {
511+
channels: BTreeMap::new(),
512+
nodes: BTreeMap::new(),
513+
}
514+
}
515+
508516
/// For an already known node (from channel announcements), update its stored properties from a given node announcement
509517
/// Announcement signatures are checked here only if Secp256k1 object is provided.
510518
fn update_node_from_announcement(&mut self, msg: &msgs::NodeAnnouncement, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {
@@ -615,10 +623,10 @@ impl NetworkGraph {
615623
/// If permanent, removes a channel from the local storage.
616624
/// May cause the removal of nodes too, if this was their last channel.
617625
/// If not permanent, makes channels unavailable for routing.
618-
pub fn close_channel_from_update(&mut self, short_channel_id: &u64, is_permanent: &bool) {
619-
if *is_permanent {
620-
if let Some(chan) = self.channels.remove(short_channel_id) {
621-
Self::remove_channel_in_nodes(&mut self.nodes, &chan, *short_channel_id);
626+
pub fn close_channel_from_update(&mut self, short_channel_id: u64, is_permanent: bool) {
627+
if is_permanent {
628+
if let Some(chan) = self.channels.remove(&short_channel_id) {
629+
Self::remove_channel_in_nodes(&mut self.nodes, &chan, short_channel_id);
622630
}
623631
} else {
624632
if let Some(chan) = self.channels.get_mut(&short_channel_id) {
@@ -632,8 +640,8 @@ impl NetworkGraph {
632640
}
633641
}
634642

635-
fn fail_node(&mut self, _node_id: &PublicKey, is_permanent: &bool) {
636-
if *is_permanent {
643+
fn fail_node(&mut self, _node_id: &PublicKey, is_permanent: bool) {
644+
if is_permanent {
637645
// TODO: Wholly remove the node
638646
} else {
639647
// TODO: downgrade the node

0 commit comments

Comments
 (0)