core, light: send chain events using event.Feed (#14865)

This commit is contained in:
Miya Chen
2017-08-18 18:58:36 +08:00
committed by Felix Lange
parent a4da8416ee
commit bf1e263128
37 changed files with 786 additions and 372 deletions

View File

@ -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
}