Skip to content

Commit 4bf6a8c

Browse files
committed
Reintroduce addresses to NodeAnnouncementInfo.
1 parent 1d452d0 commit 4bf6a8c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

lightning/src/routing/gossip.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ pub struct ChannelInfo {
872872
/// The timestamp when we received the announcement, if we are running with feature = "std"
873873
/// (which we can probably assume we are - no-std environments probably won't have a full
874874
/// network graph in memory!).
875-
announcement_received_time: u64,
875+
pub announcement_received_time: u64,
876876
}
877877

878878
impl ChannelInfo {
@@ -1143,32 +1143,35 @@ pub struct NodeAnnouncementInfo {
11431143
/// May be invalid or malicious (eg control chars),
11441144
/// should not be exposed to the user.
11451145
pub alias: NodeAlias,
1146+
1147+
/// Internet-level addresses via which one can connect to the node
1148+
pub addresses: Vec<SocketAddress>,
1149+
11461150
/// An initial announcement of the node
11471151
/// Mostly redundant with the data we store in fields explicitly.
11481152
/// Everything else is useful only for sending out for initial routing sync.
11491153
/// Not stored if contains excess data to prevent DoS.
1150-
pub announcement_message: Option<NodeAnnouncement>
1154+
pub announcement_message: Option<NodeAnnouncement>,
11511155
}
11521156

11531157
impl NodeAnnouncementInfo {
11541158
/// Internet-level addresses via which one can connect to the node
11551159
pub fn addresses(&self) -> &[SocketAddress] {
11561160
self.announcement_message.as_ref()
11571161
.map(|msg| msg.contents.addresses.as_slice())
1158-
.unwrap_or_default()
1162+
.unwrap_or(self.addresses.as_slice())
11591163
}
11601164
}
11611165

11621166
impl Writeable for NodeAnnouncementInfo {
11631167
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1164-
let empty_addresses = Vec::<SocketAddress>::new();
11651168
write_tlv_fields!(writer, {
11661169
(0, self.features, required),
11671170
(2, self.last_update, required),
11681171
(4, self.rgb, required),
11691172
(6, self.alias, required),
11701173
(8, self.announcement_message, option),
1171-
(10, empty_addresses, required_vec), // Versions prior to 0.0.115 require this field
1174+
(10, self.addresses, required_vec), // Versions prior to 0.0.115 require this field
11721175
});
11731176
Ok(())
11741177
}
@@ -1182,11 +1185,16 @@ impl Readable for NodeAnnouncementInfo {
11821185
(4, rgb, required),
11831186
(6, alias, required),
11841187
(8, announcement_message, option),
1185-
(10, _addresses, optional_vec), // deprecated, not used anymore
1188+
(10, addresses, optional_vec),
11861189
});
1187-
let _: Option<Vec<SocketAddress>> = _addresses;
1188-
Ok(Self { features: features.0.unwrap(), last_update: last_update.0.unwrap(), rgb: rgb.0.unwrap(),
1189-
alias: alias.0.unwrap(), announcement_message })
1190+
Ok(Self {
1191+
features: features.0.unwrap(),
1192+
last_update: last_update.0.unwrap(),
1193+
rgb: rgb.0.unwrap(),
1194+
alias: alias.0.unwrap(),
1195+
addresses: addresses.unwrap_or(Vec::new()),
1196+
announcement_message,
1197+
})
11901198
}
11911199
}
11921200

@@ -1504,6 +1512,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15041512
last_update: msg.timestamp,
15051513
rgb: msg.rgb,
15061514
alias: msg.alias,
1515+
addresses: msg.addresses.clone(),
15071516
announcement_message: if should_relay { full_msg.cloned() } else { None },
15081517
});
15091518

@@ -3453,6 +3462,7 @@ pub(crate) mod tests {
34533462
last_update: 0,
34543463
rgb: [0u8; 3],
34553464
alias: NodeAlias([0u8; 32]),
3465+
addresses: announcement_message.contents.addresses.clone(),
34563466
announcement_message: Some(announcement_message)
34573467
};
34583468

@@ -3487,8 +3497,8 @@ pub(crate) mod tests {
34873497
let old_ann_info_with_addresses = <Vec<u8>>::from_hex("3f0009000708a000080a51220204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014104d2").unwrap();
34883498
let ann_info_with_addresses = NodeAnnouncementInfo::read(&mut old_ann_info_with_addresses.as_slice())
34893499
.expect("to be able to read an old NodeAnnouncementInfo with addresses");
3490-
// This serialized info has an address field but no announcement_message, therefore the addresses returned by our function will still be empty
3491-
assert!(ann_info_with_addresses.addresses().is_empty());
3500+
// This serialized info has no announcement_message but its address field should still be considered
3501+
assert!(!ann_info_with_addresses.addresses().is_empty());
34923502
}
34933503

34943504
#[test]

0 commit comments

Comments
 (0)