-
Notifications
You must be signed in to change notification settings - Fork 404
Align get_route's interface with ChannelManager and Invoice #946
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
Align get_route's interface with ChannelManager and Invoice #946
Conversation
Codecov Report
@@ Coverage Diff @@
## main #946 +/- ##
==========================================
- Coverage 90.59% 90.57% -0.03%
==========================================
Files 60 60
Lines 30425 30423 -2
==========================================
- Hits 27564 27556 -8
- Misses 2861 2867 +6
Continue to review full report at Codecov.
|
b883ade
to
422f79b
Compare
Lets land this for 0.0.98 to clean up the API which will clean up our docs and sample a good chunk. |
422f79b
to
2e00de6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This basically looks good.
lightning/src/routing/router.rs
Outdated
pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option<InvoiceFeatures>, first_hops: Option<&[&ChannelDetails]>, | ||
last_hops: &[&RouteHintHop], final_value_msat: u64, final_cltv: u32, logger: L) -> Result<Route, LightningError> where L::Target: Logger { | ||
pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option<InvoiceFeatures>, first_hops: Option<&[ChannelDetails]>, | ||
last_hops: Vec<&RouteHint>, final_value_msat: u64, final_cltv: u32, logger: L) -> Result<Route, LightningError> where L::Target: Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take a &[&RouteHint]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to make it easy for callers by allowing them to pass the result of Invoice::route_hints
directly. I guess they could just take a slice now that route_hints
does the conversion, but I'll have to either touch or revert a bunch of code. Any specific reason a slice would be preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any reason to need this by-value here? I suppose &Vec is also fine but slice is more general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to take a slice.
2e00de6
to
b1abfb2
Compare
Used for extracting more than one field of the same type.
199ea3f
to
7ea6106
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can you squash fixups?
7ea6106
to
b56fdd0
Compare
lightning/src/routing/router.rs
Outdated
@@ -343,8 +347,8 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> { | |||
/// The fees on channels from us to next-hops are ignored (as they are assumed to all be | |||
/// equal), however the enabled/disabled bit on such channels as well as the | |||
/// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. | |||
pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option<InvoiceFeatures>, first_hops: Option<&[&ChannelDetails]>, | |||
last_hops: &[&RouteHintHop], final_value_msat: u64, final_cltv: u32, logger: L) -> Result<Route, LightningError> where L::Target: Logger { | |||
pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, payee: &PublicKey, payee_features: Option<InvoiceFeatures>, first_hops: Option<&[ChannelDetails]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, ugh, the ChannelDetails
reference is here mostly for the bindings - the bindings take an array of pointers with some additional metadata, so they can't trivially convert them to [ChannelDetails]
without a bunch of copies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped the commit but it does make the user do more work at the call site. Here is what the guide is looking like:
let amt_pico_btc = invoice.amount_pico_btc()
.expect("ERROR: invalid invoice: must contain amount to pay");
let amt_msat = amt_pico_btc / 10;
let payer_pubkey = channel_manager.get_our_node_id();
let network_graph = router.network_graph.read().unwrap();
let payee_pubkey = invoice.recover_payee_pub_key();
let payee_features = invoice.features().cloned();
let first_hops = channel_manager.list_usable_channels();
let last_hops = invoice.route_hints();
let final_cltv = invoice.min_final_cltv_expiry() as u32;
let route = router::get_route(
&payer_pubkey, &network_graph, &payee_pubkey, payee_features,
Some(&first_hops.iter().collect::<Vec<_>>()), &last_hops,
amt_msat, final_cltv, logger.clone(),
).expect("ERROR: failed to find route");
let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
let payment_secret = invoice.payment_secret().cloned();
channel_manager.send_payment(&route, payment_hash, &payment_secret)
.expect("ERROR: failed to send payment");
Later, we may want take a pass through how our interfaces to see how well they mesh together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, its very not-ideal, I agree. I'm not really sure how to fix it in the bindings context, though, sadly.
b56fdd0
to
abf1deb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs squash.
Lightning invoices allow for zero or more multi-hop route hints. Update get_route's interface to accept such hints, although only the last hop from each is used for the time being. Moves RouteHint from lightning-invoice crate to lightning crate. Adds a PrivateRoute wrapper around RouteHint for use in lightning-invoice.
abf1deb
to
d0355b7
Compare
@@ -128,7 +123,7 @@ mod test { | |||
&invoice.recover_payee_pub_key(), | |||
Some(invoice.features().unwrap().clone()), | |||
Some(&first_hops.iter().collect::<Vec<_>>()), | |||
&last_hops.iter().collect::<Vec<_>>(), | |||
&last_hops, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer
Update
get_route
's interface to work better withChannelManager
andInvoice
.pass result ofChannelManager::list_usable_channels
asfirst_hops
without convertinglast_hops
fromInvoice::routes
without copyingThis is only the interface change for #945. Only the last hop from each
RouteHint
is considered byget_route
for now.