aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go51
-rw-r--r--eth/handler.go5
2 files changed, 13 insertions, 43 deletions
diff --git a/eth/backend.go b/eth/backend.go
index deb6d3d0f..349dfa613 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -128,7 +128,7 @@ type Config struct {
// NewDB is used to create databases.
// If nil, the default is to create leveldb databases on disk.
- NewDB func(path string) (common.Database, error)
+ NewDB func(path string) (ethdb.Database, error)
}
func (cfg *Config) parseBootNodes() []*discover.Node {
@@ -210,11 +210,8 @@ type Ethereum struct {
shutdownChan chan bool
// DB interfaces
- chainDb common.Database // Block chain databe
- dappDb common.Database // Dapp database
-
- // Closed when databases are flushed and closed
- databasesClosed chan bool
+ chainDb ethdb.Database // Block chain database
+ dappDb ethdb.Database // Dapp database
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
@@ -267,7 +264,7 @@ func New(config *Config) (*Ethereum, error) {
newdb := config.NewDB
if newdb == nil {
- newdb = func(path string) (common.Database, error) { return ethdb.NewLDBDatabase(path, config.DatabaseCache) }
+ newdb = func(path string) (ethdb.Database, error) { return ethdb.NewLDBDatabase(path, config.DatabaseCache) }
}
// Open the chain database and perform any upgrades needed
@@ -337,7 +334,6 @@ func New(config *Config) (*Ethereum, error) {
eth := &Ethereum{
shutdownChan: make(chan bool),
- databasesClosed: make(chan bool),
chainDb: chainDb,
dappDb: dappDb,
eventMux: &event.TypeMux{},
@@ -527,8 +523,8 @@ func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcess
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
-func (s *Ethereum) ChainDb() common.Database { return s.chainDb }
-func (s *Ethereum) DappDb() common.Database { return s.dappDb }
+func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
+func (s *Ethereum) DappDb() ethdb.Database { return s.dappDb }
func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
@@ -549,8 +545,6 @@ func (s *Ethereum) Start() error {
if err != nil {
return err
}
- // periodically flush databases
- go s.syncDatabases()
if s.AutoDAG {
s.StartAutoDAG()
@@ -566,32 +560,6 @@ func (s *Ethereum) Start() error {
return nil
}
-// sync databases every minute. If flushing fails we exit immediatly. The system
-// may not continue under any circumstances.
-func (s *Ethereum) syncDatabases() {
- ticker := time.NewTicker(1 * time.Minute)
-done:
- for {
- select {
- case <-ticker.C:
- // don't change the order of database flushes
- if err := s.dappDb.Flush(); err != nil {
- glog.Fatalf("fatal error: flush dappDb: %v (Restart your node. We are aware of this issue)\n", err)
- }
- if err := s.chainDb.Flush(); err != nil {
- glog.Fatalf("fatal error: flush chainDb: %v (Restart your node. We are aware of this issue)\n", err)
- }
- case <-s.shutdownChan:
- break done
- }
- }
-
- s.chainDb.Close()
- s.dappDb.Close()
-
- close(s.databasesClosed)
-}
-
func (s *Ethereum) StartForTest() {
jsonlogger.LogJson(&logger.LogStarting{
ClientString: s.net.Name,
@@ -622,12 +590,13 @@ func (s *Ethereum) Stop() {
}
s.StopAutoDAG()
+ s.chainDb.Close()
+ s.dappDb.Close()
close(s.shutdownChan)
}
// This function will wait for a shutdown and resumes main thread execution
func (s *Ethereum) WaitForShutdown() {
- <-s.databasesClosed
<-s.shutdownChan
}
@@ -717,7 +686,7 @@ func dagFiles(epoch uint64) (string, string) {
return dag, "full-R" + dag
}
-func saveBlockchainVersion(db common.Database, bcVersion int) {
+func saveBlockchainVersion(db ethdb.Database, bcVersion int) {
d, _ := db.Get([]byte("BlockchainVersion"))
blockchainVersion := common.NewValue(d).Uint()
@@ -728,7 +697,7 @@ func saveBlockchainVersion(db common.Database, bcVersion int) {
// upgradeChainDatabase ensures that the chain database stores block split into
// separate header and body entries.
-func upgradeChainDatabase(db common.Database) error {
+func upgradeChainDatabase(db ethdb.Database) error {
// Short circuit if the head block is stored already as separate header and body
data, err := db.Get([]byte("LastBlock"))
if err != nil {
diff --git a/eth/handler.go b/eth/handler.go
index 4aef69043..0a06ea335 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/fetcher"
+ "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
@@ -61,7 +62,7 @@ func (ep extProt) GetBlock(hashes []common.Hash) error { return ep.getBlocks(has
type ProtocolManager struct {
txpool txPool
chainman *core.ChainManager
- chaindb common.Database
+ chaindb ethdb.Database
downloader *downloader.Downloader
fetcher *fetcher.Fetcher
@@ -86,7 +87,7 @@ type ProtocolManager struct {
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
-func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, chainman *core.ChainManager, chaindb common.Database) *ProtocolManager {
+func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, chainman *core.ChainManager, chaindb ethdb.Database) *ProtocolManager {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
eventMux: mux,