Skip to content

Handle initial_routing_sync requests from peers in their Init messages (issue 148) #202

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

SWvheerden
Copy link
Contributor

I have made an initial outline for #148.
Although the code currently sits in router, I am thinking of doing it the same way as router and channelmanger is linked to peer_handler.

There is two ways we can do this, one through a new independent trait, which means that peer_handler will have two ref to router.
Or we replace MessageHandler.route_handler with a trait that incorporates RoutingMessagerHandler and NetworkAPI.

@ariard
Copy link

ariard commented Oct 2, 2018

Which are the reasons to split the 2 APIs in different traits ? Seems to me a Network store which can get you channel/node announcements but you can't update with new msgs from peers isn't gonna be really useful, is it ?

One of the reason could be easing the management of different networks (public/privates) ?

@SWvheerden
Copy link
Contributor Author

This comes back the SOLID principle, as currently the traits are quite clearly only message handling.
I think the better question would be to find out what the reasoning behind making them traits and open to implementation. Do we want the user to be able to chose which way he wants to handle the routing, network calls, both or only a single one?

As to your question for our implementation using the router struct, we should ensure both pointers point to the same object which seems kinda stupid.

The only advantage of splitting the message handling and network api traits is if for some reason you as a user might want to add some kind of middleware between one or both. But I cant think of a reason why you would want to do this.

@SWvheerden
Copy link
Contributor Author

I believe this is much cleaner code. I combined the two traits, and it now requires both from the same object. I have kept the naming in place for now, but I dont think they will be completely correct if we follow this layout.

@SWvheerden
Copy link
Contributor Author

So I have played around with the idea of caching messages, as we need them to be signed. I dont think we can sign them as we need secret keys for that.

@TheBlueMatt
Copy link
Collaborator

Dunno why email response got dropped...

Hmm, I think you missed my point about the pagination - if, for each peer currently getting a channel dump, you keep only the short_channel_id of the highest channel that we have told it about, then you keep it's network buffer full with updates by querying the Router for the next N updates starting at I'd X (and you can ensure they don't miss anything by relaying normally updates below X).

In the current model you query, get a full list of updates and shove them into the Peet's network buffer all at once. Even if you re-query for the full set of channels each time more room is available in the network buffer (which would be expensive in its own) and send starting from some index you remember, you still end up with race conditions where you will either re-relay information about channels to them or miss relaying information to them because of updates while you were sending them the full set.

@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch 2 times, most recently from f0672a4 to cc88399 Compare October 17, 2018 11:43
@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch 3 times, most recently from f6ef81d to 1c7e142 Compare October 25, 2018 05:23
@SWvheerden SWvheerden changed the title RFC for initial outline for issue 148 Handle initial_routing_sync requests from peers in their Init messages (issue 148) Oct 25, 2018
src/ln/msgs.rs Outdated
@@ -591,6 +592,8 @@ pub trait RoutingMessageHandler : Send + Sync {
fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, HandleError>;
/// Handle some updates to the route graph that we learned due to an outbound failed payment.
fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate);
///This returns a vec of vec's, one for ChannelAnnouncements, one for ChannelUpdates and one for NodeAnnouncements. It also returns the id of the last channel passed through
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't return a vec of vecs? Also this doc doesn't describe what the function is for.

//we wait to see if the buffer clears before we retrieve more message to send
//we push up to 15 message out, 5 remaining means they have cleared 2/3rds
while peer.pending_outbound_buffer.len()>5{
thread::sleep(time::Duration::from_millis(50));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't sleep here, we should instead mark where we are in the peer and add more messages to the outbound queue when we get a write_event() from the user.

@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch from 1c7e142 to adb39ae Compare October 29, 2018 15:32
@SWvheerden
Copy link
Contributor Author

Okay, so I created another macro that firs checks the messages then passes it on towards the encode and send macro

@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch from f212c5e to 4577cae Compare October 30, 2018 09:06
@SWvheerden
Copy link
Contributor Author

Okay, I think I added this to the correct location

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.

Yea, I think this is the right approach, nice. Doesn't look like it should work (looks panic-y to me), but I didn't test it yet. Ideally this would come with a test, but I dont think we currently have any tests for PeerHandler, so I won't suggest its blocking, but it would be really nice to have something that tests PeerHandler if its gonna grow any more complicated.

@SWvheerden
Copy link
Contributor Author

SWvheerden commented Oct 31, 2018

I agree on the test thing, but we need to create tests to test the message interaction first (simulate the network with announcement and update messages)

Otherwise its going to be a very fake kinda useless test, as we need to test the routing with this.

@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch 3 times, most recently from 244ad7e to 00f3c88 Compare November 1, 2018 13:05
@SWvheerden SWvheerden mentioned this pull request Nov 1, 2018
4 tasks
@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch 3 times, most recently from 40e8774 to 0a2aed9 Compare November 5, 2018 12:44
@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch from 82926a3 to 44e5203 Compare November 6, 2018 05:18
@SWvheerden SWvheerden force-pushed the Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages branch from 1716ddb to fda1096 Compare November 6, 2018 05:38
@TheBlueMatt
Copy link
Collaborator

Will take as #247 the patch from this PR to that is TheBlueMatt@b46c3cc.

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