Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support onion message pathfinding #1669

Conversation

valentinewallace
Copy link
Contributor

We could reuse router::get_route, but it's better to start from scratch
because get_route includes a lot of payment-specific computations that impact
performance.

Partially addresses #1607

Used in upcoming commit(s) to test onion message pathfinding
We *could* reuse router::get_route, but it's better to start from scratch
because get_route includes a lot of payment-specific computations that impact
performance.
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

The Dijkstras implementation could be cleaned up a lot...

}

// Heavily adapted from https://github.com/samueltardieu/pathfinding/blob/master/src/directed/dijkstra.rs
// TODO: how2credit the repo (is that necessary?)?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmmmm, good question. In general, the MIT and Apache licenses both require attribution, including of downstream projects. However, the Apache license only requires it if there is a file called "NOTICE" or any "copyright, patent, trademark, and attribution notices", which then must be provided downstream, and the MIT license only requires that "the above copyright notice be included", but the original repo doesn't actually include the MIT license anywhere, nor does it include any relevant notices as far as I can see, so there is no relevant "above copyright notice" to include, aside from the first paragraph of the MIT license, which we of course include as LICENSE-MIT. Thus, I think we can reasonably argue that a simple comment above this code indicating that it is adapted from (link) which is code Copyright Samuel Tardieu should suffice, which complies with the Apache "You must cause any modified files to carry prominent noticesstating that You changed the files" requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1724 ended up not adapting this crate's implementation anymore (shoutout to Wikpedia)

lightning/src/onion_message/router.rs Show resolved Hide resolved
lightning/src/onion_message/router.rs Show resolved Hide resolved
lightning/src/onion_message/router.rs Show resolved Hide resolved
lightning/src/onion_message/router.rs Show resolved Hide resolved
lightning/src/onion_message/router.rs Show resolved Hide resolved
@valentinewallace
Copy link
Contributor Author

Ok it's clearly less readable than I thought with a generic Dijkstra's. Staying generic would allow us to pretty much reuse the test vectors in the original repo, but it doesn't seem worth. Gonna convert to draft for now and rewrite the generic portions

@valentinewallace valentinewallace marked this pull request as draft August 17, 2022 17:49
@TheBlueMatt
Copy link
Collaborator

I believe the upstream dijkstras you pulled from is actually buggy, anyway, so the generic-ness isn't worth much :p

@tnull
Copy link
Contributor

tnull commented Aug 18, 2022

Ok it's clearly less readable than I thought with a generic Dijkstra's. Staying generic would allow us to pretty much reuse the test vectors in the original repo, but it doesn't seem worth. Gonna convert to draft for now and rewrite the generic portions

Ah, didn't realize keeping it generic had that intention. Well, it's not unreadable and reusing test vectors may be worth it.
If we however also see a way of refactoring the payment pathfinding to reuse the same generic implementation, we'd should definitely consider it, IMO.

@valentinewallace
Copy link
Contributor Author

I believe the upstream dijkstras you pulled from is actually buggy, anyway, so the generic-ness isn't worth much :p

Lol I might've introduced bugs in my quest to eliminate all vecs from the original, to be fair

@valentinewallace
Copy link
Contributor Author

Ok it's clearly less readable than I thought with a generic Dijkstra's. Staying generic would allow us to pretty much reuse the test vectors in the original repo, but it doesn't seem worth. Gonna convert to draft for now and rewrite the generic portions

Ah, didn't realize keeping it generic had that intention. Well, it's not unreadable and reusing test vectors may be worth it. If we however also see a way of refactoring the payment pathfinding to reuse the same generic implementation, we'd should definitely consider it, IMO.

I did wonder if there were other cases where we'd want a generic implementation. I have no idea whether that'd be realistic with our payment pathfinding though lol, we'd need a way to "decrement available liquidity" for hops in paths that were already found, at least, but maybe that's easy? 🤔

@TheBlueMatt TheBlueMatt reopened this Aug 18, 2022
@TheBlueMatt
Copy link
Collaborator

Oops, sorry lol didn't mean to close.

I did wonder if there were other cases where we'd want a generic implementation. I have no idea whether that'd be realistic with our payment pathfinding though lol

I kinda doubt it - we've ended up with a few algorithmic tweaks in addition to basic dijkstra's, so I'd be surprised if we could munge it back.

/// Find a path for sending an onion message.
pub fn find_path<L: Deref, GL: Deref>(
our_node_pubkey: &PublicKey, receiver_pubkey: &PublicKey, network_graph: &NetworkGraph<GL>, first_hops: Option<&[&PublicKey]>, logger: L
) -> Result<Vec<PublicKey>, LightningError> where L::Target: Logger, GL::Target: Logger
Copy link

Choose a reason for hiding this comment

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

So we wouldn't reuse all the information we're learning and storing in our ProbabilisticScorer. I can see how we're limited with the current penalty being based on the link-level and here we might be interested by node-level reliability in the path construction. That said, we can also assume that a reliable channel == a reliable onion message communication channel and go with it. I don't know if the spec says anything here or what are the thinking of other implementations ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is an option in the spec to return a separate error for "peer offline" from "no capacity", but I'm not sure how common that is. Once we land the historical scoring PR, we could use the "time in the zero-available-capacity bucket" as a score here.

@valentinewallace
Copy link
Contributor Author

Thanks for all the feedback! This needs a lot of work and I'm switching it up to work on custom OMs first -- closing for now.

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.

4 participants