@@ -28,7 +28,7 @@ use std;
28
28
pub struct NetGraphMsgHandler {
29
29
secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
30
30
/// Representation of the payment channel network
31
- pub network_map : RwLock < NetworkMap > ,
31
+ pub network_graph : RwLock < NetworkGraph > ,
32
32
chain_monitor : Arc < ChainWatchInterface > ,
33
33
full_syncs_requested : AtomicUsize ,
34
34
logger : Arc < Logger > ,
@@ -50,7 +50,7 @@ impl NetGraphMsgHandler {
50
50
} ) ;
51
51
NetGraphMsgHandler {
52
52
secp_ctx : Secp256k1 :: verification_only ( ) ,
53
- network_map : RwLock :: new ( NetworkMap {
53
+ network_graph : RwLock :: new ( NetworkGraph {
54
54
channels : BTreeMap :: new ( ) ,
55
55
nodes : nodes,
56
56
} ) ,
@@ -62,7 +62,7 @@ impl NetGraphMsgHandler {
62
62
63
63
/// Get network addresses by node id
64
64
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 ( ) ;
66
66
network. get_nodes ( ) . get ( pubkey) . map ( |n| n. addresses . clone ( ) )
67
67
}
68
68
@@ -71,7 +71,7 @@ impl NetGraphMsgHandler {
71
71
( $node_id: expr) => {
72
72
if let BtreeEntry :: Occupied ( mut entry) = nodes. entry( $node_id) {
73
73
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)
75
75
} ) ;
76
76
if entry. get( ) . channels. is_empty( ) {
77
77
entry. remove_entry( ) ;
@@ -98,7 +98,7 @@ impl NetGraphMsgHandler {
98
98
/// Dumps the entire network view of this NetGraphMsgHandler to the logger provided in the constructor at
99
99
/// level Trace
100
100
pub fn trace_state ( & self ) {
101
- log_trace ! ( self , "{}" , self . network_map . read( ) . unwrap( ) ) ;
101
+ log_trace ! ( self , "{}" , self . network_graph . read( ) . unwrap( ) ) ;
102
102
}
103
103
104
104
}
@@ -112,7 +112,7 @@ impl Writeable for NetGraphMsgHandler {
112
112
writer. write_all ( & [ SERIALIZATION_VERSION ; 1 ] ) ?;
113
113
writer. write_all ( & [ MIN_SERIALIZATION_VERSION ; 1 ] ) ?;
114
114
115
- let network = self . network_map . read ( ) . unwrap ( ) ;
115
+ let network = self . network_graph . read ( ) . unwrap ( ) ;
116
116
network. write ( writer) ?;
117
117
Ok ( ( ) )
118
118
}
@@ -139,10 +139,10 @@ impl ReadableArgs<NetGraphMsgHandlerReadArgs> for NetGraphMsgHandler {
139
139
if min_ver > SERIALIZATION_VERSION {
140
140
return Err ( DecodeError :: UnknownVersion ) ;
141
141
}
142
- let network_map = Readable :: read ( reader) ?;
142
+ let network_graph = Readable :: read ( reader) ?;
143
143
Ok ( NetGraphMsgHandler {
144
144
secp_ctx : Secp256k1 :: verification_only ( ) ,
145
- network_map : RwLock :: new ( network_map ) ,
145
+ network_graph : RwLock :: new ( network_graph ) ,
146
146
chain_monitor : args. chain_monitor ,
147
147
full_syncs_requested : AtomicUsize :: new ( 0 ) ,
148
148
logger : args. logger . clone ( ) ,
@@ -347,13 +347,13 @@ impl Readable for NodeInfo {
347
347
348
348
/// Represents the network as nodes and channels between them
349
349
#[ derive( PartialEq ) ]
350
- pub struct NetworkMap {
350
+ pub struct NetworkGraph {
351
351
channels : BTreeMap < u64 , ChannelInfo > ,
352
352
/// A set of known Lightning nodes and their properties
353
353
nodes : BTreeMap < PublicKey , NodeInfo > ,
354
354
}
355
355
356
- impl NetworkMap {
356
+ impl NetworkGraph {
357
357
/// Returns a list of known valid channels
358
358
pub fn get_channels < ' a > ( & ' a self ) -> & ' a BTreeMap < u64 , ChannelInfo > { & self . channels }
359
359
/// Returns a mutable reference to an existing channel
@@ -372,7 +372,7 @@ impl NetworkMap {
372
372
}
373
373
}
374
374
375
- impl Writeable for NetworkMap {
375
+ impl Writeable for NetworkGraph {
376
376
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
377
377
( self . channels . len ( ) as u64 ) . write ( writer) ?;
378
378
for ( ref chan_id, ref chan_info) in self . channels . iter ( ) {
@@ -388,8 +388,8 @@ impl Writeable for NetworkMap {
388
388
}
389
389
}
390
390
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 > {
393
393
let channels_count: u64 = Readable :: read ( reader) ?;
394
394
let mut channels = BTreeMap :: new ( ) ;
395
395
for _ in 0 ..channels_count {
@@ -404,14 +404,14 @@ impl Readable for NetworkMap {
404
404
let node_info = Readable :: read ( reader) ?;
405
405
nodes. insert ( node_id, node_info) ;
406
406
}
407
- Ok ( NetworkMap {
407
+ Ok ( NetworkGraph {
408
408
channels,
409
409
nodes,
410
410
} )
411
411
}
412
412
}
413
413
414
- impl std:: fmt:: Display for NetworkMap {
414
+ impl std:: fmt:: Display for NetworkGraph {
415
415
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> Result < ( ) , std:: fmt:: Error > {
416
416
write ! ( f, "Network map\n [Channels]\n " ) ?;
417
417
for ( key, val) in self . channels . iter ( ) {
@@ -425,7 +425,7 @@ impl std::fmt::Display for NetworkMap {
425
425
}
426
426
}
427
427
428
- impl NetworkMap {
428
+ impl NetworkGraph {
429
429
#[ inline]
430
430
/// Key used to link channel on the Bitcoin chain to other entities
431
431
pub fn get_key ( short_channel_id : u64 , _: Sha256dHash ) -> u64 {
@@ -445,7 +445,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
445
445
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
446
446
secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id) ;
447
447
448
- let mut network = self . network_map . write ( ) . unwrap ( ) ;
448
+ let mut network = self . network_graph . write ( ) . unwrap ( ) ;
449
449
match network. get_node_mut ( & msg. contents . node_id ) {
450
450
None => Err ( LightningError { err : "No existing channels for node_announcement" , action : ErrorAction :: IgnoreError } ) ,
451
451
Some ( node) => {
@@ -506,7 +506,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
506
506
} ,
507
507
} ;
508
508
509
- let mut network_lock = self . network_map . write ( ) . unwrap ( ) ;
509
+ let mut network_lock = self . network_graph . write ( ) . unwrap ( ) ;
510
510
let network = & mut * network_lock;
511
511
512
512
let should_relay = msg. contents . excess_data . is_empty ( ) ;
@@ -540,7 +540,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
540
540
announcement_message : if should_relay { Some ( msg. clone ( ) ) } else { None } ,
541
541
} ;
542
542
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 ) ) {
544
544
BtreeEntry :: Occupied ( mut entry) => {
545
545
//TODO: because asking the blockchain if short_channel_id is valid is only optional
546
546
//in the blockchain API, we need to handle it smartly here, though it's unclear
@@ -569,11 +569,11 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
569
569
( $node_id: expr ) => {
570
570
match network. nodes. entry( $node_id) {
571
571
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) ) ;
573
573
} ,
574
574
BtreeEntry :: Vacant ( node_entry) => {
575
575
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) ) ,
577
577
lowest_inbound_channel_fees: None ,
578
578
features: NodeFeatures :: empty( ) ,
579
579
last_update: None ,
@@ -600,7 +600,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
600
600
let _ = self . handle_channel_update ( msg) ;
601
601
} ,
602
602
& 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 ( ) ;
604
604
if * is_permanent {
605
605
if let Some ( chan) = network. channels . remove ( short_channel_id) {
606
606
Self :: remove_channel_in_nodes ( & mut network. nodes , & chan, * short_channel_id) ;
@@ -623,12 +623,12 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
623
623
}
624
624
625
625
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 ( ) ;
627
627
let dest_node_id;
628
628
let chan_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
629
629
let chan_was_enabled;
630
630
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 ) ) {
632
632
None => return Err ( LightningError { err : "Couldn't find channel for update" , action : ErrorAction :: IgnoreError } ) ,
633
633
Some ( channel) => {
634
634
macro_rules! maybe_update_channel_info {
@@ -709,7 +709,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
709
709
710
710
fn get_next_channel_announcements ( & self , starting_point : u64 , batch_amount : u8 ) -> Vec < ( msgs:: ChannelAnnouncement , Option < msgs:: ChannelUpdate > , Option < msgs:: ChannelUpdate > ) > {
711
711
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 ( ) ;
713
713
let mut iter = network. channels . range ( starting_point..) ;
714
714
while result. len ( ) < batch_amount as usize {
715
715
if let Some ( ( _, ref chan) ) = iter. next ( ) {
@@ -730,7 +730,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
730
730
731
731
fn get_next_node_announcements ( & self , starting_point : Option < & PublicKey > , batch_amount : u8 ) -> Vec < msgs:: NodeAnnouncement > {
732
732
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 ( ) ;
734
734
let mut iter = if let Some ( pubkey) = starting_point {
735
735
let mut iter = network. nodes . range ( ( * pubkey) ..) ;
736
736
iter. next ( ) ;
@@ -767,7 +767,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
767
767
mod tests {
768
768
use chain:: chaininterface;
769
769
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 } ;
771
771
use ln:: msgs:: { RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
772
772
UnsignedChannelAnnouncement , ChannelAnnouncement , UnsignedChannelUpdate , ChannelUpdate , HTLCFailChannelUpdate } ;
773
773
use util:: test_utils;
@@ -952,7 +952,7 @@ mod tests {
952
952
excess_data : Vec :: new ( ) ,
953
953
} ;
954
954
955
- let channel_key = NetworkMap :: get_key ( unsigned_announcement. short_channel_id ,
955
+ let channel_key = NetworkGraph :: get_key ( unsigned_announcement. short_channel_id ,
956
956
unsigned_announcement. chain_hash ) ;
957
957
958
958
let mut msghash = hash_to_message ! ( & Sha256dHash :: hash( & unsigned_announcement. encode( ) [ ..] ) [ ..] ) ;
@@ -972,7 +972,7 @@ mod tests {
972
972
_ => panic ! ( )
973
973
} ;
974
974
{
975
- let network = net_graph_msg_handler. network_map . write ( ) . unwrap ( ) ;
975
+ let network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
976
976
match network. channels . get ( & channel_key) {
977
977
None => panic ! ( ) ,
978
978
Some ( _) => ( )
@@ -1009,7 +1009,7 @@ mod tests {
1009
1009
// Now test if the transaction is found in the UTXO set and the script is correct.
1010
1010
unsigned_announcement. short_channel_id += 1 ;
1011
1011
* 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 ,
1013
1013
unsigned_announcement. chain_hash ) ;
1014
1014
1015
1015
msghash = hash_to_message ! ( & Sha256dHash :: hash( & unsigned_announcement. encode( ) [ ..] ) [ ..] ) ;
@@ -1025,7 +1025,7 @@ mod tests {
1025
1025
_ => panic ! ( )
1026
1026
} ;
1027
1027
{
1028
- let network = net_graph_msg_handler. network_map . write ( ) . unwrap ( ) ;
1028
+ let network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
1029
1029
match network. channels . get ( & channel_key) {
1030
1030
None => panic ! ( ) ,
1031
1031
Some ( _) => ( )
@@ -1056,7 +1056,7 @@ mod tests {
1056
1056
_ => panic ! ( )
1057
1057
} ;
1058
1058
{
1059
- let mut network = net_graph_msg_handler. network_map . write ( ) . unwrap ( ) ;
1059
+ let mut network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
1060
1060
match network. channels . entry ( channel_key) {
1061
1061
BtreeEntry :: Occupied ( channel_entry) => {
1062
1062
assert_eq ! ( channel_entry. get( ) . features, ChannelFeatures :: empty( ) ) ;
@@ -1122,7 +1122,7 @@ mod tests {
1122
1122
let zero_hash = Sha256dHash :: hash ( & [ 0 ; 32 ] ) ;
1123
1123
let short_channel_id = 0 ;
1124
1124
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) ;
1126
1126
1127
1127
1128
1128
{
@@ -1176,7 +1176,7 @@ mod tests {
1176
1176
} ;
1177
1177
1178
1178
{
1179
- let network = net_graph_msg_handler. network_map . write ( ) . unwrap ( ) ;
1179
+ let network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
1180
1180
match network. channels . get ( & channel_key) {
1181
1181
None => panic ! ( ) ,
1182
1182
Some ( channel_info) => {
@@ -1253,11 +1253,11 @@ mod tests {
1253
1253
1254
1254
let short_channel_id = 0 ;
1255
1255
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) ;
1257
1257
1258
1258
{
1259
1259
// 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 ( ) ;
1261
1261
assert_eq ! ( network. nodes. len( ) , 1 ) ;
1262
1262
assert_eq ! ( network. nodes. contains_key( & our_id) , true ) ;
1263
1263
}
@@ -1299,7 +1299,7 @@ mod tests {
1299
1299
1300
1300
{
1301
1301
// 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 ( ) ;
1303
1303
match network. channels . get ( & channel_key) {
1304
1304
None => panic ! ( ) ,
1305
1305
Some ( channel_info) => {
@@ -1318,7 +1318,7 @@ mod tests {
1318
1318
1319
1319
{
1320
1320
// 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 ( ) ;
1322
1322
assert_eq ! ( network. channels. len( ) , 0 ) ;
1323
1323
// Nodes are also deleted because there are no associated channels anymore
1324
1324
// Only the local node remains in the table.
@@ -1341,7 +1341,7 @@ mod tests {
1341
1341
1342
1342
let short_channel_id = 1 ;
1343
1343
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) ;
1345
1345
1346
1346
// Channels were not announced yet.
1347
1347
let channels_with_announcements = net_graph_msg_handler. get_next_channel_announcements ( 0 , 1 ) ;
@@ -1580,12 +1580,12 @@ mod tests {
1580
1580
}
1581
1581
1582
1582
#[ test]
1583
- fn network_map_serialization ( ) {
1583
+ fn network_graph_serialization ( ) {
1584
1584
let ( secp_ctx, our_id, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1585
1585
let node1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1586
1586
let node1 = PublicKey :: from_secret_key ( & secp_ctx, node1_privkey) ;
1587
1587
1588
- let mut network = net_graph_msg_handler. network_map . write ( ) . unwrap ( ) ;
1588
+ let mut network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
1589
1589
let zero_hash = Sha256dHash :: hash ( & [ 0 ; 32 ] ) ;
1590
1590
1591
1591
@@ -1594,7 +1594,7 @@ mod tests {
1594
1594
proportional_millionths : 0 ,
1595
1595
} ;
1596
1596
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( ) ) ) ,
1598
1598
lowest_inbound_channel_fees : Some ( node_routing_fees) ,
1599
1599
features : NodeFeatures :: supported ( ) ,
1600
1600
last_update : Some ( 1 ) ,
@@ -1603,7 +1603,7 @@ mod tests {
1603
1603
addresses : Vec :: new ( ) ,
1604
1604
announcement_message : None ,
1605
1605
} ) ;
1606
- network. add_channel ( NetworkMap :: get_key ( 1 , zero_hash. clone ( ) ) , ChannelInfo {
1606
+ network. add_channel ( NetworkGraph :: get_key ( 1 , zero_hash. clone ( ) ) , ChannelInfo {
1607
1607
features : ChannelFeatures :: supported ( ) ,
1608
1608
one_to_two : DirectionalChannelInfo {
1609
1609
src_node_id : our_id. clone ( ) ,
@@ -1635,6 +1635,6 @@ mod tests {
1635
1635
assert ! ( !network. channels. is_empty( ) ) ;
1636
1636
assert ! ( !network. nodes. is_empty( ) ) ;
1637
1637
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) ;
1639
1639
}
1640
1640
}
0 commit comments