Skip to content

Commit ce07ed5

Browse files
committed
Support reading channel_updates in onions with message type bytes
Historically c-lightning and eclair have always sent `channel_update` messages inside the onion error packets with the two message type bytes (`0x0102` for `channel_update` messages) but lnd and us skipped those bytes. We only supported decoding messages matching our own encoding - decoding a bogus `channel_update` if the extra bytes were included. Here we detect the type bytes and, if they're present, start reading at offset 2. We also take this opportunity to improve loging and make the severity more accurate for the previous error. Fixes #1450.
1 parent 72069bf commit ce07ed5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,15 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
404404
else if error_code & UPDATE == UPDATE {
405405
if let Some(update_len_slice) = err_packet.failuremsg.get(debug_field_size+2..debug_field_size+4) {
406406
let update_len = u16::from_be_bytes(update_len_slice.try_into().expect("len is 2")) as usize;
407-
if let Some(update_slice) = err_packet.failuremsg.get(debug_field_size + 4..debug_field_size + 4 + update_len) {
407+
if let Some(mut update_slice) = err_packet.failuremsg.get(debug_field_size + 4..debug_field_size + 4 + update_len) {
408+
// Historically, the BOLTs were unclear if the message type
409+
// bytes should be included here or not. The BOLTs have now
410+
// been updated to indicate that they *are* included, but many
411+
// nodes still send messages without the type bytes, so we
412+
// support both here.
413+
if update_slice.len() > 2 && update_slice[0..2] == [0x01, 0x02] {
414+
update_slice = &update_slice[2..];
415+
}
408416
if let Ok(chan_update) = msgs::ChannelUpdate::read(&mut Cursor::new(&update_slice)) {
409417
// if channel_update should NOT have caused the failure:
410418
// MAY treat the channel_update as invalid.
@@ -434,6 +442,8 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
434442
// short channel id.
435443
if failing_route_hop.short_channel_id == chan_update.contents.short_channel_id {
436444
short_channel_id = Some(failing_route_hop.short_channel_id);
445+
} else {
446+
log_info!(logger, "Node provided a channel_update for which it was not authoritative, ignoring.");
437447
}
438448
network_update = Some(NetworkUpdate::ChannelUpdateMessage {
439449
msg: chan_update,
@@ -478,10 +488,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
478488

479489
let (description, title) = errors::get_onion_error_description(error_code);
480490
if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size {
481-
log_warn!(logger, "Onion Error[from {}: {}({:#x}) {}({})] {}", route_hop.pubkey, title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description);
491+
log_info!(logger, "Onion Error[from {}: {}({:#x}) {}({})] {}", route_hop.pubkey, title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description);
482492
}
483493
else {
484-
log_warn!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description);
494+
log_info!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description);
485495
}
486496
} else {
487497
// Useless packet that we can't use but it passed HMAC, so it

0 commit comments

Comments
 (0)