Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,18 +2249,6 @@ fn build_with_store_internal(

let pathfinding_scores_sync_url = pathfinding_scores_sync_config.map(|c| c.url.clone());

#[cfg(cycle_tests)]
let mut _leak_checker = crate::LeakChecker(Vec::new());
#[cfg(cycle_tests)]
{
use std::any::Any;
use std::sync::Weak;

_leak_checker.0.push(Arc::downgrade(&channel_manager) as Weak<dyn Any + Send + Sync>);
_leak_checker.0.push(Arc::downgrade(&network_graph) as Weak<dyn Any + Send + Sync>);
_leak_checker.0.push(Arc::downgrade(&wallet) as Weak<dyn Any + Send + Sync>);
}

let prober = probing_config.map(|probing_cfg| {
let strategy: Arc<dyn ProbingStrategy> = match &probing_cfg.kind {
ProbingStrategyKind::HighDegree { top_node_count } => {
Expand Down Expand Up @@ -2306,6 +2294,18 @@ fn build_with_store_internal(
})
});

#[cfg(cycle_tests)]
let mut _leak_checker = crate::LeakChecker(Vec::new());
#[cfg(cycle_tests)]
{
use std::any::Any;
use std::sync::Weak;

_leak_checker.0.push(Arc::downgrade(&channel_manager) as Weak<dyn Any + Send + Sync>);
_leak_checker.0.push(Arc::downgrade(&network_graph) as Weak<dyn Any + Send + Sync>);
_leak_checker.0.push(Arc::downgrade(&wallet) as Weak<dyn Any + Send + Sync>);
}

Ok(Node {
runtime,
stop_sender,
Expand Down
30 changes: 21 additions & 9 deletions src/probing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl RandomWalkStrategy {
// Retrieve the direction-specific update via the public ChannelInfo fields.
// as_directed_from already checked both directions are Some, but we break
// defensively rather than unwrap.
let update = match if directed.source() == &next_channel.node_one {
let channel_update_info = match if directed.source() == &next_channel.node_one {
next_channel.one_to_two.as_ref()
} else {
next_channel.two_to_one.as_ref()
Expand All @@ -604,15 +604,15 @@ impl RandomWalkStrategy {
None => break,
};

if !update.enabled {
if !channel_update_info.enabled {
break;
}

route_least_htlc_upper_bound =
route_least_htlc_upper_bound.min(update.htlc_maximum_msat);
route_least_htlc_upper_bound.min(channel_update_info.htlc_maximum_msat);

route_greatest_htlc_lower_bound =
route_greatest_htlc_lower_bound.max(update.htlc_minimum_msat);
route_greatest_htlc_lower_bound.max(channel_update_info.htlc_minimum_msat);

let next_pubkey = match PublicKey::try_from(*next_node_id) {
Ok(pk) => pk,
Expand Down Expand Up @@ -682,25 +682,37 @@ impl RandomWalkStrategy {
let (_, next_scid, _) = route[i + 1];
let next_channel = graph.channel(next_scid)?;
let (directed, _) = next_channel.as_directed_from(&node_id)?;
let update = match if directed.source() == &next_channel.node_one {
let channel_update_info = match if directed.source() == &next_channel.node_one {
next_channel.one_to_two.as_ref()
} else {
next_channel.two_to_one.as_ref()
} {
Some(u) => u,
None => return None,
};
let fee = update.fees.base_msat as u64
+ (forwarded * update.fees.proportional_millionths as u64 / 1_000_000);
forwarded += fee;
// forwarded is the amount sent over next_channel (before this hop's own fee is
// added on top for the preceding channel), so check it against next_channel's
// own advertised bounds before computing the fee.
if forwarded > channel_update_info.htlc_maximum_msat
|| forwarded < channel_update_info.htlc_minimum_msat
{
return None;
}

// Overflow prevention
let proportional_fee = forwarded
.checked_mul(channel_update_info.fees.proportional_millionths as u64)
.map(|v| v / 1_000_000)?;
let fee = (channel_update_info.fees.base_msat as u64).checked_add(proportional_fee)?;
forwarded = forwarded.checked_add(fee)?;

@tnull tnull Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex:

  • [P2] Check the HTLC bound before adding the current hop’s fee — /home/tnull/worktrees/ldk-node/pr-1004-latest-20260724/src/probing.rs:698

    forwarded initially represents the amount sent through next_channel, including only downstream fees. The code adds the current node’s fee and then compares against that channel’s bounds. That fee is collected on the preceding channel and must not count toward
    next_channel.htlc_maximum_msat.

    For example, if B→C has a 1,000,000-msat maximum and B charges 1,000 msat, delivering exactly 1,000,000 msat over B→C is valid. This code checks 1,001,000 and rejects the path.

    BOLT 7 defines the maximum as what the origin node will send through that channel, while its fee is calculated from amount_to_forward. BOLT 7 channel updates and HTLC fees (https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#htlc-fees)

    The bound check should occur before calculating and adding fee.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


hops.push(RouteHop {
pubkey,
node_features,
short_channel_id: via_scid,
channel_features,
fee_msat: fee,
cltv_expiry_delta: update.cltv_expiry_delta as u32,
cltv_expiry_delta: channel_update_info.cltv_expiry_delta as u32,
maybe_announced_channel,
});
}
Expand Down
Loading