Skip to content

Commit

Permalink
fix pending block null issue (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro authored Aug 10, 2021
1 parent 955c78b commit 6fcce0d
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 6fcce0d

Please sign in to comment.