Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R3R]fix pending block null issue #358

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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