mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
miner: add mutex to protect the pending block
This commit is contained in:
parent
4cf7e955cd
commit
0115bb7bcf
1 changed files with 5 additions and 0 deletions
|
|
@ -72,6 +72,7 @@ type Miner struct {
|
|||
txpool *txpool.TxPool
|
||||
chain *core.BlockChain
|
||||
pending *pending
|
||||
pendingMu sync.Mutex // Lock protects the pending block
|
||||
}
|
||||
|
||||
// New creates a new miner with provided config.
|
||||
|
|
@ -137,9 +138,13 @@ func (miner *Miner) getPending() *newPayloadResult {
|
|||
miner.confMu.RUnlock()
|
||||
|
||||
header := miner.chain.CurrentHeader()
|
||||
miner.pendingMu.Lock()
|
||||
if cached := miner.pending.resolve(header.Hash(), coinbase); cached != nil {
|
||||
miner.pendingMu.Unlock()
|
||||
return cached
|
||||
}
|
||||
defer miner.pendingMu.Unlock()
|
||||
|
||||
var (
|
||||
timestamp = uint64(time.Now().Unix())
|
||||
withdrawal types.Withdrawals
|
||||
|
|
|
|||
Loading…
Reference in a new issue