@@ -98,7 +98,7 @@ type headerTask struct {
9898}
9999
100100type Downloader struct {
101- mode uint32 // Synchronisation mode defining the strategy used (per sync cycle), use d.getMode() to get the SyncMode
101+ mode atomic. Uint32 // Synchronisation mode defining the strategy used (per sync cycle), use d.getMode() to get the SyncMode
102102 mux * event.TypeMux // Event multiplexer to announce sync operation events
103103
104104 checkpoint uint64 // Checkpoint block number to enforce head against (e.g. snap sync)
@@ -122,9 +122,9 @@ type Downloader struct {
122122
123123 // Status
124124 synchroniseMock func (id string , hash common.Hash ) error // Replacement for synchronise during testing
125- synchronising int32
126- notified int32
127- committed int32
125+ synchronising atomic. Bool
126+ notified atomic. Bool
127+ committed atomic. Bool
128128 ancientLimit uint64 // The maximum block number which can be regarded as ancient data.
129129
130130 // Channels
@@ -292,7 +292,7 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
292292
293293// Synchronising returns whether the downloader is currently retrieving blocks.
294294func (d * Downloader ) Synchronising () bool {
295- return atomic . LoadInt32 ( & d .synchronising ) > 0
295+ return d .synchronising . Load ()
296296}
297297
298298// RegisterPeer injects a new download peer into the set of block source to be
@@ -392,13 +392,13 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
392392 return d .synchroniseMock (id , hash )
393393 }
394394 // Make sure only one goroutine is ever allowed past this point at once
395- if ! atomic . CompareAndSwapInt32 ( & d .synchronising , 0 , 1 ) {
395+ if ! d .synchronising . CompareAndSwap ( false , true ) {
396396 return errBusy
397397 }
398- defer atomic . StoreInt32 ( & d .synchronising , 0 )
398+ defer d .synchronising . Store ( false )
399399
400400 // Post a user notification of the sync (only once per session)
401- if atomic . CompareAndSwapInt32 ( & d .notified , 0 , 1 ) {
401+ if d .notified . CompareAndSwap ( false , true ) {
402402 log .Info ("Block synchronisation started" )
403403 }
404404 if mode == SnapSync {
@@ -435,7 +435,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
435435 defer d .Cancel () // No matter what, we can't leave the cancel channel open
436436
437437 // Atomically set the requested sync mode
438- atomic . StoreUint32 ( & d .mode , uint32 (mode ))
438+ d .mode . Store ( uint32 (mode ))
439439
440440 // Retrieve the origin peer and initiate the downloading process
441441 var p * peerConnection
@@ -452,7 +452,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
452452}
453453
454454func (d * Downloader ) getMode () SyncMode {
455- return SyncMode (atomic . LoadUint32 ( & d .mode ))
455+ return SyncMode (d .mode . Load ( ))
456456}
457457
458458// syncWithPeer starts a block synchronization based on the hash chain from the
@@ -562,9 +562,9 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
562562 rawdb .WriteLastPivotNumber (d .stateDB , pivotNumber )
563563 }
564564 }
565- d .committed = 1
565+ d .committed . Store ( true )
566566 if mode == SnapSync && pivot .Number .Uint64 () != 0 {
567- d .committed = 0
567+ d .committed . Store ( false )
568568 }
569569 if mode == SnapSync {
570570 // Set the ancient data limitation. If we are running snap sync, all block
@@ -1128,7 +1128,7 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
11281128 // If no more headers are inbound, notify the content fetchers and return
11291129 if len (headers ) == 0 {
11301130 // Don't abort header fetches while the pivot is downloading
1131- if atomic . LoadInt32 ( & d .committed ) == 0 && pivot <= from {
1131+ if ! d .committed . Load () && pivot <= from {
11321132 p .log .Debug ("No headers, waiting for pivot commit" )
11331133 select {
11341134 case <- time .After (fsHeaderContCheck ):
@@ -1669,7 +1669,7 @@ func (d *Downloader) processSnapSyncContent() error {
16691669 results = append (append ([]* fetchResult {oldPivot }, oldTail ... ), results ... )
16701670 }
16711671 // Split around the pivot block and process the two sides via snap/full sync
1672- if atomic . LoadInt32 ( & d .committed ) == 0 {
1672+ if ! d .committed . Load () {
16731673 latest := results [len (results )- 1 ].Header
16741674 // If the height is above the pivot block by 2 sets, it means the pivot
16751675 // become stale in the network and it was garbage collected, move to a
@@ -1794,7 +1794,7 @@ func (d *Downloader) commitPivotBlock(result *fetchResult) error {
17941794 if err := d .blockchain .SnapSyncCommitHead (block .Hash ()); err != nil {
17951795 return err
17961796 }
1797- atomic . StoreInt32 ( & d .committed , 1 )
1797+ d .committed . Store ( true )
17981798 return nil
17991799}
18001800
0 commit comments