Skip to content

Commit

Permalink
miner: recover state if parent is too old
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed Dec 9, 2021
1 parent e631876 commit 7c56c0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion miner/miner.go
Expand Up @@ -35,10 +35,12 @@ import (
"github.com/ethereum/go-ethereum/params"
)

// Backend wraps all methods required for mining.
// Backend wraps all methods required for mining. Only full node is capable
// to offer all the functions here.
type Backend interface {
BlockChain() *core.BlockChain
TxPool() *core.TxPool
StateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, checkLive bool, preferDisk bool) (statedb *state.StateDB, err error)
}

// Config is the configuration parameters of mining.
Expand Down
14 changes: 10 additions & 4 deletions miner/worker.go
Expand Up @@ -749,11 +749,17 @@ func (w *worker) resultLoop() {
// makeEnv creates a new environment for the sealing block.
func (w *worker) makeEnv(parent *types.Block, header *types.Header, coinbase common.Address) (*environment, error) {
// Retrieve the parent state to execute on top and start a prefetcher for
// the miner to speed block sealing up a bit. Note since the sealing block
// can be created upon the arbitrary parent block, but the state of parent
// block may already be pruned, so the necessary state recovery is needed
// here in the future. TODO(rjl493456442).
// the miner to speed block sealing up a bit.
state, err := w.chain.StateAt(parent.Root())
if err != nil {
// Note since the sealing block can be created upon the arbitrary parent
// block, but the state of parent block may already be pruned, so the necessary
// state recovery is needed here in the future.
//
// The maximum acceptable reorg depth can be limited by the finalised block
// somehow. TODO(rjl493456442) fix the hard-coded number here later.
state, err = w.eth.StateAtBlock(parent, 1024, nil, false, false)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7c56c0a

Please sign in to comment.