@@ -70,9 +70,9 @@ type LightChain struct {
70
70
wg sync.WaitGroup
71
71
72
72
// Atomic boolean switches:
73
- running int32 // whether LightChain is running or stopped
74
- procInterrupt int32 // interrupts chain insert
75
- disableCheckFreq int32 // disables header verification
73
+ stopped atomic. Bool // whether LightChain is stopped or running
74
+ procInterrupt atomic. Bool // interrupts chain insert
75
+ disableCheckFreq atomic. Bool // disables header verification
76
76
}
77
77
78
78
// NewLightChain returns a fully initialised light chain using information
@@ -114,7 +114,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
114
114
}
115
115
116
116
func (lc * LightChain ) getProcInterrupt () bool {
117
- return atomic . LoadInt32 ( & lc .procInterrupt ) == 1
117
+ return lc .procInterrupt . Load ()
118
118
}
119
119
120
120
// Odr returns the ODR backend of the chain
@@ -302,7 +302,7 @@ func (lc *LightChain) GetBlockByNumber(ctx context.Context, number uint64) (*typ
302
302
// Stop stops the blockchain service. If any imports are currently in progress
303
303
// it will abort them using the procInterrupt.
304
304
func (lc * LightChain ) Stop () {
305
- if ! atomic . CompareAndSwapInt32 ( & lc .running , 0 , 1 ) {
305
+ if ! lc .stopped . CompareAndSwap ( false , true ) {
306
306
return
307
307
}
308
308
close (lc .quit )
@@ -315,7 +315,7 @@ func (lc *LightChain) Stop() {
315
315
// errInsertionInterrupted as soon as possible. Insertion is permanently disabled after
316
316
// calling this method.
317
317
func (lc * LightChain ) StopInsert () {
318
- atomic . StoreInt32 ( & lc .procInterrupt , 1 )
318
+ lc .procInterrupt . Store ( true )
319
319
}
320
320
321
321
// Rollback is designed to remove a chain of links from the database that aren't
@@ -393,7 +393,7 @@ func (lc *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (i
393
393
if len (chain ) == 0 {
394
394
return 0 , nil
395
395
}
396
- if atomic . LoadInt32 ( & lc .disableCheckFreq ) == 1 {
396
+ if lc .disableCheckFreq . Load () {
397
397
checkFreq = 0
398
398
}
399
399
start := time .Now ()
@@ -541,10 +541,10 @@ func (lc *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
541
541
542
542
// DisableCheckFreq disables header validation. This is used for ultralight mode.
543
543
func (lc * LightChain ) DisableCheckFreq () {
544
- atomic . StoreInt32 ( & lc .disableCheckFreq , 1 )
544
+ lc .disableCheckFreq . Store ( true )
545
545
}
546
546
547
547
// EnableCheckFreq enables header validation.
548
548
func (lc * LightChain ) EnableCheckFreq () {
549
- atomic . StoreInt32 ( & lc .disableCheckFreq , 0 )
549
+ lc .disableCheckFreq . Store ( false )
550
550
}
0 commit comments