Skip to content

simln-lib/feat: Surface send_to_route for SimGraph #268

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chuksys
Copy link
Contributor

@chuksys chuksys commented May 16, 2025

Description

This PR makes it possible for a user of simln-lib (in sim-node mode) to send payments to a predetermined route. This addresses the need for end-users to send custom payments, crucial for scenarios like channel jamming attacks or pathfinding experiments, which the current activity paradigm doesn't support.

Changes

  • A send_to_route method was added to SimGraph.
  • A track_payment_to_route method was added to SimGraph.
  • A build_payment_route helper function was added.
  • 3 test cases were added to test successful route payment and tracking, route building errors and payment tracking errors.

This PR closes #257

@carlaKC carlaKC self-requested a review May 16, 2025 17:37
@carlaKC carlaKC requested a review from f3r10 May 20, 2025 15:23
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Worried about the layering of adding this functionality to SimGraph, would like to take another look at the high level design here.

Also needs a rebase!

/// Uses the provided `hops` and `amount_msat` to build an LDK route.
/// This is a helper function to build a route easily.
/// The route built using this function can be passed into `SimGraph::send_to_route`.
pub fn build_payment_route(
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, not sure that we need this helper for an advanced user?

Perhaps we an just point to build_route_from_hops on the docs for send_to_route?

})
}

pub async fn send_to_route(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about adding this in SimGraph - feels like a layering violation. I can see how the discussion on the issue was a bit ambiguous - should have pointed out that it should still go on the node even though we don't need to implement it on the other types.

I think that this should live on SimNode so that we can re-use the infrastructure that's already there (eg, we wouldn't need another track payment function, we already have it).

I think it's reasonable to expect the end user to look up the dispatching node that they want and then call SimNode.send_to_route.

@chuksys chuksys force-pushed the surface-send-to-route branch from bd09d2b to b1db235 Compare May 26, 2025 16:57
@chuksys
Copy link
Contributor Author

chuksys commented May 26, 2025

I didn't add any test cases this time around since test_simulated_node in tests already does most of the testing we require by testing the dispatch_payment fn (this is most of the functionality for the send_to_route fn except the newly derived route).

@chuksys chuksys requested a review from carlaKC May 26, 2025 17:35
@chuksys chuksys force-pushed the surface-send-to-route branch from e7684ad to f7f511a Compare May 27, 2025 14:52
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Looking good, just one API q from me + a test ask.

Comment on lines +535 to +536
let preimage = PaymentPreimage(rand::random());
let payment_hash = preimage.into();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm I wonder whether there's any use for people to pass in their own payment hash?

WDYT, I'm on the fence...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this could be helpful if the user wants to simulate payments in an application that relies on a custom payment flow - for example the user could have a payment flow that requires generating the preimage and hash much earlier in their process, perhaps for coordination with other parts of their application, well before the send_to_route method is called.

I think allowing users to pass in their own payment hash would give them the flexibility to accurately model such scenarios.

let payment_hash = preimage.into();

// Check for payment hash collision, failing the payment if we happen to repeat one.
match self.in_flight.entry(payment_hash) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just add one test case that covers sending / tracking a payment with this API - good to have the coverage.

@@ -527,6 +527,33 @@ impl<'a, T: SimNetwork> SimNode<'a, T> {
scorer,
}
}

/// The [`lightning::routing::router::build_route_from_hops`] function can be used to build the route to be passed here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: also note what this function does in the public doc, specifically that it dispatches the payment but it still needs to be tracked for a payment outcome.

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.

Feature Request: Surface Send To Route on LightningNode trait
2 participants