Skip to content

Commit e7a0eb7

Browse files
committed
Rename NetworkMap in NetworkGraph
1 parent a41ad7b commit e7a0eb7

File tree

2 files changed

+77
-77
lines changed

2 files changed

+77
-77
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std;
2828
pub struct NetGraphMsgHandler {
2929
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
3030
/// Representation of the payment channel network
31-
pub network_map: RwLock<NetworkMap>,
31+
pub network_graph: RwLock<NetworkGraph>,
3232
chain_monitor: Arc<ChainWatchInterface>,
3333
full_syncs_requested: AtomicUsize,
3434
logger: Arc<Logger>,
@@ -50,7 +50,7 @@ impl NetGraphMsgHandler {
5050
});
5151
NetGraphMsgHandler {
5252
secp_ctx: Secp256k1::verification_only(),
53-
network_map: RwLock::new(NetworkMap {
53+
network_graph: RwLock::new(NetworkGraph {
5454
channels: BTreeMap::new(),
5555
nodes: nodes,
5656
}),
@@ -62,7 +62,7 @@ impl NetGraphMsgHandler {
6262

6363
/// Get network addresses by node id
6464
pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
65-
let network = self.network_map.read().unwrap();
65+
let network = self.network_graph.read().unwrap();
6666
network.get_nodes().get(pubkey).map(|n| n.addresses.clone())
6767
}
6868

@@ -71,7 +71,7 @@ impl NetGraphMsgHandler {
7171
($node_id: expr) => {
7272
if let BtreeEntry::Occupied(mut entry) = nodes.entry($node_id) {
7373
entry.get_mut().channels.retain(|chan_id| {
74-
short_channel_id != *NetworkMap::get_short_id(chan_id)
74+
short_channel_id != *NetworkGraph::get_short_id(chan_id)
7575
});
7676
if entry.get().channels.is_empty() {
7777
entry.remove_entry();
@@ -98,7 +98,7 @@ impl NetGraphMsgHandler {
9898
/// Dumps the entire network view of this NetGraphMsgHandler to the logger provided in the constructor at
9999
/// level Trace
100100
pub fn trace_state(&self) {
101-
log_trace!(self, "{}", self.network_map.read().unwrap());
101+
log_trace!(self, "{}", self.network_graph.read().unwrap());
102102
}
103103

104104
}
@@ -112,7 +112,7 @@ impl Writeable for NetGraphMsgHandler {
112112
writer.write_all(&[SERIALIZATION_VERSION; 1])?;
113113
writer.write_all(&[MIN_SERIALIZATION_VERSION; 1])?;
114114

115-
let network = self.network_map.read().unwrap();
115+
let network = self.network_graph.read().unwrap();
116116
network.write(writer)?;
117117
Ok(())
118118
}
@@ -139,10 +139,10 @@ impl ReadableArgs<NetGraphMsgHandlerReadArgs> for NetGraphMsgHandler {
139139
if min_ver > SERIALIZATION_VERSION {
140140
return Err(DecodeError::UnknownVersion);
141141
}
142-
let network_map = Readable::read(reader)?;
142+
let network_graph = Readable::read(reader)?;
143143
Ok(NetGraphMsgHandler {
144144
secp_ctx: Secp256k1::verification_only(),
145-
network_map: RwLock::new(network_map),
145+
network_graph: RwLock::new(network_graph),
146146
chain_monitor: args.chain_monitor,
147147
full_syncs_requested: AtomicUsize::new(0),
148148
logger: args.logger.clone(),
@@ -347,13 +347,13 @@ impl Readable for NodeInfo {
347347

348348
/// Represents the network as nodes and channels between them
349349
#[derive(PartialEq)]
350-
pub struct NetworkMap {
350+
pub struct NetworkGraph {
351351
channels: BTreeMap<u64, ChannelInfo>,
352352
/// A set of known Lightning nodes and their properties
353353
nodes: BTreeMap<PublicKey, NodeInfo>,
354354
}
355355

356-
impl NetworkMap {
356+
impl NetworkGraph {
357357
/// Returns a list of known valid channels
358358
pub fn get_channels<'a>(&'a self) -> &'a BTreeMap<u64, ChannelInfo> { &self.channels }
359359
/// Returns a mutable reference to an existing channel
@@ -372,7 +372,7 @@ impl NetworkMap {
372372
}
373373
}
374374

375-
impl Writeable for NetworkMap {
375+
impl Writeable for NetworkGraph {
376376
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
377377
(self.channels.len() as u64).write(writer)?;
378378
for (ref chan_id, ref chan_info) in self.channels.iter() {
@@ -388,8 +388,8 @@ impl Writeable for NetworkMap {
388388
}
389389
}
390390

391-
impl Readable for NetworkMap {
392-
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NetworkMap, DecodeError> {
391+
impl Readable for NetworkGraph {
392+
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError> {
393393
let channels_count: u64 = Readable::read(reader)?;
394394
let mut channels = BTreeMap::new();
395395
for _ in 0..channels_count {
@@ -404,14 +404,14 @@ impl Readable for NetworkMap {
404404
let node_info = Readable::read(reader)?;
405405
nodes.insert(node_id, node_info);
406406
}
407-
Ok(NetworkMap {
407+
Ok(NetworkGraph {
408408
channels,
409409
nodes,
410410
})
411411
}
412412
}
413413

414-
impl std::fmt::Display for NetworkMap {
414+
impl std::fmt::Display for NetworkGraph {
415415
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
416416
write!(f, "Network map\n[Channels]\n")?;
417417
for (key, val) in self.channels.iter() {
@@ -425,7 +425,7 @@ impl std::fmt::Display for NetworkMap {
425425
}
426426
}
427427

428-
impl NetworkMap {
428+
impl NetworkGraph {
429429
#[inline]
430430
/// Key used to link channel on the Bitcoin chain to other entities
431431
pub fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 {
@@ -445,7 +445,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
445445
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
446446
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id);
447447

448-
let mut network = self.network_map.write().unwrap();
448+
let mut network = self.network_graph.write().unwrap();
449449
match network.get_node_mut(&msg.contents.node_id) {
450450
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
451451
Some(node) => {
@@ -506,7 +506,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
506506
},
507507
};
508508

509-
let mut network_lock = self.network_map.write().unwrap();
509+
let mut network_lock = self.network_graph.write().unwrap();
510510
let network = &mut *network_lock;
511511

512512
let should_relay = msg.contents.excess_data.is_empty();
@@ -540,7 +540,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
540540
announcement_message: if should_relay { Some(msg.clone()) } else { None },
541541
};
542542

543-
match network.channels.entry(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
543+
match network.channels.entry(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
544544
BtreeEntry::Occupied(mut entry) => {
545545
//TODO: because asking the blockchain if short_channel_id is valid is only optional
546546
//in the blockchain API, we need to handle it smartly here, though it's unclear
@@ -569,11 +569,11 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
569569
( $node_id: expr ) => {
570570
match network.nodes.entry($node_id) {
571571
BtreeEntry::Occupied(node_entry) => {
572-
node_entry.into_mut().channels.push(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash));
572+
node_entry.into_mut().channels.push(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash));
573573
},
574574
BtreeEntry::Vacant(node_entry) => {
575575
node_entry.insert(NodeInfo {
576-
channels: vec!(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)),
576+
channels: vec!(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)),
577577
lowest_inbound_channel_fees: None,
578578
features: NodeFeatures::empty(),
579579
last_update: None,
@@ -600,7 +600,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
600600
let _ = self.handle_channel_update(msg);
601601
},
602602
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => {
603-
let mut network = self.network_map.write().unwrap();
603+
let mut network = self.network_graph.write().unwrap();
604604
if *is_permanent {
605605
if let Some(chan) = network.channels.remove(short_channel_id) {
606606
Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id);
@@ -623,12 +623,12 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
623623
}
624624

625625
fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> {
626-
let mut network = self.network_map.write().unwrap();
626+
let mut network = self.network_graph.write().unwrap();
627627
let dest_node_id;
628628
let chan_enabled = msg.contents.flags & (1 << 1) != (1 << 1);
629629
let chan_was_enabled;
630630

631-
match network.get_channel_mut(&NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
631+
match network.get_channel_mut(&NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
632632
None => return Err(LightningError{err: "Couldn't find channel for update", action: ErrorAction::IgnoreError}),
633633
Some(channel) => {
634634
macro_rules! maybe_update_channel_info {
@@ -709,7 +709,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
709709

710710
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
711711
let mut result = Vec::with_capacity(batch_amount as usize);
712-
let network = self.network_map.read().unwrap();
712+
let network = self.network_graph.read().unwrap();
713713
let mut iter = network.channels.range(starting_point..);
714714
while result.len() < batch_amount as usize {
715715
if let Some((_, ref chan)) = iter.next() {
@@ -730,7 +730,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
730730

731731
fn get_next_node_announcements(&self, starting_point: Option<&PublicKey>, batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {
732732
let mut result = Vec::with_capacity(batch_amount as usize);
733-
let network = self.network_map.read().unwrap();
733+
let network = self.network_graph.read().unwrap();
734734
let mut iter = if let Some(pubkey) = starting_point {
735735
let mut iter = network.nodes.range((*pubkey)..);
736736
iter.next();
@@ -767,7 +767,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
767767
mod tests {
768768
use chain::chaininterface;
769769
use ln::features::{ChannelFeatures, NodeFeatures};
770-
use routing::network_graph::{NetGraphMsgHandler, NetworkMap, DirectionalChannelInfo, ChannelInfo, NodeInfo, RoutingFees};
770+
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph, DirectionalChannelInfo, ChannelInfo, NodeInfo, RoutingFees};
771771
use ln::msgs::{RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement,
772772
UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, HTLCFailChannelUpdate};
773773
use util::test_utils;
@@ -952,7 +952,7 @@ mod tests {
952952
excess_data: Vec::new(),
953953
};
954954

955-
let channel_key = NetworkMap::get_key(unsigned_announcement.short_channel_id,
955+
let channel_key = NetworkGraph::get_key(unsigned_announcement.short_channel_id,
956956
unsigned_announcement.chain_hash);
957957

958958
let mut msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
@@ -972,7 +972,7 @@ mod tests {
972972
_ => panic!()
973973
};
974974
{
975-
let network = net_graph_msg_handler.network_map.write().unwrap();
975+
let network = net_graph_msg_handler.network_graph.write().unwrap();
976976
match network.channels.get(&channel_key) {
977977
None => panic!(),
978978
Some(_) => ()
@@ -1009,7 +1009,7 @@ mod tests {
10091009
// Now test if the transaction is found in the UTXO set and the script is correct.
10101010
unsigned_announcement.short_channel_id += 1;
10111011
*chain_monitor.utxo_ret.lock().unwrap() = Ok((good_script.clone(), 0));
1012-
let channel_key = NetworkMap::get_key(unsigned_announcement.short_channel_id,
1012+
let channel_key = NetworkGraph::get_key(unsigned_announcement.short_channel_id,
10131013
unsigned_announcement.chain_hash);
10141014

10151015
msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
@@ -1025,7 +1025,7 @@ mod tests {
10251025
_ => panic!()
10261026
};
10271027
{
1028-
let network = net_graph_msg_handler.network_map.write().unwrap();
1028+
let network = net_graph_msg_handler.network_graph.write().unwrap();
10291029
match network.channels.get(&channel_key) {
10301030
None => panic!(),
10311031
Some(_) => ()
@@ -1056,7 +1056,7 @@ mod tests {
10561056
_ => panic!()
10571057
};
10581058
{
1059-
let mut network = net_graph_msg_handler.network_map.write().unwrap();
1059+
let mut network = net_graph_msg_handler.network_graph.write().unwrap();
10601060
match network.channels.entry(channel_key) {
10611061
BtreeEntry::Occupied(channel_entry) => {
10621062
assert_eq!(channel_entry.get().features, ChannelFeatures::empty());
@@ -1122,7 +1122,7 @@ mod tests {
11221122
let zero_hash = Sha256dHash::hash(&[0; 32]);
11231123
let short_channel_id = 0;
11241124
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1125-
let channel_key = NetworkMap::get_key(short_channel_id, chain_hash);
1125+
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
11261126

11271127

11281128
{
@@ -1176,7 +1176,7 @@ mod tests {
11761176
};
11771177

11781178
{
1179-
let network = net_graph_msg_handler.network_map.write().unwrap();
1179+
let network = net_graph_msg_handler.network_graph.write().unwrap();
11801180
match network.channels.get(&channel_key) {
11811181
None => panic!(),
11821182
Some(channel_info) => {
@@ -1253,11 +1253,11 @@ mod tests {
12531253

12541254
let short_channel_id = 0;
12551255
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1256-
let channel_key = NetworkMap::get_key(short_channel_id, chain_hash);
1256+
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
12571257

12581258
{
12591259
// There is only local node in the table at the beginning.
1260-
let network = net_graph_msg_handler.network_map.read().unwrap();
1260+
let network = net_graph_msg_handler.network_graph.read().unwrap();
12611261
assert_eq!(network.nodes.len(), 1);
12621262
assert_eq!(network.nodes.contains_key(&our_id), true);
12631263
}
@@ -1299,7 +1299,7 @@ mod tests {
12991299

13001300
{
13011301
// Non-permanent closing just disables a channel
1302-
let network = net_graph_msg_handler.network_map.write().unwrap();
1302+
let network = net_graph_msg_handler.network_graph.write().unwrap();
13031303
match network.channels.get(&channel_key) {
13041304
None => panic!(),
13051305
Some(channel_info) => {
@@ -1318,7 +1318,7 @@ mod tests {
13181318

13191319
{
13201320
// Permanent closing deletes a channel
1321-
let network = net_graph_msg_handler.network_map.read().unwrap();
1321+
let network = net_graph_msg_handler.network_graph.read().unwrap();
13221322
assert_eq!(network.channels.len(), 0);
13231323
// Nodes are also deleted because there are no associated channels anymore
13241324
// Only the local node remains in the table.
@@ -1341,7 +1341,7 @@ mod tests {
13411341

13421342
let short_channel_id = 1;
13431343
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1344-
let channel_key = NetworkMap::get_key(short_channel_id, chain_hash);
1344+
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
13451345

13461346
// Channels were not announced yet.
13471347
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(0, 1);
@@ -1580,12 +1580,12 @@ mod tests {
15801580
}
15811581

15821582
#[test]
1583-
fn network_map_serialization() {
1583+
fn network_graph_serialization() {
15841584
let (secp_ctx, our_id, net_graph_msg_handler) = create_net_graph_msg_handler();
15851585
let node1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
15861586
let node1 = PublicKey::from_secret_key(&secp_ctx, node1_privkey);
15871587

1588-
let mut network = net_graph_msg_handler.network_map.write().unwrap();
1588+
let mut network = net_graph_msg_handler.network_graph.write().unwrap();
15891589
let zero_hash = Sha256dHash::hash(&[0; 32]);
15901590

15911591

@@ -1594,7 +1594,7 @@ mod tests {
15941594
proportional_millionths: 0,
15951595
};
15961596
network.add_node(node1.clone(), NodeInfo {
1597-
channels: vec!(NetworkMap::get_key(1, zero_hash.clone()), NetworkMap::get_key(3, zero_hash.clone())),
1597+
channels: vec!(NetworkGraph::get_key(1, zero_hash.clone()), NetworkGraph::get_key(3, zero_hash.clone())),
15981598
lowest_inbound_channel_fees: Some(node_routing_fees),
15991599
features: NodeFeatures::supported(),
16001600
last_update: Some(1),
@@ -1603,7 +1603,7 @@ mod tests {
16031603
addresses: Vec::new(),
16041604
announcement_message: None,
16051605
});
1606-
network.add_channel(NetworkMap::get_key(1, zero_hash.clone()), ChannelInfo {
1606+
network.add_channel(NetworkGraph::get_key(1, zero_hash.clone()), ChannelInfo {
16071607
features: ChannelFeatures::supported(),
16081608
one_to_two: DirectionalChannelInfo {
16091609
src_node_id: our_id.clone(),
@@ -1635,6 +1635,6 @@ mod tests {
16351635
assert!(!network.channels.is_empty());
16361636
assert!(!network.nodes.is_empty());
16371637
network.write(&mut w).unwrap();
1638-
assert!(<NetworkMap>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap() == *network);
1638+
assert!(<NetworkGraph>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap() == *network);
16391639
}
16401640
}

0 commit comments

Comments
 (0)