mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
les: protocol manager wait group filled in main goroutine
This commit is contained in:
parent
853d5d3fd0
commit
a231fdbf79
2 changed files with 3 additions and 17 deletions
|
|
@ -20,7 +20,6 @@ package les
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -118,21 +117,17 @@ func newLightFetcher(pm *ProtocolManager) *lightFetcher {
|
||||||
maxConfirmedTd: big.NewInt(0),
|
maxConfirmedTd: big.NewInt(0),
|
||||||
}
|
}
|
||||||
pm.peers.notify(f)
|
pm.peers.notify(f)
|
||||||
|
|
||||||
|
f.pm.wg.Add(1)
|
||||||
go f.syncLoop()
|
go f.syncLoop()
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncLoop is the main event loop of the light fetcher
|
// syncLoop is the main event loop of the light fetcher
|
||||||
func (f *lightFetcher) syncLoop() {
|
func (f *lightFetcher) syncLoop() {
|
||||||
once := true
|
|
||||||
requesting := false
|
requesting := false
|
||||||
for {
|
|
||||||
if once && atomic.LoadInt32(f.pm.isClosed) != closed {
|
|
||||||
once = false
|
|
||||||
f.pm.wg.Add(1)
|
|
||||||
defer f.pm.wg.Done()
|
defer f.pm.wg.Done()
|
||||||
}
|
for {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-f.pm.quitSync:
|
case <-f.pm.quitSync:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -125,16 +124,10 @@ type ProtocolManager struct {
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
started int32 = iota
|
|
||||||
closed
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
||||||
// with the ethereum network.
|
// with the ethereum network.
|
||||||
func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, networkId uint64, mux *event.TypeMux, engine consensus.Engine, peers *peerSet, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, txrelay *LesTxRelay, quitSync chan struct{}, wg *sync.WaitGroup) (*ProtocolManager, error) {
|
func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, networkId uint64, mux *event.TypeMux, engine consensus.Engine, peers *peerSet, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, txrelay *LesTxRelay, quitSync chan struct{}, wg *sync.WaitGroup) (*ProtocolManager, error) {
|
||||||
// Create the protocol manager with the base fields
|
// Create the protocol manager with the base fields
|
||||||
isClosed := started
|
|
||||||
manager := &ProtocolManager{
|
manager := &ProtocolManager{
|
||||||
lightSync: lightSync,
|
lightSync: lightSync,
|
||||||
eventMux: mux,
|
eventMux: mux,
|
||||||
|
|
@ -147,7 +140,6 @@ func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, network
|
||||||
txrelay: txrelay,
|
txrelay: txrelay,
|
||||||
peers: peers,
|
peers: peers,
|
||||||
newPeerCh: make(chan *peer),
|
newPeerCh: make(chan *peer),
|
||||||
isClosed: &isClosed,
|
|
||||||
quitSync: quitSync,
|
quitSync: quitSync,
|
||||||
wg: wg,
|
wg: wg,
|
||||||
noMorePeers: make(chan struct{}),
|
noMorePeers: make(chan struct{}),
|
||||||
|
|
@ -252,7 +244,6 @@ func (pm *ProtocolManager) Stop() {
|
||||||
pm.peers.Close()
|
pm.peers.Close()
|
||||||
|
|
||||||
// Wait for any process action. Wait should be executed after all pm.wg.Add()
|
// Wait for any process action. Wait should be executed after all pm.wg.Add()
|
||||||
atomic.StoreInt32(pm.isClosed, closed)
|
|
||||||
pm.wg.Wait()
|
pm.wg.Wait()
|
||||||
|
|
||||||
log.Info("Light Ethereum protocol stopped")
|
log.Info("Light Ethereum protocol stopped")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue