Skip to content

Implement local channel tracking by Router at channel_update #207

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

ariard
Copy link

@ariard ariard commented Oct 12, 2018

Add test_channel_update_local_channel

Issue #149

@ariard
Copy link
Author

ariard commented Oct 12, 2018

A lot of shorts locks picking, maybe need some more care.

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Oct 15, 2018 via email

@ariard ariard force-pushed the 149-local_channel_tracking_route_gen branch from 5dbf16e to 8501947 Compare November 16, 2018 02:11
@ariard
Copy link
Author

ariard commented Nov 16, 2018

Heyy I rebased this stuff and changed some to avoid useless lock but sorry don't understand your last comment because how PeerHandler is supposed to filter our local channels to Router without accessing ChannelManager channels ? Need handle_local_channel on ChannelMessageHandler to get them no ?

@TheBlueMatt
Copy link
Collaborator

My point was that we shouldn't even need to modify the Router DB for this - we should keep the fee knowledge in the Channel object itself and then the user can use list_usable_channels()'s return value as a get_route() argument and we can use the info in get_route that way. Would need a little bit of augmentation of the information provided in ChannelDetails to include feerate information, but I think we'd have less layer violations that way (Router shouldn't need to know about what channels are ours).

@ariard
Copy link
Author

ariard commented Nov 17, 2018

Hmm so #149 is about using feerates from ChannelDetails to improve get_route ? Sorry last comment doesn't align with your first comment in #149 "I think the obvious solution is to track local channels in Router"..

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Nov 21, 2018 via email

@ariard ariard force-pushed the 149-local_channel_tracking_route_gen branch from 8501947 to c13ee0f Compare December 7, 2018 02:38
@ariard
Copy link
Author

ariard commented Dec 7, 2018

Rebased and updated with IRC comments (11-21-2018)

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.

Nice! This looks good modulo a few small things to fix.

@@ -2040,6 +2046,14 @@ impl Channel {

}

/// Set channel fields with remote peer forwarding parameters, used mainly by ChannelDetails to feed the Router
pub fn channel_update(&mut self, msg: &msgs::ChannelUpdate) {
self.their_to_self_delay = msg.contents.cltv_expiry_delta;
Copy link
Collaborator

Choose a reason for hiding this comment

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

to_self_delay is the time before their commitment transaction loses the CSV delay, CLTV_EXPIRY_DELTA is the required difference between an incoming HTLC and the corresponding outgoing HTLC, they're very different values.

Copy link
Author

Choose a reason for hiding this comment

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

urgh, ugly from my part, corrected, was thinking to_self_delay was CLTV_EXPIRY_DELTA while writing this by distraction, even if I'm pretty sure I used it correctly as CSV in others times

/// Set channel fields with remote peer forwarding parameters, used mainly by ChannelDetails to feed the Router
pub fn channel_update(&mut self, msg: &msgs::ChannelUpdate) {
self.their_to_self_delay = msg.contents.cltv_expiry_delta;
self.their_htlc_minimum_msat = msg.contents.htlc_minimum_msat;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be sanity-checked against funding_satoshis (see new_from_req), and while ideally we'd sanity-check against the channel_limits we dont keep those around and I think its probably OK to let counterparties update such things if they need to temporarily disable a channel. This needs to be documented in Config, though, noting that a counterparty can increase this value once the channel is established beyond the minimum, but this is equivalent to them just rejecting all HTLCs so we can't enforce it anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, added comments in Config and sanity-check against channel_value_satoshis (funding_satoshis) and if fail reject the whole update, but should we send back a ChannelError:Close here, or as you said interpret it as temporary disabling of channel?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if they send back something completely bogus, nothing wrong with a ChannelError::Close.

Copy link
Author

Choose a reason for hiding this comment

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

Updated, but don't do comparison for others fields because I think we don't have reference bases

@@ -2776,6 +2792,17 @@ impl ChannelMessageHandler for ChannelManager {
handle_error!(self, self.internal_announcement_signatures(their_node_id, msg), their_node_id)
}

fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<(), HandleError> {
let mut channel_state_lock = self.channel_state.lock().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

While technically I think its safe without it, probably best to keep consistency and add a total_consistency_lock.read().unwrap() at the top.

Copy link
Author

Choose a reason for hiding this comment

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

Added

@@ -8130,4 +8157,5 @@ mod tests {
assert_eq!(spend_txn.len(), 1);
check_spends!(spend_txn[0], closing_tx);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: stray newline.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@ariard ariard force-pushed the 149-local_channel_tracking_route_gen branch from c13ee0f to 3333e6d Compare December 13, 2018 01:27
let channel_state = channel_state_lock.borrow_parts();
if let Some(channel_id) = channel_state.short_to_id.get(&msg.contents.short_channel_id) {
if let Some(chan) = channel_state.by_id.get_mut(channel_id) {
chan.channel_update(&msg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to check the source of the message ie their_node_id as in all the other handler functions.

Copy link
Author

Choose a reason for hiding this comment

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

So refactored function with an internal part to catch easily MsgHandleErrInternal

@ariard ariard force-pushed the 149-local_channel_tracking_route_gen branch from 3333e6d to 1b6093f Compare December 14, 2018 01:12
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.

Oops, sorry, guess I didnt give this one a good shake, why are you tracking the HTLC minimum and fee info? See comment on get_route but the fees a node takes are always calculated on the basis of the announced fees for a given outbound channel. ie the channels from us dont matter for fee calculation, only the HTLC minimum needs to be respected.

@TheBlueMatt
Copy link
Collaborator

Also this needs the corresponding updates in get_route so that we do enforce that requirement.

@ariard
Copy link
Author

ariard commented Dec 15, 2018

Was thinking we needed to track our local channel to do cycle payment to ourselves, because BOLT 7 say "SHOULD accept channel_updates for its own channels (even if non-public), in order to learn the associated origin nodes' forwarding parameters". If we have topology A <--> B <--> C, what does forwarding parameters mean here ? Policy apply by B on link B -> C, or on link A <- B, or on link A -> B as relaying node ? Because if it means the last option, HTLC minimum_msat on A -> B is useless as it gonna be also enforced on B -> C (and seems to me that what really interested us is the lowest HTLC_minimum_msat of the whole payment route)

@TheBlueMatt
Copy link
Collaborator

Hmmmmmm, now I'm really confused. That requirement in the spec may be bogus. At a high level, if A is routing via B to C, the only fees taken are by B and they are the fees B announces on the B->C channel (the rationale being its up to A/the source of an HTLC to figure out what they want to charge to forward along a route, ie you care about the action of forwarding, not accepting). That said, the htlc_minimum_msat value is defined as "the minimum HTLC value (in millisatoshi) that the channel peer will accept" ie B should be announcing the value that we sent it in our channel_open/channel_accept, and I dont see a way to change this value at runtime, so maybe the "SHOULD accept channel_updates for its own channels (even if non-public), in order to learn the associated origin nodes' forwarding parameters." requirement is just bogus? Probably worth asking some other folks and investigating what others do and fixing the spec to make it much clearer in any case.

In any case we definitely need include our counterparty's current htlc_minimum_msat in route calculations (and need some tests for route calculations with htlc_minimums).

@TheBlueMatt
Copy link
Collaborator

The spec isn't wrong here, but its kinda a layer violation implied - I believe its really about learning the inbound fees so that you can include them in route hints in invoices. There's no other reason we'd need that data, but, indeed, route hints are important.

@valentinewallace
Copy link
Contributor

Superseded by #841 :)

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