Skip to content

Initialisation of lightning-background-prober - #2397

Closed
007harshmahajan wants to merge 11 commits into
lightningdevkit:mainfrom
007harshmahajan:background_probing_service
Closed

007harshmahajan wants to merge 11 commits into
lightningdevkit:mainfrom
007harshmahajan:background_probing_service

Conversation

@007harshmahajan

Copy link
Copy Markdown

This library basically provides payment channel probing as standalone service

@ariard

ariard commented Jul 8, 2023 •

Copy link
Copy Markdown

If this is standalone module and this can be its own rust crate, I would recommend to have it in its own new repository still under the lightningdevkit/ organization if the other contributors find it relevant.

We have already the following modules (code accounting at 3236be1d):

  • lightning/ : 80256 LoC
  • lightning-background-processor/: 1356 LoC
  • lightning-block-sync/: 2860 LoC
  • lightning-custom-message/ : 103 LoC
  • lightning-invoice/ : 5276 LoC
  • lightning-net-tokio/ : 511 LoC
  • lightning-persister/ : 403 LoC
  • lightning-rapid-gossip-sync : 803 LoC
  • lightning-transaction-sync : 664 LoC

From a viewpoint of backward compatibility, inter-operability and security of an open-source project like LDK, where ultimately you have user funds safety involved for marginal mistake, a conservative approach would be to have all (non-critical and non-default) utilities crates to be moved in their own repository to have their own maintenance cycles (quite at the image of how the Linux kernel “cascade” development is organized).

My thinking only, and my apologies if it’s a “cold shower” for a first contribution. Independently of this more organizational review feedback, a background prober for LDK is a good idea!

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I would recommend to have it in its own new repository still under the lightningdevkit/ organization if the other contributors find it relevant.

Hmm, we don't have a policy in the org for this kinda thing. Historically for any other Rust crates which are run as a part of an LDK node in one form or another, we've mostly put them in the same repo (just as separate crates in the workspace). There are two real exceptions - (a) ldk-node, which is really a pretty-separate project, and really downstream of the main LDK crates, with its own language bindings approach and runtime, and (b) ldk-lsp-client, which is quite recent and still early alpha, which largely went into a separate repo so it could move faster and not be hung up on the same release cycle. For ldk-lsp-client, I'd really like to move it into the main rust-lightning repo eventually so that it can be shipped with all the other rust-lightning language bindings and be kept in-sync API-wise with CI.

One really nice thing with pieces being in the same repo is it allows us to run CI across the whole set of "LDK crates", updating them in lock-step as APIs change. With multiple repos that isn't really practical and creates some burden on the release steps.

From a viewpoint of backward compatibility, inter-operability and security of an open-source project like LDK, where ultimately you have user funds safety involved for marginal mistake, a conservative approach would be to have all (non-critical and non-default) utilities crates to be moved in their own repository...

I strongly disagree with this. Keeping it all in one repo keeps everything visible to all contributors, and for a relatively small project where that's still tenable, I see no reason to change that.

quite at the image of how the Linux kernel “cascade” development is organized)

Linux is one repository, with one build-system and one release cycle, across many modules and sub-modules. I wouldn't mind that :)

@ariard

ariard commented Jul 9, 2023

Copy link
Copy Markdown

(a) ldk-node, which is really a pretty-separate project, and really downstream of the main LDK crates, with its own language bindings approach and runtime, and (b) ldk-lsp-client, which is quite recent and still early alpha, which largely went into a separate repo so it could move faster and not be hung up on the same release cycle. For ldk-lsp-client, I'd really like to move it into the main rust-lightning repo eventually so that it can be shipped with all the other rust-lightning language bindings and be kept in-sync API-wise with CI.

Yeah for ldk-node I favor too to have it in its own repository too as you have a runtime, and as such it’s better to have it in its own release cycle. For ldk-lsp-client, it’s a good question if it makes more sense to have in this repository. There is one lesson from the recent disclosure on the mailing list about invoice handling, application devs have a hard time getting right Lightning APIs, and somehow I expect all the LSP logic to become more complex with things like async payments. So it can makes sense to have it under this repository.

One really nice thing with pieces being in the same repo is it allows us to run CI across the whole set of "LDK crates", updating them in lock-step as APIs change. With multiple repos that isn't really practical and creates some burden on the release steps.

Yes, I share the observation than having all the crates under the same repo means we can run everything on the same CI or fuzzing infrastructure, rather than every crates team re-doing the boring work here. And moving the API in lock-step yes reduce the silent breakage.

I strongly disagree with this. Keeping it all in one repo keeps everything visible to all contributors, and for a relatively small project where that's still tenable, I see no reason to change that.

Keeping everything visible to all contributors is a good point, on the other hand it means we’ll have issues in term of review process scalability. A thing like a lightning-background-prober might become very sophisticated with time if you have to deal with future jamming mitigations (whatever the ones deployed) and there is a upfront fees attach to the probe, or you start to have privacy-preserving considerations to mask your probing strategy from routing hops. And same with things like lightning-custom-message where you might have fields sanitizers provided in the utilities as we deploy more Noise peer-to-peer messages (e.g for LSP or jamming purposes).

It sounds to me it’s more a question of maintenance and release cycles, in the sense of being able to have things like lightning-background-prober or maybe ldk-lsp-client with their own dedicated maintainers to advance at their own pace in a way which is not frustrating for the contributors of the specialized crates.

On the other hand, if we do so it’s better than maintainers start to be more “domain experts” a la Linux, as I wouldn’t be okay to have lightning-background-prober maintainers to merge things related to channel-monitoring or on-chain transaction broadcast, which is heavily context-dependent (or at least not before they have demonstrated understanding of those subsystems). Question is how long the project is going to stay “relatively small” :)

Linux is one repository, with one build-system and one release cycle, across many modules and sub-modules. I wouldn't mind that :)

Sure on the one build-system, what I like with Linux culture is the clear’s MAINTAINERS (acpi, driver, network, cpu schedule, memory etc) where you know who are the “domain experts” to whom to submit a patch and the scalability of their review and development process. We can have more maintainers than Core as there is no consensus engine where all the subsystems have to stay in strict sync with it to avoid money-loss bugs.

@jkczyz
jkczyz self-requested a review July 10, 2023 14:20
@007harshmahajan
007harshmahajan force-pushed the background_probing_service branch from a32ae0e to 4a04b0c Compare July 13, 2023 17:17
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Let us know what kind of feedback you're looking for here - mostly I'd recommend you not worry too much about building all the infrastructure up here and focus on the single method of "okay, its time to probe again, given a NetworkGraph and ProbabilisticScorer who do I choose to target with my probe". Everything else beyond that we can figure out later, but that problem itself is really hard.

@ariard

ariard commented Aug 1, 2023

Copy link
Copy Markdown

Let us know what kind of feedback you're looking for here - mostly I'd recommend you not worry too much about building all the infrastructure up here and focus on the single method of "okay, its time to probe again, given a NetworkGraph and ProbabilisticScorer who do I choose to target with my probe”

+1 if we think it’s breaking something of existent interface or bad interference with Lightning network, we’ll let it know during review. Would be very nice to have proving infra in LDK :)

@007harshmahajan

Copy link
Copy Markdown
Author

It seems that the problem stated "okay, its time to probe again, given a NetworkGraph and ProbabilisticScorer who do I choose to target with my probe", has some satisfactory solution with 2 specific method in last commit node_selector which takes NetworkGraph and gives back "Top 1% of nodes with respect to Number of channels" . value_selector works by taking to important parameters of sorted_MAX_HTLC_list, sorted_MIN_HTLC_list and sorted_channel_capacity. The main logic for probe value selection is based on binary search

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Hmm. Focusing on the nodes with the most channels isn't a bad idea, but I think just doing normal route-finding isn't super great. One thing we want to consider is having a custom ScoreLookUp (which wraps the ProbabilisticScorer) which ensures that we try a diverse set of paths. If we have a ton of recent data about a path, and we're confident we can pay over it, our scorer is going to strongly prefer that. That's great for paying, but when probing we generally want the opposite - we're trying to gather data, success rate isn't the goal.

@007harshmahajan

007harshmahajan commented Aug 29, 2023 •

Copy link
Copy Markdown
Author

So the thing is lightning network is big and dynamic, probing for all channel is neither feasible nor practical, because if we are about to know complete graph knowledge, it changes and doing sending node a payment at same time would overwhelm
the network, hence without complete knowledge or greed to know so, let defocus and see "why we are probing ?" to make our payment reliable. so using the standard router, same a payment will yield better result for our payments. Hence same path and same router
And yes the ProbabilisticScorer need to be setup, it will be updated by event handle of probe events

Also, complete probing has be its new repo (same as ldk-sample or ldk-node )as in future it will be stand alone service

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Right, I didn't mean to imply that we should week to gather knowledge about every single channel in the network, indeed that's not really practical, nor useful. However, if there are three "preferred" paths for us to get to node C, and we learn that the first path is good, probing that same path over and over and over again isn't all that interesting - we aren't learning anything new, and we're wasting network resources to do so. Rather, it'd be very nice to use our probing to also learn a bit about the other two paths that we think look good, that way when our first-choice paths fails we have some information about other choices, rather than flying completely blind.

@007harshmahajan

Copy link
Copy Markdown
Author

Yes, that would work great, I would try to implement that soon

@tnull

tnull commented Aug 30, 2023 •

Copy link
Copy Markdown
Contributor

Right, I didn't mean to imply that we should week to gather knowledge about every single channel in the network, indeed that's not really practical, nor useful. However, if there are three "preferred" paths for us to get to node C, and we learn that the first path is good, probing that same path over and over and over again isn't all that interesting - we aren't learning anything new, and we're wasting network resources to do so. Rather, it'd be very nice to use our probing to also learn a bit about the other two paths that we think look good, that way when our first-choice paths fails we have some information about other choices, rather than flying completely blind.

It might even be worth to take a look at some advanced graph algorithms to find some paths that provide optimal coverage of a set of picked edges or nodes with as little as possible overlap. In contrast to our usual on-device routing, it might be worth to optimize the background prober for probing capital efficiency rather than algorithmic runtime.

@007harshmahajan

Copy link
Copy Markdown
Author

Well, due to time constrains its was implemented with DefaultRouter, but the next steps would be having background-probing specific router, which will be optimised for probing, and maybe using this server with existing node, because in current state, we have to create a completely new nodes, and need to setup the channels

@jkczyz jkczyz left a comment

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.

Discussed offline. Let's clean up value_selector and make sure it is thoroughly documented and all cases are unit tested.

Comment thread lightning-background-prober/src/lib.rs Outdated
Comment on lines +422 to +424
let vec_len = node_rating.probes.len();

if vec_len == 0 {

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.

Why do we need a Vec for probes? What's the significance of checking its length?

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.

It is used to know number of probes send till now, as first probe values depend on max_htlc_list and channel_capacity_list, I didnt found any good method, without any counter (It might not be updated correctly) or Vec.len()

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.

It is used to know number of probes send till now, as first probe values depend on max_htlc_list and channel_capacity_list,

Could you describe in detail how the Vec is used? I'm not entirely convinced it is necessary. Does the number of probes in the Vec ever decrease? We can't have a data structure that is constantly growing.

I didnt found any good method, without any counter (It might not be updated correctly) or Vec.len()

I'm not sure what you mean by this.

@007harshmahajan 007harshmahajan Sep 1, 2023 •

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.

There has to be some counter to know "How many probes has been sent to target_node" and Vec keeps count of that alonge with various info like probe_value, as we discussed First probe, don't have any knowledge of path, hence it uses min(max_htlc_list[0].1, capacity_list[0].1.unwrap())

If Vec.len() == 0 hence no probe has been sent
else if Vec.len() == 1 hence 1 probe has been sent

And for every newly network graph graph, which is currently 24hrs, complete NodeRating (Local Probe persister) will be dropped and new instance will be created

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.

There has to be some counter to know "How many probes has been sent to target_node" and Vec keeps count of that alonge with various info like probe_value, as we discussed First probe, don't have any knowledge of path, hence it uses min(max_htlc_list[0].1, capacity_list[0].1.unwrap())

If Vec.len() == 0 hence no probe has been sent else if Vec.len() == 1 hence 1 probe has been sent

Why not an Option? When would we need to know about more than one probe?

And for every newly network graph graph, which is currently 24hrs, complete NodeRating (Local Probe persister) will be dropped and new instance will be created

That's still needlessly using memory that isn't needed during the 24 hours, no?

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.

Got your point, it only need 2 probes persisted, one is 'last successful probe' and second is 'last probe', will make the required changes

return val
}
ProbeStatus::Failure => {
let val = (0.5*((value) as f64)).floor() as u64;

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.

Integer division should be sufficient.

Comment thread lightning-background-prober/src/lib.rs Outdated
Comment on lines +447 to +450
if let Some(last_probe) = node_rating.probes.last_mut() {
last_probe.update_path(path);
last_probe.update_value(val);
}

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.

I don't quite follow the logic. What's the purpose of this?

Comment thread lightning-background-prober/src/lib.rs Outdated
Comment on lines +427 to +431
node_rating.probes.push(ProbePersister::new(nodeid));
if let Some(last_probe) = node_rating.probes.last_mut() {
last_probe.update_path(path);
last_probe.update_value(val);
}

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.

Seems like you can set these before inserting into the Vec?

Comment thread lightning-background-prober/src/lib.rs Outdated
Comment on lines +484 to +485
let val_mid = node_rating.probes.get(vec_len-2).unwrap().value.unwrap();
let val = (0.5*((value + val_mid) as f64)).floor() as u64;

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.

Other than these lines, it looks like the else block is entirely the same as the preceding else if block. Could you write this to avoid repeating yourself?

Comment on lines +409 to +410
//Value selector for probing (Uses binary search method)
async fn value_selector (

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.

Please add more thorough documentation.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Patch coverage: 71.21% and project coverage change: -0.14% ⚠️

Comparison is base (e9d9711) 90.58% compared to head (bdcadbd) 90.45%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2397      +/-   ##
==========================================
- Coverage   90.58%   90.45%   -0.14%     
==========================================
  Files         110      111       +1     
  Lines       57526    57922     +396     
  Branches    57526    57922     +396     
==========================================
+ Hits        52112    52392     +280     
- Misses       5414     5530     +116     
Files Changed Coverage Δ
lightning-background-prober/src/lib.rs 71.21% <71.21%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@007harshmahajan

007harshmahajan commented Sep 13, 2023 •

Copy link
Copy Markdown
Author

@TheBlueMatt and @jkczyz I would like to get some direction for this project going forward

  • working on better node_selector with total_capacity node handles and number of good_channels (each channel's capacity and frequency of transaction )
  • make probing_router
  • implementing it as server, This can be done by referencing the ldk-sample and ldk-node (having is separate repo has to be considered)

@jkczyz

jkczyz commented Sep 13, 2023

Copy link
Copy Markdown
Contributor

@TheBlueMatt and @jkczyz I would like to get some direction for this project going forward

  • working on better node_selector with total_capacity node handles and number of good_channels (each channel's capacity and frequency of transaction )
  • make probing_router
  • implementing it as server, This can be done by referencing the ldk-sample and ldk-node (having is separate repo has to be considered)

Will discuss offline, but I don't believe there is much code here for us to use without substantial changes to work in LDK's event model and without a heavy amount of review cycles.

Comment on lines +657 to +661
if let a = max_htlc_list.is_empty() {
// only if max_htlc_list is empty and last_probe == None
// DEFAULT_FINAL_VALUE_MSAT = 1000
return DEFAULT_FINAL_VALUE_MSAT;
}

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.

This pattern will always match, so the early return is hit and none of the code that follows would ever be executed.

If you remove #![allow(warnings)], the compiler will tell you:

warning: irrefutable `if let` pattern
   --> lightning-background-prober/src/lib.rs:657:9
    |
657 |                     if let a = max_htlc_list.is_empty() {
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this pattern will always match, so the `if let` is useless
    = help: consider replacing the `if let` with a `let`
    = note: `#[warn(irrefutable_let_patterns)]` on by default

You'll want:

if max_htlc_list.is_empty() {
	 return DEFAULT_FINAL_VALUE_MSAT;
}

Likewise in a few other places below. So seems like you are missing some test coverage.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Gonna go ahead and close this as abandoned. While it was a valiant effort, I think biting off a bit less in any new attempt would be good - simply focus on a single public function that takes a NetworkGraph and returns a Path to probe, with a focus on paths for which we have less information.

@TheBlueMatt TheBlueMatt closed this Dec 5, 2023
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.

6 participants