Skip to content

Implement local channel tracking by Router at channel_update - #207

Closed
ariard wants to merge 1 commit into
lightningdevkit:masterfrom
ariard:149-local_channel_tracking_route_gen
Closed

Implement local channel tracking by Router at channel_update#207
ariard wants to merge 1 commit into
lightningdevkit:masterfrom
ariard:149-local_channel_tracking_route_gen

Conversation

@ariard

@ariard ariard commented Oct 12, 2018

Copy link
Copy Markdown

Add test_channel_update_local_channel

Issue #149

@ariard

ariard commented Oct 12, 2018

Copy link
Copy Markdown
Author

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

@TheBlueMatt

TheBlueMatt commented Oct 15, 2018 via email

Copy link
Copy Markdown
Collaborator

@ariard

ariard commented Nov 16, 2018

Copy link
Copy Markdown
Author

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
Copy Markdown
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

ariard commented Nov 17, 2018

Copy link
Copy Markdown
Author

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

TheBlueMatt commented Nov 21, 2018 via email

Copy link
Copy Markdown
Collaborator

@ariard

ariard commented Dec 7, 2018

Copy link
Copy Markdown
Author

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

@TheBlueMatt TheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread src/ln/channel.rs Outdated

/// 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
Copy Markdown
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
Copy Markdown
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

Comment thread src/ln/channel.rs
/// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread src/ln/channelmanager.rs Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added

Comment thread src/ln/channelmanager.rs Outdated
assert_eq!(spend_txn.len(), 1);
check_spends!(spend_txn[0], closing_tx);
}

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed

Comment thread src/ln/channelmanager.rs Outdated
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
Copy Markdown
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
Copy Markdown
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

@TheBlueMatt TheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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

@ariard

ariard commented Dec 15, 2018

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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