diff --git a/eth/handler.go b/eth/handler.go index 29f224910a..453feea7cd 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -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 + } + } +}