mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-24 03:00:25 +00:00
6bc55d4e6f
* Kvt: Implemented multi-descriptor access on the same backend why: This behaviour mirrors the one of Aristo and can be used for simultaneous transactions on Aristo + Kvt * Kvt: Update database iterators why: Forgot to run on the top layer first * Kvt: Misc fixes * Aristo, use `openArray[byte]` rather than `Blob` in prototype * Aristo, by default hashify right after cloning descriptor why: Typically, a completed descriptor is expected after cloning. Hashing can be suppressed by argument flag. * Aristo provides `replicate()` iterator, similar to legacy `replicate()` * Aristo API fixes and updates * CoreDB: Rename `legacy_persistent` => `legacy_rocksdb` why: More systematic, will be in line with Aristo DB which might have more than one persistent backends * CoreDB: Prettify API sources why: Better to read and maintain details: Annotating with custom pragmas which cleans up the prototypes * CoreDB: Update MPT/put() prototype allowing `CatchableError` why: Will be needed for Aristo API (legacy is OK with `RlpError`)
87 lines
2.6 KiB
Nim
87 lines
2.6 KiB
Nim
# nimbus-eth1
|
|
# Copyright (c) 2021 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.
|
|
|
|
## Non persistent constructors for Kvt DB
|
|
## ======================================
|
|
##
|
|
{.push raises: [].}
|
|
|
|
import
|
|
../kvt_desc,
|
|
../kvt_desc/desc_backend,
|
|
"."/[init_common, memory_db]
|
|
|
|
type
|
|
VoidBackendRef* = ref object of TypedBackendRef
|
|
## Dummy descriptor type, used as `nil` reference
|
|
|
|
MemOnlyBackend* = VoidBackendRef|MemBackendRef
|
|
|
|
export
|
|
BackendType,
|
|
MemBackendRef
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public helpers
|
|
# -----------------------------------------------------------------------------
|
|
|
|
proc kind*(
|
|
be: BackendRef;
|
|
): BackendType =
|
|
## Retrieves the backend type symbol for a `be` backend database argument
|
|
## where `BackendVoid` is returned for the`nil` backend.
|
|
if be.isNil:
|
|
BackendVoid
|
|
else:
|
|
be.TypedBackendRef.beKind
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public database constuctors, destructor
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc init*(
|
|
T: type KvtDbRef; # Target type
|
|
B: type MemOnlyBackend; # Backend type
|
|
): T =
|
|
## Memory backend constructor.
|
|
##
|
|
when B is VoidBackendRef:
|
|
KvtDbRef(top: LayerRef())
|
|
|
|
elif B is MemBackendRef:
|
|
KvtDbRef(top: LayerRef(), backend: memoryBackend())
|
|
|
|
proc init*(
|
|
T: type KvtDbRef; # Target type
|
|
): T =
|
|
## Shortcut for `KvtDbRef.init(VoidBackendRef)`
|
|
KvtDbRef.init VoidBackendRef
|
|
|
|
|
|
proc finish*(db: KvtDbRef; flush = false) =
|
|
## Backend destructor. The argument `flush` indicates that a full database
|
|
## deletion is requested. If set `false` the outcome might differ depending
|
|
## on the type of backend (e.g. the `BackendMemory` backend will always
|
|
## flush on close.)
|
|
##
|
|
## This distructor may be used on already *destructed* descriptors.
|
|
##
|
|
if not db.isNil:
|
|
if not db.backend.isNil:
|
|
db.backend.closeFn flush
|
|
|
|
let lebo = db.getCentre
|
|
discard lebo.forgetOthers()
|
|
lebo[] = KvtDbObj()
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|