-
Notifications
You must be signed in to change notification settings - Fork 407
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
Routing improvements #651
Conversation
6818e76
to
922be75
Compare
@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. |
922be75
to
5f551a8
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.
Thanks for the contribution @naumenkogs =]
a96ba6c
to
a761fb4
Compare
Ready for review again :) |
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). |
26fb2e0
to
80308d8
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.
Looks good. A few minor nits, but great work!
} | ||
} | ||
|
||
// TODO check that htlc_maximum_msat is less than max_htlc_value_in_flight_msat |
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.
Why not just do it now :)
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.
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).
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.
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.
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.
Let me re-iterate on your suggestion:
- Add
max_htlc_value_in_flight
field toChannelDetails
struct - When calling for
ChannelDetails
bylist_channels
, this value should be filled from theChannel
record - Then a user will be providing these channels to
get_route
viafirst_hops
field - Inside
get_route
, make suremax_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?
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, definitely belongs in a separate pr, and your understanding is correct. This TODO is just out of place given that context.
8b62d1a
to
d2bd959
Compare
b0141e2
to
f3b4d8d
Compare
f3b4d8d
to
45ee4e8
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
lightning/src/ln/channelmanager.rs
Outdated
@@ -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}; |
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.
flags is a u8, I think this diff hunk can be droped.
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.
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?
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.
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.
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.
Addressed.
lightning/src/ln/channelmanager.rs
Outdated
@@ -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}; |
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.
Same here.
905ba70
to
a086924
Compare
a086924
to
dd0e4f4
Compare
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