Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move rocksdb support to eth1 #927

Merged
merged 6 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move rocksdb support to eth1
only used here / causes unnecessary build deps
  • Loading branch information
arnetheduck committed Apr 4, 2022
commit 30bbcff9264b1ad7941e0e9cd9fed6157cce8302
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ nimcache
/debug*.json
/block*.json
/.update.timestamp

*.generated.nim

/dist

# Nimble user files
Expand Down
3 changes: 2 additions & 1 deletion nimbus.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ requires "nim >= 1.2.0",
"libbacktrace",
"nimcrypto",
"stew",
"stint"
"stint",
"rocksdb"

binDir = "build"

Expand Down
52 changes: 52 additions & 0 deletions nimbus/db/kvstore_rocksdb.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{.push raises: [Defect].}

import
std/os,
rocksdb, stew/results,
eth/db/kvstore

export results, kvstore

const maxOpenFiles = 512

type
RocksStoreRef* = ref object of RootObj
store: RocksDBInstance

proc get*(db: RocksStoreRef, key: openArray[byte], onData: kvstore.DataProc): KvResult[bool] =
db.store.get(key, onData)

proc find*(db: RocksStoreRef, prefix: openArray[byte], onFind: kvstore.KeyValueProc): KvResult[int] =
raiseAssert "Unimplemented"

proc put*(db: RocksStoreRef, key, value: openArray[byte]): KvResult[void] =
db.store.put(key, value)

proc contains*(db: RocksStoreRef, key: openArray[byte]): KvResult[bool] =
db.store.contains(key)

proc del*(db: RocksStoreRef, key: openArray[byte]): KvResult[void] =
db.store.del(key)

proc close*(db: RocksStoreRef) =
db.store.close

proc init*(
T: type RocksStoreRef, basePath: string, name: string,
readOnly = false): KvResult[T] =
let
dataDir = basePath / name / "data"
backupsDir = basePath / name / "backups"

try:
createDir(dataDir)
createDir(backupsDir)
except OSError, IOError:
return err("rocksdb: cannot create database directory")

var store: RocksDBInstance
if (let v = store.init(
dataDir, backupsDir, readOnly, maxOpenFiles = maxOpenFiles); v.isErr):
return err(v.error)

ok(T(store: store))
2 changes: 1 addition & 1 deletion nimbus/db/select_backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ when dbBackend == sqlite:
let db = SqStoreRef.init(path, "nimbus").expect("working database")
ChainDB(kv: kvStore db.openKvStore().expect("working database"))
elif dbBackend == rocksdb:
import eth/db/kvstore_rocksdb as database_backend
import ./kvstore_rocksdb as database_backend
proc newChainDB*(path: string): ChainDB =
ChainDB(kv: kvStore RocksStoreRef.init(path, "nimbus").tryGet())
elif dbBackend == lmdb:
Expand Down
4 changes: 2 additions & 2 deletions tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ cliBuilder:
./test_configuration,
./test_keyed_queue_rlp,
./test_txpool,
./test_merge

./test_merge,
./db/test_kvstore_rocksdb
19 changes: 19 additions & 0 deletions tests/db/test_kvstore_rocksdb.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{.used.}

import
std/os,
unittest2,
chronicles,
eth/db/kvstore,
../../nimbus/db/kvstore_rocksdb,
eth/../tests/db/test_kvstore

suite "RocksStoreRef":
test "KvStore interface":
let tmp = getTempDir() / "nimbus-test-db"
removeDir(tmp)

let db = RocksStoreRef.init(tmp, "test")[]
defer: db.close()

testKvStore(kvStore db, false)
2 changes: 1 addition & 1 deletion vendor/nim-eth