diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-15 06:37:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-15 06:37:21 +0800 |
commit | d9966d615813130c8d31b3b10a59d43d00fd9943 (patch) | |
tree | b5a196dd1ef20050160eb384c876ccaba1c4eebf /eth | |
parent | 12cee1377f8795608bae3cad38ee22c032b3b865 (diff) | |
parent | 67f8f83a1ba2a4dbd0f6f2fd075bb440f5c420ad (diff) | |
download | go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.gz go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.bz2 go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.lz go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.xz go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.zst go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.zip |
merge
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/eth/backend.go b/eth/backend.go index bb203b4a6..346fc43bc 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" @@ -61,6 +62,10 @@ type Config struct { MinerThreads int AccountManager *accounts.Manager + + // NewDB is used to create databases. + // If nil, the default is to create leveldb databases on disk. + NewDB func(path string) (ethutil.Database, error) } func (cfg *Config) parseBootNodes() []*discover.Node { @@ -120,6 +125,7 @@ type Ethereum struct { blockPool *blockpool.BlockPool accountManager *accounts.Manager whisper *whisper.Whisper + pow *ethash.Ethash net *p2p.Server eventMux *event.TypeMux @@ -138,11 +144,15 @@ func New(config *Config) (*Ethereum, error) { // Boostrap database servlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) - blockDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain")) + newdb := config.NewDB + if newdb == nil { + newdb = func(path string) (ethutil.Database, error) { return ethdb.NewLDBDatabase(path) } + } + blockDb, err := newdb(path.Join(config.DataDir, "blockchain")) if err != nil { return nil, err } - stateDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "state")) + stateDb, err := newdb(path.Join(config.DataDir, "state")) if err != nil { return nil, err } @@ -170,16 +180,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, extraDb, pow, eth.txPool, eth.chainManager, eth.EventMux()) + eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, 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 { @@ -209,6 +219,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 { |