Skip to content

Commit 12379c6

Browse files
committed
les: remove delayed les server starting
1 parent f5348e1 commit 12379c6

File tree

4 files changed

+5
-37
lines changed

4 files changed

+5
-37
lines changed

eth/backend.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ type Config struct {
105105

106106
type LesServer interface {
107107
Start(srvr *p2p.Server)
108-
Synced()
109108
Stop()
110109
Protocols() []p2p.Protocol
111110
}

eth/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int
173173
return blockchain.CurrentBlock().NumberU64()
174174
}
175175
inserter := func(blocks types.Blocks) (int, error) {
176-
manager.setSynced() // Mark initial sync done on any fetcher import
176+
atomic.StoreUint32(&manager.synced, 1) // Mark initial sync done on any fetcher import
177177
return manager.insertChain(blocks)
178178
}
179179
manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer)

eth/sync.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
181181
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
182182
return
183183
}
184-
pm.setSynced() // Mark initial sync done
184+
atomic.StoreUint32(&pm.synced, 1) // Mark initial sync done
185185

186186
// If fast sync was enabled, and we synced up, disable it
187187
if atomic.LoadUint32(&pm.fastSync) == 1 {
@@ -192,10 +192,3 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
192192
}
193193
}
194194
}
195-
196-
// setSynced sets the synced flag and notifies the light server if present
197-
func (pm *ProtocolManager) setSynced() {
198-
if atomic.SwapUint32(&pm.synced, 1) == 0 && pm.lesServer != nil {
199-
pm.lesServer.Synced()
200-
}
201-
}

les/server.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ type LesServer struct {
4242
fcManager *flowcontrol.ClientManager // nil if our node is client only
4343
fcCostStats *requestCostStats
4444
defParams *flowcontrol.ServerParams
45-
srvr *p2p.Server
46-
synced, stopped bool
47-
lock sync.Mutex
45+
stopped bool
4846
}
4947

5048
func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
@@ -70,35 +68,13 @@ func (s *LesServer) Protocols() []p2p.Protocol {
7068
return s.protocolManager.SubProtocols
7169
}
7270

73-
// Start only starts the actual service if the ETH protocol has already been synced,
74-
// otherwise it will be started by Synced()
71+
// Start starts the LES server
7572
func (s *LesServer) Start(srvr *p2p.Server) {
76-
s.lock.Lock()
77-
defer s.lock.Unlock()
78-
79-
s.srvr = srvr
80-
if s.synced {
81-
s.protocolManager.Start(s.srvr)
82-
}
83-
}
84-
85-
// Synced notifies the server that the ETH protocol has been synced and LES service can be started
86-
func (s *LesServer) Synced() {
87-
s.lock.Lock()
88-
defer s.lock.Unlock()
89-
90-
s.synced = true
91-
if s.srvr != nil && !s.stopped {
92-
s.protocolManager.Start(s.srvr)
93-
}
73+
s.protocolManager.Start(srvr)
9474
}
9575

9676
// Stop stops the LES service
9777
func (s *LesServer) Stop() {
98-
s.lock.Lock()
99-
defer s.lock.Unlock()
100-
101-
s.stopped = true
10278
s.fcCostStats.store()
10379
s.fcManager.Stop()
10480
go func() {

0 commit comments

Comments
 (0)