mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +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
|
||||
}
|
||||
|
||||
func (self *worker) pending() (*types.Block, *state.StateDB) {
|
||||
self.currentMu.Lock()
|
||||
defer self.currentMu.Unlock()
|
||||
|
||||
if atomic.LoadInt32(&self.mining) == 0 {
|
||||
return types.NewBlock(
|
||||
self.current.header,
|
||||
self.current.txs,
|
||||
nil,
|
||||
self.current.receipts,
|
||||
), self.current.state.Copy()
|
||||
// pending returns the pending state and corresponding block. The returned
|
||||
// values can be nil in case the pending block is not initialized.
|
||||
func (w *worker) pending() (*types.Block, *state.StateDB) {
|
||||
w.snapshotMu.RLock()
|
||||
defer w.snapshotMu.RUnlock()
|
||||
if w.snapshotState == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return self.current.Block, self.current.state.Copy()
|
||||
return w.snapshotBlock, w.snapshotState.Copy()
|
||||
}
|
||||
|
||||
func (self *worker) pendingBlock() *types.Block {
|
||||
self.currentMu.Lock()
|
||||
defer self.currentMu.Unlock()
|
||||
|
||||
if atomic.LoadInt32(&self.mining) == 0 {
|
||||
return types.NewBlock(
|
||||
self.current.header,
|
||||
self.current.txs,
|
||||
nil,
|
||||
self.current.receipts,
|
||||
)
|
||||
}
|
||||
return self.current.Block
|
||||
// pendingBlock returns pending block. The returned block can be nil in case the
|
||||
// pending block is not initialized.
|
||||
func (w *worker) pendingBlock() *types.Block {
|
||||
w.snapshotMu.RLock()
|
||||
defer w.snapshotMu.RUnlock()
|
||||
return w.snapshotBlock
|
||||
}
|
||||
|
||||
// pendingBlockAndReceipts returns pending block and corresponding receipts.
|
||||
|
|
|
|||
Loading…
Reference in a new issue