diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-07 01:26:16 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-07 01:26:16 +0800 |
commit | cd856cb2133d390758bb24b88fa3b538bb7bc306 (patch) | |
tree | c6d75750802c2de16ae095569a8f2e0c05ce256f /eth | |
parent | ed84b58af57809a743e5be6f6ea53c079c50b765 (diff) | |
download | dexon-cd856cb2133d390758bb24b88fa3b538bb7bc306.tar.gz dexon-cd856cb2133d390758bb24b88fa3b538bb7bc306.tar.zst dexon-cd856cb2133d390758bb24b88fa3b538bb7bc306.zip |
Separated block db from state db. Partial fix for #416
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/eth/backend.go b/eth/backend.go index 799937510..584d60c7e 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -111,7 +111,8 @@ type Ethereum struct { shutdownChan chan bool // DB interface - db ethutil.Database + blockDb ethutil.Database + stateDb ethutil.Database //*** SERVICES *** // State manager for processing new blocks and managing the over all states @@ -140,13 +141,17 @@ func New(config *Config) (*Ethereum, error) { // Boostrap database ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) - db, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain")) + blockDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain")) + if err != nil { + return nil, err + } + stateDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "state")) if err != nil { return nil, err } // Perform database sanity checks - d, _ := db.Get([]byte("ProtocolVersion")) + d, _ := blockDb.Get([]byte("ProtocolVersion")) protov := ethutil.NewValue(d).Uint() if protov != ProtocolVersion && protov != 0 { path := path.Join(config.DataDir, "blockchain") @@ -157,7 +162,7 @@ func New(config *Config) (*Ethereum, error) { var keyManager *crypto.KeyManager switch config.KeyStore { case "db": - keyManager = crypto.NewDBKeyManager(db) + keyManager = crypto.NewDBKeyManager(blockDb) case "file": keyManager = crypto.NewFileKeyManager(config.DataDir) default: @@ -166,23 +171,24 @@ func New(config *Config) (*Ethereum, error) { // Initialise the keyring keyManager.Init(config.KeyRing, 0, false) - saveProtocolVersion(db) + saveProtocolVersion(blockDb) //ethutil.Config.Db = db eth := &Ethereum{ shutdownChan: make(chan bool), - db: db, + blockDb: blockDb, + stateDb: stateDb, keyManager: keyManager, eventMux: &event.TypeMux{}, logger: ethlogger, DataDir: config.DataDir, } - eth.chainManager = core.NewChainManager(db, eth.EventMux()) + eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) pow := ethash.New(eth.chainManager) eth.txPool = core.NewTxPool(eth.EventMux()) - eth.blockProcessor = core.NewBlockProcessor(db, pow, eth.txPool, eth.chainManager, eth.EventMux()) + eth.blockProcessor = core.NewBlockProcessor(stateDb, pow, eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) eth.whisper = whisper.New() eth.miner = miner.New(keyManager.Address(), eth, pow, config.MinerThreads) @@ -228,7 +234,8 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool } func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } -func (s *Ethereum) Db() ethutil.Database { return s.db } +func (s *Ethereum) BlockDb() ethutil.Database { return s.blockDb } +func (s *Ethereum) StateDb() ethutil.Database { return s.stateDb } func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } @@ -279,7 +286,8 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error { func (s *Ethereum) Stop() { // Close the database - defer s.db.Close() + defer s.blockDb.Close() + defer s.stateDb.Close() s.txSub.Unsubscribe() // quits txBroadcastLoop s.blockSub.Unsubscribe() // quits blockBroadcastLoop |