mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-28 11:50:45 +00:00
Merge AristoTxRef/KvtTxRef with their LayerRef (#3078)
* Merge AristoTxRef/KvtTxRef with their LayerRef also clean up unused files * rm unused test_rocksdb * Fix tests * lint
This commit is contained in:
parent
caca11b30b
commit
a1a9c6b027
1
Makefile
1
Makefile
@ -241,7 +241,6 @@ endif
|
|||||||
|
|
||||||
# builds and runs the nimbus test suite
|
# builds and runs the nimbus test suite
|
||||||
test: | build deps rocksdb
|
test: | build deps rocksdb
|
||||||
$(ENV_SCRIPT) nim test_rocksdb $(NIM_PARAMS) nimbus.nims
|
|
||||||
$(ENV_SCRIPT) nim test $(NIM_PARAMS) nimbus.nims
|
$(ENV_SCRIPT) nim test $(NIM_PARAMS) nimbus.nims
|
||||||
|
|
||||||
test_import: nimbus_execution_client
|
test_import: nimbus_execution_client
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# nimbus-eth1
|
# nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -19,10 +19,10 @@ export
|
|||||||
aristo_api, aristo_constants
|
aristo_api, aristo_constants
|
||||||
|
|
||||||
import
|
import
|
||||||
aristo/aristo_init
|
aristo/aristo_init/memory_only,
|
||||||
|
aristo/aristo_init/init_common
|
||||||
export
|
export
|
||||||
MemBackendRef,
|
MemBackendRef,
|
||||||
VoidBackendRef,
|
|
||||||
finish,
|
finish,
|
||||||
init
|
init
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ import
|
|||||||
results,
|
results,
|
||||||
./aristo_desc/desc_backend,
|
./aristo_desc/desc_backend,
|
||||||
./aristo_init/memory_db,
|
./aristo_init/memory_db,
|
||||||
"."/[aristo_delete, aristo_desc, aristo_fetch, aristo_init, aristo_merge,
|
./aristo_init/memory_only,
|
||||||
|
./aristo_init/init_common,
|
||||||
|
"."/[aristo_delete, aristo_desc, aristo_fetch, aristo_merge,
|
||||||
aristo_part, aristo_path, aristo_persist, aristo_profile, aristo_tx_frame]
|
aristo_part, aristo_path, aristo_persist, aristo_profile, aristo_tx_frame]
|
||||||
|
|
||||||
export
|
export
|
||||||
@ -379,9 +381,6 @@ proc dup(be: BackendRef): BackendRef =
|
|||||||
when AristoPersistentBackendOk:
|
when AristoPersistentBackendOk:
|
||||||
return RdbBackendRef(be).dup
|
return RdbBackendRef(be).dup
|
||||||
|
|
||||||
of BackendVoid:
|
|
||||||
discard
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public API constuctors
|
# Public API constuctors
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -17,7 +17,7 @@ import
|
|||||||
eth/common/hashes,
|
eth/common/hashes,
|
||||||
results,
|
results,
|
||||||
./aristo_walk/persistent,
|
./aristo_walk/persistent,
|
||||||
"."/[aristo_desc, aristo_get, aristo_init],
|
"."/[aristo_desc, aristo_get, aristo_init/memory_only],
|
||||||
./aristo_check/[check_be, check_top, check_twig]
|
./aristo_check/[check_be, check_top, check_twig]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -71,9 +71,6 @@ proc checkBE*(
|
|||||||
return MemBackendRef.checkBE db
|
return MemBackendRef.checkBE db
|
||||||
of BackendRocksDB:
|
of BackendRocksDB:
|
||||||
return RdbBackendRef.checkBE db
|
return RdbBackendRef.checkBE db
|
||||||
of BackendVoid:
|
|
||||||
return VoidBackendRef.checkBE db
|
|
||||||
|
|
||||||
|
|
||||||
proc check*(
|
proc check*(
|
||||||
db: AristoTxRef; # Database
|
db: AristoTxRef; # Database
|
||||||
|
@ -17,13 +17,13 @@ import
|
|||||||
stew/interval_set,
|
stew/interval_set,
|
||||||
../../aristo,
|
../../aristo,
|
||||||
../aristo_walk/persistent,
|
../aristo_walk/persistent,
|
||||||
".."/[aristo_desc, aristo_get, aristo_layers]
|
".."/[aristo_desc, aristo_get]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc checkBE*[T: RdbBackendRef|MemBackendRef|VoidBackendRef](
|
proc checkBE*[T: RdbBackendRef|MemBackendRef](
|
||||||
_: type T;
|
_: type T;
|
||||||
db: AristoDbRef; # Database, top layer
|
db: AristoDbRef; # Database, top layer
|
||||||
): Result[void,(VertexID,AristoError)] =
|
): Result[void,(VertexID,AristoError)] =
|
||||||
|
@ -75,7 +75,7 @@ proc checkTopCommon*(
|
|||||||
let
|
let
|
||||||
kMapCount = db.layersWalkKey.toSeq.mapIt(it[1]).filterIt(it.isValid).len
|
kMapCount = db.layersWalkKey.toSeq.mapIt(it[1]).filterIt(it.isValid).len
|
||||||
kMapNilCount = db.layersWalkKey.toSeq.len - kMapCount
|
kMapNilCount = db.layersWalkKey.toSeq.len - kMapCount
|
||||||
vTop = db.layer.vTop
|
vTop = db.vTop
|
||||||
var
|
var
|
||||||
topVid = VertexID(0)
|
topVid = VertexID(0)
|
||||||
stoRoots: HashSet[VertexID]
|
stoRoots: HashSet[VertexID]
|
||||||
|
@ -25,7 +25,7 @@ import
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
func orDefault(db: AristoTxRef): AristoTxRef =
|
func orDefault(db: AristoTxRef): AristoTxRef =
|
||||||
if db.isNil: AristoTxRef(layer: LayerRef()) else: db
|
if db.isNil: AristoTxRef() else: db
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ proc ppXMap*(
|
|||||||
|
|
||||||
|
|
||||||
proc ppBalancer(
|
proc ppBalancer(
|
||||||
fl: LayerRef;
|
fl: AristoTxRef;
|
||||||
db: AristoTxRef;
|
db: AristoTxRef;
|
||||||
indent: int;
|
indent: int;
|
||||||
): string =
|
): string =
|
||||||
@ -434,7 +434,7 @@ proc ppBe[T](be: T; db: AristoTxRef; limit: int; indent: int): string =
|
|||||||
result &= "[]"
|
result &= "[]"
|
||||||
|
|
||||||
proc ppLayer(
|
proc ppLayer(
|
||||||
layer: LayerRef;
|
layer: AristoTxRef;
|
||||||
db: AristoTxRef;
|
db: AristoTxRef;
|
||||||
vTopOk: bool;
|
vTopOk: bool;
|
||||||
sTabOk: bool;
|
sTabOk: bool;
|
||||||
@ -663,7 +663,7 @@ func pp*(wp: VidVtxPair; db: AristoTxRef): string =
|
|||||||
|
|
||||||
|
|
||||||
proc pp*(
|
proc pp*(
|
||||||
layer: LayerRef;
|
layer: AristoTxRef;
|
||||||
db: AristoTxRef;
|
db: AristoTxRef;
|
||||||
indent = 4;
|
indent = 4;
|
||||||
sTabOk = true,
|
sTabOk = true,
|
||||||
@ -679,14 +679,12 @@ proc pp*(
|
|||||||
limit = 100;
|
limit = 100;
|
||||||
indent = 4;
|
indent = 4;
|
||||||
): string =
|
): string =
|
||||||
result = db.layer.ppBalancer(db, indent+1) & indent.toPfx
|
result = db.ppBalancer(db, indent+1) & indent.toPfx
|
||||||
case be.kind:
|
case be.kind:
|
||||||
of BackendMemory:
|
of BackendMemory:
|
||||||
result &= be.MemBackendRef.ppBe(db, limit, indent+1)
|
result &= be.MemBackendRef.ppBe(db, limit, indent+1)
|
||||||
of BackendRocksDB:
|
of BackendRocksDB:
|
||||||
result &= be.RdbBackendRef.ppBe(db, limit, indent+1)
|
result &= be.RdbBackendRef.ppBe(db, limit, indent+1)
|
||||||
of BackendVoid:
|
|
||||||
result &= "<NoBackend>"
|
|
||||||
|
|
||||||
proc pp*(
|
proc pp*(
|
||||||
db: AristoTxRef;
|
db: AristoTxRef;
|
||||||
|
@ -41,10 +41,40 @@ export
|
|||||||
type
|
type
|
||||||
AristoTxRef* = ref object
|
AristoTxRef* = ref object
|
||||||
## Transaction descriptor
|
## Transaction descriptor
|
||||||
db*: AristoDbRef ## Database descriptor
|
##
|
||||||
parent*: AristoTxRef ## Previous transaction
|
## Delta layers are stacked implying a tables hierarchy. Table entries on
|
||||||
layer*: LayerRef
|
## a higher level take precedence over lower layer table entries. So an
|
||||||
blockNumber*: Opt[uint64] ## Block number set when freezing the frame
|
## existing key-value table entry of a layer on top supersedes same key
|
||||||
|
## entries on all lower layers. A missing entry on a higher layer indicates
|
||||||
|
## that the key-value pair might be fond on some lower layer.
|
||||||
|
##
|
||||||
|
## A zero value (`nil`, empty hash etc.) is considered am missing key-value
|
||||||
|
## pair. Tables on the `LayerDelta` may have stray zero key-value pairs for
|
||||||
|
## missing entries due to repeated transactions while adding and deleting
|
||||||
|
## entries. There is no need to purge redundant zero entries.
|
||||||
|
##
|
||||||
|
## As for `kMap[]` entries, there might be a zero value entriy relating
|
||||||
|
## (i.e. indexed by the same vertex ID) to an `sMap[]` non-zero value entry
|
||||||
|
## (of the same layer or a lower layer whatever comes first.) This entry
|
||||||
|
## is kept as a reminder that the hash value of the `kMap[]` entry needs
|
||||||
|
## to be re-compiled.
|
||||||
|
##
|
||||||
|
## The reasoning behind the above scenario is that every vertex held on the
|
||||||
|
## `sTab[]` tables must correspond to a hash entry held on the `kMap[]`
|
||||||
|
## tables. So a corresponding zero value or missing entry produces an
|
||||||
|
## inconsistent state that must be resolved.
|
||||||
|
db*: AristoDbRef ## Database descriptor
|
||||||
|
parent*: AristoTxRef ## Previous transaction
|
||||||
|
|
||||||
|
sTab*: Table[RootedVertexID,VertexRef] ## Structural vertex table
|
||||||
|
kMap*: Table[RootedVertexID,HashKey] ## Merkle hash key mapping
|
||||||
|
vTop*: VertexID ## Last used vertex ID
|
||||||
|
|
||||||
|
accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
|
||||||
|
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef
|
||||||
|
|
||||||
|
cTop*: VertexID ## Last committed vertex ID
|
||||||
|
blockNumber*: Opt[uint64] ## Block number set when freezing the frame
|
||||||
|
|
||||||
AristoDbRef* = ref object
|
AristoDbRef* = ref object
|
||||||
## Three tier database object supporting distributed instances.
|
## Three tier database object supporting distributed instances.
|
||||||
@ -120,8 +150,8 @@ func isValid*(nd: NodeRef): bool =
|
|||||||
func isValid*(pid: PathID): bool =
|
func isValid*(pid: PathID): bool =
|
||||||
pid != VOID_PATH_ID
|
pid != VOID_PATH_ID
|
||||||
|
|
||||||
func isValid*(layer: LayerRef): bool =
|
func isValid*(tx: AristoTxRef): bool =
|
||||||
layer != LayerRef(nil)
|
tx != AristoTxRef(nil)
|
||||||
|
|
||||||
func isValid*(root: Hash32): bool =
|
func isValid*(root: Hash32): bool =
|
||||||
root != emptyRoot
|
root != emptyRoot
|
||||||
@ -163,21 +193,21 @@ iterator stack*(tx: AristoTxRef): AristoTxRef =
|
|||||||
while frames.len > 0:
|
while frames.len > 0:
|
||||||
yield frames.pop()
|
yield frames.pop()
|
||||||
|
|
||||||
iterator rstack*(tx: AristoTxRef): (LayerRef, int) =
|
iterator rstack*(tx: AristoTxRef): (AristoTxRef, int) =
|
||||||
# Stack in reverse order, ie going from tx to base
|
# Stack in reverse order, ie going from tx to base
|
||||||
var tx = tx
|
var tx = tx
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
while tx != nil:
|
while tx != nil:
|
||||||
let level = if tx.parent == nil: -1 else: i
|
let level = if tx.parent == nil: -1 else: i
|
||||||
yield (tx.layer, level)
|
yield (tx, level)
|
||||||
tx = tx.parent
|
tx = tx.parent
|
||||||
|
|
||||||
proc deltaAtLevel*(db: AristoTxRef, level: int): LayerRef =
|
proc deltaAtLevel*(db: AristoTxRef, level: int): AristoTxRef =
|
||||||
if level == -2:
|
if level == -2:
|
||||||
nil
|
nil
|
||||||
elif level == -1:
|
elif level == -1:
|
||||||
db.db.txRef.layer
|
db.db.txRef
|
||||||
else:
|
else:
|
||||||
var
|
var
|
||||||
frame = db
|
frame = db
|
||||||
@ -187,7 +217,7 @@ proc deltaAtLevel*(db: AristoTxRef, level: int): LayerRef =
|
|||||||
frame = frame.parent
|
frame = frame.parent
|
||||||
level -= 1
|
level -= 1
|
||||||
|
|
||||||
frame.layer
|
frame
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -12,17 +12,6 @@ type
|
|||||||
AristoError* = enum
|
AristoError* = enum
|
||||||
NothingSerious = 0
|
NothingSerious = 0
|
||||||
|
|
||||||
# Miscelaneous/unclassified handy helpers
|
|
||||||
GenericError
|
|
||||||
|
|
||||||
|
|
||||||
# Data record transcoders, `blobify()` from `blobify.nim`
|
|
||||||
BlobifyBranchMissingRefs
|
|
||||||
BlobifyExtMissingRefs
|
|
||||||
BlobifyExtPathOverflow
|
|
||||||
BlobifyLeafPathOverflow
|
|
||||||
BlobifyNilVertex
|
|
||||||
|
|
||||||
|
|
||||||
# Cache checker `checkCache()`
|
# Cache checker `checkCache()`
|
||||||
CheckAnyVidDeadStorageRoot
|
CheckAnyVidDeadStorageRoot
|
||||||
@ -79,17 +68,6 @@ type
|
|||||||
DelStoRootNotAccepted
|
DelStoRootNotAccepted
|
||||||
DelVidStaleVtx
|
DelVidStaleVtx
|
||||||
|
|
||||||
# Functions from `aristo_desc.nim`
|
|
||||||
DescMustBeOnCentre
|
|
||||||
DescNotAllowedOnCentre
|
|
||||||
DescStaleDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
# Functions from `aristo_delta.nim`
|
|
||||||
FilBackendRoMode
|
|
||||||
FilSiblingsCommitUnfinshed
|
|
||||||
|
|
||||||
|
|
||||||
# Fetch functions from `aristo_fetch.nim`
|
# Fetch functions from `aristo_fetch.nim`
|
||||||
FetchAccInaccessible
|
FetchAccInaccessible
|
||||||
FetchAccPathWithoutLeaf
|
FetchAccPathWithoutLeaf
|
||||||
@ -205,7 +183,6 @@ type
|
|||||||
PartVtxSlotWasNotModified
|
PartVtxSlotWasNotModified
|
||||||
|
|
||||||
# RocksDB backend
|
# RocksDB backend
|
||||||
RdbBeCantCreateDataDir
|
|
||||||
RdbBeCantCreateTmpDir
|
RdbBeCantCreateTmpDir
|
||||||
RdbBeDriverDelAdmError
|
RdbBeDriverDelAdmError
|
||||||
RdbBeDriverDelKeyError
|
RdbBeDriverDelKeyError
|
||||||
|
@ -94,37 +94,6 @@ type
|
|||||||
key*: Hash32 ## Some state hash (if any)
|
key*: Hash32 ## Some state hash (if any)
|
||||||
serial*: uint64 ## Generic identifier from application
|
serial*: uint64 ## Generic identifier from application
|
||||||
|
|
||||||
LayerRef* = ref Layer
|
|
||||||
Layer* = object
|
|
||||||
## Delta layers are stacked implying a tables hierarchy. Table entries on
|
|
||||||
## a higher level take precedence over lower layer table entries. So an
|
|
||||||
## existing key-value table entry of a layer on top supersedes same key
|
|
||||||
## entries on all lower layers. A missing entry on a higher layer indicates
|
|
||||||
## that the key-value pair might be fond on some lower layer.
|
|
||||||
##
|
|
||||||
## A zero value (`nil`, empty hash etc.) is considered am missing key-value
|
|
||||||
## pair. Tables on the `LayerDelta` may have stray zero key-value pairs for
|
|
||||||
## missing entries due to repeated transactions while adding and deleting
|
|
||||||
## entries. There is no need to purge redundant zero entries.
|
|
||||||
##
|
|
||||||
## As for `kMap[]` entries, there might be a zero value entriy relating
|
|
||||||
## (i.e. indexed by the same vertex ID) to an `sMap[]` non-zero value entry
|
|
||||||
## (of the same layer or a lower layer whatever comes first.) This entry
|
|
||||||
## is kept as a reminder that the hash value of the `kMap[]` entry needs
|
|
||||||
## to be re-compiled.
|
|
||||||
##
|
|
||||||
## The reasoning behind the above scenario is that every vertex held on the
|
|
||||||
## `sTab[]` tables must correspond to a hash entry held on the `kMap[]`
|
|
||||||
## tables. So a corresponding zero value or missing entry produces an
|
|
||||||
## inconsistent state that must be resolved.
|
|
||||||
##
|
|
||||||
sTab*: Table[RootedVertexID,VertexRef] ## Structural vertex table
|
|
||||||
kMap*: Table[RootedVertexID,HashKey] ## Merkle hash key mapping
|
|
||||||
vTop*: VertexID ## Last used vertex ID
|
|
||||||
|
|
||||||
accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
|
|
||||||
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef
|
|
||||||
|
|
||||||
GetVtxFlag* = enum
|
GetVtxFlag* = enum
|
||||||
PeekCache
|
PeekCache
|
||||||
## Peek into, but don't update cache - useful on work loads that are
|
## Peek into, but don't update cache - useful on work loads that are
|
||||||
|
@ -19,7 +19,6 @@ const
|
|||||||
|
|
||||||
type
|
type
|
||||||
BackendType* = enum
|
BackendType* = enum
|
||||||
BackendVoid = 0 ## For providing backend-less constructor
|
|
||||||
BackendMemory
|
BackendMemory
|
||||||
BackendRocksDB
|
BackendRocksDB
|
||||||
|
|
||||||
@ -100,7 +99,7 @@ proc init*(
|
|||||||
let
|
let
|
||||||
vTop = if backend == nil: VertexID(0) else: ?backend.getTuvFn()
|
vTop = if backend == nil: VertexID(0) else: ?backend.getTuvFn()
|
||||||
db = AristoDbRef(
|
db = AristoDbRef(
|
||||||
txRef: AristoTxRef(layer: LayerRef(vTop: vTop)),
|
txRef: AristoTxRef(vTop: vTop),
|
||||||
backend: backend,
|
backend: backend,
|
||||||
accLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
|
accLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
|
||||||
stoLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
|
stoLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
## backend access
|
## backend access
|
||||||
## ::
|
## ::
|
||||||
## import
|
## import
|
||||||
## aristo/aristo_init,
|
|
||||||
## aristo/aristo_init/aristo_memory
|
## aristo/aristo_init/aristo_memory
|
||||||
##
|
##
|
||||||
## let rc = newAristoDbRef(BackendMemory)
|
## let rc = newAristoDbRef(BackendMemory)
|
||||||
|
@ -18,12 +18,6 @@ import
|
|||||||
../aristo_desc/desc_backend,
|
../aristo_desc/desc_backend,
|
||||||
"."/[init_common, memory_db]
|
"."/[init_common, memory_db]
|
||||||
|
|
||||||
type
|
|
||||||
VoidBackendRef* = ref object of TypedBackendRef
|
|
||||||
## Dummy descriptor type, used as `nil` reference
|
|
||||||
|
|
||||||
MemOnlyBackend* = VoidBackendRef|MemBackendRef
|
|
||||||
|
|
||||||
export
|
export
|
||||||
BackendType,
|
BackendType,
|
||||||
GuestDbRef,
|
GuestDbRef,
|
||||||
@ -37,36 +31,23 @@ proc kind*(
|
|||||||
be: BackendRef;
|
be: BackendRef;
|
||||||
): BackendType =
|
): BackendType =
|
||||||
## Retrieves the backend type symbol for a `be` backend database argument
|
## Retrieves the backend type symbol for a `be` backend database argument
|
||||||
## where `BackendVoid` is returned for the`nil` backend.
|
doAssert(not be.isNil)
|
||||||
if be.isNil:
|
be.TypedBackendRef.beKind
|
||||||
BackendVoid
|
|
||||||
else:
|
|
||||||
be.TypedBackendRef.beKind
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public database constuctors, destructor
|
# Public database constuctors, destructor
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc init*(
|
proc init*(
|
||||||
T: type AristoDbRef; # Target type
|
T: type AristoDbRef; # Target type
|
||||||
B: type MemOnlyBackend; # Backend type
|
B: type MemBackendRef; # Backend type
|
||||||
): T =
|
): T =
|
||||||
## Memory backend constructor.
|
## Memory backend constructor.
|
||||||
##
|
##
|
||||||
|
AristoDbRef.init(memoryBackend())[]
|
||||||
|
|
||||||
when B is VoidBackendRef:
|
proc init*(T: type AristoDbRef): T =
|
||||||
AristoDbRef.init(nil)[]
|
AristoDbRef.init(MemBackendRef)
|
||||||
|
|
||||||
elif B is MemBackendRef:
|
|
||||||
AristoDbRef.init(memoryBackend())[]
|
|
||||||
else:
|
|
||||||
raiseAssert "Unknown backend"
|
|
||||||
|
|
||||||
proc init*(
|
|
||||||
T: type AristoDbRef; # Target type
|
|
||||||
): T =
|
|
||||||
## Shortcut for `AristoDbRef.init(VoidBackendRef)`
|
|
||||||
AristoDbRef.init VoidBackendRef
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -72,8 +72,8 @@ func layersPutVtx*(
|
|||||||
vtx: VertexRef;
|
vtx: VertexRef;
|
||||||
) =
|
) =
|
||||||
## Store a (potentally empty) vertex on the top layer
|
## Store a (potentally empty) vertex on the top layer
|
||||||
db.layer.sTab[rvid] = vtx
|
db.sTab[rvid] = vtx
|
||||||
db.layer.kMap.del(rvid)
|
db.kMap.del(rvid)
|
||||||
|
|
||||||
func layersResVtx*(
|
func layersResVtx*(
|
||||||
db: AristoTxRef;
|
db: AristoTxRef;
|
||||||
@ -90,8 +90,8 @@ func layersPutKey*(
|
|||||||
key: HashKey;
|
key: HashKey;
|
||||||
) =
|
) =
|
||||||
## Store a (potentally void) hash key on the top layer
|
## Store a (potentally void) hash key on the top layer
|
||||||
db.layer.sTab[rvid] = vtx
|
db.sTab[rvid] = vtx
|
||||||
db.layer.kMap[rvid] = key
|
db.kMap[rvid] = key
|
||||||
|
|
||||||
func layersResKey*(db: AristoTxRef; rvid: RootedVertexID, vtx: VertexRef) =
|
func layersResKey*(db: AristoTxRef; rvid: RootedVertexID, vtx: VertexRef) =
|
||||||
## Shortcut for `db.layersPutKey(vid, VOID_HASH_KEY)`. It is sort of the
|
## Shortcut for `db.layersPutKey(vid, VOID_HASH_KEY)`. It is sort of the
|
||||||
@ -104,16 +104,16 @@ func layersResKeys*(db: AristoTxRef; hike: Hike) =
|
|||||||
db.layersResKey((hike.root, hike.legs[^i].wp.vid), hike.legs[^i].wp.vtx)
|
db.layersResKey((hike.root, hike.legs[^i].wp.vid), hike.legs[^i].wp.vtx)
|
||||||
|
|
||||||
func layersPutAccLeaf*(db: AristoTxRef; accPath: Hash32; leafVtx: VertexRef) =
|
func layersPutAccLeaf*(db: AristoTxRef; accPath: Hash32; leafVtx: VertexRef) =
|
||||||
db.layer.accLeaves[accPath] = leafVtx
|
db.accLeaves[accPath] = leafVtx
|
||||||
|
|
||||||
func layersPutStoLeaf*(db: AristoTxRef; mixPath: Hash32; leafVtx: VertexRef) =
|
func layersPutStoLeaf*(db: AristoTxRef; mixPath: Hash32; leafVtx: VertexRef) =
|
||||||
db.layer.stoLeaves[mixPath] = leafVtx
|
db.stoLeaves[mixPath] = leafVtx
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
func isEmpty*(ly: LayerRef): bool =
|
func isEmpty*(ly: AristoTxRef): bool =
|
||||||
## Returns `true` if the layer does not contain any changes, i.e. all the
|
## Returns `true` if the layer does not contain any changes, i.e. all the
|
||||||
## tables are empty.
|
## tables are empty.
|
||||||
ly.sTab.len == 0 and
|
ly.sTab.len == 0 and
|
||||||
@ -121,7 +121,7 @@ func isEmpty*(ly: LayerRef): bool =
|
|||||||
ly.accLeaves.len == 0 and
|
ly.accLeaves.len == 0 and
|
||||||
ly.stoLeaves.len == 0
|
ly.stoLeaves.len == 0
|
||||||
|
|
||||||
proc mergeAndReset*(trg, src: var Layer) =
|
proc mergeAndReset*(trg, src: AristoTxRef) =
|
||||||
## Merges the argument `src` into the argument `trg` and clears `src`.
|
## Merges the argument `src` into the argument `trg` and clears `src`.
|
||||||
trg.vTop = src.vTop
|
trg.vTop = src.vTop
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus
|
# Nimbus
|
||||||
# Copyright (c) 2024 Status Research & Development GmbH
|
# Copyright (c) 2024-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -11,7 +11,7 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, math, sequtils, strformat, strutils, tables, times],
|
std/[algorithm, math, sequtils, strformat, tables, times],
|
||||||
eth/common
|
eth/common
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -27,14 +27,10 @@ proc txFrameBegin*(db: AristoDbRef, parent: AristoTxRef): AristoTxRef =
|
|||||||
else:
|
else:
|
||||||
parent
|
parent
|
||||||
|
|
||||||
let
|
|
||||||
vTop = parent.layer.vTop
|
|
||||||
layer = LayerRef(vTop: vTop)
|
|
||||||
|
|
||||||
AristoTxRef(
|
AristoTxRef(
|
||||||
db: db,
|
db: db,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
layer: layer)
|
vTop: parent.vTop)
|
||||||
|
|
||||||
proc baseTxFrame*(db: AristoDbRef): AristoTxRef=
|
proc baseTxFrame*(db: AristoDbRef): AristoTxRef=
|
||||||
db.txRef
|
db.txRef
|
||||||
@ -56,7 +52,7 @@ proc txFramePersist*(
|
|||||||
txFrame: AristoTxRef;
|
txFrame: AristoTxRef;
|
||||||
) =
|
) =
|
||||||
|
|
||||||
if txFrame == db.txRef and txFrame.layer.sTab.len == 0:
|
if txFrame == db.txRef and txFrame.sTab.len == 0:
|
||||||
# No changes in frame - no `checkpoint` requirement - nothing to do here
|
# No changes in frame - no `checkpoint` requirement - nothing to do here
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -76,7 +72,7 @@ proc txFramePersist*(
|
|||||||
for frame in txFrame.stack():
|
for frame in txFrame.stack():
|
||||||
if frame == db.txRef:
|
if frame == db.txRef:
|
||||||
continue
|
continue
|
||||||
mergeAndReset(db.txRef.layer[], frame.layer[])
|
mergeAndReset(db.txRef, frame)
|
||||||
db.txRef.blockNumber = frame.blockNumber
|
db.txRef.blockNumber = frame.blockNumber
|
||||||
|
|
||||||
frame.dispose() # This will also dispose `txFrame` itself!
|
frame.dispose() # This will also dispose `txFrame` itself!
|
||||||
@ -86,13 +82,13 @@ proc txFramePersist*(
|
|||||||
db.txRef = txFrame
|
db.txRef = txFrame
|
||||||
|
|
||||||
# Store structural single trie entries
|
# Store structural single trie entries
|
||||||
for rvid, vtx in txFrame.layer.sTab:
|
for rvid, vtx in db.txRef.sTab:
|
||||||
txFrame.layer.kMap.withValue(rvid, key) do:
|
txFrame.kMap.withValue(rvid, key) do:
|
||||||
be.putVtxFn(batch, rvid, vtx, key[])
|
be.putVtxFn(batch, rvid, vtx, key[])
|
||||||
do:
|
do:
|
||||||
be.putVtxFn(batch, rvid, vtx, default(HashKey))
|
be.putVtxFn(batch, rvid, vtx, default(HashKey))
|
||||||
|
|
||||||
be.putTuvFn(batch, txFrame.layer.vTop)
|
be.putTuvFn(batch, txFrame.vTop)
|
||||||
be.putLstFn(batch, lSst)
|
be.putLstFn(batch, lSst)
|
||||||
|
|
||||||
# TODO above, we only prepare the changes to the database but don't actually
|
# TODO above, we only prepare the changes to the database but don't actually
|
||||||
@ -101,16 +97,16 @@ proc txFramePersist*(
|
|||||||
# in-memory and on-disk state)
|
# in-memory and on-disk state)
|
||||||
|
|
||||||
# Copy back updated payloads
|
# Copy back updated payloads
|
||||||
for accPath, vtx in txFrame.layer.accLeaves:
|
for accPath, vtx in txFrame.accLeaves:
|
||||||
db.accLeaves.put(accPath, vtx)
|
db.accLeaves.put(accPath, vtx)
|
||||||
|
|
||||||
for mixPath, vtx in txFrame.layer.stoLeaves:
|
for mixPath, vtx in txFrame.stoLeaves:
|
||||||
db.stoLeaves.put(mixPath, vtx)
|
db.stoLeaves.put(mixPath, vtx)
|
||||||
|
|
||||||
txFrame.layer.sTab.clear()
|
txFrame.sTab.clear()
|
||||||
txFrame.layer.kMap.clear()
|
txFrame.kMap.clear()
|
||||||
txFrame.layer.accLeaves.clear()
|
txFrame.accLeaves.clear()
|
||||||
txFrame.layer.stoLeaves.clear()
|
txFrame.stoLeaves.clear()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -23,11 +23,11 @@ import
|
|||||||
proc vidFetch*(db: AristoTxRef, n = 1): VertexID =
|
proc vidFetch*(db: AristoTxRef, n = 1): VertexID =
|
||||||
## Fetch next vertex ID.
|
## Fetch next vertex ID.
|
||||||
##
|
##
|
||||||
if db.layer.vTop == 0:
|
if db.vTop == 0:
|
||||||
db.layer.vTop = VertexID(LEAST_FREE_VID)
|
db.vTop = VertexID(LEAST_FREE_VID)
|
||||||
var ret = db.layer.vTop
|
var ret = db.vTop
|
||||||
ret.inc
|
ret.inc
|
||||||
db.layer.vTop.inc(n)
|
db.vTop.inc(n)
|
||||||
ret
|
ret
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Nimbus - Types, data structures and shared utilities used in network sync
|
# Nimbus - Types, data structures and shared utilities used in network sync
|
||||||
#
|
#
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -14,7 +14,7 @@
|
|||||||
##
|
##
|
||||||
import
|
import
|
||||||
../aristo_init/[memory_db, memory_only],
|
../aristo_init/[memory_db, memory_only],
|
||||||
".."/[aristo_desc, aristo_init],
|
".."/[aristo_desc],
|
||||||
./walk_private
|
./walk_private
|
||||||
|
|
||||||
export
|
export
|
||||||
@ -26,7 +26,7 @@ export
|
|||||||
# Public iterators (all in one)
|
# Public iterators (all in one)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
iterator walkVtxBe*[T: MemBackendRef|VoidBackendRef](
|
iterator walkVtxBe*[T: MemBackendRef](
|
||||||
_: type T;
|
_: type T;
|
||||||
db: AristoDbRef;
|
db: AristoDbRef;
|
||||||
kinds = {Branch, Leaf};
|
kinds = {Branch, Leaf};
|
||||||
@ -37,7 +37,7 @@ iterator walkVtxBe*[T: MemBackendRef|VoidBackendRef](
|
|||||||
for (rvid,vtx) in walkVtxBeImpl[T](db, kinds):
|
for (rvid,vtx) in walkVtxBeImpl[T](db, kinds):
|
||||||
yield (rvid,vtx)
|
yield (rvid,vtx)
|
||||||
|
|
||||||
iterator walkKeyBe*[T: MemBackendRef|VoidBackendRef](
|
iterator walkKeyBe*[T: MemBackendRef](
|
||||||
_: type T;
|
_: type T;
|
||||||
db: AristoDbRef;
|
db: AristoDbRef;
|
||||||
): tuple[rvid: RootedVertexID, key: HashKey] =
|
): tuple[rvid: RootedVertexID, key: HashKey] =
|
||||||
@ -47,7 +47,7 @@ iterator walkKeyBe*[T: MemBackendRef|VoidBackendRef](
|
|||||||
|
|
||||||
# -----------
|
# -----------
|
||||||
|
|
||||||
iterator walkPairs*[T: MemBackendRef|VoidBackendRef](
|
iterator walkPairs*[T: MemBackendRef](
|
||||||
_: type T;
|
_: type T;
|
||||||
db: AristoDbRef;
|
db: AristoDbRef;
|
||||||
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
|
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
import
|
import
|
||||||
std/[algorithm, sequtils, sets, tables],
|
std/[algorithm, sequtils, sets, tables],
|
||||||
results,
|
results,
|
||||||
".."/[aristo_desc, aristo_init, aristo_layers]
|
".."/[aristo_desc, aristo_layers]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public generic iterators
|
# Public generic iterators
|
||||||
@ -23,24 +23,20 @@ iterator walkVtxBeImpl*[T](
|
|||||||
kinds: set[VertexType];
|
kinds: set[VertexType];
|
||||||
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
|
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
|
||||||
## Generic iterator
|
## Generic iterator
|
||||||
when T is VoidBackendRef:
|
mixin walkVtx
|
||||||
let filter = if db.txRef.isNil: LayerRef() else: db.txRef.layer
|
|
||||||
|
|
||||||
else:
|
let filter = AristoTxRef()
|
||||||
mixin walkVtx
|
if not db.txRef.isNil:
|
||||||
|
filter.sTab = db.txRef.sTab # copy table
|
||||||
|
|
||||||
let filter = LayerRef()
|
for (rvid,vtx) in db.backend.T.walkVtx(kinds):
|
||||||
if not db.txRef.isNil:
|
if filter.sTab.hasKey rvid:
|
||||||
filter.sTab = db.txRef.layer.sTab # copy table
|
let fVtx = filter.sTab.getOrVoid rvid
|
||||||
|
if fVtx.isValid:
|
||||||
for (rvid,vtx) in db.backend.T.walkVtx(kinds):
|
yield (rvid,fVtx)
|
||||||
if filter.sTab.hasKey rvid:
|
filter.sTab.del rvid
|
||||||
let fVtx = filter.sTab.getOrVoid rvid
|
else:
|
||||||
if fVtx.isValid:
|
yield (rvid,vtx)
|
||||||
yield (rvid,fVtx)
|
|
||||||
filter.sTab.del rvid
|
|
||||||
else:
|
|
||||||
yield (rvid,vtx)
|
|
||||||
|
|
||||||
for rvid in filter.sTab.keys:
|
for rvid in filter.sTab.keys:
|
||||||
let vtx = filter.sTab.getOrVoid rvid
|
let vtx = filter.sTab.getOrVoid rvid
|
||||||
@ -54,24 +50,20 @@ iterator walkKeyBeImpl*[T](
|
|||||||
db: AristoDbRef; # Database with optional backend filter
|
db: AristoDbRef; # Database with optional backend filter
|
||||||
): tuple[rvid: RootedVertexID, key: HashKey] =
|
): tuple[rvid: RootedVertexID, key: HashKey] =
|
||||||
## Generic iterator
|
## Generic iterator
|
||||||
when T is VoidBackendRef:
|
mixin walkKey
|
||||||
let filter = if db.txRef.isNil: LayerRef() else: db.txRef.layer
|
|
||||||
|
|
||||||
else:
|
let filter = AristoTxRef()
|
||||||
mixin walkKey
|
if not db.txRef.isNil:
|
||||||
|
filter.kMap = db.txRef.kMap # copy table
|
||||||
|
|
||||||
let filter = LayerRef()
|
for (rvid,key) in db.backend.T.walkKey:
|
||||||
if not db.txRef.isNil:
|
if filter.kMap.hasKey rvid:
|
||||||
filter.kMap = db.txRef.layer.kMap # copy table
|
let fKey = filter.kMap.getOrVoid rvid
|
||||||
|
if fKey.isValid:
|
||||||
for (rvid,key) in db.backend.T.walkKey:
|
yield (rvid,fKey)
|
||||||
if filter.kMap.hasKey rvid:
|
filter.kMap.del rvid
|
||||||
let fKey = filter.kMap.getOrVoid rvid
|
else:
|
||||||
if fKey.isValid:
|
yield (rvid,key)
|
||||||
yield (rvid,fKey)
|
|
||||||
filter.kMap.del rvid
|
|
||||||
else:
|
|
||||||
yield (rvid,key)
|
|
||||||
|
|
||||||
for rvid in filter.kMap.keys.toSeq.sorted:
|
for rvid in filter.kMap.keys.toSeq.sorted:
|
||||||
let key = filter.kMap.getOrVoid rvid
|
let key = filter.kMap.getOrVoid rvid
|
||||||
|
@ -48,11 +48,6 @@ proc newMemoryCoreDbRef*(): CoreDbRef =
|
|||||||
KvtDbRef.init(use_kvt.MemBackendRef),
|
KvtDbRef.init(use_kvt.MemBackendRef),
|
||||||
AristoDbRef.init(use_ari.MemBackendRef))
|
AristoDbRef.init(use_ari.MemBackendRef))
|
||||||
|
|
||||||
proc newVoidCoreDbRef*(): CoreDbRef =
|
|
||||||
AristoDbVoid.create(
|
|
||||||
KvtDbRef.init(use_kvt.VoidBackendRef),
|
|
||||||
AristoDbRef.init(use_ari.VoidBackendRef))
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus
|
# Nimbus
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -20,7 +20,6 @@ type
|
|||||||
Ooops
|
Ooops
|
||||||
AristoDbMemory ## Memory backend emulator
|
AristoDbMemory ## Memory backend emulator
|
||||||
AristoDbRocks ## RocksDB backend
|
AristoDbRocks ## RocksDB backend
|
||||||
AristoDbVoid ## No backend
|
|
||||||
|
|
||||||
const
|
const
|
||||||
CoreDbPersistentTypes* = {AristoDbRocks}
|
CoreDbPersistentTypes* = {AristoDbRocks}
|
||||||
|
@ -41,9 +41,6 @@ proc newCoreDbRef*(
|
|||||||
when dbType == AristoDbMemory:
|
when dbType == AristoDbMemory:
|
||||||
newMemoryCoreDbRef()
|
newMemoryCoreDbRef()
|
||||||
|
|
||||||
elif dbType == AristoDbVoid:
|
|
||||||
newVoidCoreDbRef()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
{.error: "Unsupported constructor " & $dbType & ".newCoreDbRef()".}
|
{.error: "Unsupported constructor " & $dbType & ".newCoreDbRef()".}
|
||||||
|
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
# Nimbus
|
|
||||||
# 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)
|
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
||||||
# http://opensource.org/licenses/MIT)
|
|
||||||
# at your option. This file may not be copied, modified, or distributed except
|
|
||||||
# according to those terms.
|
|
||||||
|
|
||||||
{.push raises: [].}
|
|
||||||
|
|
||||||
import
|
|
||||||
std/[os, sequtils],
|
|
||||||
results,
|
|
||||||
rocksdb,
|
|
||||||
eth/db/kvstore
|
|
||||||
|
|
||||||
export kvstore
|
|
||||||
|
|
||||||
type
|
|
||||||
RocksStoreRef* = ref object of RootObj
|
|
||||||
db: RocksDbReadWriteRef
|
|
||||||
|
|
||||||
RocksNamespaceRef* = ref object of RootObj
|
|
||||||
colFamily: ColFamilyReadWrite
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# RocksStoreRef procs
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
proc rocksDb*(store: RocksStoreRef): RocksDbReadWriteRef =
|
|
||||||
store.db
|
|
||||||
|
|
||||||
proc get*(
|
|
||||||
store: RocksStoreRef,
|
|
||||||
key: openArray[byte],
|
|
||||||
onData: kvstore.DataProc): KvResult[bool] =
|
|
||||||
store.db.get(key, onData)
|
|
||||||
|
|
||||||
proc find*(
|
|
||||||
store: RocksStoreRef,
|
|
||||||
prefix: openArray[byte],
|
|
||||||
onFind: kvstore.KeyValueProc): KvResult[int] =
|
|
||||||
raiseAssert "Unimplemented"
|
|
||||||
|
|
||||||
proc put*(store: RocksStoreRef, key, value: openArray[byte]): KvResult[void] =
|
|
||||||
store.db.put(key, value)
|
|
||||||
|
|
||||||
proc contains*(store: RocksStoreRef, key: openArray[byte]): KvResult[bool] =
|
|
||||||
store.db.keyExists(key)
|
|
||||||
|
|
||||||
proc del*(store: RocksStoreRef, key: openArray[byte]): KvResult[bool] =
|
|
||||||
|
|
||||||
let rc = store.db.keyExists(key)
|
|
||||||
if rc.isErr:
|
|
||||||
return rc
|
|
||||||
if not rc.value:
|
|
||||||
return ok(false)
|
|
||||||
|
|
||||||
let res = store.db.delete(key)
|
|
||||||
if res.isErr():
|
|
||||||
return err(res.error())
|
|
||||||
|
|
||||||
ok(true)
|
|
||||||
|
|
||||||
proc clear*(store: RocksStoreRef): KvResult[bool] =
|
|
||||||
raiseAssert "Unimplemented"
|
|
||||||
|
|
||||||
proc close*(store: RocksStoreRef) =
|
|
||||||
store.db.close()
|
|
||||||
|
|
||||||
proc init*(
|
|
||||||
T: type RocksStoreRef,
|
|
||||||
basePath: string,
|
|
||||||
name: string,
|
|
||||||
namespaces = @["default"]): KvResult[T] =
|
|
||||||
|
|
||||||
let dataDir = basePath / name / "data"
|
|
||||||
|
|
||||||
try:
|
|
||||||
createDir(dataDir)
|
|
||||||
except OSError, IOError:
|
|
||||||
return err("RocksStoreRef: cannot create database directory")
|
|
||||||
|
|
||||||
let db = ? openRocksDb(dataDir, columnFamilies = namespaces.mapIt(
|
|
||||||
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))))
|
|
||||||
ok(T(db: db))
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# RocksNamespaceRef procs
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
proc name*(store: RocksNamespaceRef): string =
|
|
||||||
store.colFamily.name
|
|
||||||
|
|
||||||
proc get*(
|
|
||||||
ns: RocksNamespaceRef,
|
|
||||||
key: openArray[byte],
|
|
||||||
onData: kvstore.DataProc): KvResult[bool] =
|
|
||||||
ns.colFamily.get(key, onData)
|
|
||||||
|
|
||||||
proc find*(
|
|
||||||
ns: RocksNamespaceRef,
|
|
||||||
prefix: openArray[byte],
|
|
||||||
onFind: kvstore.KeyValueProc): KvResult[int] =
|
|
||||||
raiseAssert "Unimplemented"
|
|
||||||
|
|
||||||
proc put*(ns: RocksNamespaceRef, key, value: openArray[byte]): KvResult[void] =
|
|
||||||
ns.colFamily.put(key, value)
|
|
||||||
|
|
||||||
proc contains*(ns: RocksNamespaceRef, key: openArray[byte]): KvResult[bool] =
|
|
||||||
ns.colFamily.keyExists(key)
|
|
||||||
|
|
||||||
proc del*(ns: RocksNamespaceRef, key: openArray[byte]): KvResult[bool] =
|
|
||||||
let exists = ? ns.colFamily.keyExists(key)
|
|
||||||
if not exists:
|
|
||||||
return ok(false)
|
|
||||||
|
|
||||||
let res = ns.colFamily.delete(key)
|
|
||||||
if res.isErr():
|
|
||||||
return err(res.error())
|
|
||||||
|
|
||||||
ok(true)
|
|
||||||
|
|
||||||
proc clear*(ns: RocksNamespaceRef): KvResult[bool] =
|
|
||||||
raiseAssert "Unimplemented"
|
|
||||||
|
|
||||||
proc close*(ns: RocksNamespaceRef) =
|
|
||||||
# To close the database, call close on RocksStoreRef.
|
|
||||||
raiseAssert "Unimplemented"
|
|
||||||
|
|
||||||
proc openNamespace*(
|
|
||||||
store: RocksStoreRef,
|
|
||||||
name: string): KvResult[RocksNamespaceRef] =
|
|
||||||
doAssert not store.db.isClosed()
|
|
||||||
|
|
||||||
ok(RocksNamespaceRef(colFamily: ?store.db.getColFamily(name)))
|
|
@ -1,5 +1,5 @@
|
|||||||
# nimbus-eth1
|
# nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -19,10 +19,9 @@ export
|
|||||||
kvt_api, kvt_constants
|
kvt_api, kvt_constants
|
||||||
|
|
||||||
import
|
import
|
||||||
kvt/kvt_init
|
kvt/kvt_init/memory_only
|
||||||
export
|
export
|
||||||
MemBackendRef,
|
MemBackendRef,
|
||||||
VoidBackendRef,
|
|
||||||
finish,
|
finish,
|
||||||
init
|
init
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import
|
|||||||
../aristo/aristo_profile,
|
../aristo/aristo_profile,
|
||||||
./kvt_desc/desc_backend,
|
./kvt_desc/desc_backend,
|
||||||
./kvt_init/memory_db,
|
./kvt_init/memory_db,
|
||||||
"."/[kvt_desc, kvt_init, kvt_persist, kvt_tx_frame, kvt_utils]
|
./kvt_init/memory_only,
|
||||||
|
"."/[kvt_desc, kvt_persist, kvt_tx_frame, kvt_utils]
|
||||||
|
|
||||||
const
|
const
|
||||||
AutoValidateApiHooks = defined(release).not
|
AutoValidateApiHooks = defined(release).not
|
||||||
@ -117,13 +118,10 @@ proc dup(be: BackendRef): BackendRef =
|
|||||||
of BackendMemory:
|
of BackendMemory:
|
||||||
return MemBackendRef(be).dup
|
return MemBackendRef(be).dup
|
||||||
|
|
||||||
of BackendRocksDB, BackendRdbTriggered:
|
of BackendRocksDB:
|
||||||
when KvtPersistentBackendOk:
|
when KvtPersistentBackendOk:
|
||||||
return RdbBackendRef(be).dup
|
return RdbBackendRef(be).dup
|
||||||
|
|
||||||
of BackendVoid:
|
|
||||||
discard
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public API constuctors
|
# Public API constuctors
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# nimbus-eth1
|
# nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -131,7 +131,7 @@ proc ppBe[T](be: T; db: KvtDbRef; indent: int): string =
|
|||||||
spc = if 0 < n: pfx2 else: " "
|
spc = if 0 < n: pfx2 else: " "
|
||||||
"<" & $be.kind & ">" & pfx1 & "tab" & spc & "{" & data & "}"
|
"<" & $be.kind & ">" & pfx1 & "tab" & spc & "{" & data & "}"
|
||||||
|
|
||||||
proc ppLayer(layer: LayerRef; db: KvtDbRef; indent = 4): string =
|
proc ppLayer(layer: AristoTxRef; db: KvtDbRef; indent = 4): string =
|
||||||
let
|
let
|
||||||
tLen = layer.sTab.len
|
tLen = layer.sTab.len
|
||||||
info = "tab(" & $tLen & ")"
|
info = "tab(" & $tLen & ")"
|
||||||
@ -151,10 +151,8 @@ proc pp*(
|
|||||||
case be.kind:
|
case be.kind:
|
||||||
of BackendMemory:
|
of BackendMemory:
|
||||||
result &= be.MemBackendRef.ppBe(db, indent)
|
result &= be.MemBackendRef.ppBe(db, indent)
|
||||||
of BackendRocksDB,BackendRdbTriggered:
|
of BackendRocksDB:
|
||||||
result &= be.RdbBackendRef.ppBe(db, indent)
|
result &= be.RdbBackendRef.ppBe(db, indent)
|
||||||
of BackendVoid:
|
|
||||||
result &= "<NoBackend>"
|
|
||||||
|
|
||||||
proc pp*(
|
proc pp*(
|
||||||
db: KvtDbRef;
|
db: KvtDbRef;
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
import
|
import
|
||||||
std/[hashes, tables],
|
std/[hashes, tables],
|
||||||
./kvt_constants,
|
./kvt_constants,
|
||||||
./kvt_desc/[desc_error, desc_structural]
|
./kvt_desc/[desc_error]
|
||||||
|
|
||||||
from ./kvt_desc/desc_backend
|
from ./kvt_desc/desc_backend
|
||||||
import BackendRef, PutHdlRef
|
import BackendRef, PutHdlRef
|
||||||
|
|
||||||
# Not auto-exporting backend
|
# Not auto-exporting backend
|
||||||
export
|
export
|
||||||
hashes, tables, kvt_constants, desc_error, desc_structural, PutHdlRef
|
hashes, tables, kvt_constants, desc_error, PutHdlRef
|
||||||
|
|
||||||
type
|
type
|
||||||
KvtTxRef* = ref object
|
KvtTxRef* = ref object
|
||||||
## Transaction descriptor
|
## Transaction descriptor
|
||||||
db*: KvtDbRef ## Database descriptor
|
db*: KvtDbRef ## Database descriptor
|
||||||
parent*: KvtTxRef ## Previous transaction
|
parent*: KvtTxRef ## Previous transaction
|
||||||
layer*: LayerRef
|
sTab*: Table[seq[byte],seq[byte]] ## Structural data table
|
||||||
|
|
||||||
KvtDbRef* = ref object of RootRef
|
KvtDbRef* = ref object of RootRef
|
||||||
## Three tier database object supporting distributed instances.
|
## Three tier database object supporting distributed instances.
|
||||||
@ -58,8 +58,8 @@ func getOrVoid*(tab: Table[seq[byte],seq[byte]]; w: seq[byte]): seq[byte] =
|
|||||||
func isValid*(key: seq[byte]): bool =
|
func isValid*(key: seq[byte]): bool =
|
||||||
key != EmptyBlob
|
key != EmptyBlob
|
||||||
|
|
||||||
func isValid*(layer: LayerRef): bool =
|
func isValid*(tx: KvtTxRef): bool =
|
||||||
layer != LayerRef(nil)
|
tx != KvtTxRef(nil)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, miscellaneous
|
# Public functions, miscellaneous
|
||||||
@ -79,11 +79,11 @@ iterator stack*(tx: KvtTxRef): KvtTxRef =
|
|||||||
while frames.len > 0:
|
while frames.len > 0:
|
||||||
yield frames.pop()
|
yield frames.pop()
|
||||||
|
|
||||||
iterator rstack*(tx: KvtTxRef): LayerRef =
|
iterator rstack*(tx: KvtTxRef): KvtTxRef =
|
||||||
var tx = tx
|
var tx = tx
|
||||||
# Stack in reverse order
|
# Stack in reverse order
|
||||||
while tx != nil:
|
while tx != nil:
|
||||||
yield tx.layer
|
yield tx
|
||||||
tx = tx.parent
|
tx = tx.parent
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -11,32 +11,15 @@
|
|||||||
type
|
type
|
||||||
KvtError* = enum
|
KvtError* = enum
|
||||||
NothingSerious = 0
|
NothingSerious = 0
|
||||||
GenericError
|
|
||||||
|
|
||||||
GetNotFound
|
GetNotFound
|
||||||
KeyInvalid
|
KeyInvalid
|
||||||
DataInvalid
|
DataInvalid
|
||||||
|
|
||||||
# RocksDB backend
|
# RocksDB backend
|
||||||
RdbBeCantCreateDataDir
|
|
||||||
RdbBeDelayedAlreadyRegistered
|
|
||||||
RdbBeDelayedLocked
|
|
||||||
RdbBeDelayedNotReady
|
|
||||||
RdbBeDriverDelError
|
RdbBeDriverDelError
|
||||||
RdbBeDriverGetError
|
RdbBeDriverGetError
|
||||||
RdbBeDriverInitError
|
|
||||||
RdbBeDriverPutError
|
RdbBeDriverPutError
|
||||||
RdbBeDriverWriteError
|
RdbBeDriverWriteError
|
||||||
RdbBeHostError
|
|
||||||
RdbBeHostNotApplicable
|
|
||||||
|
|
||||||
# Filter management
|
|
||||||
FilBackendRoMode
|
|
||||||
FilSiblingsCommitUnfinshed
|
|
||||||
|
|
||||||
# Functions from `kvt_desc`
|
|
||||||
MustBeOnCentre
|
|
||||||
NotAllowedOnCentre
|
|
||||||
StaleDescriptor
|
|
||||||
|
|
||||||
# End
|
# End
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
# nimbus-eth1
|
|
||||||
# Copyright (c) 2023-2025 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)
|
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
||||||
# http://opensource.org/licenses/MIT)
|
|
||||||
# at your option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
## Kvt DB -- structural data types
|
|
||||||
## ===============================
|
|
||||||
##
|
|
||||||
{.push raises: [].}
|
|
||||||
|
|
||||||
import
|
|
||||||
std/tables
|
|
||||||
|
|
||||||
export tables
|
|
||||||
|
|
||||||
type
|
|
||||||
LayerRef* = ref Layer
|
|
||||||
Layer* = object
|
|
||||||
## Kvt database layer structures. Any layer holds the full
|
|
||||||
## change relative to the backend.
|
|
||||||
sTab*: Table[seq[byte],seq[byte]] ## Structural data table
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Public helpers (misc)
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func init*(T: type LayerRef): T =
|
|
||||||
## Constructor, returns empty layer
|
|
||||||
T()
|
|
||||||
|
|
||||||
func dup*(ly: LayerRef): LayerRef =
|
|
||||||
## Duplicate/copy
|
|
||||||
LayerRef(sTab: ly.sTab)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# End
|
|
||||||
# ------------------------------------------------------------------------------
|
|
@ -1,21 +0,0 @@
|
|||||||
# nimbus-eth1
|
|
||||||
# Copyright (c) 2023 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)
|
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
||||||
# http://opensource.org/licenses/MIT)
|
|
||||||
# at your option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
## Constructors for Key-Value Table DB
|
|
||||||
## ====================================
|
|
||||||
##
|
|
||||||
{.push raises: [].}
|
|
||||||
|
|
||||||
import
|
|
||||||
./kvt_init/memory_only
|
|
||||||
export
|
|
||||||
memory_only
|
|
||||||
|
|
||||||
# End
|
|
@ -1,5 +1,5 @@
|
|||||||
# nimbus-eth1
|
# nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -20,10 +20,8 @@ const
|
|||||||
|
|
||||||
type
|
type
|
||||||
BackendType* = enum
|
BackendType* = enum
|
||||||
BackendVoid = 0 ## For providing backend-less constructor
|
|
||||||
BackendMemory ## Same as Aristo
|
BackendMemory ## Same as Aristo
|
||||||
BackendRocksDB ## Same as Aristo
|
BackendRocksDB ## Same as Aristo
|
||||||
BackendRdbTriggered ## Piggybacked on remote write session
|
|
||||||
|
|
||||||
TypedBackendRef* = ref TypedBackendObj
|
TypedBackendRef* = ref TypedBackendObj
|
||||||
TypedBackendObj* = object of BackendObj
|
TypedBackendObj* = object of BackendObj
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
## backend access
|
## backend access
|
||||||
## ::
|
## ::
|
||||||
## import
|
## import
|
||||||
## kvt/kvt_init,
|
|
||||||
## kvt/kvt_init/kvt_memory
|
## kvt/kvt_init/kvt_memory
|
||||||
##
|
##
|
||||||
## let rc = newKvtDbRef(BackendMemory)
|
## let rc = newKvtDbRef(BackendMemory)
|
||||||
|
@ -18,12 +18,6 @@ import
|
|||||||
../kvt_desc/desc_backend,
|
../kvt_desc/desc_backend,
|
||||||
"."/[init_common, memory_db]
|
"."/[init_common, memory_db]
|
||||||
|
|
||||||
type
|
|
||||||
VoidBackendRef* = ref object of TypedBackendRef
|
|
||||||
## Dummy descriptor type, used as `nil` reference
|
|
||||||
|
|
||||||
MemOnlyBackend* = VoidBackendRef|MemBackendRef
|
|
||||||
|
|
||||||
export
|
export
|
||||||
BackendType,
|
BackendType,
|
||||||
MemBackendRef
|
MemBackendRef
|
||||||
@ -37,10 +31,8 @@ func kind*(
|
|||||||
): BackendType =
|
): BackendType =
|
||||||
## Retrieves the backend type symbol for a `be` backend database argument
|
## Retrieves the backend type symbol for a `be` backend database argument
|
||||||
## where `BackendVoid` is returned for the`nil` backend.
|
## where `BackendVoid` is returned for the`nil` backend.
|
||||||
if be.isNil:
|
doAssert(not be.isNil)
|
||||||
BackendVoid
|
be.TypedBackendRef.beKind
|
||||||
else:
|
|
||||||
be.TypedBackendRef.beKind
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public database constuctors, destructor
|
# Public database constuctors, destructor
|
||||||
@ -48,25 +40,14 @@ func kind*(
|
|||||||
|
|
||||||
proc init*(
|
proc init*(
|
||||||
T: type KvtDbRef; # Target type
|
T: type KvtDbRef; # Target type
|
||||||
B: type MemOnlyBackend; # Backend type
|
B: type MemBackendRef; # Backend type
|
||||||
): T =
|
): T =
|
||||||
## Memory backend constructor.
|
## Memory backend constructor.
|
||||||
##
|
##
|
||||||
let db = when B is VoidBackendRef:
|
let db = KvtDbRef(txRef: KvtTxRef(), backend: memoryBackend())
|
||||||
KvtDbRef(txRef: KvtTxRef(layer: LayerRef.init()))
|
|
||||||
|
|
||||||
elif B is MemBackendRef:
|
|
||||||
KvtDbRef(txRef: KvtTxRef(layer: LayerRef.init()), backend: memoryBackend())
|
|
||||||
db.txRef.db = db
|
db.txRef.db = db
|
||||||
db
|
db
|
||||||
|
|
||||||
proc init*(
|
|
||||||
T: type KvtDbRef; # Target type
|
|
||||||
): T =
|
|
||||||
## Shortcut for `KvtDbRef.init(VoidBackendRef)`
|
|
||||||
KvtDbRef.init VoidBackendRef
|
|
||||||
|
|
||||||
|
|
||||||
proc finish*(db: KvtDbRef; eradicate = false) =
|
proc finish*(db: KvtDbRef; eradicate = false) =
|
||||||
## Backend destructor. The argument `eradicate` indicates that a full
|
## Backend destructor. The argument `eradicate` indicates that a full
|
||||||
## database deletion is requested. If set `false` the outcome might differ
|
## database deletion is requested. If set `false` the outcome might differ
|
||||||
|
@ -43,7 +43,7 @@ proc init*(
|
|||||||
## Generic constructor for `RocksDb` backend
|
## Generic constructor for `RocksDb` backend
|
||||||
##
|
##
|
||||||
let db = KvtDbRef(
|
let db = KvtDbRef(
|
||||||
txRef: KvtTxRef(layer: LayerRef.init()),
|
txRef: KvtTxRef(),
|
||||||
backend: rocksDbKvtBackend(baseDb))
|
backend: rocksDbKvtBackend(baseDb))
|
||||||
db.txRef.db = db
|
db.txRef.db = db
|
||||||
ok db
|
ok db
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
## backend access
|
## backend access
|
||||||
## ::
|
## ::
|
||||||
## import
|
## import
|
||||||
## kvt/kvt_init,
|
|
||||||
## kvt/kvt_init/kvt_rocksdb
|
## kvt/kvt_init/kvt_rocksdb
|
||||||
##
|
##
|
||||||
## let rc = KvtDb.init(BackendRocksDB, "/var/tmp")
|
## let rc = KvtDb.init(BackendRocksDB, "/var/tmp")
|
||||||
|
@ -56,20 +56,20 @@ func layersGet*(db: KvtTxRef; key: openArray[byte]|seq[byte]): Opt[seq[byte]] =
|
|||||||
|
|
||||||
func layersPut*(db: KvtTxRef; key: openArray[byte]; data: openArray[byte]) =
|
func layersPut*(db: KvtTxRef; key: openArray[byte]; data: openArray[byte]) =
|
||||||
## Store a (potentally empty) value on the top layer
|
## Store a (potentally empty) value on the top layer
|
||||||
db.layer.sTab[@key] = @data
|
db.sTab[@key] = @data
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc mergeAndReset*(trg, src: var Layer) =
|
proc mergeAndReset*(trg, src: KvtTxRef) =
|
||||||
mergeAndReset(trg.sTab, src.sTab)
|
mergeAndReset(trg.sTab, src.sTab)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
func layersCc*(db: KvtDbRef; level = high(int)): LayerRef =
|
func layersCc*(db: KvtDbRef; level = high(int)): KvtTxRef =
|
||||||
## Provide a collapsed copy of layers up to a particular transaction level.
|
## Provide a collapsed copy of layers up to a particular transaction level.
|
||||||
## If the `level` argument is too large, the maximum transaction level is
|
## If the `level` argument is too large, the maximum transaction level is
|
||||||
## returned. For the result layer, the `txUid` value set to `0`.
|
## returned. For the result layer, the `txUid` value set to `0`.
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
# nimbus-eth1
|
|
||||||
# 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)
|
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
||||||
# http://opensource.org/licenses/MIT)
|
|
||||||
# at your option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
import
|
|
||||||
kvt_init/persistent as init_persistent,
|
|
||||||
kvt_walk/persistent as walk_persistent
|
|
||||||
export
|
|
||||||
init_persistent,
|
|
||||||
walk_persistent
|
|
||||||
|
|
||||||
# End
|
|
@ -36,7 +36,6 @@ proc txFrameBegin*(db: KvtDbRef, parent: KvtTxRef): KvtTxRef =
|
|||||||
let parent = if parent == nil: db.txRef else: parent
|
let parent = if parent == nil: db.txRef else: parent
|
||||||
KvtTxRef(
|
KvtTxRef(
|
||||||
db: db,
|
db: db,
|
||||||
layer: LayerRef(),
|
|
||||||
parent: parent,
|
parent: parent,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +45,6 @@ proc baseTxFrame*(db: KvtDbRef): KvtTxRef =
|
|||||||
proc dispose*(
|
proc dispose*(
|
||||||
tx: KvtTxRef;
|
tx: KvtTxRef;
|
||||||
) =
|
) =
|
||||||
|
|
||||||
tx[].reset()
|
tx[].reset()
|
||||||
|
|
||||||
proc txFramePersist*(
|
proc txFramePersist*(
|
||||||
@ -65,7 +63,7 @@ proc txFramePersist*(
|
|||||||
for frame in txFrame.stack():
|
for frame in txFrame.stack():
|
||||||
if frame == db.txRef:
|
if frame == db.txRef:
|
||||||
continue
|
continue
|
||||||
mergeAndReset(db.txRef.layer[], frame.layer[])
|
mergeAndReset(db.txRef, frame)
|
||||||
frame.dispose()
|
frame.dispose()
|
||||||
|
|
||||||
# Put the now-merged contents in txFrame and make it the new base
|
# Put the now-merged contents in txFrame and make it the new base
|
||||||
@ -73,14 +71,15 @@ proc txFramePersist*(
|
|||||||
db.txRef = txFrame
|
db.txRef = txFrame
|
||||||
|
|
||||||
# Store structural single trie entries
|
# Store structural single trie entries
|
||||||
for k,v in txFrame.layer.sTab:
|
for k,v in txFrame.sTab:
|
||||||
be.putKvpFn(batch, k, v)
|
be.putKvpFn(batch, k, v)
|
||||||
# TODO above, we only prepare the changes to the database but don't actually
|
# TODO above, we only prepare the changes to the database but don't actually
|
||||||
# write them to disk - the code below that updates the frame should
|
# write them to disk - the code below that updates the frame should
|
||||||
# really run after things have been written (to maintain sync betweeen
|
# really run after things have been written (to maintain sync betweeen
|
||||||
# in-memory and on-disk state)
|
# in-memory and on-disk state)
|
||||||
|
|
||||||
txFrame.layer.sTab.clear()
|
# Done with txRef, all saved to backend
|
||||||
|
txFrame.sTab.clear()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus-eth1
|
# Nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -13,7 +13,7 @@
|
|||||||
##
|
##
|
||||||
import
|
import
|
||||||
../kvt_init/[memory_db, memory_only],
|
../kvt_init/[memory_db, memory_only],
|
||||||
".."/[kvt_desc, kvt_init],
|
".."/kvt_desc,
|
||||||
./walk_private
|
./walk_private
|
||||||
|
|
||||||
export
|
export
|
||||||
@ -24,7 +24,7 @@ export
|
|||||||
# Public iterators (all in one)
|
# Public iterators (all in one)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
iterator walkPairs*[T: MemBackendRef|VoidBackendRef](
|
iterator walkPairs*[T: MemBackendRef](
|
||||||
_: type T;
|
_: type T;
|
||||||
db: KvtDbRef;
|
db: KvtDbRef;
|
||||||
): tuple[key: seq[byte], data: seq[byte]] =
|
): tuple[key: seq[byte], data: seq[byte]] =
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus-eth1
|
# Nimbus-eth1
|
||||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
# Copyright (c) 2023-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
std/sets,
|
std/sets,
|
||||||
".."/[kvt_desc, kvt_init, kvt_layers]
|
".."/[kvt_desc, kvt_layers]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public generic iterators
|
# Public generic iterators
|
||||||
@ -26,12 +26,11 @@ iterator walkPairsImpl*[T](
|
|||||||
if data.isValid:
|
if data.isValid:
|
||||||
yield (key,data)
|
yield (key,data)
|
||||||
|
|
||||||
when T isnot VoidBackendRef:
|
mixin walk
|
||||||
mixin walk
|
|
||||||
|
|
||||||
for (key,data) in db.backend.T.walk:
|
for (key,data) in db.backend.T.walk:
|
||||||
if key notin seen and data.isValid:
|
if key notin seen and data.isValid:
|
||||||
yield (key,data)
|
yield (key,data)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -72,9 +72,6 @@ proc test(path: string, name: string, params = "", lang = "c") =
|
|||||||
task test, "Run tests":
|
task test, "Run tests":
|
||||||
test "tests", "all_tests", "-d:chronicles_log_level=ERROR"
|
test "tests", "all_tests", "-d:chronicles_log_level=ERROR"
|
||||||
|
|
||||||
task test_rocksdb, "Run rocksdb tests":
|
|
||||||
test "tests/db", "test_kvstore_rocksdb", "-d:chronicles_log_level=ERROR"
|
|
||||||
|
|
||||||
task test_import, "Run block import test":
|
task test_import, "Run block import test":
|
||||||
let tmp = getTempDir() / "nimbus-eth1-block-import"
|
let tmp = getTempDir() / "nimbus-eth1-block-import"
|
||||||
if dirExists(tmp):
|
if dirExists(tmp):
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
# Nimbus
|
|
||||||
# Copyright (c) 2023-2025 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)
|
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
||||||
# http://opensource.org/licenses/MIT)
|
|
||||||
# at your option. This file may not be copied, modified, or distributed except
|
|
||||||
# according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
{.used.}
|
|
||||||
|
|
||||||
import
|
|
||||||
std/os,
|
|
||||||
unittest2,
|
|
||||||
eth/db/kvstore,
|
|
||||||
../../execution_chain/db/kvstore_rocksdb,
|
|
||||||
eth/../tests/db/test_kvstore
|
|
||||||
|
|
||||||
suite "KvStore RocksDb Tests":
|
|
||||||
const
|
|
||||||
NS_DEFAULT = "default"
|
|
||||||
NS_OTHER = "other"
|
|
||||||
|
|
||||||
test "RocksStoreRef KvStore interface":
|
|
||||||
let tmp = getTempDir() / "nimbus-test-db"
|
|
||||||
removeDir(tmp)
|
|
||||||
|
|
||||||
let db = RocksStoreRef.init(tmp, "test")[]
|
|
||||||
defer:
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
testKvStore(kvStore db, false, false)
|
|
||||||
|
|
||||||
test "RocksNamespaceRef KvStore interface - default namespace":
|
|
||||||
let tmp = getTempDir() / "nimbus-test-db"
|
|
||||||
removeDir(tmp)
|
|
||||||
|
|
||||||
let db = RocksStoreRef.init(tmp, "test")[]
|
|
||||||
defer:
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
let defaultNs = db.openNamespace(NS_DEFAULT)[]
|
|
||||||
testKvStore(kvStore defaultNs, false, false)
|
|
||||||
|
|
||||||
test "RocksNamespaceRef KvStore interface - multiple namespace":
|
|
||||||
let tmp = getTempDir() / "nimbus-test-db"
|
|
||||||
removeDir(tmp)
|
|
||||||
|
|
||||||
let db = RocksStoreRef.init(tmp, "test",
|
|
||||||
namespaces = @[NS_DEFAULT, NS_OTHER])[]
|
|
||||||
defer:
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
let defaultNs = db.openNamespace(NS_DEFAULT)[]
|
|
||||||
testKvStore(kvStore defaultNs, false, false)
|
|
||||||
|
|
||||||
let otherNs = db.openNamespace(NS_OTHER)[]
|
|
||||||
testKvStore(kvStore otherNs, false, false)
|
|
@ -20,15 +20,13 @@ import
|
|||||||
aristo_delete,
|
aristo_delete,
|
||||||
aristo_merge,
|
aristo_merge,
|
||||||
aristo_desc,
|
aristo_desc,
|
||||||
aristo_init,
|
aristo_init/memory_only,
|
||||||
aristo_persist,
|
aristo_persist,
|
||||||
aristo_tx_frame,
|
aristo_tx_frame,
|
||||||
]
|
]
|
||||||
|
|
||||||
func x(s: string): seq[byte] =
|
func x(s: string): seq[byte] =
|
||||||
s.hexToSeqByte
|
s.hexToSeqByte
|
||||||
func k(s: string): HashKey =
|
|
||||||
HashKey.fromBytes(s.x).value
|
|
||||||
|
|
||||||
let samples = [
|
let samples = [
|
||||||
# Somew on-the-fly provided stuff
|
# Somew on-the-fly provided stuff
|
||||||
@ -79,7 +77,7 @@ suite "Aristo compute":
|
|||||||
for n, sample in samples:
|
for n, sample in samples:
|
||||||
test "Add and delete entries " & $n:
|
test "Add and delete entries " & $n:
|
||||||
let
|
let
|
||||||
db = AristoDbRef.init VoidBackendRef
|
db = AristoDbRef.init MemBackendRef
|
||||||
txFrame = db.txRef
|
txFrame = db.txRef
|
||||||
root = VertexID(1)
|
root = VertexID(1)
|
||||||
|
|
||||||
|
@ -160,7 +160,6 @@ proc initRunnerDB(
|
|||||||
case dbType:
|
case dbType:
|
||||||
of AristoDbMemory: AristoDbMemory.newCoreDbRef()
|
of AristoDbMemory: AristoDbMemory.newCoreDbRef()
|
||||||
of AristoDbRocks: AristoDbRocks.newCoreDbRef(path, DbOptions.init())
|
of AristoDbRocks: AristoDbRocks.newCoreDbRef(path, DbOptions.init())
|
||||||
of AristoDbVoid: AristoDbVoid.newCoreDbRef()
|
|
||||||
else: raiseAssert $dbType
|
else: raiseAssert $dbType
|
||||||
|
|
||||||
when false: # or true:
|
when false: # or true:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user