aboutsummaryrefslogtreecommitdiffstats
path: root/les
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-09 16:03:22 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-10 16:53:25 +0800
commitc57c54ce96628aeb6345776310123a80593f0143 (patch)
tree1d590f2f0aee32179a57eba5a4886f4296ab1196 /les
parentc8130df1d9dcc504244a49cbb12aa4c2848e5de2 (diff)
downloadgo-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar.gz
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar.bz2
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar.lz
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar.xz
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.tar.zst
go-tangerine-c57c54ce96628aeb6345776310123a80593f0143.zip
eth, les: defer starting LES service until ETH initial sync is finished
Diffstat (limited to 'les')
-rw-r--r--les/handler.go4
-rw-r--r--les/server.go28
2 files changed, 29 insertions, 3 deletions
diff --git a/les/handler.go b/les/handler.go
index 3fc80e19a..048f30217 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -267,9 +267,9 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) {
} else {
if topicDisc != nil {
go func() {
- glog.V(logger.Debug).Infoln("Starting registering topic", string(lesTopic))
+ glog.V(logger.Info).Infoln("Starting registering topic", string(lesTopic))
topicDisc.RegisterTopic(lesTopic, pm.quitSync)
- glog.V(logger.Debug).Infoln("Stopped registering topic", string(lesTopic))
+ glog.V(logger.Info).Infoln("Stopped registering topic", string(lesTopic))
}()
}
go func() {
diff --git a/les/server.go b/les/server.go
index c763e8c63..03cc2bb5e 100644
--- a/les/server.go
+++ b/les/server.go
@@ -42,6 +42,9 @@ type LesServer struct {
fcManager *flowcontrol.ClientManager // nil if our node is client only
fcCostStats *requestCostStats
defParams *flowcontrol.ServerParams
+ srvr *p2p.Server
+ synced, stopped bool
+ lock sync.Mutex
}
func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
@@ -67,12 +70,35 @@ func (s *LesServer) Protocols() []p2p.Protocol {
return s.protocolManager.SubProtocols
}
+// Start only starts the actual service if the ETH protocol has already been synced,
+// otherwise it will be started by Synced()
func (s *LesServer) Start(srvr *p2p.Server) {
- s.protocolManager.Start(srvr)
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
+ s.srvr = srvr
+ if s.synced {
+ s.protocolManager.Start(s.srvr)
+ }
+}
+
+// Synced notifies the server that the ETH protocol has been synced and LES service can be started
+func (s *LesServer) Synced() {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+ s.synced = true
+ if s.srvr != nil && !s.stopped {
+ s.protocolManager.Start(s.srvr)
+ }
}
+// Stop stops the LES service
func (s *LesServer) Stop() {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
+ s.stopped = true
s.fcCostStats.store()
s.fcManager.Stop()
go func() {