mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
miner: change bool to atomic int
This commit is contained in:
parent
97f5cb2fdd
commit
924b5e8285
1 changed files with 10 additions and 10 deletions
|
|
@ -169,12 +169,12 @@ type worker struct {
|
|||
running int32 // The indicator whether the consensus engine is running or not.
|
||||
newTxs int32 // New arrival transaction count since last sealing work submitting.
|
||||
|
||||
// noempty is the flag used to control whether the feature of pre-seal
|
||||
// empty block is enabled. The default value is false.
|
||||
// But in some special scenario the consensus engine will seal blocks
|
||||
// instantaneously, in this case this feature will add all empty blocks
|
||||
// into canonical chain non-stop and no real transaction will be included.
|
||||
noempty bool
|
||||
// noempty is the flag used to control whether the feature of pre-seal empty
|
||||
// block is enabled. The default value is false(pre-seal is enabled by default).
|
||||
// But in some special scenario the consensus engine will seal blocks instantaneously,
|
||||
// in this case this feature will add all empty blocks into canonical chain
|
||||
// non-stop and no real transaction will be included.
|
||||
noempty uint32
|
||||
|
||||
// External functions
|
||||
isLocalBlock func(block *types.Block) bool // Function used to determine whether the specified block is mined by local miner.
|
||||
|
|
@ -256,12 +256,12 @@ func (w *worker) setRecommitInterval(interval time.Duration) {
|
|||
|
||||
// disablePreseal disables pre-sealing mining feature
|
||||
func (w *worker) disablePreseal() {
|
||||
w.noempty = true
|
||||
atomic.StoreUint32(&w.noempty, 1)
|
||||
}
|
||||
|
||||
// enablePreseal enables pre-sealing mining feature
|
||||
func (w *worker) enablePreseal() {
|
||||
w.noempty = false
|
||||
atomic.StoreUint32(&w.noempty, 0)
|
||||
}
|
||||
|
||||
// pending returns the pending state and corresponding block.
|
||||
|
|
@ -930,7 +930,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||
|
||||
// Create an empty block based on temporary copied state for
|
||||
// sealing in advance without waiting block execution finished.
|
||||
if !noempty && !w.noempty {
|
||||
if !noempty && atomic.LoadUint32(&w.noempty) == 0 {
|
||||
w.commit(uncles, nil, false, tstart)
|
||||
}
|
||||
|
||||
|
|
@ -943,7 +943,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||
// Short circuit if there is no available pending transactions.
|
||||
// But if we disable empty precommit already, ignore it. Since
|
||||
// empty block is necessary to keep the liveness of the network.
|
||||
if len(pending) == 0 && !w.noempty {
|
||||
if len(pending) == 0 && atomic.LoadUint32(&w.noempty) == 0 {
|
||||
w.updateSnapshot()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue