Skip to content

Commit

Permalink
fix pending block null issue
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Aug 10, 2021
1 parent 3bd4e29 commit 6951bcd
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,21 @@ func (miner *Miner) SetRecommitInterval(interval time.Duration) {
// Pending returns the currently pending block and associated state.
func (miner *Miner) Pending() (*types.Block, *state.StateDB) {
if miner.worker.isRunning() {
return miner.worker.pending()
} else {
// fallback to latest block
block := miner.worker.chain.CurrentBlock()
if block == nil {
return nil, nil
pendingBlock, pendingState := miner.worker.pending()
if pendingState != nil && pendingBlock != nil {
return pendingBlock, pendingState
}
stateDb, err := miner.worker.chain.StateAt(block.Root())
if err != nil {
return nil, nil
}
return block, stateDb
}
// fallback to latest block
block := miner.worker.chain.CurrentBlock()
if block == nil {
return nil, nil
}
stateDb, err := miner.worker.chain.StateAt(block.Root())
if err != nil {
return nil, nil
}
return block, stateDb
}

// PendingBlock returns the currently pending block.
Expand All @@ -206,11 +208,13 @@ func (miner *Miner) Pending() (*types.Block, *state.StateDB) {
// change between multiple method calls
func (miner *Miner) PendingBlock() *types.Block {
if miner.worker.isRunning() {
return miner.worker.pendingBlock()
} else {
// fallback to latest block
return miner.worker.chain.CurrentBlock()
pendingBlock := miner.worker.pendingBlock()
if pendingBlock != nil {
return pendingBlock
}
}
// fallback to latest block
return miner.worker.chain.CurrentBlock()
}

func (miner *Miner) SetEtherbase(addr common.Address) {
Expand Down

0 comments on commit 6951bcd

Please sign in to comment.