2023-07-31 14:43:38 +01: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-07-31 14:43:38 +01: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
|
2023-10-25 15:03:09 +01:00
|
|
|
std/typetraits,
|
2023-07-31 14:43:38 +01:00
|
|
|
chronicles,
|
2023-08-02 21:46:41 +01:00
|
|
|
eth/common,
|
2023-09-26 10:21:13 +01:00
|
|
|
results,
|
|
|
|
"../.."/[constants, errors],
|
2023-12-12 17:47:41 +00:00
|
|
|
./base/[api_new_desc, api_tracking, base_desc]
|
|
|
|
|
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
|
|
|
from ../aristo
|
|
|
|
import EmptyBlob, isValid
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
const
|
|
|
|
ProvideLegacyAPI = true
|
|
|
|
## Enable legacy API. For now everybody would want this enabled.
|
|
|
|
|
|
|
|
EnableApiTracking = false
|
|
|
|
## When enabled, functions using this tracking facility need to import
|
|
|
|
## `chronicles`, as well. Tracking is enabled by setting `true` the flags
|
|
|
|
## `trackLegaApi` and/or `trackNewApi` in the `CoreDxTxRef` descriptor.
|
|
|
|
|
|
|
|
EnableApiProfiling = true
|
|
|
|
## Enables functions profiling if `EnableApiTracking` is also set `true`.
|
|
|
|
|
|
|
|
AutoValidateDescriptors = defined(release).not
|
|
|
|
## No validatinon needed for production suite.
|
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
export
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
CoreDbAccBackendRef,
|
2023-10-11 20:09:11 +01:00
|
|
|
CoreDbAccount,
|
|
|
|
CoreDbApiError,
|
2023-09-26 10:21:13 +01:00
|
|
|
CoreDbBackendRef,
|
|
|
|
CoreDbCaptFlags,
|
2023-10-11 20:09:11 +01:00
|
|
|
CoreDbErrorCode,
|
2023-10-02 19:05:17 +01:00
|
|
|
CoreDbErrorRef,
|
2023-12-12 17:47:41 +00:00
|
|
|
CoreDbFnInx,
|
2023-09-26 10:21:13 +01:00
|
|
|
CoreDbKvtBackendRef,
|
|
|
|
CoreDbMptBackendRef,
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
CoreDbPersistentTypes,
|
2023-09-26 10:21:13 +01:00
|
|
|
CoreDbRef,
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
CoreDbSaveFlags,
|
2023-09-26 10:21:13 +01:00
|
|
|
CoreDbType,
|
2023-10-11 20:09:11 +01:00
|
|
|
CoreDbVidRef,
|
|
|
|
CoreDxAccRef,
|
2023-09-26 10:21:13 +01:00
|
|
|
CoreDxCaptRef,
|
|
|
|
CoreDxKvtRef,
|
|
|
|
CoreDxMptRef,
|
|
|
|
CoreDxPhkRef,
|
2023-12-12 17:47:41 +00:00
|
|
|
CoreDxTxRef,
|
|
|
|
|
|
|
|
# Profiling support
|
|
|
|
byElapsed,
|
|
|
|
byMean,
|
|
|
|
byVisits,
|
|
|
|
stats
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
const
|
2023-12-12 17:47:41 +00:00
|
|
|
CoreDbProvideLegacyAPI* = ProvideLegacyAPI
|
|
|
|
CoreDbEnableApiTracking* = EnableApiTracking
|
|
|
|
CoreDbEnableApiProfiling* = EnableApiTracking and EnableApiProfiling
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when ProvideLegacyAPI:
|
2023-11-24 22:16:21 +00:00
|
|
|
import
|
2023-12-12 17:47:41 +00:00
|
|
|
./base/api_legacy_desc
|
2023-11-24 22:16:21 +00:00
|
|
|
export
|
|
|
|
api_legacy_desc
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when AutoValidateDescriptors:
|
|
|
|
import ./base/validate
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when EnableApiTracking and EnableApiProfiling:
|
|
|
|
var coreDbProfTab*: CoreDbProfFnInx
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
# More settings
|
|
|
|
const
|
2023-11-24 22:16:21 +00:00
|
|
|
logTxt = "CoreDb "
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
legaApiTxt = logTxt & "legacy API"
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
newApiTxt = logTxt & "new API"
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
# Annotation helpers
|
|
|
|
{.pragma: apiRaise, gcsafe, raises: [CoreDbApiError].}
|
|
|
|
{.pragma: catchRaise, gcsafe, raises: [CatchableError].}
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-25 15:03:09 +01:00
|
|
|
# Private helpers
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-08-02 21:46:41 +01:00
|
|
|
template itNotImplemented(db: CoreDbRef, name: string) =
|
2023-11-24 22:16:21 +00:00
|
|
|
warn logTxt & "iterator not implemented", dbType=db.dbType, meth=name
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
# ---------
|
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
when EnableApiTracking:
|
2023-12-12 17:47:41 +00:00
|
|
|
when EnableApiProfiling:
|
|
|
|
{.warning: "*** Provided API profiling for CoreDB (disabled by default)".}
|
|
|
|
else:
|
|
|
|
{.warning: "*** Provided API logging for CoreDB (disabled by default)".}
|
2023-10-25 15:03:09 +01:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
import
|
2023-12-12 17:47:41 +00:00
|
|
|
std/[sequtils, times]
|
2023-10-25 15:03:09 +01:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
proc `$`[T](rc: CoreDbRc[T]): string = rc.toStr
|
|
|
|
proc `$`(q: set[CoreDbCaptFlags]): string = q.toStr
|
|
|
|
proc `$`(t: Duration): string = t.toStr
|
|
|
|
proc `$`(e: EthAddress): string = e.toStr
|
|
|
|
proc `$`(v: CoreDbVidRef): string = v.toStr
|
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
|
|
|
proc `$`(h: Hash256): string = h.toStr
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
when ProvideLegacyAPI:
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
proc `$`(k: CoreDbKvtRef): string = k.toStr
|
|
|
|
|
|
|
|
template setTrackLegaApi(
|
|
|
|
w: CoreDbApiTrackRef;
|
2023-12-12 17:47:41 +00:00
|
|
|
s: static[CoreDbFnInx];
|
|
|
|
code: untyped;
|
2023-11-24 22:16:21 +00:00
|
|
|
) =
|
2023-12-12 17:47:41 +00:00
|
|
|
## Template with code section that will be discarded if logging is
|
|
|
|
## disabled at compile time when `EnableApiTracking` is `false`.
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
w.beginLegaApi()
|
2023-12-12 17:47:41 +00:00
|
|
|
code
|
|
|
|
const ctx {.inject,used.} = s
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
template setTrackLegaApi(
|
|
|
|
w: CoreDbApiTrackRef;
|
2023-12-12 17:47:41 +00:00
|
|
|
s: static[CoreDbFnInx];
|
2023-11-24 22:16:21 +00:00
|
|
|
) =
|
2023-12-12 17:47:41 +00:00
|
|
|
w.setTrackLegaApi(s):
|
|
|
|
discard
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
template ifTrackLegaApi(w: CoreDbApiTrackRef; code: untyped) =
|
|
|
|
when EnableApiTracking:
|
|
|
|
w.endLegaApiIf:
|
2023-12-12 17:47:41 +00:00
|
|
|
when EnableApiProfiling:
|
|
|
|
coreDbProfTab.update(ctx, elapsed)
|
2023-11-24 22:16:21 +00:00
|
|
|
code
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
template setTrackNewApi(
|
|
|
|
w: CoreDxApiTrackRef;
|
2023-12-12 17:47:41 +00:00
|
|
|
s: static[CoreDbFnInx];
|
|
|
|
code: untyped;
|
2023-11-24 22:16:21 +00:00
|
|
|
) =
|
2023-12-12 17:47:41 +00:00
|
|
|
## Template with code section that will be discarded if logging is
|
|
|
|
## disabled at compile time when `EnableApiTracking` is `false`.
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
w.beginNewApi()
|
2023-12-12 17:47:41 +00:00
|
|
|
code
|
|
|
|
const ctx {.inject,used.} = s
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
template setTrackNewApi(
|
|
|
|
w: CoreDxApiTrackRef;
|
2023-12-12 17:47:41 +00:00
|
|
|
s: static[CoreDbFnInx];
|
2023-11-24 22:16:21 +00:00
|
|
|
) =
|
2023-12-12 17:47:41 +00:00
|
|
|
w.setTrackNewApi(s):
|
|
|
|
discard
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
template ifTrackNewApi(w: CoreDxApiTrackRef; code: untyped) =
|
|
|
|
when EnableApiTracking:
|
|
|
|
w.endNewApiIf:
|
2023-12-12 17:47:41 +00:00
|
|
|
when EnableApiProfiling:
|
|
|
|
coreDbProfTab.update(ctx, elapsed)
|
2023-11-24 22:16:21 +00:00
|
|
|
code
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
# ---------
|
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
func toCoreDxPhkRef(mpt: CoreDxMptRef): CoreDxPhkRef =
|
2023-08-02 21:46:41 +01:00
|
|
|
## MPT => pre-hashed MPT (aka PHK)
|
2023-09-26 10:21:13 +01:00
|
|
|
result = CoreDxPhkRef(
|
|
|
|
fromMpt: mpt,
|
|
|
|
methods: mpt.methods)
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
result.methods.fetchFn =
|
2023-09-26 10:21:13 +01:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[Blob] =
|
2023-10-11 20:09:11 +01:00
|
|
|
mpt.methods.fetchFn(k.keccakHash.data)
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
result.methods.deleteFn =
|
2023-09-26 10:21:13 +01:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[void] =
|
2023-10-11 20:09:11 +01:00
|
|
|
mpt.methods.deleteFn(k.keccakHash.data)
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
result.methods.mergeFn =
|
|
|
|
proc(k:openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
|
|
|
|
mpt.methods.mergeFn(k.keccakHash.data, v)
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
result.methods.hasPathFn =
|
2023-09-26 10:21:13 +01:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[bool] =
|
2023-11-08 12:18:32 +00:00
|
|
|
mpt.methods.hasPathFn(k.keccakHash.data)
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
result.methods.pairsIt =
|
2023-11-24 22:16:21 +00:00
|
|
|
iterator(): (Blob, Blob) =
|
2023-10-25 15:03:09 +01:00
|
|
|
mpt.parent.itNotImplemented("phk/pairs()")
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
result.methods.replicateIt =
|
2023-11-24 22:16:21 +00:00
|
|
|
iterator(): (Blob, Blob) =
|
2023-10-25 15:03:09 +01:00
|
|
|
mpt.parent.itNotImplemented("phk/replicate()")
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
when AutoValidateDescriptors:
|
2023-09-26 10:21:13 +01:00
|
|
|
result.validate
|
2023-07-31 14:43:38 +01:00
|
|
|
|
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
func parent(phk: CoreDxPhkRef): CoreDbRef =
|
|
|
|
phk.fromMpt.parent
|
2023-07-31 14:43:38 +01:00
|
|
|
|
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
|
|
|
proc prettyText(e: CoreDbErrorRef): string =
|
|
|
|
$e.error & "(" & e.parent.methods.errorPrintFn(e) & ")"
|
|
|
|
|
|
|
|
proc prettyText(vid: CoreDbVidRef): string =
|
|
|
|
if vid.isNil or not vid.ready: "$ø" else: vid.parent.methods.vidPrintFn(vid)
|
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 20:09:11 +01:00
|
|
|
# Public constructor helper
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc bless*(db: CoreDbRef): CoreDbRef =
|
|
|
|
## Verify descriptor
|
|
|
|
when AutoValidateDescriptors:
|
|
|
|
db.validate
|
|
|
|
db
|
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc bless*(db: CoreDbRef; child: CoreDbVidRef): CoreDbVidRef =
|
|
|
|
## Complete sub-module descriptor, fill in `parent` and actvate it.
|
2023-09-26 10:21:13 +01:00
|
|
|
child.parent = db
|
2023-10-11 20:09:11 +01:00
|
|
|
child.ready = true
|
2023-09-26 10:21:13 +01:00
|
|
|
when AutoValidateDescriptors:
|
|
|
|
child.validate
|
|
|
|
child
|
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc bless*(db: CoreDbRef; child: CoreDxKvtRef): CoreDxKvtRef =
|
|
|
|
## Complete sub-module descriptor, fill in `parent` and de-actvate
|
|
|
|
## iterator for persistent database.
|
|
|
|
child.parent = db
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
# Disable interator for non-memory instances
|
2023-10-11 20:09:11 +01:00
|
|
|
if db.dbType in CoreDbPersistentTypes:
|
|
|
|
child.methods.pairsIt = iterator(): (Blob, Blob) =
|
2023-09-26 10:21:13 +01:00
|
|
|
db.itNotImplemented "pairs/kvt"
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
when AutoValidateDescriptors:
|
2023-10-11 20:09:11 +01:00
|
|
|
child.validate
|
|
|
|
child
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
proc bless*[T: CoreDxTrieRelated | CoreDbBackends](
|
2023-10-11 20:09:11 +01:00
|
|
|
db: CoreDbRef;
|
|
|
|
child: T;
|
|
|
|
): auto =
|
|
|
|
## Complete sub-module descriptor, fill in `parent`.
|
|
|
|
child.parent = db
|
2023-08-02 21:46:41 +01:00
|
|
|
when AutoValidateDescriptors:
|
2023-10-11 20:09:11 +01:00
|
|
|
child.validate
|
|
|
|
child
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
|
|
|
|
proc bless*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
error: CoreDbErrorCode;
|
|
|
|
child: CoreDbErrorRef;
|
|
|
|
): CoreDbErrorRef =
|
|
|
|
child.parent = db
|
|
|
|
child.error = error
|
|
|
|
when AutoValidateDescriptors:
|
|
|
|
child.validate
|
|
|
|
child
|
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 21:46:41 +01:00
|
|
|
# Public main descriptor methods
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-08-02 21:46:41 +01:00
|
|
|
proc dbType*(db: CoreDbRef): CoreDbType =
|
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
|
|
|
## Getter, print DB type identifier
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseDbTypeFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = db.dbType
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
proc compensateLegacySetup*(db: CoreDbRef) =
|
2023-10-11 20:09:11 +01:00
|
|
|
## On the persistent legacy hexary trie, this function is needed for
|
|
|
|
## bootstrapping and Genesis setup when the `purge` flag is activated.
|
|
|
|
## Otherwise the database backend may defect on an internal inconsistency.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseLegacySetupFn
|
2023-08-02 21:46:41 +01:00
|
|
|
db.methods.legacySetupFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
|
|
|
|
|
|
|
proc level*(db: CoreDbRef): int =
|
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
|
|
|
## Getter, retrieve transaction level (zero if there is no pending
|
|
|
|
## transaction)
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseLevelFn
|
2023-11-24 22:16:21 +00:00
|
|
|
result = db.methods.levelFn()
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
proc parent*(cld: CoreDxChldRefs): CoreDbRef =
|
2023-09-26 10:21:13 +01:00
|
|
|
## Getter, common method for all sub-modules
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cld.parent
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc backend*(dsc: CoreDxKvtRef | CoreDxTrieRelated | CoreDbRef): auto =
|
|
|
|
## Getter, retrieves the *raw* backend object for special/localised support.
|
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
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackNewApi AnyBackendFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = dsc.methods.backendFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-10-11 20:09:11 +01:00
|
|
|
|
|
|
|
proc finish*(db: CoreDbRef; flush = false) =
|
|
|
|
## Database destructor. If the argument `flush` is set `false`, the database
|
|
|
|
## is left as-is and only the in-memory handlers are cleaned up.
|
|
|
|
##
|
|
|
|
## Otherwise the destructor is allowed to remove the database. This feature
|
|
|
|
## depends on the backend database. Currently, only the `AristoDbRocks` type
|
|
|
|
## backend removes the database on `true`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseFinishFn
|
2023-10-11 20:09:11 +01:00
|
|
|
db.methods.destroyFn flush
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-10-02 19:05:17 +01:00
|
|
|
proc `$$`*(e: CoreDbErrorRef): string =
|
2023-09-26 10:21:13 +01:00
|
|
|
## Pretty print error symbol, note that this directive may have side effects
|
|
|
|
## as it calls a backend function.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
e.setTrackNewApi ErrorPrintFn
|
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
|
|
|
result = e.prettyText()
|
2023-11-24 22:16:21 +00:00
|
|
|
e.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
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
|
|
|
proc `$$`*(vid: CoreDbVidRef): string =
|
|
|
|
## Pretty print vertex ID symbol, note that this directive may have side
|
|
|
|
## effects as it calls a backend function.
|
|
|
|
##
|
|
|
|
vid.setTrackNewApi VidPrintFn
|
|
|
|
result = vid.prettyText()
|
|
|
|
vid.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc hash*(vid: CoreDbVidRef): CoreDbRc[Hash256] =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Getter (well, sort of), retrieves the hash for a `vid` argument. The
|
|
|
|
## function might fail if there is currently no hash available (e.g. on
|
|
|
|
## `Aristo`.) Note that this is different from succeeding with an
|
|
|
|
## `EMPTY_ROOT_HASH` value.
|
|
|
|
##
|
|
|
|
## The value `EMPTY_ROOT_HASH` is also returned on an empty `vid` argument
|
|
|
|
## `CoreDbVidRef(nil)`, say.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
vid.setTrackNewApi VidHashFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = block:
|
|
|
|
if not vid.isNil and vid.ready:
|
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
|
|
|
vid.parent.methods.vidHashFn vid
|
2023-10-25 15:03:09 +01:00
|
|
|
else:
|
|
|
|
ok EMPTY_ROOT_HASH
|
|
|
|
# Note: tracker will be silent if `vid` is NIL
|
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
|
|
|
vid.ifTrackNewApi: debug newApiTxt, ctx, elapsed, vid, result
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
proc hashOrEmpty*(vid: CoreDbVidRef): Hash256 =
|
|
|
|
## Convenience wrapper, returns `EMPTY_ROOT_HASH` where `hash()` would fail.
|
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
|
|
|
vid.hash().valueOr: EMPTY_ROOT_HASH
|
2023-10-11 20:09:11 +01:00
|
|
|
|
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
|
|
|
func isValid*(vid: CoreDbVidRef): bool =
|
|
|
|
## This function returns `true` if the argument `vid` exists and is properly
|
|
|
|
## initialised.
|
|
|
|
##
|
|
|
|
not vid.isNil and vid.ready
|
|
|
|
|
|
|
|
proc recast*(account: CoreDbAccount): CoreDbRc[Account] =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Convert the argument `account` to the portable Ethereum representation
|
|
|
|
## of an account. This conversion may fail if the storage root hash (see
|
|
|
|
## `hash()` above) is currently unavailable.
|
|
|
|
##
|
|
|
|
## Note that for the legacy backend, this function always succeeds.
|
|
|
|
##
|
2023-10-25 15:03:09 +01:00
|
|
|
let vid = account.storageVid
|
2023-12-12 17:47:41 +00:00
|
|
|
vid.setTrackNewApi EthAccRecastFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = block:
|
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
|
|
|
let rc = vid.hash()
|
2023-10-25 15:03:09 +01:00
|
|
|
if rc.isOk:
|
|
|
|
ok Account(
|
|
|
|
nonce: account.nonce,
|
|
|
|
balance: account.balance,
|
|
|
|
codeHash: account.codeHash,
|
|
|
|
storageRoot: rc.value)
|
|
|
|
else:
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
err(rc.error)
|
2023-11-24 22:16:21 +00:00
|
|
|
vid.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
|
|
|
proc getRoot*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
root: Hash256;
|
|
|
|
): CoreDbRc[CoreDbVidRef] =
|
|
|
|
## Find root node with argument hash `root` in database and return the
|
|
|
|
## corresponding `CoreDbVidRef` object. If the `root` arguent is set
|
|
|
|
## `EMPTY_CODE_HASH`, this function always succeeds, otherwise it fails
|
|
|
|
## unless a root node with the corresponding hash exists.
|
|
|
|
##
|
|
|
|
## This function is intended to open a virtual accounts trie database as in:
|
|
|
|
## ::
|
|
|
|
## proc openAccountLedger(db: CoreDbRef, rootHash: Hash256): CoreDxMptRef =
|
2023-11-08 12:18:32 +00:00
|
|
|
## let root = db.getRoot(rootHash).valueOr:
|
2023-10-11 20:09:11 +01:00
|
|
|
## # some error handling
|
|
|
|
## return
|
|
|
|
## db.newAccMpt root
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseGetRootFn
|
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
|
|
|
result = db.methods.getRootFn root
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 21:46:41 +01:00
|
|
|
# Public key-value table methods
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
proc newKvt*(db: CoreDbRef; saveMode = AutoSave): CoreDxKvtRef =
|
|
|
|
## Constructor, will defect on failure.
|
|
|
|
##
|
|
|
|
## Depending on the argument `saveMode`, the contructed object will have
|
|
|
|
## the following properties.
|
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## * `Shared`
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## Subscribe to the common base object shared with other subscribed
|
2023-11-24 22:16:21 +00:00
|
|
|
## `AutoSave` or `Shared` descriptors. So any changes are immediately
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## visible among subscribers. On automatic destruction (when the
|
|
|
|
## constructed object gets out of scope), changes are not saved to the
|
|
|
|
## backend database but are still available to subscribers.
|
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## This mode would used for short time read-only database descriptors.
|
|
|
|
##
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## * `AutoSave`
|
2023-11-24 22:16:21 +00:00
|
|
|
## This mode works similar to `Shared` with the difference that changes
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## are saved to the backend database on automatic destruction when this
|
|
|
|
## is permissible, i.e. there is a backend available and there is no
|
|
|
|
## pending transaction on the common base object.
|
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## * `TopShot`
|
|
|
|
## The contructed object will be a new descriptor with a separate snapshot
|
|
|
|
## of the common shared base object. If there are pending transactions
|
|
|
|
## on the shared base object, the snapsot will squash them to a single
|
|
|
|
## pending transaction. On automatic destruction, changes will be discarded.
|
|
|
|
##
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## * `Companion`
|
2023-11-24 22:16:21 +00:00
|
|
|
## The contructed object will be a new separate descriptor with a clean
|
|
|
|
## cache (similar to `TopShot` with empty cache and no pending
|
|
|
|
## transactions.) On automatic destruction, changes will be discarded.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## The constructed object can be manually descructed (see `forget()`) without
|
|
|
|
## saving and can be forced to save (see `persistent()`.)
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
|
|
|
## The legacy backend always assumes `AutoSave` mode regardless of the
|
|
|
|
## function argument.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewKvtFn
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
result = db.methods.newKvtFn(saveMode).valueOr:
|
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
|
|
|
raiseAssert error.prettyText()
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, saveMode
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc get*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
2023-11-08 12:18:32 +00:00
|
|
|
## This function always returns a non-empty `Blob` or an error code.
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtGetFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = kvt.methods.getFn key
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
proc getOrEmpty*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
|
|
|
## This function sort of mimics the behaviour of the legacy database
|
|
|
|
## returning an empty `Blob` if the argument `key` is not found on the
|
|
|
|
## database.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtGetOrEmptyFn
|
2023-11-08 12:18:32 +00:00
|
|
|
result = kvt.methods.getFn key
|
|
|
|
if result.isErr and result.error.error == KvtNotFound:
|
|
|
|
result = CoreDbRc[Blob].ok(EmptyBlob)
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-11-08 12:18:32 +00:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc del*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtDelFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = kvt.methods.delFn key
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc put*(
|
|
|
|
kvt: CoreDxKvtRef;
|
|
|
|
key: openArray[byte];
|
2023-10-25 15:03:09 +01:00
|
|
|
val: openArray[byte];
|
2023-09-26 10:21:13 +01:00
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtPutFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = kvt.methods.putFn(key, val)
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi:
|
|
|
|
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
proc hasKey*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
|
|
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtHasKeyFn
|
2023-11-08 12:18:32 +00:00
|
|
|
result = kvt.methods.hasKeyFn key
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
proc persistent*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## For the legacy database, this function has no effect and succeeds always.
|
2023-11-24 22:16:21 +00:00
|
|
|
## It will nevertheless return a discardable error if there is a pending
|
|
|
|
## transaction.
|
|
|
|
##
|
|
|
|
## This function saves the current cache to the database if possible,
|
|
|
|
## regardless of the save/share mode assigned to the constructor.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## Caveat:
|
|
|
|
## If `dsc` is a detached descriptor of `Companion` or `TopShot` mode which
|
|
|
|
## could be persistently saved, the changes are immediately visible on all
|
|
|
|
## other descriptors unless they are hidden by newer versions of key-value
|
|
|
|
## items in the cache.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackNewApi KvtPersistentFn
|
2023-11-24 22:16:21 +00:00
|
|
|
result = dsc.methods.persistentFn()
|
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc forget*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## For the legacy database, this function has no effect and succeeds always.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## This function destroys the current descriptor without any further action
|
|
|
|
## regardless of the save/share mode assigned to the constructor.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## For desciptors constructed with modes `saveMode` or`Shared`, nothing will
|
|
|
|
## change on the current database if there are other descriptors referring
|
|
|
|
## to the same shared database view. Creating a new `saveMode` or`Shared`
|
|
|
|
## descriptor will retrieve this state.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## For other desciptors constructed as `Companion` ot `TopShot`, the latest
|
|
|
|
## changes (after the last `persistent()` call) will be discarded.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackNewApi KvtForgetFn
|
2023-11-24 22:16:21 +00:00
|
|
|
result = dsc.methods.forgetFn()
|
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
iterator pairs*(kvt: CoreDxKvtRef): (Blob, Blob) {.apiRaise.} =
|
2023-08-02 21:46:41 +01:00
|
|
|
## Iterator supported on memory DB (otherwise implementation dependent)
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtPairsIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in kvt.methods.pairsIt(): yield (k,v)
|
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-07-31 14:43:38 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 21:46:41 +01:00
|
|
|
# Public Merkle Patricia Tree, hexary trie constructors
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
proc newMpt*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
root: CoreDbVidRef;
|
|
|
|
prune = true;
|
|
|
|
saveMode = AutoSave;
|
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
|
|
|
): CoreDbRc[CoreDxMptRef] =
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## Constructor, will defect on failure. The argument `prune` is currently
|
2023-11-24 22:16:21 +00:00
|
|
|
## ignored on other than the legacy backend. The legacy backend always
|
|
|
|
## assumes `AutoSave` mode regardless of the function argument.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
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
|
|
|
## If the `root` argument is `nil`, a new sub-trie root will be created
|
|
|
|
## on-the-fly. In order to access that root so that it can be used at a
|
|
|
|
## later stage, the function `rootVid()` can be used after at least one
|
|
|
|
## data item was successfully merged (using `merge()`) to that sub-trie.
|
|
|
|
##
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## See the discussion at `newKvt()` for an explanation of the `saveMode`
|
|
|
|
## argument.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewMptFn
|
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
|
|
|
result = db.methods.newMptFn(root, prune, saveMode)
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, prune, saveMode, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
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
|
|
|
proc newMpt*(db: CoreDbRef; prune=true; saveMode=AutoSave): CoreDxMptRef =
|
|
|
|
## Shortcut for `newMpt(CoreDbVidRef(nil), prune, saveMode)`. This function
|
|
|
|
## will always return a non-nil descriptor or throw an exception.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewMptFn
|
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
|
|
|
result = db.methods.newMptFn(CoreDbVidRef(nil), prune, saveMode).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode
|
2023-11-08 12:18:32 +00:00
|
|
|
|
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
|
|
|
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
proc newMpt*(acc: CoreDxAccRef): CoreDxMptRef =
|
2023-11-24 22:16:21 +00:00
|
|
|
## Constructor, will defect on failure.
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
##
|
|
|
|
## Variant of `newMpt()` where the input arguments are taken from the
|
|
|
|
## current `acc` descriptor settings.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccToMptFn
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
result = acc.methods.newMptFn().valueOr:
|
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
|
|
|
raiseAssert error.prettyText()
|
2023-11-24 22:16:21 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
|
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
|
|
|
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
proc newAccMpt*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
root: CoreDbVidRef;
|
|
|
|
prune = true;
|
|
|
|
saveMode = AutoSave;
|
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
|
|
|
): CoreDbRc[CoreDxAccRef] =
|
2023-11-24 22:16:21 +00:00
|
|
|
## Constructor, will defect on failure. The argument `prune` is currently
|
|
|
|
## ignored on other than the legacy backend. The legacy backend always
|
|
|
|
## assumes `AutoSave` mode regardless of the function argument.
|
|
|
|
##
|
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
|
|
|
## For a `saveMode` argument value `Shared`, the `root` descriptor argument
|
|
|
|
## might be pre-set (i.e. non-nil). Other arguments will be rejected by the
|
|
|
|
## `Aristo` backend and should be avoided for other backends. The pre-set
|
|
|
|
## `root` argument must refer to the state root for the accounts sub-trie
|
|
|
|
## which can be retrieved by `getRoot()`.
|
|
|
|
##
|
|
|
|
## Example:
|
|
|
|
## ::
|
|
|
|
## let vid = db.getRoot(<some-hash>).valueOr:
|
|
|
|
## ... # No node with <some-hash>
|
|
|
|
## return
|
|
|
|
##
|
|
|
|
## let acc = db.newAccMpt(vid, saveMode=Shared)
|
|
|
|
## ... # Was not the state root for the accounts sub-trie
|
|
|
|
## return
|
|
|
|
##
|
|
|
|
##
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## This function works similar to `newMpt()` for handling accounts. Although
|
|
|
|
## this sub-trie can be emulated by means of `newMpt(..).toPhk()`, it is
|
|
|
|
## recommended using this particular constructor for accounts because it
|
|
|
|
## provides its own subset of methods to handle accounts.
|
|
|
|
##
|
|
|
|
## See the discussion at `newKvt()` for an explanation of the `saveMode`
|
|
|
|
## argument.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewAccFn
|
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
|
|
|
result = db.methods.newAccFn(root, prune, saveMode)
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, prune, saveMode, result
|
|
|
|
|
|
|
|
proc newAccMpt*(db: CoreDbRef; prune=true; saveMode=AutoSave): CoreDxAccRef =
|
|
|
|
## Shortcut for `newAccMpt(CoreDbVidRef(nil), prune, saveMode)`. This function
|
|
|
|
## will always return a non-nil descriptor or throw an exception.
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseNewAccFn
|
|
|
|
result = db.methods.newAccFn(CoreDbVidRef(nil), prune, saveMode).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode
|
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
|
|
|
|
## Replaces the pre-hashed argument trie `phk` by the non pre-hashed *MPT*.
|
2023-10-11 20:09:11 +01:00
|
|
|
## Note that this does not apply to an accounts trie that was created by
|
|
|
|
## `newAccMpt()`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.setTrackNewApi PhkToMptFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = phk.fromMpt
|
2023-11-24 22:16:21 +00:00
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc toPhk*(mpt: CoreDxMptRef): CoreDxPhkRef =
|
|
|
|
## Replaces argument `mpt` by a pre-hashed *MPT*.
|
2023-10-11 20:09:11 +01:00
|
|
|
## Note that this does not apply to an accounts trie that was created by
|
|
|
|
## `newAaccMpt()`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptToPhkFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = mpt.toCoreDxPhkRef
|
2023-11-24 22:16:21 +00:00
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-07-31 14:43:38 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 20:09:11 +01:00
|
|
|
# Public common methods for all hexary trie databases (`mpt`, `phk`, or `acc`)
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc isPruning*(dsc: CoreDxTrieRefs): bool =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Getter
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackNewApi AnyIsPruningFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = dsc.methods.isPruningFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc rootVid*(acc: CoreDxAccRef): CoreDbVidRef =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Getter, result is not `nil`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccRootVidFn
|
|
|
|
result = acc.methods.rootVidFn()
|
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc rootVid*(mpt: CoreDxMptRef): CoreDbVidRef =
|
|
|
|
## Variant of `rootVid()`
|
|
|
|
mpt.setTrackNewApi MptRootVidFn
|
|
|
|
result = mpt.methods.rootVidFn()
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc rootVid*(phk: CoreDxPhkRef): CoreDbVidRef =
|
|
|
|
## Variant of `rootVid()`
|
|
|
|
phk.setTrackNewApi PhkRootVidFn
|
|
|
|
result = phk.methods.rootVidFn()
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
|
|
|
|
proc persistent*(acc: CoreDxAccRef): CoreDbRc[void] {.discardable.} =
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## For the legacy database, this function has no effect and succeeds always.
|
2023-11-24 22:16:21 +00:00
|
|
|
## It will nevertheless return a discardable error if there is a pending
|
|
|
|
## transaction.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## This function saves the current cache to the database if possible,
|
|
|
|
## regardless of the save/share mode assigned to the constructor.
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
##
|
2023-11-24 22:16:21 +00:00
|
|
|
## Caveat:
|
|
|
|
## If `dsc` is a detached descriptor of `Companion` or `TopShot` mode which
|
|
|
|
## could be persistently saved, no changes are visible on other descriptors.
|
|
|
|
## This is different from the behaviour of a `Kvt` descriptor. Saving any
|
|
|
|
## other descriptor will undo the changes.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccPersistentFn
|
|
|
|
result = acc.methods.persistentFn()
|
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc persistent*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `persistent()`
|
|
|
|
mpt.setTrackNewApi MptPersistentFn
|
|
|
|
result = mpt.methods.persistentFn()
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc persistent*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `persistent()`
|
|
|
|
phk.setTrackNewApi PhkPersistentFn
|
|
|
|
result = phk.methods.persistentFn()
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc forget*(acc: CoreDxAccRef): CoreDbRc[void] {.discardable.} =
|
2023-11-24 22:16:21 +00:00
|
|
|
## For the legacy database, this function has no effect and succeeds always.
|
|
|
|
##
|
|
|
|
## This function destroys the current descriptor without any further action
|
|
|
|
## regardless of the save/share mode assigned to the constructor.
|
|
|
|
##
|
|
|
|
## See the discussion at `forget()` for a `CoreDxKvtRef` type argument
|
|
|
|
## descriptor an explanation of how this function works.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccForgetFn
|
|
|
|
result = acc.methods.forgetFn()
|
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc forget*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `forget()`
|
|
|
|
mpt.setTrackNewApi MptForgetFn
|
|
|
|
result = mpt.methods.forgetFn()
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
proc forget*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `forget()`
|
|
|
|
phk.setTrackNewApi PhkForgetFn
|
|
|
|
result = phk.methods.forgetFn()
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 20:09:11 +01:00
|
|
|
# Public generic hexary trie database methods (`mpt` or `phk`)
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc fetch*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
2023-11-08 12:18:32 +00:00
|
|
|
## Fetch data from the argument `trie`. The function always returns a
|
|
|
|
## non-empty `Blob` or an error code.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptFetchFn
|
|
|
|
result = mpt.methods.fetchFn key
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
proc fetch*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
|
|
|
|
## Variant of `fetch()"
|
|
|
|
phk.setTrackNewApi PhkFetchFn
|
|
|
|
result = phk.methods.fetchFn key
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-11-08 12:18:32 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc fetchOrEmpty*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
2023-11-08 12:18:32 +00:00
|
|
|
## This function returns an empty `Blob` if the argument `key` is not found
|
|
|
|
## on the database.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptFetchOrEmptyFn
|
|
|
|
result = mpt.methods.fetchFn key
|
|
|
|
if result.isErr and result.error.error == MptNotFound:
|
|
|
|
result = CoreDbRc[Blob].ok(EmptyBlob)
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
proc fetchOrEmpty*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
|
|
|
|
## Variant of `fetchOrEmpty()`
|
|
|
|
phk.setTrackNewApi PhkFetchOrEmptyFn
|
|
|
|
result = phk.methods.fetchFn key
|
2023-11-08 12:18:32 +00:00
|
|
|
if result.isErr and result.error.error == MptNotFound:
|
2023-12-12 17:47:41 +00:00
|
|
|
result = CoreDbRc[Blob].ok(EmptyBlob)
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
|
|
|
|
proc delete*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[void] =
|
|
|
|
mpt.setTrackNewApi MptDeleteFn
|
|
|
|
result = mpt.methods.deleteFn key
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
proc delete*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[void] =
|
|
|
|
phk.setTrackNewApi PhkDeleteFn
|
|
|
|
result = phk.methods.deleteFn key
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc merge*(
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt: CoreDxMptRef;
|
2023-07-31 14:43:38 +01:00
|
|
|
key: openArray[byte];
|
2023-10-25 15:03:09 +01:00
|
|
|
val: openArray[byte];
|
2023-09-26 10:21:13 +01:00
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptMergeFn
|
|
|
|
result = mpt.methods.mergeFn(key, val)
|
|
|
|
mpt.ifTrackNewApi:
|
2023-11-24 22:16:21 +00:00
|
|
|
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc merge*(
|
|
|
|
phk: CoreDxPhkRef;
|
|
|
|
key: openArray[byte];
|
|
|
|
val: openArray[byte];
|
|
|
|
): CoreDbRc[void] =
|
|
|
|
phk.setTrackNewApi PhkMergeFn
|
|
|
|
result = phk.methods.mergeFn(key, val)
|
|
|
|
phk.ifTrackNewApi:
|
|
|
|
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr, result
|
|
|
|
|
|
|
|
|
|
|
|
proc hasPath*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
|
|
## This function would be named `contains()` if it returned `bool` rather
|
|
|
|
## than a `Result[]`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptHasPathFn
|
|
|
|
result = mpt.methods.hasPathFn key
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
proc hasPath*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
|
|
## Variant of `hasPath()`
|
|
|
|
phk.setTrackNewApi PhkHasPathFn
|
|
|
|
result = phk.methods.hasPathFn key
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
iterator pairs*(mpt: CoreDxMptRef): (Blob, Blob) {.apiRaise.} =
|
|
|
|
## Trie traversal, only supported for `CoreDxMptRef`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptPairsIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in mpt.methods.pairsIt(): yield (k,v)
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
iterator replicate*(mpt: CoreDxMptRef): (Blob, Blob) {.apiRaise.} =
|
|
|
|
## Low level trie dump, only supported for `CoreDxMptRef`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptReplicateIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in mpt.methods.replicateIt(): yield (k,v)
|
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public trie database methods for accounts
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc fetch*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
|
2023-12-12 17:47:41 +00:00
|
|
|
## Fetch data from the argument `acc`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccFetchFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = acc.methods.fetchFn address
|
2023-11-24 22:16:21 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
|
|
|
proc delete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccDeleteFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = acc.methods.deleteFn address
|
2023-11-24 22:16:21 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
|
|
|
proc merge*(
|
|
|
|
acc: CoreDxAccRef;
|
|
|
|
address: EthAddress;
|
|
|
|
account: CoreDbAccount;
|
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccMergeFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = acc.methods.mergeFn(address, account)
|
2023-11-24 22:16:21 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
proc hasPath*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[bool] =
|
|
|
|
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccHasPathFn
|
2023-11-08 12:18:32 +00:00
|
|
|
result = acc.methods.hasPathFn address
|
2023-11-24 22:16:21 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public transaction related methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc newTransaction*(db: CoreDbRef): CoreDbRc[CoreDxTxRef] =
|
2023-08-02 21:46:41 +01:00
|
|
|
## Constructor
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewTxFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = db.methods.beginFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi:
|
|
|
|
debug newApiTxt, ctx, elapsed, newLevel=db.methods.levelFn(), result
|
|
|
|
|
|
|
|
proc level*(tx: CoreDxTxRef): int =
|
|
|
|
## Print positive argument `tx` transaction level
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxLevelFn
|
2023-11-24 22:16:21 +00:00
|
|
|
result = tx.methods.levelFn()
|
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc commit*(tx: CoreDxTxRef, applyDeletes = true): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxCommitFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.methods.levelFn()
|
2023-10-25 15:03:09 +01:00
|
|
|
result = tx.methods.commitFn applyDeletes
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc rollback*(tx: CoreDxTxRef): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxRollbackFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.methods.levelFn()
|
2023-10-25 15:03:09 +01:00
|
|
|
result = tx.methods.rollbackFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc dispose*(tx: CoreDxTxRef): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxDisposeFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.methods.levelFn()
|
2023-10-25 15:03:09 +01:00
|
|
|
result = tx.methods.disposeFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc safeDispose*(tx: CoreDxTxRef): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxSaveDisposeFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.methods.levelFn()
|
2023-10-25 15:03:09 +01:00
|
|
|
result = tx.methods.safeDisposeFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public tracer methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
proc newCapture*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
flags: set[CoreDbCaptFlags] = {};
|
|
|
|
): CoreDbRc[CoreDxCaptRef] =
|
2023-08-02 21:46:41 +01:00
|
|
|
## Constructor
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseCaptureFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = db.methods.captureFn flags
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
proc recorder*(cp: CoreDxCaptRef): CoreDbRc[CoreDbRef] =
|
2023-08-02 21:46:41 +01:00
|
|
|
## Getter
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackNewApi CptRecorderFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cp.methods.recorderFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 21:46:41 +01:00
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
proc logDb*(cp: CoreDxCaptRef): CoreDbRc[CoreDbRef] =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackNewApi CptLogDbFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cp.methods.logDbFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
proc flags*(cp: CoreDxCaptRef): set[CoreDbCaptFlags] =
|
2023-08-02 21:46:41 +01:00
|
|
|
## Getter
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackNewApi CptFlagsFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cp.methods.getFlagsFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 14:43:38 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public methods, legacy API
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when ProvideLegacyAPI:
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-10-25 15:03:09 +01:00
|
|
|
proc parent*(cld: CoreDbChldRefs): CoreDbRef =
|
2023-09-26 10:21:13 +01:00
|
|
|
## Getter, common method for all sub-modules
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cld.distinctBase.parent
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc backend*(dsc: CoreDbChldRefs): auto =
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackLegaApi LegaBackendFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = dsc.distinctBase.backend
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-11 20:09:11 +01:00
|
|
|
|
2023-09-26 10:21:13 +01:00
|
|
|
# ----------------
|
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc kvt*(db: CoreDbRef): CoreDbKvtRef =
|
2023-09-26 10:21:13 +01:00
|
|
|
## Legacy pseudo constructor, see `toKvt()` for production constructor
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaNewKvtFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = db.newKvt().CoreDbKvtRef
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc get*(kvt: CoreDbKvtRef; key: openArray[byte]): Blob =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackLegaApi LegaKvtGetFn
|
|
|
|
result = kvt.distinctBase.getOrEmpty(key).expect $ctx
|
2023-10-25 15:03:09 +01:00
|
|
|
kvt.ifTrackLegaApi:
|
2023-11-24 22:16:21 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, result=result.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc del*(kvt: CoreDbKvtRef; key: openArray[byte]): void =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackLegaApi LegaKvtDelFn
|
|
|
|
kvt.distinctBase.del(key).expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
proc put*(kvt: CoreDbKvtRef; key: openArray[byte]; val: openArray[byte]) =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackLegaApi LegaKvtPutFn
|
|
|
|
kvt.distinctBase.parent.newKvt().put(key, val).expect $ctx
|
2023-10-25 15:03:09 +01:00
|
|
|
kvt.ifTrackLegaApi:
|
2023-11-24 22:16:21 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc contains*(kvt: CoreDbKvtRef; key: openArray[byte]): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackLegaApi LegaKvtContainsFn
|
|
|
|
result = kvt.distinctBase.hasKey(key).expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
iterator pairs*(kvt: CoreDbKvtRef): (Blob, Blob) {.apiRaise.} =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackLegaApi LegaKvtPairsIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in kvt.distinctBase.pairs(): yield (k,v)
|
|
|
|
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc toMpt*(phk: CoreDbPhkRef): CoreDbMptRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.setTrackLegaApi LegaToMptFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = phk.distinctBase.toMpt.CoreDbMptRef
|
2023-11-24 22:16:21 +00:00
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc mptPrune*(db: CoreDbRef; root: Hash256; prune = true): CoreDbMptRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaNewMptFn
|
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
|
|
|
let
|
|
|
|
vid = block:
|
|
|
|
if root.isValid: db.getRoot(root).expect $ctx
|
|
|
|
else: CoreDbVidRef(nil)
|
|
|
|
mpt = db.newMpt(vid, prune).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
|
|
|
result = mpt.CoreDbMptRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc mptPrune*(db: CoreDbRef; prune = true): CoreDbMptRef =
|
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
|
|
|
db.setTrackLegaApi LegaNewMptFn
|
|
|
|
result = db.newMpt(prune).CoreDbMptRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prune
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc toPhk*(mpt: CoreDbMptRef): CoreDbPhkRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackLegaApi LegaToPhkFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = mpt.distinctBase.toPhk.CoreDbPhkRef
|
2023-11-24 22:16:21 +00:00
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc phkPrune*(db: CoreDbRef; root: Hash256; prune = true): CoreDbPhkRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaNewPhkFn
|
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
|
|
|
let
|
|
|
|
vid = block:
|
|
|
|
if root.isValid: db.getRoot(root).expect $ctx
|
|
|
|
else: CoreDbVidRef(nil)
|
|
|
|
phk = db.newMpt(vid, prune).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
|
|
|
result = phk.toCoreDxPhkRef.CoreDbPhkRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc phkPrune*(db: CoreDbRef; prune = true): CoreDbPhkRef =
|
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
|
|
|
db.setTrackLegaApi LegaNewPhkFn
|
|
|
|
result = db.newMpt(prune).toCoreDxPhkRef.CoreDbPhkRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prune
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
2023-10-11 20:09:11 +01:00
|
|
|
proc isPruning*(trie: CoreDbTrieRefs): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
trie.setTrackLegaApi LegaIsPruningFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = trie.distinctBase.isPruning()
|
2023-11-24 22:16:21 +00:00
|
|
|
trie.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc get*(mpt: CoreDbMptRef; key: openArray[byte]): Blob =
|
|
|
|
mpt.setTrackLegaApi LegaMptGetFn
|
|
|
|
result = mpt.distinctBase.fetchOrEmpty(key).expect $ctx
|
|
|
|
mpt.ifTrackLegaApi:
|
2023-11-24 22:16:21 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, result=result.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc get*(phk: CoreDbPhkRef; key: openArray[byte]): Blob =
|
|
|
|
phk.setTrackLegaApi LegaPhkGetFn
|
|
|
|
result = phk.distinctBase.fetchOrEmpty(key).expect $ctx
|
|
|
|
phk.ifTrackLegaApi:
|
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, result=result.toStr
|
|
|
|
|
|
|
|
|
|
|
|
proc del*(mpt: CoreDbMptRef; key: openArray[byte]) =
|
|
|
|
mpt.setTrackLegaApi LegaMptDelFn
|
|
|
|
mpt.distinctBase.delete(key).expect $ctx
|
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc del*(phk: CoreDbPhkRef; key: openArray[byte]) =
|
|
|
|
phk.setTrackLegaApi LegaPhkDelFn
|
|
|
|
phk.distinctBase.delete(key).expect $ctx
|
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
|
|
|
|
|
|
|
|
|
|
|
|
proc put*(mpt: CoreDbMptRef; key: openArray[byte]; val: openArray[byte]) =
|
|
|
|
mpt.setTrackLegaApi LegaMptPutFn
|
|
|
|
mpt.distinctBase.merge(key, val).expect $ctx
|
|
|
|
mpt.ifTrackLegaApi:
|
2023-11-24 22:16:21 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc put*(phk: CoreDbPhkRef; key: openArray[byte]; val: openArray[byte]) =
|
|
|
|
phk.setTrackLegaApi LegaPhkPutFn
|
|
|
|
phk.distinctBase.merge(key, val).expect $ctx
|
|
|
|
phk.ifTrackLegaApi:
|
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toSeq.toStr
|
|
|
|
|
|
|
|
|
|
|
|
proc contains*(mpt: CoreDbMptRef; key: openArray[byte]): bool =
|
|
|
|
mpt.setTrackLegaApi LegaMptContainsFn
|
|
|
|
result = mpt.distinctBase.hasPath(key).expect $ctx
|
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
proc contains*(phk: CoreDbPhkRef; key: openArray[byte]): bool =
|
|
|
|
phk.setTrackLegaApi LegaPhkContainsFn
|
|
|
|
result = phk.distinctBase.hasPath(key).expect $ctx
|
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
|
|
|
|
|
|
|
|
|
|
|
proc rootHash*(mpt: CoreDbMptRef): Hash256 =
|
|
|
|
mpt.setTrackLegaApi LegaMptRootHashFn
|
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
|
|
|
result = mpt.distinctBase.rootVid().hash().expect $ctx
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result=result.toStr
|
|
|
|
|
|
|
|
proc rootHash*(phk: CoreDbPhkRef): Hash256 =
|
|
|
|
phk.setTrackLegaApi LegaPhkRootHashFn
|
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
|
|
|
result = phk.distinctBase.rootVid().hash().expect $ctx
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result=result.toStr
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
iterator pairs*(mpt: CoreDbMptRef): (Blob, Blob) {.apiRaise.} =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Trie traversal, not supported for `CoreDbPhkRef`
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackLegaApi LegaMptPairsIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in mpt.distinctBase.pairs(): yield (k,v)
|
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
iterator replicate*(mpt: CoreDbMptRef): (Blob, Blob) {.apiRaise.} =
|
2023-10-11 20:09:11 +01:00
|
|
|
## Low level trie dump, not supported for `CoreDbPhkRef`
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackLegaApi LegaMptReplicateIt
|
2023-11-24 22:16:21 +00:00
|
|
|
for k,v in mpt.distinctBase.replicate(): yield (k,v)
|
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc getTransactionID*(db: CoreDbRef): CoreDbTxID =
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaGetTxIdFn
|
|
|
|
result = db.methods.getIdFn().expect($ctx).CoreDbTxID
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc shortTimeReadOnly*(
|
|
|
|
id: CoreDbTxID;
|
|
|
|
action: proc() {.catchRaise.};
|
|
|
|
) {.catchRaise.} =
|
2023-12-12 17:47:41 +00:00
|
|
|
id.setTrackLegaApi LegaShortTimeRoFn
|
2023-09-26 10:21:13 +01:00
|
|
|
var oops = none(ref CatchableError)
|
|
|
|
proc safeFn() =
|
|
|
|
try:
|
|
|
|
action()
|
|
|
|
except CatchableError as e:
|
|
|
|
oops = some(e)
|
|
|
|
# Action has finished now
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
id.distinctBase.methods.roWrapperFn(safeFn).expect $ctx
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# Delayed exception
|
|
|
|
if oops.isSome:
|
|
|
|
let
|
|
|
|
e = oops.unsafeGet
|
|
|
|
msg = "delayed and reraised" &
|
|
|
|
", name=\"" & $e.name & "\", msg=\"" & e.msg & "\""
|
|
|
|
raise (ref TxWrapperApiError)(msg: msg)
|
2023-11-24 22:16:21 +00:00
|
|
|
id.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc beginTransaction*(db: CoreDbRef): CoreDbTxRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaBeginTxFn
|
|
|
|
result = (db.distinctBase.methods.beginFn().expect $ctx).CoreDbTxRef
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackLegaApi:
|
|
|
|
debug legaApiTxt, ctx, elapsed, newLevel=db.methods.levelFn()
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc commit*(tx: CoreDbTxRef, applyDeletes = true) =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackLegaApi LegaTxCommitFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.distinctBase.commit(applyDeletes).expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc rollback*(tx: CoreDbTxRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackLegaApi LegaTxCommitFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.distinctBase.rollback().expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc dispose*(tx: CoreDbTxRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackLegaApi LegaTxDisposeFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.distinctBase.dispose().expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
proc safeDispose*(tx: CoreDbTxRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackLegaApi LegaTxSaveDisposeFn:
|
2023-11-24 22:16:21 +00:00
|
|
|
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.distinctBase.safeDispose().expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
|
2023-09-26 10:21:13 +01:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc capture*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
flags: set[CoreDbCaptFlags] = {};
|
|
|
|
): CoreDbCaptRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaCaptureFn
|
|
|
|
result = db.newCapture(flags).expect($ctx).CoreDbCaptRef
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
proc recorder*(cp: CoreDbCaptRef): CoreDbRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptRecorderFn
|
|
|
|
result = cp.distinctBase.recorder().expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
proc logDb*(cp: CoreDbCaptRef): CoreDbRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptLogDbFn
|
|
|
|
result = cp.distinctBase.logDb().expect $ctx
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-25 15:03:09 +01:00
|
|
|
|
|
|
|
proc flags*(cp: CoreDbCaptRef): set[CoreDbCaptFlags] =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptFlagsFn
|
2023-10-25 15:03:09 +01:00
|
|
|
result = cp.distinctBase.flags()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 10:21:13 +01:00
|
|
|
|
2023-07-31 14:43:38 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|