From d8949174589c6a92073a602ec123c99309284053 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 18 Oct 2017 15:18:02 -0700 Subject: [PATCH] server: add new shouldRequestGraphSync method to gate third feature bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we add a new method shouldRequestGraphSync which the server will use in order to determine if we should request a full channel graph sync from a newly connected remote peer. Atm, we’ll only request a full sync iff, we have less than two peers. This is only the initial basic logic, as we’ll later extend this to be more comprehensive. With this change, we’ll no longer be blasted by full channel graph dumps for _each_ new connection after we deem that we’ve been sufficiently bootstrapped to the network. --- server.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server.go b/server.go index 9455ab43..2fa3cbff 100644 --- a/server.go +++ b/server.go @@ -1079,6 +1079,17 @@ func (s *server) peerTerminationWatcher(p *peer) { } } +// shouldRequestGraphSync returns true if the servers deems it necessary that +// we sync channel graph state with the remote peer. This method is used to +// avoid _always_ syncing channel graph state with each peer that connects. +// +// NOTE: This MUST be called with the server's mutex held. +func (s *server) shouldRequestGraphSync() bool { + // Initially, we'll only request a graph sync iff we have less than two + // peers. + return len(s.peersByPub) <= 2 +} + // peerConnected is a function that handles initialization a newly connected // peer by adding it to the server's global list of all active peers, and // starting all the goroutines the peer needs to function properly. @@ -1095,6 +1106,13 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, // With the brontide connection established, we'll now craft the local // feature vector to advertise to the remote node. localFeatures := lnwire.NewRawFeatureVector() + + // We'll only request a full channel graph sync if we detect that that + // we aren't fully synced yet. + if s.shouldRequestGraphSync() { + localFeatures.Set(lnwire.InitialRoutingSync) + } + // Now that we've established a connection, create a peer, and it to // the set of currently active peers. p, err := newPeer(conn, connReq, s, peerAddr, inbound, localFeatures)