forked from cerc-io/plugeth
Merge pull request #14685 from karalabe/ethdb-metrics-fail-fix
eth: gracefully error if database cannot be opened
This commit is contained in:
commit
46d0d04f97
@ -200,10 +200,13 @@ func makeExtraData(extra []byte) []byte {
|
|||||||
// CreateDB creates the chain database.
|
// CreateDB creates the chain database.
|
||||||
func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) {
|
func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) {
|
||||||
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
|
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if db, ok := db.(*ethdb.LDBDatabase); ok {
|
if db, ok := db.(*ethdb.LDBDatabase); ok {
|
||||||
db.Meter("eth/db/chaindata/")
|
db.Meter("eth/db/chaindata/")
|
||||||
}
|
}
|
||||||
return db, err
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
|
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
|
||||||
|
@ -43,7 +43,11 @@ func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (et
|
|||||||
if ctx.config.DataDir == "" {
|
if ctx.config.DataDir == "" {
|
||||||
return ethdb.NewMemDatabase()
|
return ethdb.NewMemDatabase()
|
||||||
}
|
}
|
||||||
return ethdb.NewLDBDatabase(ctx.config.resolvePath(name), cache, handles)
|
db, err := ethdb.NewLDBDatabase(ctx.config.resolvePath(name), cache, handles)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolvePath resolves a user path into the data directory if that was relative
|
// ResolvePath resolves a user path into the data directory if that was relative
|
||||||
|
Loading…
Reference in New Issue
Block a user