erigon-pulse/consensus/db/db.go
Andrew Ashikhmin 7286a0fef7
Create in-memory MDBX inside dirs.Tmp (#5702)
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.
2022-10-11 16:49:38 +01:00

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()
}