@@ -59,7 +59,9 @@ type blockFetcherFn func([]common.Hash) error
5959type ProtocolManager struct {
6060 networkId int
6161
62- fastSync uint32
62+ fastSync uint32 // Flag whether fast sync is enabled (gets disabled if we already have blocks)
63+ synced uint32 // Flag whether we're considered synchronised (enables transaction processing)
64+
6365 txpool txPool
6466 blockchain * core.BlockChain
6567 chaindb ethdb.Database
@@ -161,7 +163,11 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
161163 heighter := func () uint64 {
162164 return blockchain .CurrentBlock ().NumberU64 ()
163165 }
164- manager .fetcher = fetcher .New (blockchain .GetBlock , validator , manager .BroadcastBlock , heighter , manager .insertChain , manager .removePeer )
166+ inserter := func (blocks types.Blocks ) (int , error ) {
167+ atomic .StoreUint32 (& manager .synced , 1 ) // Mark initial sync done on any fetcher import
168+ return manager .insertChain (blocks )
169+ }
170+ manager .fetcher = fetcher .New (blockchain .GetBlock , validator , manager .BroadcastBlock , heighter , inserter , manager .removePeer )
165171
166172 if blockchain .Genesis ().Hash ().Hex () == defaultGenesisHash && networkId == 1 {
167173 glog .V (logger .Debug ).Infoln ("Bad Block Reporting is enabled" )
@@ -698,8 +704,8 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
698704 }
699705
700706 case msg .Code == TxMsg :
701- // Transactions arrived, make sure we have a valid chain to handle them
702- if atomic .LoadUint32 (& pm .fastSync ) == 1 {
707+ // Transactions arrived, make sure we have a valid and fresh chain to handle them
708+ if atomic .LoadUint32 (& pm .synced ) == 0 {
703709 break
704710 }
705711 // Transactions can be processed, parse all of them and deliver to the pool
0 commit comments