mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 13:40:05 +00:00
7286a0fef7
Previously "in-memory" MDBX instances for fork validation and mining were created inside `os.TempDir()`. We should create them inside Erigon's datadir so that the file permissions and the disk are the same as for the main database. Prerequisite: https://github.com/ledgerwatch/erigon-lib/pull/676.
22 lines
425 B
Go
22 lines
425 B
Go
package db
|
|
|
|
import (
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
|
"github.com/ledgerwatch/log/v3"
|
|
)
|
|
|
|
func OpenDatabase(path string, logger log.Logger, inMem bool, readonly bool) kv.RwDB {
|
|
opts := mdbx.NewMDBX(logger).Label(kv.ConsensusDB)
|
|
if readonly {
|
|
opts = opts.Readonly()
|
|
}
|
|
if inMem {
|
|
opts = opts.InMem("")
|
|
} else {
|
|
opts = opts.Path(path)
|
|
}
|
|
|
|
return opts.MustOpen()
|
|
}
|