Skip to content

Commit bda9b52

Browse files
committed
Consider channel balance certainty in blinded path
How certain a scorer is about a channel's liquidity balance is useful in determining if the channel should be included in a blinded payment path. Channels with uncertain balances should be avoided to facilitate successful payments. Expand ScoreLookUp with a channel_balance_certainty method and use it in DefaultRouter::create_blinded_payment_paths.
1 parent 6353f21 commit bda9b52

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lightning/src/routing/router.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
102102
// recipient's node_id.
103103
const MIN_PEER_CHANNELS: usize = 3;
104104

105+
// The minimum channel balance certainty required for using a channel in a blinded path.
106+
const MIN_CHANNEL_CERTAINTY: f64 = 0.5;
107+
105108
let network_graph = self.network_graph.deref().read_only();
106109
let counterparty_channels = first_hops.into_iter()
107110
.filter(|details| details.counterparty.features.supports_route_blinding())
@@ -147,6 +150,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
147150
Some((forward_node, counterparty_channels))
148151
});
149152

153+
let scorer = self.scorer.read_lock();
150154
let three_hop_paths = counterparty_channels.clone()
151155
// Pair counterparties with their other channels
152156
.flat_map(|(forward_node, counterparty_channels)|
@@ -166,6 +170,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
166170
)
167171
.filter(|(_, _, info)| amount_msats >= info.direction().htlc_minimum_msat)
168172
.filter(|(_, _, info)| amount_msats <= info.direction().htlc_maximum_msat)
173+
.filter(|(_, scid, info)| {
174+
scorer.channel_balance_certainty(*scid, info) >= MIN_CHANNEL_CERTAINTY
175+
})
169176
.map(move |(source, scid, info)| (source, scid, info, forward_node.clone()))
170177
)
171178
// Construct blinded paths where the counterparty's counterparty is the introduction

lightning/src/routing/scoring.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//! [`find_route`]: crate::routing::router::find_route
5858
5959
use crate::ln::msgs::DecodeError;
60-
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId};
60+
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, NetworkGraph, NodeId};
6161
use crate::routing::router::{Path, CandidateRouteHop, PublicHopCandidate};
6262
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
6363
use crate::util::logger::Logger;
@@ -96,6 +96,7 @@ pub trait ScoreLookUp {
9696
/// on a per-routefinding-call basis through to the scorer methods,
9797
/// which are used to determine the parameters for the suitability of channels for use.
9898
type ScoreParams;
99+
99100
/// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
100101
/// given channel in the direction from `source` to `target`.
101102
///
@@ -107,6 +108,16 @@ pub trait ScoreLookUp {
107108
fn channel_penalty_msat(
108109
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams
109110
) -> u64;
111+
112+
/// Returns how certain any knowledge gained about the channel's liquidity balance is.
113+
///
114+
/// Expected to return a value between `0.0` and `1.0`, inclusive, where `0.0` indicates
115+
/// complete uncertainty and `1.0` complete certainty.
116+
///
117+
/// This is useful to determine whether a channel should be included in a blinded path.
118+
fn channel_balance_certainty(
119+
&self, _short_channel_id: u64, _info: &DirectedChannelInfo
120+
) -> f64 { 0.5 }
110121
}
111122

112123
/// `ScoreUpdate` is used to update the scorer's internal state after a payment attempt.

0 commit comments

Comments
 (0)