Skip to content

Commit 6c569d8

Browse files
committed
Make NetworkGraph Clone-able again
There isn't a lot of user-utility for cloning `NetworkGraph` directly (its a rather large struct, and there probably isn't a lot of reason to have *multiple* `NetworkGraph`s). Thus, when locks were pushed down into it, the `Clone`-ability of it was dropped as well. Sadly, mapping the Java memory model onto: * `Read`-ing a `NetworkGraph`, creating a Java-owned `NetworkGraph` object that the JVM will destruct for us, * Passing it to a `NetGraphMsgHandler`, which now expects to own the `NetworkGraph`, including destructing it, isn't really practical without adding a clone in between. Given this, and the fact that there's nothing inherently wrong with clone-ing a `NetworkGraph`, we simply re-add `Clone` here.
1 parent 367a2cc commit 6c569d8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ pub struct NetworkGraph {
5858
nodes: RwLock<BTreeMap<PublicKey, NodeInfo>>,
5959
}
6060

61+
impl Clone for NetworkGraph {
62+
fn clone(&self) -> Self {
63+
let channels = self.channels.read().unwrap();
64+
let nodes = self.nodes.read().unwrap();
65+
Self {
66+
genesis_hash: self.genesis_hash.clone(),
67+
channels: RwLock::new(channels.clone()),
68+
nodes: RwLock::new(nodes.clone()),
69+
}
70+
}
71+
}
72+
6173
/// A read-only view of [`NetworkGraph`].
6274
pub struct ReadOnlyNetworkGraph<'a> {
6375
channels: RwLockReadGuard<'a, BTreeMap<u64, ChannelInfo>>,

0 commit comments

Comments
 (0)