|
|
@ -115,7 +115,6 @@ type Ethereum struct { |
|
|
|
protocolManager *ProtocolManager |
|
|
|
protocolManager *ProtocolManager |
|
|
|
// DB interfaces
|
|
|
|
// DB interfaces
|
|
|
|
chainDb ethdb.Database // Block chain database
|
|
|
|
chainDb ethdb.Database // Block chain database
|
|
|
|
dappDb ethdb.Database // Dapp database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventMux *event.TypeMux |
|
|
|
eventMux *event.TypeMux |
|
|
|
pow *ethash.Ethash |
|
|
|
pow *ethash.Ethash |
|
|
@ -142,7 +141,7 @@ type Ethereum struct { |
|
|
|
// New creates a new Ethereum object (including the
|
|
|
|
// New creates a new Ethereum object (including the
|
|
|
|
// initialisation of the common Ethereum object)
|
|
|
|
// initialisation of the common Ethereum object)
|
|
|
|
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { |
|
|
|
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { |
|
|
|
chainDb, dappDb, err := CreateDBs(ctx, config) |
|
|
|
chainDb, err := createDB(ctx, config) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -157,7 +156,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { |
|
|
|
|
|
|
|
|
|
|
|
eth := &Ethereum{ |
|
|
|
eth := &Ethereum{ |
|
|
|
chainDb: chainDb, |
|
|
|
chainDb: chainDb, |
|
|
|
dappDb: dappDb, |
|
|
|
|
|
|
|
eventMux: ctx.EventMux, |
|
|
|
eventMux: ctx.EventMux, |
|
|
|
accountManager: ctx.AccountManager, |
|
|
|
accountManager: ctx.AccountManager, |
|
|
|
pow: pow, |
|
|
|
pow: pow, |
|
|
@ -243,25 +241,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { |
|
|
|
return eth, nil |
|
|
|
return eth, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreateDBs creates the chain and dapp databases for an Ethereum service
|
|
|
|
// createDB creates the chain database.
|
|
|
|
func CreateDBs(ctx *node.ServiceContext, config *Config) (chainDb, dappDb ethdb.Database, err error) { |
|
|
|
func createDB(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { |
|
|
|
// Open the chain database and perform any upgrades needed
|
|
|
|
db, err := ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles) |
|
|
|
chainDb, err = ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles) |
|
|
|
if db, ok := db.(*ethdb.LDBDatabase); ok { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if db, ok := chainDb.(*ethdb.LDBDatabase); ok { |
|
|
|
|
|
|
|
db.Meter("eth/db/chaindata/") |
|
|
|
db.Meter("eth/db/chaindata/") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return db, err |
|
|
|
dappDb, err = ctx.OpenDatabase("dapp", config.DatabaseCache, config.DatabaseHandles) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if db, ok := dappDb.(*ethdb.LDBDatabase); ok { |
|
|
|
|
|
|
|
db.Meter("eth/db/dapp/") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SetupGenesisBlock initializes the genesis block for an Ethereum service
|
|
|
|
// SetupGenesisBlock initializes the genesis block for an Ethereum service
|
|
|
@ -389,7 +375,6 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } |
|
|
|
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } |
|
|
|
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } |
|
|
|
func (s *Ethereum) Pow() *ethash.Ethash { return s.pow } |
|
|
|
func (s *Ethereum) Pow() *ethash.Ethash { return s.pow } |
|
|
|
func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } |
|
|
|
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) IsListening() bool { return true } // Always listening
|
|
|
|
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } |
|
|
|
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } |
|
|
|
func (s *Ethereum) NetVersion() int { return s.netVersionId } |
|
|
|
func (s *Ethereum) NetVersion() int { return s.netVersionId } |
|
|
@ -427,7 +412,6 @@ func (s *Ethereum) Stop() error { |
|
|
|
s.StopAutoDAG() |
|
|
|
s.StopAutoDAG() |
|
|
|
|
|
|
|
|
|
|
|
s.chainDb.Close() |
|
|
|
s.chainDb.Close() |
|
|
|
s.dappDb.Close() |
|
|
|
|
|
|
|
close(s.shutdownChan) |
|
|
|
close(s.shutdownChan) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|