Skip to content

Commit 650a468

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 1c73e56 commit 650a468

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,
@@ -1247,6 +1253,7 @@ mod tests {
12471253
announcement_message: None,
12481254
});
12491255
network.nodes.insert(node2.clone(), NodeInfo {
1256+
node_id: node2.clone(),
12501257
channels: vec!(NetworkMap::get_key(2, zero_hash.clone()), NetworkMap::get_key(4, zero_hash.clone())),
12511258
lowest_inbound_channel_fee_base_msat: 0,
12521259
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1282,6 +1289,7 @@ mod tests {
12821289
announcement_message: None,
12831290
});
12841291
network.nodes.insert(node8.clone(), NodeInfo {
1292+
node_id: node8.clone(),
12851293
channels: vec!(NetworkMap::get_key(12, zero_hash.clone()), NetworkMap::get_key(13, zero_hash.clone())),
12861294
lowest_inbound_channel_fee_base_msat: 0,
12871295
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1317,6 +1325,7 @@ mod tests {
13171325
announcement_message: None,
13181326
});
13191327
network.nodes.insert(node3.clone(), NodeInfo {
1328+
node_id: node3.clone(),
13201329
channels: vec!(
13211330
NetworkMap::get_key(3, zero_hash.clone()),
13221331
NetworkMap::get_key(4, zero_hash.clone()),
@@ -1406,6 +1415,7 @@ mod tests {
14061415
announcement_message: None,
14071416
});
14081417
network.nodes.insert(node4.clone(), NodeInfo {
1418+
node_id: node4.clone(),
14091419
channels: vec!(NetworkMap::get_key(5, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
14101420
lowest_inbound_channel_fee_base_msat: 0,
14111421
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1441,6 +1451,7 @@ mod tests {
14411451
announcement_message: None,
14421452
});
14431453
network.nodes.insert(node5.clone(), NodeInfo {
1454+
node_id: node5.clone(),
14441455
channels: vec!(NetworkMap::get_key(6, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
14451456
lowest_inbound_channel_fee_base_msat: 0,
14461457
lowest_inbound_channel_fee_proportional_millionths: 0,
@@ -1500,6 +1511,7 @@ mod tests {
15001511
announcement_message: None,
15011512
});
15021513
network.nodes.insert(node6.clone(), NodeInfo {
1514+
node_id: node6.clone(),
15031515
channels: vec!(NetworkMap::get_key(7, zero_hash.clone())),
15041516
lowest_inbound_channel_fee_base_msat: 0,
15051517
lowest_inbound_channel_fee_proportional_millionths: 0,

0 commit comments

Comments
 (0)