Skip to content

Commit a98e8c0

Browse files
authored
Merge pull request #3413 from zsfelfoldi/light-topic4
les, p2p/discv5: implement server pool, improve peer selection, light fetcher and topic searching
2 parents ee445a2 + f12f8a6 commit a98e8c0

21 files changed

+1913
-546
lines changed

eth/backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type Config struct {
104104

105105
type LesServer interface {
106106
Start(srvr *p2p.Server)
107+
Synced()
107108
Stop()
108109
Protocols() []p2p.Protocol
109110
}
@@ -145,6 +146,7 @@ type Ethereum struct {
145146

146147
func (s *Ethereum) AddLesServer(ls LesServer) {
147148
s.lesServer = ls
149+
s.protocolManager.lesServer = ls
148150
}
149151

150152
// New creates a new Ethereum object (including the

eth/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ type ProtocolManager struct {
8787
quitSync chan struct{}
8888
noMorePeers chan struct{}
8989

90+
lesServer LesServer
91+
9092
// wait group is used for graceful shutdowns during downloading
9193
// and processing
9294
wg sync.WaitGroup
@@ -171,7 +173,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int
171173
return blockchain.CurrentBlock().NumberU64()
172174
}
173175
inserter := func(blocks types.Blocks) (int, error) {
174-
atomic.StoreUint32(&manager.synced, 1) // Mark initial sync done on any fetcher import
176+
manager.setSynced() // Mark initial sync done on any fetcher import
175177
return manager.insertChain(blocks)
176178
}
177179
manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer)

eth/sync.go

Lines changed: 8 additions & 1 deletion
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-
atomic.StoreUint32(&pm.synced, 1) // Mark initial sync done
184+
pm.setSynced() // 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,3 +192,10 @@ 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+
}

0 commit comments

Comments
 (0)