@@ -22,6 +22,7 @@ import (
22
22
"math"
23
23
"math/big"
24
24
"sync"
25
+ "sync/atomic"
25
26
"time"
26
27
27
28
"github.com/ethereum/go-ethereum/common"
@@ -58,7 +59,7 @@ type blockFetcherFn func([]common.Hash) error
58
59
type ProtocolManager struct {
59
60
networkId int
60
61
61
- fastSync bool
62
+ fastSync uint32
62
63
txpool txPool
63
64
blockchain * core.BlockChain
64
65
chaindb ethdb.Database
@@ -87,15 +88,9 @@ type ProtocolManager struct {
87
88
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
88
89
// with the ethereum network.
89
90
func NewProtocolManager (config * core.ChainConfig , fastSync bool , networkId int , mux * event.TypeMux , txpool txPool , pow pow.PoW , blockchain * core.BlockChain , chaindb ethdb.Database ) (* ProtocolManager , error ) {
90
- // Figure out whether to allow fast sync or not
91
- if fastSync && blockchain .CurrentBlock ().NumberU64 () > 0 {
92
- glog .V (logger .Info ).Infof ("blockchain not empty, fast sync disabled" )
93
- fastSync = false
94
- }
95
91
// Create the protocol manager with the base fields
96
92
manager := & ProtocolManager {
97
93
networkId : networkId ,
98
- fastSync : fastSync ,
99
94
eventMux : mux ,
100
95
txpool : txpool ,
101
96
blockchain : blockchain ,
@@ -106,6 +101,14 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
106
101
txsyncCh : make (chan * txsync ),
107
102
quitSync : make (chan struct {}),
108
103
}
104
+ // Figure out whether to allow fast sync or not
105
+ if fastSync && blockchain .CurrentBlock ().NumberU64 () > 0 {
106
+ glog .V (logger .Info ).Infof ("blockchain not empty, fast sync disabled" )
107
+ fastSync = false
108
+ }
109
+ if fastSync {
110
+ manager .fastSync = uint32 (1 )
111
+ }
109
112
// Initiate a sub-protocol for every implemented version we can handle
110
113
manager .SubProtocols = make ([]p2p.Protocol , 0 , len (ProtocolVersions ))
111
114
for i , version := range ProtocolVersions {
@@ -678,7 +681,11 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
678
681
}
679
682
680
683
case msg .Code == TxMsg :
681
- // Transactions arrived, parse all of them and deliver to the pool
684
+ // Transactions arrived, make sure we have a valid chain to handle them
685
+ if atomic .LoadUint32 (& pm .fastSync ) == 1 {
686
+ break
687
+ }
688
+ // Transactions can be processed, parse all of them and deliver to the pool
682
689
var txs []* types.Transaction
683
690
if err := msg .Decode (& txs ); err != nil {
684
691
return errResp (ErrDecode , "msg %v: %v" , msg , err )
0 commit comments