2023-11-16 20:53:44 +00:00
|
|
|
# Nimbus
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-11-16 20:53:44 +00:00
|
|
|
# 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
|
|
|
|
eth/common,
|
|
|
|
results,
|
2024-03-07 19:24:05 +00:00
|
|
|
"../.."/[aristo, aristo/aristo_walk],
|
|
|
|
"../.."/[kvt, kvt/kvt_init/memory_only, kvt/kvt_walk],
|
2023-11-16 20:53:44 +00:00
|
|
|
".."/[base, base/base_desc],
|
|
|
|
./aristo_db/[common_desc, handlers_aristo, handlers_kvt]
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
import
|
|
|
|
../../aristo/aristo_init/memory_only as aristo_memory_only
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
# Caveat:
|
|
|
|
# additional direct include(s) -- not import(s) -- is placed near
|
|
|
|
# the end of this source file
|
2024-02-02 10:58:35 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
# Annotation helper(s)
|
2023-11-16 20:53:44 +00:00
|
|
|
{.pragma: noRaise, gcsafe, raises: [].}
|
|
|
|
{.pragma: rlpRaise, gcsafe, raises: [AristoApiRlpError].}
|
|
|
|
|
|
|
|
export
|
|
|
|
AristoApiRlpError,
|
2024-02-02 20:23:04 +00:00
|
|
|
AristoCoreDbKvtBE
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
AristoCoreDbRef* = ref object of CoreDbRef
|
|
|
|
## Main descriptor
|
|
|
|
kdbBase: KvtBaseRef ## Kvt subsystem
|
|
|
|
adbBase: AristoBaseRef ## Aristo subsystem
|
|
|
|
|
|
|
|
AristoCoreDbBE = ref object of CoreDbBackendRef
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc newAristoVoidCoreDbRef*(): CoreDbRef {.noRaise.}
|
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func notImplemented[T](
|
|
|
|
_: typedesc[T];
|
|
|
|
db: AristoCoreDbRef;
|
|
|
|
info: string;
|
|
|
|
): CoreDbRc[T] {.gcsafe.} =
|
|
|
|
## Applies only to `Aristo` methods
|
2024-03-14 22:17:43 +00:00
|
|
|
err((VertexID(0),aristo.NotImplemented).toError(db.adbBase, info))
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private tx and base methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc txMethods(
|
|
|
|
db: AristoCoreDbRef;
|
|
|
|
aTx: AristoTxRef;
|
|
|
|
kTx: KvtTxRef;
|
|
|
|
): CoreDbTxFns =
|
|
|
|
## To be constructed by some `CoreDbBaseFns` function
|
|
|
|
CoreDbTxFns(
|
2023-11-24 22:16:21 +00:00
|
|
|
levelFn: proc(): int =
|
|
|
|
aTx.level,
|
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
commitFn: proc(ignore: bool): CoreDbRc[void] =
|
|
|
|
const info = "commitFn()"
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.adbBase.api.commit(aTx).toVoidRc(db.adbBase, info)
|
|
|
|
? db.kdbBase.api.commit(kTx).toVoidRc(db.kdbBase, info)
|
2023-11-16 20:53:44 +00:00
|
|
|
ok(),
|
|
|
|
|
|
|
|
rollbackFn: proc(): CoreDbRc[void] =
|
|
|
|
const info = "rollbackFn()"
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.adbBase.api.rollback(aTx).toVoidRc(db.adbBase, info)
|
|
|
|
? db.kdbBase.api.rollback(kTx).toVoidRc(db.kdbBase, info)
|
2023-11-16 20:53:44 +00:00
|
|
|
ok(),
|
|
|
|
|
|
|
|
disposeFn: proc(): CoreDbRc[void] =
|
|
|
|
const info = "disposeFn()"
|
2024-03-07 19:24:05 +00:00
|
|
|
if db.adbBase.api.isTop(aTx):
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.adbBase.api.rollback(aTx).toVoidRc(db.adbBase, info)
|
2024-03-07 19:24:05 +00:00
|
|
|
if db.kdbBase.api.isTop(kTx):
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.kdbBase.api.rollback(kTx).toVoidRc(db.kdbBase, info)
|
2023-11-16 20:53:44 +00:00
|
|
|
ok(),
|
|
|
|
|
|
|
|
safeDisposeFn: proc(): CoreDbRc[void] =
|
|
|
|
const info = "safeDisposeFn()"
|
2024-03-07 19:24:05 +00:00
|
|
|
if db.adbBase.api.isTop(aTx):
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.adbBase.api.rollback(aTx).toVoidRc(db.adbBase, info)
|
2024-03-07 19:24:05 +00:00
|
|
|
if db.kdbBase.api.isTop(kTx):
|
2024-03-14 22:17:43 +00:00
|
|
|
? db.kdbBase.api.rollback(kTx).toVoidRc(db.kdbBase, info)
|
2023-11-16 20:53:44 +00:00
|
|
|
ok())
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
proc baseMethods(
|
|
|
|
db: AristoCoreDbRef;
|
|
|
|
A: typedesc;
|
|
|
|
K: typedesc;
|
|
|
|
): CoreDbBaseFns =
|
|
|
|
CoreDbBaseFns(
|
2024-02-02 20:23:04 +00:00
|
|
|
verifyFn: proc(trie: CoreDbTrieRef): bool =
|
|
|
|
db.adbBase.verify(trie),
|
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
backendFn: proc(): CoreDbBackendRef =
|
|
|
|
db.bless(AristoCoreDbBE()),
|
|
|
|
|
|
|
|
destroyFn: proc(flush: bool) =
|
|
|
|
db.adbBase.destroy(flush)
|
|
|
|
db.kdbBase.destroy(flush),
|
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
levelFn: proc(): int =
|
|
|
|
db.adbBase.getLevel,
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
tryHashFn: proc(trie: CoreDbTrieRef): CoreDbRc[Hash256] =
|
|
|
|
db.adbBase.tryHash(trie, "tryHashFn()"),
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
rootHashFn: proc(trie: CoreDbTrieRef): CoreDbRc[Hash256] =
|
|
|
|
db.adbBase.rootHash(trie, "rootHashFn()"),
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
triePrintFn: proc(vid: CoreDbTrieRef): string =
|
|
|
|
db.adbBase.triePrint(vid),
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
errorPrintFn: proc(e: CoreDbErrorRef): string =
|
|
|
|
e.errorPrint(),
|
|
|
|
|
|
|
|
legacySetupFn: proc() =
|
|
|
|
discard,
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
getTrieFn: proc(
|
|
|
|
kind: CoreDbSubTrie;
|
|
|
|
root: Hash256;
|
|
|
|
address: Option[EthAddress];
|
|
|
|
): CoreDbRc[CoreDbTrieRef] =
|
2024-03-14 22:17:43 +00:00
|
|
|
db.adbBase.newTrie(kind, root, address, "getTrieFn()"),
|
2023-11-16 20:53:44 +00:00
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
newKvtFn: proc(sharedTable: bool): CoreDbRc[CoreDxKvtRef] =
|
|
|
|
db.kdbBase.newKvtHandler(sharedTable, "newKvtFn()"),
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
newMptFn: proc(
|
2024-02-02 20:23:04 +00:00
|
|
|
trie: CoreDbTrieRef;
|
2023-11-24 22:16:21 +00:00
|
|
|
prune: bool; # ignored
|
2023-11-16 20:53:44 +00:00
|
|
|
): CoreDbRc[CoreDxMptRef] =
|
2024-03-14 22:17:43 +00:00
|
|
|
db.adbBase.newMptHandler(trie, "newMptFn()"),
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
newAccFn: proc(
|
2024-02-02 20:23:04 +00:00
|
|
|
trie: CoreDbTrieRef;
|
2023-11-24 22:16:21 +00:00
|
|
|
prune: bool; # ignored
|
2023-11-16 20:53:44 +00:00
|
|
|
): CoreDbRc[CoreDxAccRef] =
|
2024-03-14 22:17:43 +00:00
|
|
|
ok(? db.adbBase.newAccHandler(trie, "newAccFn()")),
|
2023-11-16 20:53:44 +00:00
|
|
|
|
|
|
|
beginFn: proc(): CoreDbRc[CoreDxTxRef] =
|
|
|
|
const info = "beginFn()"
|
|
|
|
let
|
|
|
|
aTx = ? db.adbBase.txBegin(info)
|
|
|
|
kTx = ? db.kdbBase.txBegin(info)
|
|
|
|
ok(db.bless CoreDxTxRef(methods: db.txMethods(aTx, kTx))),
|
|
|
|
|
|
|
|
getIdFn: proc(): CoreDbRc[CoreDxTxID] =
|
|
|
|
CoreDxTxID.notImplemented(db, "getIdFn()"),
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
newCaptureFn: proc(flags: set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] =
|
2023-11-16 20:53:44 +00:00
|
|
|
CoreDxCaptRef.notImplemented(db, "capture()"))
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private constructor helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc create(
|
|
|
|
dbType: CoreDbType;
|
|
|
|
kdb: KvtDbRef;
|
|
|
|
K: typedesc;
|
|
|
|
adb: AristoDbRef;
|
|
|
|
A: typedesc;
|
|
|
|
): CoreDbRef =
|
|
|
|
## Constructor helper
|
|
|
|
|
|
|
|
# Local extensions
|
|
|
|
var db = AristoCoreDbRef()
|
|
|
|
db.adbBase = AristoBaseRef.init(db, adb)
|
|
|
|
db.kdbBase = KvtBaseRef.init(db, kdb)
|
|
|
|
|
|
|
|
# Base descriptor
|
|
|
|
db.dbType = dbType
|
|
|
|
db.methods = db.baseMethods(A,K)
|
|
|
|
db.bless
|
|
|
|
|
|
|
|
proc init(
|
|
|
|
dbType: CoreDbType;
|
|
|
|
K: typedesc;
|
|
|
|
A: typedesc;
|
|
|
|
qlr: QidLayoutRef;
|
|
|
|
): CoreDbRef =
|
|
|
|
dbType.create(KvtDbRef.init(K), K, AristoDbRef.init(A, qlr), A)
|
|
|
|
|
|
|
|
proc init(
|
|
|
|
dbType: CoreDbType;
|
|
|
|
K: typedesc;
|
|
|
|
A: typedesc;
|
|
|
|
): CoreDbRef =
|
|
|
|
dbType.create(KvtDbRef.init(K), K, AristoDbRef.init(A), A)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc init*(
|
|
|
|
dbType: CoreDbType;
|
|
|
|
K: typedesc;
|
|
|
|
A: typedesc;
|
|
|
|
path: string;
|
|
|
|
qlr: QidLayoutRef;
|
|
|
|
): CoreDbRef =
|
|
|
|
dbType.create(
|
|
|
|
KvtDbRef.init(K, path).expect "Kvt/RocksDB init() failed", K,
|
|
|
|
AristoDbRef.init(A, path, qlr).expect "Aristo/RocksDB init() failed", A)
|
|
|
|
|
|
|
|
proc init*(
|
|
|
|
dbType: CoreDbType;
|
|
|
|
K: typedesc;
|
|
|
|
A: typedesc;
|
|
|
|
path: string;
|
|
|
|
): CoreDbRef =
|
|
|
|
dbType.create(
|
|
|
|
KvtDbRef.init(K, path).expect "Kvt/RocksDB init() failed", K,
|
|
|
|
AristoDbRef.init(A, path).expect "Aristo/RocksDB init() failed", A)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc newAristoMemoryCoreDbRef*(qlr: QidLayoutRef): CoreDbRef =
|
|
|
|
AristoDbMemory.init(kvt.MemBackendRef, aristo.MemBackendRef, qlr)
|
|
|
|
|
|
|
|
proc newAristoMemoryCoreDbRef*(): CoreDbRef =
|
|
|
|
AristoDbMemory.init(kvt.MemBackendRef, aristo.MemBackendRef)
|
|
|
|
|
|
|
|
proc newAristoVoidCoreDbRef*(): CoreDbRef =
|
|
|
|
AristoDbVoid.init(kvt.VoidBackendRef, aristo.VoidBackendRef)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2024-03-07 19:24:05 +00:00
|
|
|
# Public helpers, e.g. for direct backend access
|
2023-11-16 20:53:44 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-02-29 21:10:24 +00:00
|
|
|
func toAristoProfData*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
): tuple[aristo: AristoDbProfListRef, kvt: KvtDbProfListRef] =
|
|
|
|
when CoreDbEnableApiProfiling:
|
|
|
|
if db.isAristo:
|
|
|
|
result.aristo = db.AristoCoreDbRef.adbBase.api.AristoApiProfRef.data
|
|
|
|
result.kvt = db.AristoCoreDbRef.kdbBase.api.KvtApiProfRef.data
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
func toAristoApi*(dsc: CoreDxKvtRef): KvtApiRef =
|
|
|
|
doAssert not dsc.parent.isNil
|
|
|
|
doAssert dsc.parent.isAristo
|
|
|
|
if dsc.parent.isAristo:
|
|
|
|
return AristoCoreDbRef(dsc.parent).kdbBase.api
|
|
|
|
|
|
|
|
func toAristoApi*(dsc: CoreDxMptRef): AristoApiRef =
|
|
|
|
doAssert not dsc.parent.isNil
|
|
|
|
doAssert dsc.parent.isAristo
|
|
|
|
if dsc.parent.isAristo:
|
|
|
|
return AristoCoreDbRef(dsc.parent).adbBase.api
|
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
func toAristo*(be: CoreDbKvtBackendRef): KvtDbRef =
|
|
|
|
if be.parent.isAristo:
|
|
|
|
return be.AristoCoreDbKvtBE.kdb
|
|
|
|
|
|
|
|
func toAristo*(be: CoreDbMptBackendRef): AristoDbRef =
|
|
|
|
if be.parent.isAristo:
|
|
|
|
return be.AristoCoreDbMptBE.adb
|
|
|
|
|
|
|
|
func toAristo*(be: CoreDbAccBackendRef): AristoDbRef =
|
|
|
|
if be.parent.isAristo:
|
|
|
|
return be.AristoCoreDbAccBE.adb
|
|
|
|
|
2024-02-02 10:58:35 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public aristo iterators
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
include
|
|
|
|
./aristo_db/aristo_replicate
|
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
|
|
|
|
iterator aristoKvtPairsVoid*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
|
|
|
let
|
|
|
|
api = dsc.toAristoApi()
|
|
|
|
p = api.forkTop(dsc.to(KvtDbRef)).valueOrApiError "aristoKvtPairs()"
|
|
|
|
defer: discard api.forget(p)
|
|
|
|
for (k,v) in kvt.VoidBackendRef.walkPairs p:
|
|
|
|
yield (k,v)
|
|
|
|
|
|
|
|
iterator aristoKvtPairsMem*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
|
|
|
let
|
|
|
|
api = dsc.toAristoApi()
|
|
|
|
p = api.forkTop(dsc.to(KvtDbRef)).valueOrApiError "aristoKvtPairs()"
|
|
|
|
defer: discard api.forget(p)
|
2024-02-02 10:58:35 +00:00
|
|
|
for (k,v) in kvt.MemBackendRef.walkPairs p:
|
|
|
|
yield (k,v)
|
|
|
|
|
2024-02-16 09:08:07 +00:00
|
|
|
iterator aristoMptPairs*(dsc: CoreDxMptRef): (Blob,Blob) {.noRaise.} =
|
2024-03-07 19:24:05 +00:00
|
|
|
let
|
|
|
|
api = dsc.toAristoApi()
|
|
|
|
mpt = dsc.to(AristoDbRef)
|
2024-02-29 21:10:24 +00:00
|
|
|
for (k,v) in mpt.rightPairs LeafTie(root: dsc.rootID):
|
2024-03-07 19:24:05 +00:00
|
|
|
yield (api.pathAsBlob(k.path), api.serialise(mpt, v).valueOr(EmptyBlob))
|
2024-02-02 10:58:35 +00:00
|
|
|
|
|
|
|
iterator aristoReplicateMem*(dsc: CoreDxMptRef): (Blob,Blob) {.rlpRaise.} =
|
|
|
|
## Instantiation for `MemBackendRef`
|
|
|
|
for k,v in aristoReplicate[aristo.MemBackendRef](dsc):
|
|
|
|
yield (k,v)
|
|
|
|
|
|
|
|
iterator aristoReplicateVoid*(dsc: CoreDxMptRef): (Blob,Blob) {.rlpRaise.} =
|
|
|
|
## Instantiation for `VoidBackendRef`
|
|
|
|
for k,v in aristoReplicate[aristo.VoidBackendRef](dsc):
|
|
|
|
yield (k,v)
|
|
|
|
|
2023-11-16 20:53:44 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|