Skip to content

Routing improvements #651

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

Conversation

naumenkogs
Copy link
Contributor

A bunch of tiny fixes and introduction of 2 fields: htlc_maximum_msat (on channel update) and channel capacity, which would be later used in #646

@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch from 6818e76 to 922be75 Compare June 30, 2020 11:45
@naumenkogs
Copy link
Contributor Author

@TheBlueMatt just noticed the issue with fuzzing, do you have an idea of what's wrong here? I'm going through the fuzz logs and it's not particularly helpful.

Copy link
Contributor

@valentinewallace valentinewallace 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 contribution @naumenkogs =]

@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch 2 times, most recently from a96ba6c to a761fb4 Compare July 15, 2020 10:54
@naumenkogs
Copy link
Contributor Author

Ready for review again :)
Would use some help with figuring why fuzzing fails though.

@valentinewallace
Copy link
Contributor

valentinewallace commented Jul 15, 2020

Ready for review again :)
Would use some help with figuring why fuzzing fails though.

I was able to make progress on this by following the instructions here: https://github.com/rust-bitcoin/rust-lightning/tree/master/fuzz#a-fuzz-test-failed-on-travis-what-do-i-do

Looks related to writing out the excess data on an UnsignedChannelUpdate (specifically, it panics on this line).

@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch 3 times, most recently from 26fb2e0 to 80308d8 Compare July 18, 2020 13:52
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.

Looks good. A few minor nits, but great work!

}
}

// TODO check that htlc_maximum_msat is less than max_htlc_value_in_flight_msat
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just do it now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec says MUST set this to less than or equal to max_htlc_value_in_flight_msat it received from the peer..

I'm somewhat lost here... How can we even get this field (max_htlc_value_in_flight_msat)? I see it in OpenChannel/AcceptChannel messages, but those are relevant for our channels, not remote channels (for which we will receive channel updates).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohhh, sorry, I'd missed that that field isnt in the routing gossip. No, so what we should be doing is including max_htlc_value_in_flight in ChannelDetails in channelmanager and then use that via the first_hops argument in get_route. No need to bother crossing layers to enforce the rule in the routing graph when we already allow next-hop channels to override the graph completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me re-iterate on your suggestion:

  1. Add max_htlc_value_in_flight field to ChannelDetails struct
  2. When calling for ChannelDetails by list_channels, this value should be filled from the Channel record
  3. Then a user will be providing these channels to get_route via first_hops field
  4. Inside get_route, make sure max_htlc_value_in_flight is not violated by the payment we're sending.

But this has absolutely nothing to do with htlc_maximum_msat, which was why I initially added this comment to implement a check per the spec?
So you are suggesting to just ignore that spec part, and implement the flow I listed above?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, definitely belongs in a separate pr, and your understanding is correct. This TODO is just out of place given that context.

@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch 3 times, most recently from 8b62d1a to d2bd959 Compare July 22, 2020 12:15
@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch 6 times, most recently from b0141e2 to f3b4d8d Compare July 23, 2020 11:20
@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch from f3b4d8d to 45ee4e8 Compare July 23, 2020 11:31
@codecov
Copy link

codecov bot commented Jul 23, 2020

Codecov Report

Merging #651 into master will increase coverage by 0.04%.
The diff coverage is 99.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #651      +/-   ##
==========================================
+ Coverage   91.25%   91.29%   +0.04%     
==========================================
  Files          35       35              
  Lines       21281    21388     +107     
==========================================
+ Hits        19420    19527     +107     
  Misses       1861     1861              
Impacted Files Coverage Δ
lightning/src/routing/router.rs 96.58% <95.65%> (+0.12%) ⬆️
lightning/src/ln/channel.rs 86.64% <100.00%> (ø)
lightning/src/ln/channelmanager.rs 85.25% <100.00%> (+<0.01%) ⬆️
lightning/src/ln/functional_tests.rs 97.14% <100.00%> (+<0.01%) ⬆️
lightning/src/ln/msgs.rs 90.31% <100.00%> (+0.27%) ⬆️
lightning/src/routing/network_graph.rs 91.43% <100.00%> (+0.36%) ⬆️
lightning/src/util/test_utils.rs 86.13% <100.00%> (+0.05%) ⬆️
lightning/src/util/enforcing_trait_impls.rs 100.00% <0.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50df4cf...dd0e4f4. Read the comment docs.

@@ -1186,7 +1186,9 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
res.extend_from_slice(&byte_utils::be32_to_array(msg.cltv_expiry));
}
else if code == 0x1000 | 20 {
res.extend_from_slice(&byte_utils::be16_to_array(chan_update.contents.flags));
let mut flags = chan_update.contents.flags as u16;
if let OptionalField::Present(_) = chan_update.contents.htlc_maximum_msat {flags |= 1 << 8};
Copy link
Collaborator

Choose a reason for hiding this comment

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

flags is a u8, I think this diff hunk can be droped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chan_update.contents.flags is u8, so I get this compile error: expected u16, found u8``
If I switch to res.push(upd.contents.flags);, 4 tests fail.

But also, I don't understand why you're suggesting to omit the message_flags part of flags?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, interesting, I think this is a misreading of the spec (in the original code). See lightning/bolts#791 but my read is that we should likely be pushing two zero bytes, not the flags bytes from the update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

@@ -2494,7 +2497,9 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
let reason = if let Ok(upd) = self.get_channel_update(chan) {
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
let mut res = Vec::with_capacity(8 + 128);
res.extend_from_slice(&byte_utils::be16_to_array(upd.contents.flags));
let mut flags = upd.contents.flags as u16;
if let OptionalField::Present(_) = upd.contents.htlc_maximum_msat {flags |= 1 << 8};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch 2 times, most recently from 905ba70 to a086924 Compare July 27, 2020 10:53
@naumenkogs naumenkogs force-pushed the 2020-06-routing-data-improvements branch from a086924 to dd0e4f4 Compare July 27, 2020 11:06
@TheBlueMatt TheBlueMatt merged commit 779ff67 into lightningdevkit:master Jul 27, 2020
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.

3 participants