Merge PR 'Make Path and Route fields private' (#5068)
What changed, and why it matters
This commit makes the internal fields of two data structures, Path and Route, private and adds controlled constructors and read-only accessors. It also adds validation so that empty paths or routes are rejected. The change is primarily a defensive API hardening measure. It does not by itself fix a known exploit, but it removes a class of mistakes where outside code could construct an invalid empty path or route, which could previously lead to panics or unexpected behavior in payment handling.
Treat as a defensive hardening improvement. Review whether any downstream code still constructs Path or Route with literal struct syntax, as it will now fail to compile. If the project maintains a changelog or security advisory process, consider documenting the invariant enforcement as a robustness fix, but no urgent security response is indicated by the diff alone.
Security signals we found
Encapsulation of previously public struct fields
Addition of input validation in constructors (non-empty hops/paths)
Deserialization now rejects invalid empty paths/routes
Branch name suggests a panic fix in probe sending
No direct memory-safety or cryptographic vulnerability shown in diff
Evidence from the diff
The patch converts Path::hops and Path::blinded_tail, and Route::paths and Route::route_params, from public fields to pub(crate) fields. It introduces Path::new and Route::new constructors that enforce at least one hop/path, plus hops(), blinded_tail(), paths(), and route_params() accessors. Serialization is updated to use the constructors so that deserialization of an empty path or route now returns InvalidValue instead of creating an invalid object. Several call sites, including fuzz targets and event deserialization, are updated to use the new APIs. The branch name ‘2026-10-send-probe-panic’ hints that this may be related to a panic when sending probes, but the diff itself does not show the panic path or a CVE.
Changed components
lightning/src/routing/router.rs (Path and Route structs)lightning/src/events/mod.rs (event deserialization)fuzz/src/chanmon_consistency.rsfuzz/src/process_onion_failure.rslightning-background-processor/src/lib.rsInspect captured patch +83 / −20
### fuzz/src/chanmon_consistency.rs
@@ -2216,10 +2216,10 @@ impl PaymentTracker {
}
})
.collect();
- Path { hops, blinded_tail: None }
+ Path::new(hops, None).expect("payment path should contain at least one hop")
})
.collect();
- Route { paths, route_params }
+ Route::new(paths, route_params).expect("route should contain at least one path")
}
fn allow_failure_for_hash(&mut self, payment_hash: PaymentHash) {
@@ -2307,11 +2307,11 @@ impl PaymentTracker {
fn route_min_final_cltv_expiry(route: &Route, source_best_block_height: u32) -> u32 {
let cur_height = source_best_block_height.saturating_add(1);
route
- .paths
+ .paths()
.iter()
.map(|path| {
cur_height.saturating_add(
- path.hops
+ path.hops()
.last()
.expect("payment path should contain at least one hop")
.cltv_expiry_delta,
### fuzz/src/process_onion_failure.rs
@@ -114,7 +114,10 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
None
};
- let path = Path { hops, blinded_tail };
+ let path = match Path::new(hops, blinded_tail) {
+ Ok(path) => path,
+ Err(()) => return,
+ };
let htlc_source = HTLCSource::OutboundRoute {
path: path.clone(),
### lightning-background-processor/src/lib.rs
@@ -3917,15 +3917,15 @@ mod tests {
let node_1_privkey = SecretKey::from_slice(&[42; 32]).unwrap();
let node_1_id = PublicKey::from_secret_key(&secp_ctx, &node_1_privkey);
- let path = Path { hops: vec![RouteHop {
+ let path = Path::new(vec![RouteHop {
pubkey: node_1_id,
node_features: NodeFeatures::empty(),
short_channel_id: scored_scid,
channel_features: ChannelFeatures::empty(),
fee_msat: 0,
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
maybe_announced_channel: true,
- }], blinded_tail: None };
+ }], None).unwrap();
$nodes[0].scorer.write_lock().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {
### lightning/src/events/mod.rs
@@ -2991,8 +2991,6 @@ impl MaybeReadable for Event {
(1, network_update, upgradable_option),
(2, payment_failed_permanently, required),
(4, blinded_tail, option),
- // Added as a part of LDK 0.0.101 and always filled in since.
- // Defaults to an empty Vec, though likely should have been `Option`al.
(5, path, optional_vec),
(7, short_channel_id, option),
(11, payment_id, option),
@@ -3007,7 +3005,8 @@ impl MaybeReadable for Event {
payment_hash,
payment_failed_permanently,
failure,
- path: Path { hops: path.unwrap(), blinded_tail },
+ path: Path::new(path.unwrap(), blinded_tail)
+ .map_err(|()| msgs::DecodeError::InvalidValue)?,
short_channel_id,
#[cfg(any(test, feature = "_test_utils"))]
error_code,
@@ -3200,7 +3199,8 @@ impl MaybeReadable for Event {
Ok(Some(Event::PaymentPathSuccessful {
payment_id: payment_id.0.unwrap(),
payment_hash,
- path: Path { hops: path, blinded_tail },
+ path: Path::new(path, blinded_tail)
+ .map_err(|()| msgs::DecodeError::InvalidValue)?,
hold_times,
}))
};
@@ -3283,7 +3283,8 @@ impl MaybeReadable for Event {
Ok(Some(Event::ProbeSuccessful {
payment_id: payment_id.0.unwrap(),
payment_hash: payment_hash.0.unwrap(),
- path: Path { hops: path, blinded_tail },
+ path: Path::new(path, blinded_tail)
+ .map_err(|()| msgs::DecodeError::InvalidValue)?,
}))
};
f()
@@ -3300,7 +3301,8 @@ impl MaybeReadable for Event {
Ok(Some(Event::ProbeFailed {
payment_id: payment_id.0.unwrap(),
payment_hash: payment_hash.0.unwrap(),
- path: Path { hops: path, blinded_tail },
+ path: Path::new(path, blinded_tail)
+ .map_err(|()| msgs::DecodeError::InvalidValue)?,
short_channel_id,
}))
};
### lightning/src/routing/router.rs
@@ -768,12 +768,33 @@ impl_ser_tlv_based!(BlindedTail, {
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Path {
/// The list of unblinded hops in this [`Path`]. Must be at least length one.
- pub hops: Vec<RouteHop>,
+ pub(crate) hops: Vec<RouteHop>,
/// The blinded path at which this path terminates, if we're sending to one, and its metadata.
- pub blinded_tail: Option<BlindedTail>,
+ pub(crate) blinded_tail: Option<BlindedTail>,
}
impl Path {
+ /// Constructs a new [`Path`] from its unblinded hops and the blinded path at which it
+ /// terminates, if any.
+ ///
+ /// Returns an error if `hops` is empty.
+ pub fn new(hops: Vec<RouteHop>, blinded_tail: Option<BlindedTail>) -> Result<Self, ()> {
+ if hops.is_empty() {
+ return Err(());
+ }
+ Ok(Self { hops, blinded_tail })
+ }
+
+ /// The list of unblinded hops in this [`Path`]. Always at least length one.
+ pub fn hops(&self) -> &[RouteHop] {
+ &self.hops
+ }
+
+ /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
+ pub fn blinded_tail(&self) -> Option<&BlindedTail> {
+ self.blinded_tail.as_ref()
+ }
+
/// Gets the fees for a given path, excluding any excess paid to the recipient.
#[rustfmt::skip]
pub fn fee_msat(&self) -> u64 {
@@ -817,26 +838,63 @@ impl Path {
}
}
-impl_ser_tlv_based!(Path,{
- (1, hops, required_vec),
- (3, blinded_tail, option),
+impl_writeable_tlv_based!(Path, self, {
+ (1, self.hops, required_vec),
+ (3, self.blinded_tail, option),
});
+impl Readable for Path {
+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+ _init_and_read_len_prefixed_tlv_fields!(reader, {
+ (1, hops, required_vec),
+ (3, blinded_tail, option),
+ });
+ Self::new(hops, blinded_tail).map_err(|()| DecodeError::InvalidValue)
+ }
+}
+
/// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
/// it can take multiple paths. Each path is composed of one or more hops through the network.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Route {
/// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
/// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
/// the same.
- pub paths: Vec<Path>,
+ pub(crate) paths: Vec<Path>,
/// The `route_params` parameter passed to [`find_route`].
///
/// This is used by `ChannelManager` to track information which may be required for retries.
- pub route_params: RouteParameters,
+ pub(crate) route_params: RouteParameters,
}
impl Route {
+ /// Constructs a new [`Route`] from the [`Path`]s it takes and the [`RouteParameters`] used to
+ /// find it.
+ ///
+ /// If no [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path
+ /// must be the same.
+ ///
+ /// Returns an error if `paths` is empty.
+ pub fn new(paths: Vec<Path>, route_params: RouteParameters) -> Result<Self, ()> {
+ if paths.is_empty() {
+ return Err(());
+ }
+ Ok(Self { paths, route_params })
+ }
+
+ /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. Always contains
+ /// at least one [`Path`].
+ pub fn paths(&self) -> &[Path] {
+ &self.paths
+ }
+
+ /// The `route_params` parameter passed to [`find_route`].
+ ///
+ /// This is used by `ChannelManager` to track information which may be required for retries.
+ pub fn route_params(&self) -> &RouteParameters {
+ &self.route_params
+ }
+
/// Returns the total amount of fees paid on this [`Route`].
///
/// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made toWhy this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.