@@ -164,7 +164,7 @@ const (
164
164
165
165
// newWorkReq represents a request for new sealing work submitting with relative interrupt notifier.
166
166
type newWorkReq struct {
167
- interrupt * int32
167
+ interrupt * atomic. Int32
168
168
noempty bool
169
169
timestamp int64
170
170
}
@@ -239,15 +239,15 @@ type worker struct {
239
239
snapshotState * state.StateDB
240
240
241
241
// atomic status counters
242
- running int32 // The indicator whether the consensus engine is running or not.
243
- newTxs int32 // New arrival transaction count since last sealing work submitting.
242
+ running atomic. Bool // The indicator whether the consensus engine is running or not.
243
+ newTxs atomic. Int32 // New arrival transaction count since last sealing work submitting.
244
244
245
245
// noempty is the flag used to control whether the feature of pre-seal empty
246
246
// block is enabled. The default value is false(pre-seal is enabled by default).
247
247
// But in some special scenario the consensus engine will seal blocks instantaneously,
248
248
// in this case this feature will add all empty blocks into canonical chain
249
249
// non-stop and no real transaction will be included.
250
- noempty uint32
250
+ noempty atomic. Bool
251
251
252
252
// newpayloadTimeout is the maximum timeout allowance for creating payload.
253
253
// The default value is 2 seconds but node operator can set it to arbitrary
@@ -372,12 +372,12 @@ func (w *worker) setRecommitInterval(interval time.Duration) {
372
372
373
373
// disablePreseal disables pre-sealing feature
374
374
func (w * worker ) disablePreseal () {
375
- atomic . StoreUint32 ( & w .noempty , 1 )
375
+ w .noempty . Store ( true )
376
376
}
377
377
378
378
// enablePreseal enables pre-sealing feature
379
379
func (w * worker ) enablePreseal () {
380
- atomic . StoreUint32 ( & w .noempty , 0 )
380
+ w .noempty . Store ( false )
381
381
}
382
382
383
383
// pending returns the pending state and corresponding block.
@@ -409,24 +409,24 @@ func (w *worker) pendingBlockAndReceipts() (*types.Block, types.Receipts) {
409
409
410
410
// start sets the running status as 1 and triggers new work submitting.
411
411
func (w * worker ) start () {
412
- atomic . StoreInt32 ( & w .running , 1 )
412
+ w .running . Store ( true )
413
413
w .startCh <- struct {}{}
414
414
}
415
415
416
416
// stop sets the running status as 0.
417
417
func (w * worker ) stop () {
418
- atomic . StoreInt32 ( & w .running , 0 )
418
+ w .running . Store ( false )
419
419
}
420
420
421
421
// isRunning returns an indicator whether worker is running or not.
422
422
func (w * worker ) isRunning () bool {
423
- return atomic . LoadInt32 ( & w .running ) == 1
423
+ return w .running . Load ()
424
424
}
425
425
426
426
// close terminates all background threads maintained by the worker.
427
427
// Note the worker does not support being closed multiple times.
428
428
func (w * worker ) close () {
429
- atomic . StoreInt32 ( & w .running , 0 )
429
+ w .running . Store ( false )
430
430
close (w .exitCh )
431
431
w .wg .Wait ()
432
432
}
@@ -457,7 +457,7 @@ func recalcRecommit(minRecommit, prev time.Duration, target float64, inc bool) t
457
457
func (w * worker ) newWorkLoop (recommit time.Duration ) {
458
458
defer w .wg .Done ()
459
459
var (
460
- interrupt * int32
460
+ interrupt * atomic. Int32
461
461
minRecommit = recommit // minimal resubmit interval specified by user.
462
462
timestamp int64 // timestamp for each round of sealing.
463
463
)
@@ -469,16 +469,16 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
469
469
// commit aborts in-flight transaction execution with given signal and resubmits a new one.
470
470
commit := func (noempty bool , s int32 ) {
471
471
if interrupt != nil {
472
- atomic . StoreInt32 ( interrupt , s )
472
+ interrupt . Store ( s )
473
473
}
474
- interrupt = new (int32 )
474
+ interrupt = new (atomic. Int32 )
475
475
select {
476
476
case w .newWorkCh <- & newWorkReq {interrupt : interrupt , noempty : noempty , timestamp : timestamp }:
477
477
case <- w .exitCh :
478
478
return
479
479
}
480
480
timer .Reset (recommit )
481
- atomic . StoreInt32 ( & w .newTxs , 0 )
481
+ w .newTxs . Store ( 0 )
482
482
}
483
483
// clearPending cleans the stale pending tasks.
484
484
clearPending := func (number uint64 ) {
@@ -508,7 +508,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
508
508
// higher priced transactions. Disable this overhead for pending blocks.
509
509
if w .isRunning () && (w .chainConfig .Clique == nil || w .chainConfig .Clique .Period > 0 ) {
510
510
// Short circuit if no new transaction arrives.
511
- if atomic . LoadInt32 ( & w .newTxs ) == 0 {
511
+ if w .newTxs . Load ( ) == 0 {
512
512
timer .Reset (recommit )
513
513
continue
514
514
}
@@ -650,7 +650,7 @@ func (w *worker) mainLoop() {
650
650
w .commitWork (nil , true , time .Now ().Unix ())
651
651
}
652
652
}
653
- atomic . AddInt32 ( & w .newTxs , int32 (len (ev .Txs )))
653
+ w .newTxs . Add ( int32 (len (ev .Txs )))
654
654
655
655
// System stopped
656
656
case <- w .exitCh :
@@ -877,7 +877,7 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*
877
877
return receipt .Logs , nil
878
878
}
879
879
880
- func (w * worker ) commitTransactions (env * environment , txs * types.TransactionsByPriceAndNonce , interrupt * int32 ) error {
880
+ func (w * worker ) commitTransactions (env * environment , txs * types.TransactionsByPriceAndNonce , interrupt * atomic. Int32 ) error {
881
881
gasLimit := env .header .GasLimit
882
882
if env .gasPool == nil {
883
883
env .gasPool = new (core.GasPool ).AddGas (gasLimit )
@@ -887,7 +887,7 @@ func (w *worker) commitTransactions(env *environment, txs *types.TransactionsByP
887
887
for {
888
888
// Check interruption signal and abort building if it's fired.
889
889
if interrupt != nil {
890
- if signal := atomic . LoadInt32 ( interrupt ); signal != commitInterruptNone {
890
+ if signal := interrupt . Load ( ); signal != commitInterruptNone {
891
891
return signalToErr (signal )
892
892
}
893
893
}
@@ -1067,7 +1067,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
1067
1067
// fillTransactions retrieves the pending transactions from the txpool and fills them
1068
1068
// into the given sealing block. The transaction selection and ordering strategy can
1069
1069
// be customized with the plugin in the future.
1070
- func (w * worker ) fillTransactions (interrupt * int32 , env * environment ) error {
1070
+ func (w * worker ) fillTransactions (interrupt * atomic. Int32 , env * environment ) error {
1071
1071
// Split the pending transactions into locals and remotes
1072
1072
// Fill the block with all available pending transactions.
1073
1073
pending := w .eth .TxPool ().Pending (true )
@@ -1102,9 +1102,9 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e
1102
1102
defer work .discard ()
1103
1103
1104
1104
if ! params .noTxs {
1105
- interrupt := new (int32 )
1105
+ interrupt := new (atomic. Int32 )
1106
1106
timer := time .AfterFunc (w .newpayloadTimeout , func () {
1107
- atomic . StoreInt32 ( interrupt , commitInterruptTimeout )
1107
+ interrupt . Store ( commitInterruptTimeout )
1108
1108
})
1109
1109
defer timer .Stop ()
1110
1110
@@ -1122,7 +1122,7 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e
1122
1122
1123
1123
// commitWork generates several new sealing tasks based on the parent block
1124
1124
// and submit them to the sealer.
1125
- func (w * worker ) commitWork (interrupt * int32 , noempty bool , timestamp int64 ) {
1125
+ func (w * worker ) commitWork (interrupt * atomic. Int32 , noempty bool , timestamp int64 ) {
1126
1126
start := time .Now ()
1127
1127
1128
1128
// Set the coinbase if the worker is running or it's required
@@ -1143,7 +1143,7 @@ func (w *worker) commitWork(interrupt *int32, noempty bool, timestamp int64) {
1143
1143
}
1144
1144
// Create an empty block based on temporary copied state for
1145
1145
// sealing in advance without waiting block execution finished.
1146
- if ! noempty && atomic . LoadUint32 ( & w .noempty ) == 0 {
1146
+ if ! noempty && ! w .noempty . Load () {
1147
1147
w .commit (work .copy (), nil , false , start )
1148
1148
}
1149
1149
// Fill pending transactions from the txpool into the block.
0 commit comments