@@ -98,7 +98,7 @@ type headerTask struct {
98
98
}
99
99
100
100
type 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
102
102
mux * event.TypeMux // Event multiplexer to announce sync operation events
103
103
104
104
checkpoint uint64 // Checkpoint block number to enforce head against (e.g. snap sync)
@@ -122,9 +122,9 @@ type Downloader struct {
122
122
123
123
// Status
124
124
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
128
128
ancientLimit uint64 // The maximum block number which can be regarded as ancient data.
129
129
130
130
// Channels
@@ -292,7 +292,7 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
292
292
293
293
// Synchronising returns whether the downloader is currently retrieving blocks.
294
294
func (d * Downloader ) Synchronising () bool {
295
- return atomic . LoadInt32 ( & d .synchronising ) > 0
295
+ return d .synchronising . Load ()
296
296
}
297
297
298
298
// 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,
392
392
return d .synchroniseMock (id , hash )
393
393
}
394
394
// 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 ) {
396
396
return errBusy
397
397
}
398
- defer atomic . StoreInt32 ( & d .synchronising , 0 )
398
+ defer d .synchronising . Store ( false )
399
399
400
400
// 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 ) {
402
402
log .Info ("Block synchronisation started" )
403
403
}
404
404
if mode == SnapSync {
@@ -435,7 +435,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
435
435
defer d .Cancel () // No matter what, we can't leave the cancel channel open
436
436
437
437
// Atomically set the requested sync mode
438
- atomic . StoreUint32 ( & d .mode , uint32 (mode ))
438
+ d .mode . Store ( uint32 (mode ))
439
439
440
440
// Retrieve the origin peer and initiate the downloading process
441
441
var p * peerConnection
@@ -452,7 +452,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int,
452
452
}
453
453
454
454
func (d * Downloader ) getMode () SyncMode {
455
- return SyncMode (atomic . LoadUint32 ( & d .mode ))
455
+ return SyncMode (d .mode . Load ( ))
456
456
}
457
457
458
458
// 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 *
562
562
rawdb .WriteLastPivotNumber (d .stateDB , pivotNumber )
563
563
}
564
564
}
565
- d .committed = 1
565
+ d .committed . Store ( true )
566
566
if mode == SnapSync && pivot .Number .Uint64 () != 0 {
567
- d .committed = 0
567
+ d .committed . Store ( false )
568
568
}
569
569
if mode == SnapSync {
570
570
// 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
1128
1128
// If no more headers are inbound, notify the content fetchers and return
1129
1129
if len (headers ) == 0 {
1130
1130
// 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 {
1132
1132
p .log .Debug ("No headers, waiting for pivot commit" )
1133
1133
select {
1134
1134
case <- time .After (fsHeaderContCheck ):
@@ -1669,7 +1669,7 @@ func (d *Downloader) processSnapSyncContent() error {
1669
1669
results = append (append ([]* fetchResult {oldPivot }, oldTail ... ), results ... )
1670
1670
}
1671
1671
// 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 () {
1673
1673
latest := results [len (results )- 1 ].Header
1674
1674
// If the height is above the pivot block by 2 sets, it means the pivot
1675
1675
// become stale in the network and it was garbage collected, move to a
@@ -1794,7 +1794,7 @@ func (d *Downloader) commitPivotBlock(result *fetchResult) error {
1794
1794
if err := d .blockchain .SnapSyncCommitHead (block .Hash ()); err != nil {
1795
1795
return err
1796
1796
}
1797
- atomic . StoreInt32 ( & d .committed , 1 )
1797
+ d .committed . Store ( true )
1798
1798
return nil
1799
1799
}
1800
1800
0 commit comments