@@ -59,7 +59,9 @@ type blockFetcherFn func([]common.Hash) error
59
59
type ProtocolManager struct {
60
60
networkId int
61
61
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
+
63
65
txpool txPool
64
66
blockchain * core.BlockChain
65
67
chaindb ethdb.Database
@@ -161,7 +163,11 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
161
163
heighter := func () uint64 {
162
164
return blockchain .CurrentBlock ().NumberU64 ()
163
165
}
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 )
165
171
166
172
if blockchain .Genesis ().Hash ().Hex () == defaultGenesisHash && networkId == 1 {
167
173
glog .V (logger .Debug ).Infoln ("Bad Block Reporting is enabled" )
@@ -698,8 +704,8 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
698
704
}
699
705
700
706
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 {
703
709
break
704
710
}
705
711
// Transactions can be processed, parse all of them and deliver to the pool
0 commit comments