2023-07-31 13:43:38 +00:00
|
|
|
# Nimbus
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-07-31 13:43:38 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2023-10-25 14:03:09 +00:00
|
|
|
std/typetraits,
|
2023-07-31 13:43:38 +00:00
|
|
|
chronicles,
|
2023-08-02 20:46:41 +00:00
|
|
|
eth/common,
|
2023-09-26 09:21:13 +00: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 09:21:13 +00: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 19:09:11 +00:00
|
|
|
CoreDbAccount,
|
|
|
|
CoreDbApiError,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbBackendRef,
|
|
|
|
CoreDbCaptFlags,
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbErrorCode,
|
2023-10-02 18:05:17 +00:00
|
|
|
CoreDbErrorRef,
|
2023-12-12 17:47:41 +00:00
|
|
|
CoreDbFnInx,
|
2023-09-26 09:21:13 +00: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,
|
2024-02-29 21:10:24 +00:00
|
|
|
CoreDbProfListRef,
|
2023-09-26 09:21:13 +00: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,
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbSubTrie,
|
|
|
|
CoreDbTrieRef,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbType,
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDxAccRef,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDxCaptRef,
|
|
|
|
CoreDxKvtRef,
|
|
|
|
CoreDxMptRef,
|
|
|
|
CoreDxPhkRef,
|
2024-02-29 21:10:24 +00:00
|
|
|
CoreDxTxRef
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
const
|
2023-12-12 17:47:41 +00:00
|
|
|
CoreDbProvideLegacyAPI* = ProvideLegacyAPI
|
|
|
|
CoreDbEnableApiTracking* = EnableApiTracking
|
|
|
|
CoreDbEnableApiProfiling* = EnableApiTracking and EnableApiProfiling
|
2023-09-26 09:21:13 +00: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 09:21:13 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when AutoValidateDescriptors:
|
|
|
|
import ./base/validate
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
# More settings
|
|
|
|
const
|
2023-11-24 22:16:21 +00:00
|
|
|
logTxt = "CoreDb "
|
2023-12-12 17:47:41 +00:00
|
|
|
legaApiTxt = logTxt & "legacy API"
|
2024-02-02 20:23:04 +00:00
|
|
|
newApiTxt = logTxt & "API"
|
2023-07-31 13:43:38 +00: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 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-25 14:03:09 +00:00
|
|
|
# Private helpers
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-25 14:03:09 +00: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 14:03:09 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
import
|
2024-02-02 20:23:04 +00:00
|
|
|
std/times
|
2023-10-25 14:03:09 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
proc `$`(v: CoreDbTrieRef): 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
|
2024-02-02 20:23:04 +00:00
|
|
|
proc `$`(b: Blob): string = b.toLenStr
|
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:
|
2024-02-29 21:10:24 +00:00
|
|
|
w.beginLegaApi(s)
|
2023-12-12 17:47:41 +00:00
|
|
|
code
|
|
|
|
const ctx {.inject,used.} = s
|
2023-11-24 22:16:21 +00:00
|
|
|
|
2024-02-02 10:58:35 +00:00
|
|
|
template setTrackLegaApi*(
|
2023-11-24 22:16:21 +00:00
|
|
|
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
|
|
|
|
2024-02-02 10:58:35 +00:00
|
|
|
template ifTrackLegaApi*(w: CoreDbApiTrackRef; code: untyped) =
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
w.endLegaApiIf:
|
|
|
|
code
|
2023-10-25 14:03:09 +00: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:
|
2024-02-29 21:10:24 +00:00
|
|
|
w.beginNewApi(s)
|
2023-12-12 17:47:41 +00:00
|
|
|
code
|
|
|
|
const ctx {.inject,used.} = s
|
2023-11-24 22:16:21 +00:00
|
|
|
|
2024-02-02 10:58:35 +00:00
|
|
|
template setTrackNewApi*(
|
2023-11-24 22:16:21 +00:00
|
|
|
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
|
|
|
|
2024-02-02 10:58:35 +00:00
|
|
|
template ifTrackNewApi*(w: CoreDxApiTrackRef; code: untyped) =
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
w.endNewApiIf:
|
|
|
|
code
|
2023-10-25 14:03:09 +00:00
|
|
|
|
|
|
|
# ---------
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
func toCoreDxPhkRef(mpt: CoreDxMptRef): CoreDxPhkRef =
|
2023-08-02 20:46:41 +00:00
|
|
|
## MPT => pre-hashed MPT (aka PHK)
|
2023-09-26 09:21:13 +00:00
|
|
|
result = CoreDxPhkRef(
|
|
|
|
fromMpt: mpt,
|
|
|
|
methods: mpt.methods)
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
result.methods.fetchFn =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[Blob] =
|
2023-10-11 19:09:11 +00:00
|
|
|
mpt.methods.fetchFn(k.keccakHash.data)
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
result.methods.deleteFn =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[void] =
|
2023-10-11 19:09:11 +00:00
|
|
|
mpt.methods.deleteFn(k.keccakHash.data)
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
result.methods.mergeFn =
|
|
|
|
proc(k:openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
|
|
|
|
mpt.methods.mergeFn(k.keccakHash.data, v)
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
result.methods.hasPathFn =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[bool] =
|
2023-11-08 12:18:32 +00:00
|
|
|
mpt.methods.hasPathFn(k.keccakHash.data)
|
2023-08-02 20:46:41 +00:00
|
|
|
|
|
|
|
when AutoValidateDescriptors:
|
2023-09-26 09:21:13 +00:00
|
|
|
result.validate
|
2023-07-31 13:43:38 +00:00
|
|
|
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
func parent(phk: CoreDxPhkRef): CoreDbRef =
|
|
|
|
phk.fromMpt.parent
|
2023-07-31 13:43:38 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
# Public constructor helper
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc bless*(db: CoreDbRef): CoreDbRef =
|
|
|
|
## Verify descriptor
|
|
|
|
when AutoValidateDescriptors:
|
|
|
|
db.validate
|
2024-02-29 21:10:24 +00:00
|
|
|
when CoreDbEnableApiProfiling:
|
|
|
|
db.profTab = CoreDbProfListRef.init()
|
2023-10-11 19:09:11 +00:00
|
|
|
db
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc bless*(db: CoreDbRef; trie: CoreDbTrieRef): CoreDbTrieRef =
|
2023-10-11 19:09:11 +00:00
|
|
|
## Complete sub-module descriptor, fill in `parent` and actvate it.
|
2024-02-02 20:23:04 +00:00
|
|
|
trie.parent = db
|
|
|
|
trie.ready = true
|
2023-09-26 09:21:13 +00:00
|
|
|
when AutoValidateDescriptors:
|
2024-02-02 20:23:04 +00:00
|
|
|
trie.validate
|
|
|
|
trie
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc bless*(db: CoreDbRef; kvt: CoreDxKvtRef): CoreDxKvtRef =
|
|
|
|
## Complete sub-module descriptor, fill in `parent`.
|
|
|
|
kvt.parent = db
|
2023-08-02 20:46:41 +00:00
|
|
|
when AutoValidateDescriptors:
|
2024-02-02 20:23:04 +00:00
|
|
|
kvt.validate
|
|
|
|
kvt
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-11-08 12:18:32 +00:00
|
|
|
proc bless*[T: CoreDxTrieRelated | CoreDbBackends](
|
2023-10-11 19:09:11 +00:00
|
|
|
db: CoreDbRef;
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc: T;
|
2023-10-11 19:09:11 +00:00
|
|
|
): auto =
|
|
|
|
## Complete sub-module descriptor, fill in `parent`.
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc.parent = db
|
2023-08-02 20:46:41 +00:00
|
|
|
when AutoValidateDescriptors:
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc.validate
|
|
|
|
dsc
|
2023-11-08 12:18:32 +00:00
|
|
|
|
|
|
|
proc bless*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
error: CoreDbErrorCode;
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc: CoreDbErrorRef;
|
2023-11-08 12:18:32 +00:00
|
|
|
): CoreDbErrorRef =
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc.parent = db
|
|
|
|
dsc.error = error
|
2023-11-08 12:18:32 +00:00
|
|
|
when AutoValidateDescriptors:
|
2024-02-02 20:23:04 +00:00
|
|
|
dsc.validate
|
|
|
|
dsc
|
|
|
|
|
|
|
|
|
|
|
|
proc prettyText*(e: CoreDbErrorRef): string =
|
|
|
|
## Pretty print argument object (for tracking use `$$()`)
|
|
|
|
if e.isNil: "$ø" else: e.toStr()
|
|
|
|
|
|
|
|
proc prettyText*(trie: CoreDbTrieRef): string =
|
|
|
|
## Pretty print argument object (for tracking use `$$()`)
|
|
|
|
if trie.isNil or not trie.ready: "$ø" else: trie.toStr()
|
|
|
|
|
|
|
|
proc verify*(trie: CoreDbTrieRef): bool =
|
|
|
|
## Verify that the `trie` argument is `nil` or properly initialised. This
|
|
|
|
## function is for debugging and subject to change.
|
|
|
|
trie.isNil or (trie.ready and trie.parent.methods.verifyFn trie)
|
2023-11-08 12:18:32 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 20:46:41 +00:00
|
|
|
# Public main descriptor methods
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-02-29 21:10:24 +00:00
|
|
|
proc dbProfData*(db: CoreDbRef): CoreDbProfListRef =
|
|
|
|
## Return profiling data table (only available in profiling mode). If
|
|
|
|
## available (i.e. non-nil), result data can be organised by the functions
|
|
|
|
## available with `aristo_profile`.
|
|
|
|
when CoreDbEnableApiProfiling:
|
|
|
|
db.profTab
|
|
|
|
|
2023-08-02 20:46:41 +00: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 14:03:09 +00:00
|
|
|
result = db.dbType
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 20:46:41 +00:00
|
|
|
|
|
|
|
proc compensateLegacySetup*(db: CoreDbRef) =
|
2023-10-11 19:09:11 +00: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 20:46:41 +00: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 13:43:38 +00:00
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
proc parent*(cld: CoreDxChldRefs): CoreDbRef =
|
2023-09-26 09:21:13 +00:00
|
|
|
## Getter, common method for all sub-modules
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-10-25 14:03:09 +00:00
|
|
|
result = cld.parent
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00: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 14:03:09 +00:00
|
|
|
result = dsc.methods.backendFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-10-11 19:09:11 +00: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 19:09:11 +00:00
|
|
|
db.methods.destroyFn flush
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-02 18:05:17 +00:00
|
|
|
proc `$$`*(e: CoreDbErrorRef): string =
|
2023-09-26 09:21:13 +00: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 09:21:13 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc `$$`*(trie: CoreDbTrieRef): string =
|
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
|
|
|
## Pretty print vertex ID symbol, note that this directive may have side
|
|
|
|
## effects as it calls a backend function.
|
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
#trie.setTrackNewApi TriePrintFn
|
|
|
|
result = trie.prettyText()
|
|
|
|
#trie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc rootHash*(trie: CoreDbTrieRef): CoreDbRc[Hash256] =
|
|
|
|
## Getter (well, sort of), retrieves the root hash for the argument `trie`
|
|
|
|
## descriptor. The function might fail if there is currently no hash
|
|
|
|
## available (e.g. on `Aristo`.) Note that a failure to retrieve the hash
|
|
|
|
## (which returns an error) is different from succeeding with an
|
|
|
|
## `EMPTY_ROOT_HASH` value for an empty trie.
|
2023-10-11 19:09:11 +00:00
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
## The value `EMPTY_ROOT_HASH` is also returned on a void `trie` descriptor
|
|
|
|
## argument `CoreDbTrieRef(nil)`.
|
2023-10-11 19:09:11 +00:00
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
trie.setTrackNewApi RootHashFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = block:
|
2024-02-02 20:23:04 +00:00
|
|
|
if not trie.isNil and trie.ready:
|
|
|
|
trie.parent.methods.rootHashFn trie
|
2023-10-25 14:03:09 +00:00
|
|
|
else:
|
|
|
|
ok EMPTY_ROOT_HASH
|
|
|
|
# Note: tracker will be silent if `vid` is NIL
|
2024-02-02 20:23:04 +00:00
|
|
|
trie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, result
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc rootHashOrEmpty*(trie: CoreDbTrieRef): Hash256 =
|
2023-10-25 14:03:09 +00:00
|
|
|
## Convenience wrapper, returns `EMPTY_ROOT_HASH` where `hash()` would fail.
|
2024-02-02 20:23:04 +00:00
|
|
|
trie.rootHash.valueOr: EMPTY_ROOT_HASH
|
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 recast*(account: CoreDbAccount): CoreDbRc[Account] =
|
2023-10-11 19:09:11 +00: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.
|
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
let stoTrie = account.stoTrie
|
|
|
|
stoTrie.setTrackNewApi EthAccRecastFn
|
|
|
|
let rc =
|
|
|
|
if stoTrie.isNil or not stoTrie.ready: CoreDbRc[Hash256].ok(EMPTY_ROOT_HASH)
|
|
|
|
else: stoTrie.parent.methods.rootHashFn stoTrie
|
|
|
|
result =
|
2023-10-25 14:03:09 +00: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)
|
2024-02-02 20:23:04 +00:00
|
|
|
stoTrie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stoTrie, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
|
|
|
|
proc getTrie*(
|
2023-10-11 19:09:11 +00:00
|
|
|
db: CoreDbRef;
|
2024-02-02 20:23:04 +00:00
|
|
|
kind: CoreDbSubTrie;
|
2023-10-11 19:09:11 +00:00
|
|
|
root: Hash256;
|
2024-02-02 20:23:04 +00:00
|
|
|
address = none(EthAddress);
|
|
|
|
): CoreDbRc[CoreDbTrieRef] =
|
|
|
|
## Retrieve virtual sub-trie descriptor.
|
|
|
|
##
|
|
|
|
## For a sub-trie of type `kind` find the root node with Merkle hash `root`.
|
|
|
|
## If the `root` argument is set `EMPTY_ROOT_HASH`, this function always
|
|
|
|
## succeeds. Otherwise, the function will fail unless a root node with the
|
|
|
|
## corresponding argument Merkle hash `root` exists.
|
2023-10-11 19:09:11 +00:00
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
## For an `EMPTY_ROOT_HASH` root hash argument and a sub-trie of type `kind`
|
|
|
|
## different form `StorageTrie` and `AccuntsTrie`, the returned sub-trie
|
|
|
|
## descriptor will be flagged to flush the sub-trie when this descriptor is
|
|
|
|
## incarnated as MPT (see `newMpt()`.).
|
|
|
|
##
|
|
|
|
## If the argument `kind` is `StorageTrie`, then the `address` argument is
|
|
|
|
## needed which links an account to the result descriptor.
|
|
|
|
##
|
|
|
|
## This function is intended to open a virtual trie database as in:
|
2023-10-11 19:09:11 +00:00
|
|
|
## ::
|
2024-02-02 20:23:04 +00:00
|
|
|
## proc openAccountLedger(db: CoreDbRef, root: Hash256): CoreDxMptRef =
|
|
|
|
## let trie = db.getTrie(AccountsTrie, root).valueOr:
|
2023-10-11 19:09:11 +00:00
|
|
|
## # some error handling
|
|
|
|
## return
|
2024-02-02 20:23:04 +00:00
|
|
|
## db.newAccMpt trie
|
2023-10-11 19:09:11 +00:00
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
db.setTrackNewApi BaseGetTrieFn
|
|
|
|
result = db.methods.getTrieFn(kind, root, address)
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, kind, root, address, result
|
|
|
|
|
|
|
|
proc getTrie*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
root: Hash256;
|
|
|
|
address: EthAddress;
|
|
|
|
): CoreDbRc[CoreDbTrieRef] =
|
|
|
|
## Shortcut for `db.getTrie(StorageTrie,root,some(address))`.
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseGetTrieFn
|
|
|
|
result = db.methods.getTrieFn(StorageTrie, root, some(address))
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, address, result
|
|
|
|
|
|
|
|
proc getTrie*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
address: EthAddress;
|
|
|
|
): CoreDbTrieRef =
|
|
|
|
## Shortcut for `db.getTrie(StorageTrie,EMPTY_ROOT_HASH,address).value`. The
|
|
|
|
## function will throw an exception on error. So the result will always be a
|
|
|
|
## valid descriptor.
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseGetTrieFn
|
|
|
|
result = db.methods.getTrieFn(
|
|
|
|
StorageTrie, EMPTY_ROOT_HASH, some(address)).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 20:46:41 +00:00
|
|
|
# Public key-value table methods
|
2023-07-31 13:43: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 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
|
2024-02-02 20:23:04 +00:00
|
|
|
## are saved to the backend database some time after automatic destruction
|
|
|
|
## when this becomes permissible, i.e. there is a backend available and
|
|
|
|
## there is no pending transaction on the common base object.
|
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
|
|
|
## * `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 20:46:41 +00:00
|
|
|
|
2023-09-26 09:21:13 +00: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 14:03:09 +00: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 20:46:41 +00: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 09:21:13 +00:00
|
|
|
proc del*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtDelFn
|
2023-10-25 14:03:09 +00: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 20:46:41 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc put*(
|
|
|
|
kvt: CoreDxKvtRef;
|
|
|
|
key: openArray[byte];
|
2023-10-25 14:03:09 +00:00
|
|
|
val: openArray[byte];
|
2023-09-26 09:21:13 +00:00
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
kvt.setTrackNewApi KvtPutFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = kvt.methods.putFn(key, val)
|
2023-11-24 22:16:21 +00:00
|
|
|
kvt.ifTrackNewApi:
|
2024-02-02 20:23:04 +00:00
|
|
|
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, result
|
2023-08-02 20:46:41 +00: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 20:46:41 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-08-02 20:46:41 +00:00
|
|
|
# Public Merkle Patricia Tree, hexary trie constructors
|
2023-07-31 13:43: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 newMpt*(
|
|
|
|
db: CoreDbRef;
|
2024-02-02 20:23:04 +00:00
|
|
|
trie: CoreDbTrieRef;
|
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
|
|
|
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] =
|
2024-02-02 20:23:04 +00:00
|
|
|
## MPT sub-trie object incarnation. 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
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
## If the `trie` argument was created for an `EMPTY_ROOT_HASH` sub-trie, the
|
|
|
|
## sub-trie database will be flushed. There is no need to keep the `trie`
|
|
|
|
## argument. It can always be rerieved for this particular incarnation unsing
|
|
|
|
## the function `getTrie()` on this MPT.
|
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
|
|
|
## See the discussion at `newKvt()` for an explanation of the `saveMode`
|
|
|
|
## argument.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewMptFn
|
2024-02-02 20:23:04 +00:00
|
|
|
result = db.methods.newMptFn(trie, prune, saveMode)
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, prune, saveMode, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc newMpt*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
kind: CoreDbSubTrie;
|
|
|
|
address = none(EthAddress);
|
|
|
|
prune = true;
|
|
|
|
saveMode = AutoSave;
|
|
|
|
): CoreDxMptRef =
|
|
|
|
## Shortcut for `newMpt(trie,prune,saveMode)` where the `trie` argument is
|
|
|
|
## `db.getTrie(kind,EMPTY_ROOT_HASH).value`. 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
|
2024-02-02 20:23:04 +00:00
|
|
|
let trie = db.methods.getTrieFn(kind, EMPTY_ROOT_HASH, address).value
|
|
|
|
result = db.methods.newMptFn(trie, prune, 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, 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()
|
2024-02-02 20:23:04 +00:00
|
|
|
acc.ifTrackNewApi:
|
|
|
|
let root = result.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, root
|
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;
|
2024-02-02 20:23:04 +00:00
|
|
|
trie: CoreDbTrieRef;
|
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
|
|
|
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] =
|
2024-02-02 20:23:04 +00:00
|
|
|
## Accounts trie 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
|
|
|
##
|
|
|
|
## Example:
|
|
|
|
## ::
|
2024-02-02 20:23:04 +00:00
|
|
|
## let trie = db.getTrie(AccountsTrie,<some-hash>).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
|
|
|
## ... # No node with <some-hash>
|
|
|
|
## return
|
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
## let acc = db.newAccMpt(trie, saveMode=Shared)
|
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
|
|
|
## ... # 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
|
2024-02-02 20:23:04 +00:00
|
|
|
result = db.methods.newAccFn(trie, prune, saveMode)
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, prune, saveMode, result
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc newAccMpt*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
root = EMPTY_ROOT_HASH;
|
|
|
|
prune = true;
|
|
|
|
saveMode = AutoSave;
|
|
|
|
): CoreDxAccRef =
|
|
|
|
## Simplified version of `newAccMpt()` where the `CoreDbTrieRef` argument is
|
|
|
|
## replaced by a `root` hash argument. This function is sort of a shortcut
|
|
|
|
## for:
|
|
|
|
## ::
|
|
|
|
## let trie = db.getTrie(AccountsTrie, root).value
|
|
|
|
## result = db.newAccMpt(trie, prune, saveMode).value
|
|
|
|
##
|
|
|
|
## and will throw an exception if something goes wrong. The result reference
|
|
|
|
## will alwye be non `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
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseNewAccFn
|
2024-02-02 20:23:04 +00:00
|
|
|
let trie = db.methods.getTrieFn(AccountsTrie, root, none(EthAddress)).valueOr:
|
|
|
|
raiseAssert error.prettyText()
|
|
|
|
result = db.methods.newAccFn(trie, prune, 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()
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode
|
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
|
|
|
|
## Replaces the pre-hashed argument trie `phk` by the non pre-hashed *MPT*.
|
2023-10-11 19:09:11 +00: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 14:03:09 +00:00
|
|
|
result = phk.fromMpt
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = result.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc toPhk*(mpt: CoreDxMptRef): CoreDxPhkRef =
|
|
|
|
## Replaces argument `mpt` by a pre-hashed *MPT*.
|
2023-10-11 19:09:11 +00: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 14:03:09 +00:00
|
|
|
result = mpt.toCoreDxPhkRef
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = result.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie
|
2023-07-31 13:43:38 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
# Public common methods for all hexary trie databases (`mpt`, `phk`, or `acc`)
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
proc isPruning*(dsc: CoreDxTrieRefs): bool =
|
2023-10-11 19:09:11 +00:00
|
|
|
## Getter
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackNewApi AnyIsPruningFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = dsc.methods.isPruningFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc getTrie*(acc: CoreDxAccRef): CoreDbTrieRef =
|
2023-10-11 19:09:11 +00:00
|
|
|
## Getter, result is not `nil`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2024-02-02 20:23:04 +00:00
|
|
|
acc.setTrackNewApi AccGetTrieFn
|
|
|
|
result = acc.methods.getTrieFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc getTrie*(mpt: CoreDxMptRef): CoreDbTrieRef =
|
|
|
|
## Variant of `getTrie()`
|
|
|
|
mpt.setTrackNewApi MptGetTrieFn
|
|
|
|
result = mpt.methods.getTrieFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc getTrie*(phk: CoreDxPhkRef): CoreDbTrieRef =
|
|
|
|
## Variant of `getTrie()`
|
|
|
|
phk.setTrackNewApi PhkGetTrieFn
|
|
|
|
result = phk.methods.getTrieFn()
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
proc persistent*(acc: CoreDxAccRef): CoreDbRc[void] =
|
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()
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc persistent*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `persistent()`
|
|
|
|
phk.setTrackNewApi PhkPersistentFn
|
|
|
|
result = phk.methods.persistentFn()
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
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()
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc forget*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `forget()`
|
|
|
|
phk.setTrackNewApi PhkForgetFn
|
|
|
|
result = phk.methods.forgetFn()
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
# Public generic hexary trie database methods (`mpt` or `phk`)
|
2023-07-31 13:43:38 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc fetch*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
|
|
|
|
## Variant of `fetch()"
|
|
|
|
phk.setTrackNewApi PhkFetchFn
|
|
|
|
result = phk.methods.fetchFn key
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, 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)
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
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)
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc delete*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[void] =
|
|
|
|
mpt.setTrackNewApi MptDeleteFn
|
|
|
|
result = mpt.methods.deleteFn key
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc delete*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[void] =
|
|
|
|
phk.setTrackNewApi PhkDeleteFn
|
|
|
|
result = phk.methods.deleteFn key
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc merge*(
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt: CoreDxMptRef;
|
2023-07-31 13:43:38 +00:00
|
|
|
key: openArray[byte];
|
2023-10-25 14:03:09 +00:00
|
|
|
val: openArray[byte];
|
2023-09-26 09:21:13 +00:00
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackNewApi MptMergeFn
|
|
|
|
result = mpt.methods.mergeFn(key, val)
|
|
|
|
mpt.ifTrackNewApi:
|
2024-02-02 20:23:04 +00:00
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result
|
2023-07-31 13:43:38 +00: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:
|
2024-02-02 20:23:04 +00:00
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackNewApi:
|
|
|
|
let trie = mpt.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc hasPath*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
|
|
## Variant of `hasPath()`
|
|
|
|
phk.setTrackNewApi PhkHasPathFn
|
|
|
|
result = phk.methods.hasPathFn key
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
|
|
|
let trie = phk.methods.getTrieFn()
|
|
|
|
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
2023-10-11 19:09:11 +00: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 14:03:09 +00:00
|
|
|
result = acc.methods.fetchFn address
|
2024-02-02 20:23:04 +00:00
|
|
|
acc.ifTrackNewApi:
|
|
|
|
let stoTrie = if result.isErr: "n/a" else: result.value.stoTrie.prettyText()
|
|
|
|
debug newApiTxt, ctx, elapsed, address, stoTrie, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
|
|
|
proc delete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccDeleteFn
|
2023-10-25 14:03:09 +00: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 19:09:11 +00:00
|
|
|
|
2024-02-12 19:37:00 +00:00
|
|
|
proc stoFlush*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
|
|
|
## Recursively delete all data elements from the storage trie associated to
|
|
|
|
## the account identified by the argument `address`. After successful run,
|
|
|
|
## the storage trie will be empty.
|
|
|
|
##
|
|
|
|
## caveat:
|
|
|
|
## This function has currently no effect on the legacy backend so it must
|
|
|
|
## not be relied upon in general. On the legacy backend, storage tries
|
|
|
|
## might be shared by several accounts whereas they are unique on the
|
|
|
|
## `Aristo` backend.
|
|
|
|
##
|
|
|
|
acc.setTrackNewApi AccStoFlushFn
|
|
|
|
result = acc.methods.stoFlushFn address
|
|
|
|
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc merge*(
|
|
|
|
acc: CoreDxAccRef;
|
|
|
|
account: CoreDbAccount;
|
|
|
|
): CoreDbRc[void] =
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccMergeFn
|
2024-02-02 20:23:04 +00:00
|
|
|
result = acc.methods.mergeFn account
|
|
|
|
acc.ifTrackNewApi:
|
|
|
|
let address = account.address
|
|
|
|
debug newApiTxt, ctx, elapsed, address, result
|
2023-10-11 19:09:11 +00: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 09:21:13 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public transaction related methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc newTransaction*(db: CoreDbRef): CoreDbRc[CoreDxTxRef] =
|
2023-08-02 20:46:41 +00:00
|
|
|
## Constructor
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackNewApi BaseNewTxFn
|
2023-10-25 14:03:09 +00: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 13:43:38 +00:00
|
|
|
|
2023-09-26 09:21:13 +00: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 14:03:09 +00: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 13:43:38 +00:00
|
|
|
|
2023-09-26 09:21:13 +00: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 14:03:09 +00:00
|
|
|
result = tx.methods.rollbackFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2023-09-26 09:21:13 +00: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 14:03:09 +00:00
|
|
|
result = tx.methods.disposeFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2023-09-26 09:21:13 +00: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 14:03:09 +00:00
|
|
|
result = tx.methods.safeDisposeFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
|
2023-08-02 20:46:41 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public tracer methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc newCapture*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
flags: set[CoreDbCaptFlags] = {};
|
|
|
|
): CoreDbRc[CoreDxCaptRef] =
|
2024-03-07 19:24:05 +00:00
|
|
|
## Trace constructor providing an overlay on top of the argument database
|
|
|
|
## `db`. This overlay provides a replacement database handle that can be
|
|
|
|
## retrieved via `db.recorder()` (which can in turn be ovelayed.) While
|
|
|
|
## running the overlay stores data in a log-table which can be retrieved
|
|
|
|
## via `db.logDb()`.
|
|
|
|
##
|
|
|
|
## Caveat:
|
|
|
|
## The original database argument `db` should not be used while the tracer
|
|
|
|
## is active (i.e. exists as overlay). The behaviour for this situation
|
|
|
|
## is undefined and depends on the backend implementation of the tracer.
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseNewCaptureFn
|
|
|
|
result = db.methods.newCaptureFn flags
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc recorder*(cpt: CoreDxCaptRef): CoreDbRef =
|
|
|
|
## Getter, returns a tracer replacement handle to be used as new database.
|
|
|
|
## It records every action like fetch, store, hasKey, hasPath and delete.
|
|
|
|
## This descriptor can be superseded by a new overlay tracer (using
|
|
|
|
## `newCapture()`, again.)
|
|
|
|
##
|
|
|
|
## Caveat:
|
|
|
|
## Unless the desriptor `cpt` referes to the top level overlay tracer, the
|
|
|
|
## result is undefined and depends on the backend implementation of the
|
|
|
|
## tracer.
|
|
|
|
##
|
|
|
|
cpt.setTrackNewApi CptRecorderFn
|
|
|
|
result = cpt.methods.recorderFn()
|
|
|
|
cpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc logDb*(cp: CoreDxCaptRef): TableRef[Blob,Blob] =
|
|
|
|
## Getter, returns the logger table for the overlay tracer database.
|
|
|
|
##
|
|
|
|
## Caveat:
|
|
|
|
## Unless the desriptor `cpt` referes to the top level overlay tracer, the
|
|
|
|
## result is undefined and depends on the backend implementation of the
|
|
|
|
## tracer.
|
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackNewApi CptLogDbFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = cp.methods.logDbFn()
|
2024-03-07 19:24:05 +00:00
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc flags*(cp: CoreDxCaptRef):set[CoreDbCaptFlags] =
|
2023-08-02 20:46:41 +00:00
|
|
|
## Getter
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackNewApi CptFlagsFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = cp.methods.getFlagsFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc forget*(cp: CoreDxCaptRef): CoreDbRc[void] =
|
|
|
|
## Explicitely stop recording the current tracer instance. If this call was
|
|
|
|
## successful, the the database argument `db` used when starting the trace
|
|
|
|
## with `newCapture()` will be fully operational, again. This will also
|
|
|
|
## implicitely take place when the`NIM` garbage collector recycles an
|
|
|
|
## abondoned capture descriptor.
|
|
|
|
##
|
|
|
|
cp.setTrackNewApi CptForgetFn
|
|
|
|
result = cp.methods.forgetFn()
|
|
|
|
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public methods, legacy API
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
when ProvideLegacyAPI:
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
proc parent*(cld: CoreDbChldRefs): CoreDbRef =
|
2023-09-26 09:21:13 +00:00
|
|
|
## Getter, common method for all sub-modules
|
2023-10-25 14:03:09 +00:00
|
|
|
result = cld.distinctBase.parent
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc backend*(dsc: CoreDbChldRefs): auto =
|
2023-12-12 17:47:41 +00:00
|
|
|
dsc.setTrackLegaApi LegaBackendFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = dsc.distinctBase.backend
|
2023-11-24 22:16:21 +00:00
|
|
|
dsc.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
# ----------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc kvt*(db: CoreDbRef): CoreDbKvtRef =
|
2023-09-26 09:21:13 +00:00
|
|
|
## Legacy pseudo constructor, see `toKvt()` for production constructor
|
2023-12-12 17:47:41 +00:00
|
|
|
db.setTrackLegaApi LegaNewKvtFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = db.newKvt().CoreDbKvtRef
|
2023-11-24 22:16:21 +00:00
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-09-26 09:21:13 +00: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 14:03:09 +00: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 14:03:09 +00:00
|
|
|
kvt.ifTrackLegaApi:
|
2024-02-02 20:23:04 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
|
2023-09-26 09:21:13 +00: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 09:21:13 +00:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc toMpt*(phk: CoreDbPhkRef): CoreDbMptRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.setTrackLegaApi LegaToMptFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = phk.distinctBase.toMpt.CoreDbMptRef
|
2023-11-24 22:16:21 +00:00
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
trie = db.methods.getTrieFn(GenericTrie, root, none(EthAddress)).valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
|
|
|
mpt = db.newMpt(trie, prune).valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
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.CoreDbMptRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
result = db.newMpt(GenericTrie, none(EthAddress), prune).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.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prune
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
|
|
|
proc toPhk*(mpt: CoreDbMptRef): CoreDbPhkRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
mpt.setTrackLegaApi LegaToPhkFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = mpt.distinctBase.toPhk.CoreDbPhkRef
|
2023-11-24 22:16:21 +00:00
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
trie = db.methods.getTrieFn(GenericTrie, root, none(EthAddress)).valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
|
|
|
phk = db.newMpt(trie, prune).valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
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.toCoreDxPhkRef.CoreDbPhkRef
|
|
|
|
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
result = db.newMpt(
|
|
|
|
GenericTrie, none(EthAddress), prune).toCoreDxPhkRef.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.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prune
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# ----------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc isPruning*(trie: CoreDbTrieRefs): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
trie.setTrackLegaApi LegaIsPruningFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = trie.distinctBase.isPruning()
|
2023-11-24 22:16:21 +00:00
|
|
|
trie.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 09:21:13 +00: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
|
2024-02-02 20:23:04 +00:00
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-09-26 09:21:13 +00: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:
|
2024-02-02 20:23:04 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 09:21:13 +00: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:
|
2024-02-02 20:23:04 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
|
2023-09-26 09:21:13 +00: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:
|
2024-02-02 20:23:04 +00:00
|
|
|
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-02-02 20:23:04 +00:00
|
|
|
result = mpt.distinctBase.methods.getTrieFn().rootHash.valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
|
|
|
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
|
|
|
proc rootHash*(phk: CoreDbPhkRef): Hash256 =
|
|
|
|
phk.setTrackLegaApi LegaPhkRootHashFn
|
2024-02-02 20:23:04 +00:00
|
|
|
result = phk.distinctBase.methods.getTrieFn().rootHash.valueOr:
|
|
|
|
raiseAssert error.prettyText() & ": " & $ctx
|
|
|
|
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 09:21:13 +00: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 09:21:13 +00:00
|
|
|
|
|
|
|
proc shortTimeReadOnly*(
|
|
|
|
id: CoreDbTxID;
|
|
|
|
action: proc() {.catchRaise.};
|
|
|
|
) {.catchRaise.} =
|
2023-12-12 17:47:41 +00:00
|
|
|
id.setTrackLegaApi LegaShortTimeRoFn
|
2023-09-26 09:21:13 +00: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 09:21:13 +00:00
|
|
|
|
|
|
|
# Delayed exception
|
|
|
|
if oops.isSome:
|
|
|
|
let
|
|
|
|
e = oops.unsafeGet
|
|
|
|
msg = "delayed and reraised" &
|
2024-02-02 20:23:04 +00:00
|
|
|
", name=" & $e.name & ", msg=\"" & e.msg & "\""
|
2023-09-26 09:21:13 +00:00
|
|
|
raise (ref TxWrapperApiError)(msg: msg)
|
2023-11-24 22:16:21 +00:00
|
|
|
id.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-09-26 09:21:13 +00: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 09:21:13 +00: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 09:21:13 +00: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 09:21:13 +00: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 09:21:13 +00: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 09:21:13 +00: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 14:03:09 +00:00
|
|
|
|
|
|
|
proc recorder*(cp: CoreDbCaptRef): CoreDbRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptRecorderFn
|
2024-03-07 19:24:05 +00:00
|
|
|
result = cp.distinctBase.recorder()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2024-03-07 19:24:05 +00:00
|
|
|
proc logDb*(cp: CoreDbCaptRef): TableRef[Blob,Blob] =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptLogDbFn
|
2024-03-07 19:24:05 +00:00
|
|
|
result = cp.distinctBase.logDb()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
|
2023-10-25 14:03:09 +00:00
|
|
|
|
|
|
|
proc flags*(cp: CoreDbCaptRef): set[CoreDbCaptFlags] =
|
2023-12-12 17:47:41 +00:00
|
|
|
cp.setTrackLegaApi LegaCptFlagsFn
|
2023-10-25 14:03:09 +00:00
|
|
|
result = cp.distinctBase.flags()
|
2023-11-24 22:16:21 +00:00
|
|
|
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|