mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
refactor(eth): enable acceptTxs flag on any new block imported
This commit is contained in:
parent
78ec90717a
commit
446eb447fb
1 changed files with 21 additions and 0 deletions
|
|
@ -228,6 +228,8 @@ func (pm *ProtocolManager) Start(maxPeers int) {
|
|||
// start sync handlers
|
||||
go pm.syncer()
|
||||
go pm.txsyncLoop()
|
||||
|
||||
go pm.enableAcceptTxWhenGotNewHead()
|
||||
}
|
||||
|
||||
func (pm *ProtocolManager) Stop() {
|
||||
|
|
@ -811,3 +813,22 @@ func (pm *ProtocolManager) NodeInfo() *NodeInfo {
|
|||
Head: currentBlock.Hash(),
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *ProtocolManager) enableAcceptTxWhenGotNewHead() {
|
||||
chainHeadCh := make(chan core.ChainHeadEvent, 10)
|
||||
chainHeadSub := pm.blockchain.SubscribeChainHeadEvent(chainHeadCh)
|
||||
defer chainHeadSub.Unsubscribe()
|
||||
|
||||
for {
|
||||
select {
|
||||
case ev := <-chainHeadCh:
|
||||
if ev.Block != nil {
|
||||
atomic.StoreUint32(&pm.acceptTxs, 1) // enable accept tx
|
||||
return
|
||||
}
|
||||
|
||||
case <-pm.quitSync:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue