eth: add ResetWithGenesisBlock

This depends on a change in ethash which exposes UpdateCache.
This commit is contained in:
Felix Lange 2015-03-13 18:34:43 +01:00
parent 6f8a2d6b84
commit e463479b6c
1 changed files with 11 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/blockpool"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
@ -123,6 +124,7 @@ type Ethereum struct {
blockPool *blockpool.BlockPool
accountManager *accounts.Manager
whisper *whisper.Whisper
pow *ethash.Ethash
net *p2p.Server
eventMux *event.TypeMux
@ -175,16 +177,16 @@ func New(config *Config) (*Ethereum, error) {
}
eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux())
pow := ethash.New(eth.chainManager)
eth.pow = ethash.New(eth.chainManager)
eth.txPool = core.NewTxPool(eth.EventMux())
eth.blockProcessor = core.NewBlockProcessor(stateDb, pow, eth.txPool, eth.chainManager, eth.EventMux())
eth.blockProcessor = core.NewBlockProcessor(stateDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
eth.whisper = whisper.New()
eth.miner = miner.New(eth, pow, config.MinerThreads)
eth.miner = miner.New(eth, eth.pow, config.MinerThreads)
hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain
eth.blockPool = blockpool.New(hasBlock, insertChain, pow.Verify)
eth.blockPool = blockpool.New(hasBlock, insertChain, eth.pow.Verify)
netprv, err := config.nodeKey()
if err != nil {
@ -214,6 +216,11 @@ func New(config *Config) (*Ethereum, error) {
return eth, nil
}
func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.chainManager.ResetWithGenesisBlock(gb)
s.pow.UpdateCache(true)
}
func (s *Ethereum) StartMining() error {
cb, err := s.accountManager.Coinbase()
if err != nil {