core, light: send chain events using event.Feed (#14865)
This commit is contained in:
@ -271,7 +271,8 @@ func (s *requestCostStats) update(msgCode, reqCnt, cost uint64) {
|
||||
|
||||
func (pm *ProtocolManager) blockLoop() {
|
||||
pm.wg.Add(1)
|
||||
sub := pm.eventMux.Subscribe(core.ChainHeadEvent{})
|
||||
headCh := make(chan core.ChainHeadEvent, 10)
|
||||
headSub := pm.blockchain.SubscribeChainHeadEvent(headCh)
|
||||
newCht := make(chan struct{}, 10)
|
||||
newCht <- struct{}{}
|
||||
go func() {
|
||||
@ -280,10 +281,10 @@ func (pm *ProtocolManager) blockLoop() {
|
||||
lastBroadcastTd := common.Big0
|
||||
for {
|
||||
select {
|
||||
case ev := <-sub.Chan():
|
||||
case ev := <-headCh:
|
||||
peers := pm.peers.AllPeers()
|
||||
if len(peers) > 0 {
|
||||
header := ev.Data.(core.ChainHeadEvent).Block.Header()
|
||||
header := ev.Block.Header()
|
||||
hash := header.Hash()
|
||||
number := header.Number.Uint64()
|
||||
td := core.GetTd(pm.chainDb, hash, number)
|
||||
@ -319,7 +320,7 @@ func (pm *ProtocolManager) blockLoop() {
|
||||
}
|
||||
}()
|
||||
case <-pm.quitSync:
|
||||
sub.Unsubscribe()
|
||||
headSub.Unsubscribe()
|
||||
pm.wg.Done()
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user