Skip to content

Commit 25486bd

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 cb7ab38 commit 25486bd

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
@@ -99,6 +99,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
9999
// recipient's node_id.
100100
const MIN_PEER_CHANNELS: usize = 3;
101101

102+
// The minimum channel balance certainty required for using a channel in a blinded path.
103+
const MIN_CHANNEL_CERTAINTY: f64 = 0.5;
104+
102105
let network_graph = self.network_graph.deref().read_only();
103106
let counterparty_channels = first_hops.into_iter()
104107
.filter(|details| details.counterparty.features.supports_route_blinding())
@@ -144,6 +147,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
144147
Some((forward_node, counterparty_channels))
145148
});
146149

150+
let scorer = self.scorer.read_lock();
147151
let three_hop_paths = counterparty_channels.clone()
148152
// Pair counterparties with their other channels
149153
.flat_map(|(forward_node, counterparty_channels)|
@@ -163,6 +167,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
163167
)
164168
.filter(|(_, _, info)| amount_msats >= info.direction().htlc_minimum_msat)
165169
.filter(|(_, _, info)| amount_msats <= info.direction().htlc_maximum_msat)
170+
.filter(|(_, scid, info)| {
171+
scorer.channel_balance_certainty(*scid, info) >= MIN_CHANNEL_CERTAINTY
172+
})
166173
.map(move |(source, scid, info)| (source, scid, info, forward_node.clone()))
167174
)
168175
// 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;
@@ -97,6 +97,7 @@ pub trait ScoreLookUp {
9797
/// on a per-routefinding-call basis through to the scorer methods,
9898
/// which are used to determine the parameters for the suitability of channels for use.
9999
type ScoreParams;
100+
100101
/// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
101102
/// given channel in the direction from `source` to `target`.
102103
///
@@ -108,6 +109,16 @@ pub trait ScoreLookUp {
108109
fn channel_penalty_msat(
109110
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams
110111
) -> u64;
112+
113+
/// Returns how certain any knowledge gained about the channel's liquidity balance is.
114+
///
115+
/// Expected to return a value between `0.0` and `1.0`, inclusive, where `0.0` indicates
116+
/// complete uncertainty and `1.0` complete certainty.
117+
///
118+
/// This is useful to determine whether a channel should be included in a blinded path.
119+
fn channel_balance_certainty(
120+
&self, _short_channel_id: u64, _info: &DirectedChannelInfo
121+
) -> f64 { 0.5 }
111122
}
112123

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

0 commit comments

Comments
 (0)