Skip to content

Commit 4a37408

Browse files
committed
Add mpp_timeout and invalid_onion_payload descriptions & handling
1 parent 1a74367 commit 4a37408

File tree

6 files changed

+13
-2
lines changed

6 files changed

+13
-2
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
135135
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
136136
msgs::DecodeError::Io(e) => panic!("{:?}", e),
137137
msgs::DecodeError::UnsupportedCompression => return,
138+
msgs::DecodeError::UnknownTLV(_) => return,
138139
}
139140
}
140141
}}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
17771777
msgs::DecodeError::UnknownVersion => 0x4000 | 1, // unknown realm byte
17781778
msgs::DecodeError::UnknownRequiredFeature|
17791779
msgs::DecodeError::InvalidValue|
1780-
msgs::DecodeError::ShortRead => 0x4000 | 22, // invalid_onion_payload
1780+
msgs::DecodeError::ShortRead|
1781+
msgs::DecodeError::UnknownTLV(_) => 0x4000 | 22, // invalid_onion_payload
17811782
_ => 0x2000 | 2, // Should never happen
17821783
};
17831784
return_err!("Unable to decode our hop data", error_code, &[0;0]);

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum DecodeError {
6868
io::ErrorKind),
6969
/// The message included zlib-compressed values, which we don't support.
7070
UnsupportedCompression,
71+
/// The message included a TLV with an unknown type.
72+
UnknownTLV(u64),
7173
}
7274

7375
/// An init message to be sent or received from a peer
@@ -965,6 +967,7 @@ impl fmt::Display for DecodeError {
965967
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
966968
DecodeError::Io(ref e) => e.fmt(f),
967969
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
970+
DecodeError::UnknownTLV(tlv_type) => f.write_fmt(format_args!( "Unknown TLV type encountered: {}", tlv_type)),
968971
}
969972
}
970973
}

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
380380
// indicate that payment parameter has failed and no need to
381381
// update Route object
382382
let payment_failed = match error_code & 0xff {
383-
15|16|17|18|19 => true,
383+
15|16|17|18|19|23 => true,
384384
_ => false,
385385
} && is_from_final_node; // PERM bit observed below even if this error is from the intermediate nodes
386386

lightning/src/ln/peer_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
914914
msgs::DecodeError::UnsupportedCompression => {
915915
log_gossip!(self.logger, "We don't support zlib-compressed message fields, ignoring message");
916916
continue;
917+
},
918+
msgs::DecodeError::UnknownTLV(tlv_type) => {
919+
log_debug!(self.logger, "Got an unknown TLV type while deserializing message: {}", tlv_type);
920+
return Err(PeerHandleError { no_connection_possible: false });
917921
}
918922
}
919923
}

lightning/src/util/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ pub(crate) fn get_onion_error_description(error_code: u16) -> (&'static str, &'s
119119
_c if _c == 19 => ("The final node indicated the amount in the HTLC does not match the value in the onion", "final_incorrect_htlc_amount"),
120120
_c if _c == UPDATE|20 => ("Node indicated the outbound channel has been disabled", "channel_disabled"),
121121
_c if _c == 21 => ("Node indicated the CLTV expiry in the HTLC is too far in the future", "expiry_too_far"),
122+
_c if _c == PERM|22 => ("Node indicated that the decrypted onion per-hop payload was not understood by it or is incomplete", "invalid_onion_payload"),
123+
_c if _c == 23 => ("The final node indicated the complete amount of the multi-part payment was not received within a reasonable time", "mpp_timeout"),
122124
_ => ("Unknown", ""),
123125
}
124126
}

0 commit comments

Comments
 (0)