Skip to content

Commit 74ee9ea

Browse files
committed
Allow more than one address per type in node_announcement messages
lnd has been blatantly ignoring this line in the spec forever, so its somewhat of a lost cause trying to enforce it.
1 parent 918abca commit 74ee9ea

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

fuzz/src/router.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ pub fn do_test(data: &[u8]) {
124124
msgs::DecodeError::UnknownVersion => return,
125125
msgs::DecodeError::UnknownRequiredFeature => return,
126126
msgs::DecodeError::InvalidValue => return,
127-
msgs::DecodeError::ExtraAddressesPerType => return,
128127
msgs::DecodeError::BadLengthDescriptor => return,
129128
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
130129
msgs::DecodeError::Io(e) => panic!(format!("{}", e)),

lightning/src/ln/msgs.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ pub enum DecodeError {
4747
InvalidValue,
4848
/// Buffer too short
4949
ShortRead,
50-
/// node_announcement included more than one address of a given type!
51-
ExtraAddressesPerType,
5250
/// A length descriptor in the packet didn't describe the later data correctly
5351
BadLengthDescriptor,
5452
/// Error from std::io
@@ -677,7 +675,6 @@ impl Error for DecodeError {
677675
DecodeError::UnknownRequiredFeature => "Unknown required feature preventing decode",
678676
DecodeError::InvalidValue => "Nonsense bytes didn't map to the type they were interpreted as",
679677
DecodeError::ShortRead => "Packet extended beyond the provided bytes",
680-
DecodeError::ExtraAddressesPerType => "More than one address of a single type",
681678
DecodeError::BadLengthDescriptor => "A length descriptor in the packet didn't describe the later data correctly",
682679
DecodeError::Io(ref e) => e.description(),
683680
}
@@ -1235,36 +1232,20 @@ impl Readable for UnsignedNodeAnnouncement {
12351232
let alias: [u8; 32] = Readable::read(r)?;
12361233

12371234
let addr_len: u16 = Readable::read(r)?;
1238-
let mut addresses: Vec<NetAddress> = Vec::with_capacity(4);
1235+
let mut addresses: Vec<NetAddress> = Vec::new();
1236+
let mut highest_addr_type = 0;
12391237
let mut addr_readpos = 0;
12401238
let mut excess = false;
12411239
let mut excess_byte = 0;
12421240
loop {
12431241
if addr_len <= addr_readpos { break; }
12441242
match Readable::read(r) {
12451243
Ok(Ok(addr)) => {
1246-
match addr {
1247-
NetAddress::IPv4 { .. } => {
1248-
if addresses.len() > 0 {
1249-
return Err(DecodeError::ExtraAddressesPerType);
1250-
}
1251-
},
1252-
NetAddress::IPv6 { .. } => {
1253-
if addresses.len() > 1 || (addresses.len() == 1 && addresses[0].get_id() != 1) {
1254-
return Err(DecodeError::ExtraAddressesPerType);
1255-
}
1256-
},
1257-
NetAddress::OnionV2 { .. } => {
1258-
if addresses.len() > 2 || (addresses.len() > 0 && addresses.last().unwrap().get_id() > 2) {
1259-
return Err(DecodeError::ExtraAddressesPerType);
1260-
}
1261-
},
1262-
NetAddress::OnionV3 { .. } => {
1263-
if addresses.len() > 3 || (addresses.len() > 0 && addresses.last().unwrap().get_id() > 3) {
1264-
return Err(DecodeError::ExtraAddressesPerType);
1265-
}
1266-
},
1244+
if addr.get_id() < highest_addr_type {
1245+
// Addresses must be sorted in increasing order
1246+
return Err(DecodeError::InvalidValue);
12671247
}
1248+
highest_addr_type = addr.get_id();
12681249
if addr_len < addr_readpos + 1 + addr.len() {
12691250
return Err(DecodeError::BadLengthDescriptor);
12701251
}

lightning/src/ln/peer_handler.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
586586
log_debug!(self, "Deserialization failed due to shortness of message");
587587
return Err(PeerHandleError { no_connection_possible: false });
588588
}
589-
msgs::DecodeError::ExtraAddressesPerType => {
590-
log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407");
591-
continue;
592-
}
593589
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }),
594590
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
595591
}

0 commit comments

Comments
 (0)