Allow dbBackend == none to compile (#1996)

* Allow dbBackend == none to compile

* Fix copyright year
This commit is contained in:
andri lim 2024-01-31 18:55:30 +07:00 committed by GitHub
parent c635e160d9
commit 09f95962ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 93 additions and 65 deletions

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -17,11 +17,18 @@
import
../aristo,
./backend/[aristo_rocksdb, legacy_rocksdb],
./memory_only
./memory_only,
../select_backend
export
memory_only
# Allow hive sim to compile with dbBackend == none
when dbBackend == rocksdb:
import
./backend/[aristo_rocksdb, legacy_rocksdb]
export
memory_only,
toRocksStoreRef
proc newCoreDbRef*(
@ -32,6 +39,7 @@ proc newCoreDbRef*(
##
## Note: Using legacy notation `newCoreDbRef()` rather than
## `CoreDbRef.init()` because of compiler coughing.
when dbBackend == rocksdb:
when dbType == LegacyDbPersistent:
newLegacyPersistentCoreDbRef path
@ -50,6 +58,7 @@ proc newCoreDbRef*(
##
## Note: Using legacy notation `newCoreDbRef()` rather than
## `CoreDbRef.init()` because of compiler coughing.
when dbBackend == rocksdb:
when dbType == AristoDbRocks:
newAristoRocksDbCoreDbRef(path, qlr)

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -20,6 +20,9 @@ import
hexary_interpolate, hexary_inspect, hexary_paths, snapdb_desc,
snapdb_persistent]
import
../../../../db/select_backend
logScope:
topics = "snap-db"
@ -63,6 +66,7 @@ proc persistentAccounts(
): Result[void,HexaryError]
{.gcsafe, raises: [OSError,IOError,KeyError].} =
## Store accounts trie table on databse
when dbBackend == rocksdb:
if ps.rockDb.isNil:
let rc = db.persistentAccountsPut(ps.kvDb)
if rc.isErr: return rc

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -16,6 +16,9 @@ import
../../range_desc,
"."/[hexary_desc, hexary_error, snapdb_desc, snapdb_persistent]
import
../../../../db/select_backend
logScope:
topics = "snap-db"
@ -46,6 +49,7 @@ proc persistentContracts(
): Result[void,HexaryError]
{.gcsafe, raises: [OSError,IOError,KeyError].} =
## Store contract codes onto permanent database
when dbBackend == rocksdb:
if ps.rockDb.isNil:
let rc = data.persistentContractPut ps.kvDb
if rc.isErr:

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -35,6 +35,8 @@ type
## Global, re-usable descriptor
keyMap: Table[RepairKey,uint] ## For debugging only (will go away)
db: CoreDbRef ## General database
# Allow hive sim to compile with dbBackend == none
when dbBackend == rocksdb:
rocky: RocksStoreRef ## Set if rocksdb is available
SnapDbBaseRef* = ref object of RootRef
@ -69,6 +71,7 @@ proc keyPp(a: RepairKey; pv: SnapDbRef): string =
# Private helper
# ------------------------------------------------------------------------------
when dbBackend == rocksdb:
proc clearRockyCacheFile(rocky: RocksStoreRef): bool =
if not rocky.isNil:
# A cache file might hang about from a previous crash
@ -87,6 +90,7 @@ proc init*(
db: CoreDbRef
): T =
## Main object constructor
when dbBackend == rocksdb:
T(db: db, rocky: db.backend.toRocksStoreRef)
proc init*(
@ -134,6 +138,7 @@ proc hexaDb*(ps: SnapDbBaseRef): HexaryTreeDbRef =
## Getter, low level access to underlying session DB
ps.xDb
when dbBackend == rocksdb:
proc rockDb*(ps: SnapDbBaseRef): RocksStoreRef =
## Getter, low level access to underlying persistent rock DB interface
ps.base.rocky
@ -193,10 +198,12 @@ template toOpenArray*(k: ByteArray33): openArray[byte] =
proc dbBackendRocksDb*(pv: SnapDbRef): bool =
## Returns `true` if rocksdb features are available
when dbBackend == rocksdb:
not pv.rocky.isNil
proc dbBackendRocksDb*(ps: SnapDbBaseRef): bool =
## Returns `true` if rocksdb features are available
when dbBackend == rocksdb:
not ps.base.rocky.isNil
proc mergeProofs*(

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -21,6 +21,9 @@ import
hexary_inspect, hexary_interpolate, hexary_paths, snapdb_desc,
snapdb_persistent]
import
../../../../db/select_backend
logScope:
topics = "snap-db"
@ -60,6 +63,7 @@ proc persistentStorageSlots(
): Result[void,HexaryError]
{.gcsafe, raises: [OSError,IOError,KeyError].} =
## Store accounts trie table on databse
when dbBackend == rocksdb:
if ps.rockDb.isNil:
let rc = db.persistentStorageSlotsPut(ps.kvDb)
if rc.isErr: return rc