Skip to content

Commit

Permalink
refactor: override backend immediately after db instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR4N committed Nov 14, 2024
1 parent 2f63ee1 commit 4404e70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion triedb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
diskdb: diskdb,
preimages: preimages,
}
if db.overrideBackend(diskdb, config) {
return db
}
if config.HashDB != nil && config.PathDB != nil {
log.Crit("Both 'hash' and 'path' mode are configured")
}
Expand All @@ -121,7 +124,6 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
}
db.backend = hashdb.New(diskdb, config.HashDB, resolver)
}
db.overrideBackend(diskdb, config)
return db
}

Expand Down
6 changes: 3 additions & 3 deletions triedb/database.libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ type BackendOverride interface {
ReaderProvider
}

func (db *Database) overrideBackend(diskdb ethdb.Database, config *Config) {
func (db *Database) overrideBackend(diskdb ethdb.Database, config *Config) bool {
if config.DBOverride == nil {
return
return false
}
if config.HashDB != nil || config.PathDB != nil {
log.Crit("Database override provided when 'hash' or 'path' mode are configured")
}
db.backend.Close() //nolint:gosec // geth defaults to hashdb instances, which always return nil from Close()

db.backend = config.DBOverride(diskdb, config)
switch db.backend.(type) {
Expand All @@ -66,6 +65,7 @@ func (db *Database) overrideBackend(diskdb ethdb.Database, config *Config) {
default:
log.Crit("Database override is neither hash- nor path-based")
}
return true
}

var (
Expand Down

0 comments on commit 4404e70

Please sign in to comment.