mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-10 15:04:27 +00:00
miner: optimize function pending and pendingBlock
This commit is contained in:
parent
f8d6e064dc
commit
1b2d023da2
1 changed files with 14 additions and 25 deletions
|
|
@ -194,34 +194,23 @@ func (self *worker) setExtra(extra []byte) {
|
||||||
self.extra = extra
|
self.extra = extra
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) pending() (*types.Block, *state.StateDB) {
|
// pending returns the pending state and corresponding block. The returned
|
||||||
self.currentMu.Lock()
|
// values can be nil in case the pending block is not initialized.
|
||||||
defer self.currentMu.Unlock()
|
func (w *worker) pending() (*types.Block, *state.StateDB) {
|
||||||
|
w.snapshotMu.RLock()
|
||||||
if atomic.LoadInt32(&self.mining) == 0 {
|
defer w.snapshotMu.RUnlock()
|
||||||
return types.NewBlock(
|
if w.snapshotState == nil {
|
||||||
self.current.header,
|
return nil, nil
|
||||||
self.current.txs,
|
|
||||||
nil,
|
|
||||||
self.current.receipts,
|
|
||||||
), self.current.state.Copy()
|
|
||||||
}
|
}
|
||||||
return self.current.Block, self.current.state.Copy()
|
return w.snapshotBlock, w.snapshotState.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) pendingBlock() *types.Block {
|
// pendingBlock returns pending block. The returned block can be nil in case the
|
||||||
self.currentMu.Lock()
|
// pending block is not initialized.
|
||||||
defer self.currentMu.Unlock()
|
func (w *worker) pendingBlock() *types.Block {
|
||||||
|
w.snapshotMu.RLock()
|
||||||
if atomic.LoadInt32(&self.mining) == 0 {
|
defer w.snapshotMu.RUnlock()
|
||||||
return types.NewBlock(
|
return w.snapshotBlock
|
||||||
self.current.header,
|
|
||||||
self.current.txs,
|
|
||||||
nil,
|
|
||||||
self.current.receipts,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return self.current.Block
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pendingBlockAndReceipts returns pending block and corresponding receipts.
|
// pendingBlockAndReceipts returns pending block and corresponding receipts.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue