From e463479b6c7770e783a47aedcd07b02d3ee250b6 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 13 Mar 2015 18:34:43 +0100 Subject: [PATCH] eth: add ResetWithGenesisBlock This depends on a change in ethash which exposes UpdateCache. --- eth/backend.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 2c7c7d792..7a30902c9 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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 {