Skip to content

Commit fbced22

Browse files
author
Antoine Riard
committed
Add node_id in NodeInfo
Next commit expose publicly structure to alow displaying network graph. Even if we already index by node_id in NetworkMap, an exposed identifier makes exposition more useful.
1 parent 728a609 commit fbced22

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/ln/router.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl_writeable!(ChannelInfo, 0, {
162162

163163
#[derive(PartialEq)]
164164
struct NodeInfo {
165+
node_id: PublicKey,
165166
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
166167
channels: Vec<(u64, Sha256dHash)>,
167168
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
@@ -216,6 +217,7 @@ const MAX_ALLOC_SIZE: u64 = 64*1024;
216217
impl Readable for NodeInfo {
217218
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NodeInfo, DecodeError> {
218219
let channels_count: u64 = Readable::read(reader)?;
220+
let node_id = Readable::read(reader)?;
219221
let mut channels = Vec::with_capacity(cmp::min(channels_count, MAX_ALLOC_SIZE / 8) as usize);
220222
for _ in 0..channels_count {
221223
channels.push(Readable::read(reader)?);
@@ -238,6 +240,7 @@ impl Readable for NodeInfo {
238240
}
239241
let announcement_message = Readable::read(reader)?;
240242
Ok(NodeInfo {
243+
node_id,
241244
channels,
242245
lowest_inbound_channel_fee_base_msat,
243246
lowest_inbound_channel_fee_proportional_millionths,
@@ -558,6 +561,7 @@ impl RoutingMessageHandler for Router {
558561
},
559562
BtreeEntry::Vacant(node_entry) => {
560563
node_entry.insert(NodeInfo {
564+
node_id: $node_id,
561565
channels: vec!(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)),
562566
lowest_inbound_channel_fee_base_msat: u32::max_value(),
563567
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
@@ -772,6 +776,7 @@ impl Router {
772776
pub fn new(our_pubkey: PublicKey, chain_monitor: Arc<ChainWatchInterface>, logger: Arc<Logger>) -> Router {
773777
let mut nodes = BTreeMap::new();
774778
nodes.insert(our_pubkey.clone(), NodeInfo {
779+
node_id: our_pubkey.clone(),
775780
channels: Vec::new(),
776781
lowest_inbound_channel_fee_base_msat: u32::max_value(),
777782
lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
@@ -1212,6 +1217,7 @@ mod tests {
12121217
let mut network = router.network_map.write().unwrap();
12131218

12141219
network.nodes.insert(node1.clone(), NodeInfo {
1220+
node_id: node1.clone(),
12151221
channels: vec!(NetworkMap::get_key(1, zero_hash.clone()), NetworkMap::get_key(3, zero_hash.clone())),
12161222
lowest_inbound_channel_fee_base_msat: 100,
12171223
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1246,6 +1252,7 @@ mod tests {
12461252
announcement_message: None,
12471253
});
12481254
network.nodes.insert(node2.clone(), NodeInfo {
1255+
node_id: node2.clone(),
12491256
channels: vec!(NetworkMap::get_key(2, zero_hash.clone()), NetworkMap::get_key(4, zero_hash.clone())),
12501257
lowest_inbound_channel_fee_base_msat: 0,
12511258
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1280,6 +1287,7 @@ mod tests {
12801287
announcement_message: None,
12811288
});
12821289
network.nodes.insert(node8.clone(), NodeInfo {
1290+
node_id: node8.clone(),
12831291
channels: vec!(NetworkMap::get_key(12, zero_hash.clone()), NetworkMap::get_key(13, zero_hash.clone())),
12841292
lowest_inbound_channel_fee_base_msat: 0,
12851293
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1314,6 +1322,7 @@ mod tests {
13141322
announcement_message: None,
13151323
});
13161324
network.nodes.insert(node3.clone(), NodeInfo {
1325+
node_id: node3.clone(),
13171326
channels: vec!(
13181327
NetworkMap::get_key(3, zero_hash.clone()),
13191328
NetworkMap::get_key(4, zero_hash.clone()),
@@ -1400,6 +1409,7 @@ mod tests {
14001409
announcement_message: None,
14011410
});
14021411
network.nodes.insert(node4.clone(), NodeInfo {
1412+
node_id: node4.clone(),
14031413
channels: vec!(NetworkMap::get_key(5, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
14041414
lowest_inbound_channel_fee_base_msat: 0,
14051415
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1434,6 +1444,7 @@ mod tests {
14341444
announcement_message: None,
14351445
});
14361446
network.nodes.insert(node5.clone(), NodeInfo {
1447+
node_id: node5.clone(),
14371448
channels: vec!(NetworkMap::get_key(6, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
14381449
lowest_inbound_channel_fee_base_msat: 0,
14391450
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1491,6 +1502,7 @@ mod tests {
14911502
announcement_message: None,
14921503
});
14931504
network.nodes.insert(node6.clone(), NodeInfo {
1505+
node_id: node6.clone(),
14941506
channels: vec!(NetworkMap::get_key(7, zero_hash.clone())),
14951507
lowest_inbound_channel_fee_base_msat: 0,
14961508
lowest_inbound_channel_fee_proportional_millionths: 0,

0 commit comments

Comments
 (0)