Skip to content

Add probing service#815

Open
randomlogin wants to merge 19 commits intolightningdevkit:mainfrom
randomlogin:add-probing-service
Open

Add probing service#815
randomlogin wants to merge 19 commits intolightningdevkit:mainfrom
randomlogin:add-probing-service

Conversation

@randomlogin
Copy link
Copy Markdown

@randomlogin randomlogin commented Mar 1, 2026

Added a probing service which is used to send probes to estimate channels' capacities.

Related issue: #765.

Probing is intended to be used in two ways:

  • on a 'normal' node that allocates some liquidity to probe channels;
  • on a probing node which doesn't make any real payments, just observes the network.


For probing a new abstraction Prober is defined and is (optionally) created during node building.
Prober periodically sends probes to feed the data to the scorer.
Prober sends probes using a ProbingStrategy.

ProbingStrategy trait has only one method: fn next_probe(&self) -> Option<Probe>; every tick it generates a probe, where Probe represents how to send a probe.

To accommodate two different ways the probing is used, we either construct a probing route manually (Probe::PrebuiltRoute) or rely on the router/scorer (Probe::Destination).

Prober tracks how much liquidity is locked in-flight in probes, prevents the new probes from firing if the cap is reached.

There are two probing strategies implemented:

  • Random probing strategy, it picks a random route from the current node, the route is probed via send_probe, thus ignores scoring parameters (what hops to pick), it also ignores liquidity_limit_multiplier which prohibits taking a hop if its capacity is too small. It is a true random route.

  • High degree probing strategy, it examines the graph and finds the nodes with the biggest number of (public) channels and probes routes to them using send_spontaneous_preflight_probes which uses the current router/scorer.

The former is meant to be used on payment nodes, while the latter on probing nodes. For the HighDegreeStrategy to work it is recommended to set probing_diversity_penalty_msat to some nonzero value to prevent routes reuse, however it may fail to find any available routes.

There are three tests added:

  • check the probing locked amount increases/decreases
  • check that the new probes are not fired if the current locked amount cap is reached
  • performance testing which sets up a network of nodes and 4 observing nodes

Example output (runs for ~1 minute, needs --nocapture flag):

SCID            Direction         Probing Random               Probing HiDeg                Probing HiDeg+P              Probing nostrat              Real outbound msat
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
114349209354241 C→Random          [0, 90 100 235]              unknown                      unknown                      unknown                      0
114349209354241 Random→C          [9 899 765, 100 000 000]     unknown                      unknown                      unknown                      917 184 187
114349209419777 D→HiDeg+P         unknown                      unknown                      [0, 91 127 725]              unknown                      0
114349209419777 HiDeg+P→D         unknown                      unknown                      [8 872 275, 100 000 000]     unknown                      905 313 697
114349209485312 B→F               [0, 3 418 855]               unknown                      unknown                      unknown                      160 288 291
114349209485312 F→B               [96 581 145, 100 000 000]    unknown                      unknown                      unknown                      819 711 709
114349209550848 B→D               [0, 6 141 420]               [0, 2 988 399]               [0, 91 127 725]              unknown                      30 052 300
114349209550848 D→B               [93 858 580, 100 000 000]    [97 011 601, 100 000 000]    [8 872 275, 100 000 000]     unknown                      874 555 512
114349209616384 E→HiDeg           [0, 2 097 950]               [0, 90 455 967]              unknown                      unknown                      0
114349209616384 HiDeg→E           [97 902 050, 100 000 000]    [9 544 033, 100 000 000]     unknown                      unknown                      913 366 836
114349209681920 B→C               [98 411 698, 100 000 000]    unknown                      unknown                      unknown                      86 511 108
114349209681920 C→B               [0, 1 588 302]               unknown                      unknown                      unknown                      812 521 355
114349209747457 B→E               [0, 6 625 595]               [0, 90 455 967]              [0, 4 795 311]               unknown                      0
114349209747457 E→B               [93 374 405, 100 000 000]    [9 544 033, 100 000 000]     [95 204 689, 100 000 000]    unknown                      907 339 924
114349209812993 C→nostrat         [0, 1 113 591]               unknown                      unknown                      unknown                      0
114349209812993 nostrat→C         [98 886 409, 100 000 000]    unknown                      unknown                      unknown                      990 000 000
114349209878528 C→E               [2 097 950, 5 335 740]       [0, 90 808 929]              unknown                      unknown                      55 569 306
114349209878528 E→C               [94 664 260, 97 902 050]     [9 191 071, 100 000 000]     unknown                      unknown                      878 423 826
114349209944065 B→C               [97 243 524, 100 000 000]    unknown                      [1 698 550, 6 086 572]       unknown                      938 012 264
114349209944065 C→B               [0, 2 756 476]               unknown                      [93 913 428, 98 301 450]     unknown                      34 367 637
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Known directions                   18/20                        8/20                         8/20                         0/20                        

For performance testing I had to expose the scoring data (scorer_channel_liquidity).
Also exposed scoring_fee_params: ProbabilisticScoringFeeParameters to Config.

TODOs:

  • adjust default parameters
  • improve HighDegree strategy to take into account channel capacities
  • improve HighDegree strategy to cache results
  • improve performance test to better estimate real channel capacity

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Mar 1, 2026

👋 Thanks for assigning @kaloudis as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@randomlogin randomlogin marked this pull request as ready for review March 1, 2026 12:10
@tnull tnull self-requested a review March 2, 2026 07:56
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 4th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 5th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 6th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Copy Markdown
Contributor

@enigbe enigbe left a comment

Choose a reason for hiding this comment

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

Hi @randomlogin, thanks for the work on this! I've reviewed the first two commits:

  1. 7f3ce11: "Create probing service" and
  2. 6574bf9: "Add probing tests"

I've left a bunch of inline comments addressing configuration and public API, commit hygiene, testing infrastructure, and test flakiness.

In summary:

  1. A couple of items are exposed publicly that seem like they should be scoped to probing or gated for tests only (see scoring_fee_params in Config and scorer_channel_liquidity on Node).
  2. The probing tests duplicate existing test helpers (setup_node, MockLogFacadeLogger). Reusing and extending what's already in tests/common/ would reduce duplication and keep the test file focused on the tests themselves.
  3. test_probe_budget_blocks_when_node_offline has a race condition where the prober dispatches probes before the baseline capacity is measured, causing the assertion between the baseline and stuck capacities to fail. Details in the inline comment.
  4. A few nits about commit hygiene, import structure, and suggestions for renaming stuff.

Also needs to be rebased.

Comment thread src/builder.rs Outdated
Comment thread src/probing.rs Outdated
Comment thread src/probing.rs Outdated
pub struct HighDegreeStrategy {
network_graph: Arc<Graph>,
/// How many of the highest-degree nodes to cycle through.
pub top_n: usize,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could top_n be renamed to num_top_nodes? The latter reads less generic to me but up to you to modify or not.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd leave it as is (maybe top_k, as somehow it is more common in algorithms to describe the number of samplings).

What about top_node_count?

Personally I don't like 'num' as a short for 'number'

Comment thread src/probing.rs Outdated
Comment thread src/builder.rs Outdated
Comment thread tests/probing_tests.rs Outdated
Comment thread tests/probing_tests.rs Outdated
Comment thread tests/probing_tests.rs Outdated
Comment thread tests/probing_tests.rs Outdated
Comment thread tests/probing_tests.rs
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 7th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@randomlogin
Copy link
Copy Markdown
Author

@enigbe, thanks for a review, the updates are incoming soon.

@randomlogin randomlogin force-pushed the add-probing-service branch 3 times, most recently from 436e4a3 to 07dfde4 Compare March 19, 2026 01:24
@randomlogin randomlogin requested a review from enigbe March 19, 2026 02:10
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 8th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 1st Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 9th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 2nd Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 10th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 3rd Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Introduce a background probing service that periodically dispatches
probes to improve the scorer's liquidity estimates. Includes two
built-in strategies.
@randomlogin randomlogin force-pushed the add-probing-service branch from ff741c2 to c31f1ce Compare March 26, 2026 01:27
Copy link
Copy Markdown
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on and excuse the delay here!

Did a first review pass and this already looks great! Here are some relatively minor comments, mostly concerning the API design.

Comment thread src/builder.rs Outdated
Comment thread src/builder.rs Outdated
Comment thread src/builder.rs Outdated
Comment thread src/builder.rs Outdated
Comment thread src/builder.rs
}

let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
let mut scoring_fee_params = ProbabilisticScoringFeeParameters::default();
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.

I do wonder if we should allow the user to set the entire ProbabilisticScoringFeeParameters and ProbabilisticScoringDecayParameters via the ProbingConfigBuilder mentioned above? Do you see any reason where that would conflict with other API design decisions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think we should expose these settings (in NodeBuilder, not probing builder).
However these are for fine tuning and should be used only by advanced users. Also I would expose UserConfig, as for example user cannot decide what features do advertise.

I can add builder methods for scoring parameters, though maybe it should be in another PR aimed on exposing settings for an advanced user?

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.

Also I would expose UserConfig, as for example user cannot decide what features do advertise.

Yes, this is very intentional, as we want to provide a sane/safe API. For example letting user freely choose to set certain parameters if we don't implement them properly will just lead to a lot of footguns, in some circumstances even with the potential for money loss.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In that case I think we don't need to expose ProbabilisticScoringFeeParameters and ProbabilisticScoringFeeParameters by the very reason you mentioned.

Comment thread src/probing.rs
Comment thread src/probing.rs
Comment thread src/probing.rs
Comment thread tests/common/mod.rs Outdated
Comment thread tests/probing_tests.rs Outdated
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 4th Reminder

Hey @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@randomlogin randomlogin requested a review from tnull April 6, 2026 15:45
Copy link
Copy Markdown
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Have yet to do another full pass. However, please start looking into how we can expose the adding probing APIs as part of the uniffi bindings in the meantime. We try to keep feature parity between Rust and bindings APIs as far as possible.

Comment thread src/lib.rs Outdated
/// **Warning:** This is expensive — O(scorer size) per call. It works by serializing the
/// entire `CombinedScorer` and deserializing it as a plain `ProbabilisticScorer` to access
/// `estimated_channel_liquidity_range`. Intended for testing and debugging, not hot paths.
pub fn scorer_channel_liquidity(&self, scid: u64, target: PublicKey) -> Option<(u64, u64)> {
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.

I don't think we'll want to expose this here. If we think we need this we'd need to work out an API that is more reasonable than returning plain (u64, u64) (which are rather cryptic to begin with) and would also work in bindings. I also don't think the re-serializing of the scorer here is acceptable - if we need access to estimated_channel_liquidity_range, we probably need to work out how we can expose that in a reasonable way on CombinedScorer upstream

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed it from this PR, instead created a PR upstream: lightningdevkit/rust-lightning#4568

After some considerations I think it's indeed needed to be exposed, as it is needed to gather data about probing strategies to polish them.

Even despite the fact we cannot get the real liquidity data on live network to have 2 figures to compare (real vs estimate), it can be used in for example measuring the number of failed payments against the liquidity estimates we had on the path. Or to have a bunch of our own routing nodes with exact channel liquidity data (on signet) to compare with the estimations.

Also removed the test that naively compared strategy performances (and used this method).

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.

That PR now landed. You might need to wait for other PRs that fix pre-existing API breakages before you can use the API here. Until then, feel free to change the dependency to a branch of yours that depends on the same LDK base as our current main (but that includes the fix from LDK#4568), but note you'll also have to update bitcoin-payment-instructions to depend on the same revision accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The test which I removed was more an diagnostic, not a correctness, whether the scorer gets its estimations, it didn't assert anything, so I'm not sure if I need to return it to the PR, should not be a blocker for now.
(still of course the upstream change is needed)

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 9th Reminder

Hey @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 10th Reminder

Hey @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 11th Reminder

Hey @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@randomlogin randomlogin requested a review from tnull April 14, 2026 17:32
@randomlogin randomlogin force-pushed the add-probing-service branch from 8360b6e to 56b5b0f Compare April 14, 2026 17:37
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 12th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Copy Markdown
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for the update. It seems this is blocked now until we can bump the LDK dependency to include the upstream PR?

Comment thread src/probing.rs Outdated
Comment thread src/probing.rs Outdated
Strategy constructors (high_degree/random_walk/custom) moved from
ProbingConfig to ProbingConfigBuilder, so they live on the builder
rather than on the thing being built.
ProbingConfigBuilder setters switched from consuming `self -> Self` to
`&mut self -> &mut Self`, matching NodeBuilder. `build` now takes
`&self`. Existing fluent call sites still compile unchanged.
Removed the flat new_high_degree/new_random_walk UniFFI constructors on
ProbingConfig that replicated the builder wiring. Bindings now go
through ArcedProbingConfigBuilder (exposed as ProbingConfigBuilder via
UDL), which wraps ProbingConfigBuilder in an RwLock for the Arc
semantics UniFFI requires — mirroring ArcedNodeBuilder.
AI-assisted (Claude Code).
@randomlogin randomlogin requested a review from tnull April 15, 2026 14:38
@randomlogin randomlogin force-pushed the add-probing-service branch from 18ff1db to bd34ddf Compare April 15, 2026 15:14
@randomlogin randomlogin force-pushed the add-probing-service branch from bd34ddf to a4c4928 Compare April 15, 2026 15:43
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 13th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 1st Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment thread src/probing.rs Outdated
@ldk-reviews-bot
Copy link
Copy Markdown

🔔 14th Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 2nd Reminder

Hey @tnull @enigbe! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@tnull tnull added this to the 0.8 milestone Apr 20, 2026
Previously we always queried gossip data to construct probing route,
which would fail for unannounced channels.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@randomlogin randomlogin requested a review from kaloudis April 20, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants