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
|
|
|
|
chronicles,
|
2023-08-02 20:46:41 +00:00
|
|
|
eth/common,
|
2023-09-26 09:21:13 +00:00
|
|
|
"../.."/[constants, errors],
|
2024-04-19 18:37:27 +00:00
|
|
|
./base/[api_tracking, base_desc]
|
2023-12-12 17:47:41 +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
|
|
|
from ../aristo
|
2024-03-21 10:45:57 +00:00
|
|
|
import EmptyBlob, PayloadRef, isValid
|
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
|
|
|
const
|
|
|
|
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
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbAccount,
|
|
|
|
CoreDbApiError,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbCaptFlags,
|
2024-04-19 18:37:27 +00:00
|
|
|
CoreDbColType,
|
|
|
|
CoreDbColRef,
|
2024-03-18 19:40:23 +00:00
|
|
|
CoreDbCtxRef,
|
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,
|
2024-03-21 10:45:57 +00:00
|
|
|
CoreDbPayloadRef,
|
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,
|
|
|
|
CoreDbType,
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDxAccRef,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDxCaptRef,
|
|
|
|
CoreDxKvtRef,
|
|
|
|
CoreDxMptRef,
|
|
|
|
CoreDxPhkRef,
|
2024-03-21 10:45:57 +00:00
|
|
|
CoreDxTxRef,
|
|
|
|
PayloadRef
|
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
|
|
|
CoreDbEnableApiTracking* = EnableApiTracking
|
|
|
|
CoreDbEnableApiProfiling* = EnableApiTracking and EnableApiProfiling
|
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 "
|
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-04-19 18:37:27 +00:00
|
|
|
proc `$`(v: CoreDbColRef): string = v.toStr
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
proc `$`(h: Hash256): string = h.toStr
|
2023-12-12 17:47:41 +00:00
|
|
|
|
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
|
2024-03-18 19:40:23 +00:00
|
|
|
const api {.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(
|
2024-04-19 18:37:27 +00:00
|
|
|
toMpt: mpt,
|
2023-09-26 09:21:13 +00:00
|
|
|
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 =
|
2024-04-19 18:37:27 +00:00
|
|
|
phk.toMpt.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-04-19 18:37:27 +00:00
|
|
|
proc bless*(db: CoreDbRef; col: CoreDbColRef): CoreDbColRef =
|
2023-10-11 19:09:11 +00:00
|
|
|
## Complete sub-module descriptor, fill in `parent` and actvate it.
|
2024-04-19 18:37:27 +00:00
|
|
|
col.parent = db
|
|
|
|
col.ready = true
|
2023-09-26 09:21:13 +00:00
|
|
|
when AutoValidateDescriptors:
|
2024-04-19 18:37:27 +00:00
|
|
|
col.validate
|
|
|
|
col
|
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
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc bless*[T: CoreDxKvtRef |
|
|
|
|
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
|
|
|
CoreDxTxRef | CoreDxCaptRef |
|
|
|
|
CoreDbKvtBackendRef | CoreDbMptBackendRef](
|
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()
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc prettyText*(col: CoreDbColRef): string =
|
2024-02-02 20:23:04 +00:00
|
|
|
## Pretty print argument object (for tracking use `$$()`)
|
2024-04-19 18:37:27 +00:00
|
|
|
if col.isNil or not col.ready: "$ø" else: col.toStr()
|
2024-02-02 20:23:04 +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
|
2024-03-18 19:40:23 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2023-08-02 20:46:41 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc parent*[T: CoreDxKvtRef |
|
|
|
|
CoreDbColRef |
|
|
|
|
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
|
|
|
CoreDxTxRef |
|
|
|
|
CoreDxCaptRef |
|
|
|
|
CoreDbErrorRef](
|
|
|
|
child: T): CoreDbRef =
|
2023-09-26 09:21:13 +00:00
|
|
|
## Getter, common method for all sub-modules
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
result = child.parent
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc backend*(dsc: CoreDxKvtRef | CoreDxMptRef): auto =
|
2023-10-11 19:09:11 +00:00
|
|
|
## 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()
|
2024-03-18 19:40:23 +00:00
|
|
|
dsc.ifTrackNewApi: debug newApiTxt, api, elapsed
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-06-14 11:19:48 +00:00
|
|
|
proc finish*(db: CoreDbRef; eradicate = false) =
|
|
|
|
## Database destructor. If the argument `eradicate` is set `false`, the
|
|
|
|
## database is left as-is and only the in-memory handlers are cleaned up.
|
2023-10-11 19:09:11 +00:00
|
|
|
##
|
|
|
|
## 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
|
2024-06-14 11:19:48 +00:00
|
|
|
db.methods.destroyFn eradicate
|
2024-03-18 19:40:23 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, 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()
|
2024-03-18 19:40:23 +00:00
|
|
|
e.ifTrackNewApi: debug newApiTxt, api, elapsed, 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
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-05 20:52:04 +00:00
|
|
|
proc newKvt*(db: CoreDbRef): CoreDxKvtRef =
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
## Constructor, will defect on failure.
|
|
|
|
##
|
2024-06-05 20:52:04 +00:00
|
|
|
## This function subscribes to the common base object shared with other
|
|
|
|
## KVT descriptors. Any changes are immediately visible to subscribers.
|
|
|
|
## On destruction (when the constructed object gets out of scope), changes
|
|
|
|
## are not saved to the backend database but are still cached and available.
|
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
|
|
|
db.setTrackNewApi BaseNewKvtFn
|
2024-06-05 20:52:04 +00:00
|
|
|
result = db.methods.newKvtFn().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-06-05 20:52:04 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed
|
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
|
2024-03-18 19:40:23 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, api, 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)
|
2024-03-18 19:40:23 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, api, 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
|
2024-03-18 19:40:23 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, api, 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-03-18 19:40:23 +00:00
|
|
|
debug newApiTxt, api, 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
|
2024-03-18 19:40:23 +00:00
|
|
|
kvt.ifTrackNewApi: debug newApiTxt, api, 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
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2024-03-21 10:45:57 +00:00
|
|
|
# Public Merkle Patricia Tree context constructors and administration
|
2024-03-18 19:40:23 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc ctx*(db: CoreDbRef): CoreDbCtxRef =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Get currently active column context.
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-03-21 10:45:57 +00:00
|
|
|
db.setTrackNewApi BaseNewCtxFn
|
|
|
|
result = db.methods.newCtxFn()
|
2024-03-18 19:40:23 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed
|
|
|
|
|
2024-03-21 10:45:57 +00:00
|
|
|
proc ctxFromTx*(
|
|
|
|
db: CoreDbRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
colState: Hash256;
|
|
|
|
colType = CtAccounts;
|
2024-03-18 19:40:23 +00:00
|
|
|
): CoreDbRc[CoreDbCtxRef] =
|
|
|
|
## Create new context derived from matching transaction of the currently
|
2024-04-19 18:37:27 +00:00
|
|
|
## active column context. For the legacy backend, this function always
|
|
|
|
## returns the currently active context (i.e. the same as `db.ctx()`.)
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-03-21 10:45:57 +00:00
|
|
|
db.setTrackNewApi BaseNewCtxFromTxFn
|
2024-04-19 18:37:27 +00:00
|
|
|
result = db.methods.newCtxFromTxFn(colState, colType)
|
2024-03-21 10:45:57 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2024-03-21 10:45:57 +00:00
|
|
|
proc swapCtx*(db: CoreDbRef; ctx: CoreDbCtxRef): CoreDbCtxRef =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Activate argument context `ctx` and return the previously active column
|
|
|
|
## context. This function goes typically together with `forget()`. A valid
|
|
|
|
## scenario might look like
|
2024-03-21 10:45:57 +00:00
|
|
|
## ::
|
|
|
|
## proc doSomething(db: CoreDbRef; ctx: CoreDbCtxRef) =
|
|
|
|
## let saved = db.swapCtx ctx
|
|
|
|
## defer: db.swapCtx(saved).forget()
|
|
|
|
## ...
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-03-21 10:45:57 +00:00
|
|
|
db.setTrackNewApi BaseSwapCtxFn
|
|
|
|
result = db.methods.swapCtxFn ctx
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed
|
2024-03-18 19:40:23 +00:00
|
|
|
|
|
|
|
proc forget*(ctx: CoreDbCtxRef) =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Dispose `ctx` argument context and related columns created with this
|
|
|
|
## context. This function fails if `ctx` is the default context.
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
|
|
|
ctx.setTrackNewApi CtxForgetFn
|
|
|
|
ctx.methods.forgetFn()
|
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public Merkle Patricia Tree sub-trie abstaction management
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc newColumn*(
|
2024-03-18 19:40:23 +00:00
|
|
|
ctx: CoreDbCtxRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
colType: CoreDbColType;
|
|
|
|
colState: Hash256;
|
2024-06-14 07:31:08 +00:00
|
|
|
address = Opt.none(EthAddress);
|
2024-04-19 18:37:27 +00:00
|
|
|
): CoreDbRc[CoreDbColRef] =
|
|
|
|
## Retrieve a new column descriptor.
|
|
|
|
##
|
|
|
|
## The database is can be viewed as a matrix of rows and columns, potenially
|
|
|
|
## with values at their intersection. A row is identified by a lookup key
|
|
|
|
## and a column is identified by a state hash.
|
|
|
|
##
|
|
|
|
## Additionally, any column has a column type attribute given as `colType`
|
|
|
|
## argument. Only storage columns also have an address attribute which must
|
|
|
|
## be passed as argument `address` when the `colType` argument is `CtStorage`.
|
|
|
|
##
|
|
|
|
## If the state hash argument `colState` is passed as `EMPTY_ROOT_HASH`, this
|
|
|
|
## function always succeeds. The result is the equivalent of a potential
|
|
|
|
## column be incarnated later. If the column type is different from
|
|
|
|
## `CtStorage` and `CtAccounts`, then the returned column descriptor will be
|
|
|
|
## flagged to reset all column data when incarnated as MPT (see `newMpt()`.).
|
|
|
|
##
|
|
|
|
## Otherwise, the function will fail unless a column with the corresponding
|
|
|
|
## argument `colState` identifier exists and can be found on the database.
|
|
|
|
## Note that on a single state database like `Aristo`, the requested column
|
|
|
|
## might exist but is buried in some history journal (which needs an extra
|
|
|
|
## effort to unwrap.)
|
|
|
|
##
|
|
|
|
## This function is intended to open a column on the database as in:
|
2024-03-18 19:40:23 +00:00
|
|
|
## ::
|
2024-04-19 18:37:27 +00:00
|
|
|
## proc openAccountLedger(db: CoreDbRef, colState: Hash256): CoreDxMptRef =
|
|
|
|
## let col = db.ctx.newColumn(CtAccounts, colState).valueOr:
|
2024-03-18 19:40:23 +00:00
|
|
|
## # some error handling
|
|
|
|
## return
|
2024-04-19 18:37:27 +00:00
|
|
|
## db.getAcc col
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
ctx.setTrackNewApi CtxNewColFn
|
|
|
|
result = ctx.methods.newColFn(colType, colState, address)
|
|
|
|
ctx.ifTrackNewApi:
|
|
|
|
debug newApiTxt, api, elapsed, colType, colState, address, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc newColumn*(
|
2024-03-18 19:40:23 +00:00
|
|
|
ctx: CoreDbCtxRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
colState: Hash256;
|
2024-03-18 19:40:23 +00:00
|
|
|
address: EthAddress;
|
2024-04-19 18:37:27 +00:00
|
|
|
): CoreDbRc[CoreDbColRef] =
|
|
|
|
## Shortcut for `ctx.newColumn(CtStorage,colState,some(address))`.
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
ctx.setTrackNewApi CtxNewColFn
|
2024-06-14 07:31:08 +00:00
|
|
|
result = ctx.methods.newColFn(CtStorage, colState, Opt.some(address))
|
2024-04-19 18:37:27 +00:00
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, colState, address, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc newColumn*(
|
2024-03-18 19:40:23 +00:00
|
|
|
ctx: CoreDbCtxRef;
|
|
|
|
address: EthAddress;
|
2024-04-19 18:37:27 +00:00
|
|
|
): CoreDbColRef =
|
|
|
|
## Shortcut for `ctx.newColumn(EMPTY_ROOT_HASH,address).value`. The function
|
2024-03-18 19:40:23 +00:00
|
|
|
## will throw an exception on error. So the result will always be a valid
|
|
|
|
## descriptor.
|
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
ctx.setTrackNewApi CtxNewColFn
|
|
|
|
result = ctx.methods.newColFn(
|
2024-06-14 07:31:08 +00:00
|
|
|
CtStorage, EMPTY_ROOT_HASH, Opt.some(address)).valueOr:
|
2024-03-18 19:40:23 +00:00
|
|
|
raiseAssert error.prettyText()
|
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
|
|
|
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc `$$`*(col: CoreDbColRef): string =
|
|
|
|
## Pretty print the column descriptor. Note that this directive may have side
|
2024-03-18 19:40:23 +00:00
|
|
|
## effects as it calls a backend function.
|
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
#col.setTrackNewApi ColPrintFn
|
|
|
|
result = col.prettyText()
|
|
|
|
#col.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2024-06-17 13:29:07 +00:00
|
|
|
proc stateEmpty*(col: CoreDbColRef): CoreDbRc[bool] =
|
|
|
|
## Getter (well, sort of). It retrieves the column state hash for the
|
|
|
|
## argument `col` descriptor. The function might fail unless the current
|
|
|
|
## state is available (e.g. on `Aristo`.)
|
|
|
|
##
|
|
|
|
## The value `EMPTY_ROOT_HASH` is returned on the void `col` descriptor
|
|
|
|
## argument `CoreDbColRef(nil)`.
|
|
|
|
##
|
|
|
|
col.setTrackNewApi BaseColStateEmptyFn
|
|
|
|
result = block:
|
|
|
|
if not col.isNil and col.ready:
|
|
|
|
col.parent.methods.colStateEmptyFn col
|
|
|
|
else:
|
|
|
|
ok true
|
|
|
|
# Note: tracker will be silent if `vid` is NIL
|
|
|
|
col.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc state*(col: CoreDbColRef): CoreDbRc[Hash256] =
|
|
|
|
## Getter (well, sort of). It retrieves the column state hash for the
|
|
|
|
## argument `col` descriptor. The function might fail unless the current
|
|
|
|
## state is available (e.g. on `Aristo`.)
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
## The value `EMPTY_ROOT_HASH` is returned on the void `col` descriptor
|
|
|
|
## argument `CoreDbColRef(nil)`.
|
2024-03-18 19:40:23 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
col.setTrackNewApi BaseColStateFn
|
2024-03-18 19:40:23 +00:00
|
|
|
result = block:
|
2024-04-19 18:37:27 +00:00
|
|
|
if not col.isNil and col.ready:
|
|
|
|
col.parent.methods.colStateFn col
|
2024-03-18 19:40:23 +00:00
|
|
|
else:
|
|
|
|
ok EMPTY_ROOT_HASH
|
|
|
|
# Note: tracker will be silent if `vid` is NIL
|
2024-04-19 18:37:27 +00:00
|
|
|
col.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc stateOrVoid*(col: CoreDbColRef): Hash256 =
|
|
|
|
## Convenience wrapper, returns `EMPTY_ROOT_HASH` where `state()` would fail.
|
|
|
|
col.state.valueOr: EMPTY_ROOT_HASH
|
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
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
proc getMpt*(
|
|
|
|
ctx: CoreDbCtxRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
col: CoreDbColRef;
|
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-06-05 20:52:04 +00:00
|
|
|
## Get an MPT sub-trie view.
|
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-04-19 18:37:27 +00:00
|
|
|
## If the `col` argument descriptor was created for an `EMPTY_ROOT_HASH`
|
|
|
|
## column state of type different form `CtStorage` or `CtAccounts`, all
|
|
|
|
## column will be flushed. There is no need to hold the `col` argument for
|
|
|
|
## later use. It can always be rerieved for this particular MPT using the
|
|
|
|
## function `getColumn()`.
|
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-03-18 19:40:23 +00:00
|
|
|
ctx.setTrackNewApi CtxGetMptFn
|
2024-06-05 20:52:04 +00:00
|
|
|
result = ctx.methods.getMptFn col
|
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
proc getMpt*(
|
|
|
|
ctx: CoreDbCtxRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
colType: CoreDbColType;
|
2024-06-14 07:31:08 +00:00
|
|
|
address = Opt.none(EthAddress);
|
2024-02-02 20:23:04 +00:00
|
|
|
): CoreDxMptRef =
|
2024-06-05 20:52:04 +00:00
|
|
|
## Shortcut for `getMpt(col)` where the `col` argument is
|
2024-04-19 18:37:27 +00:00
|
|
|
## `db.getColumn(colType,EMPTY_ROOT_HASH).value`. This function will always
|
2024-02-02 20:23:04 +00:00
|
|
|
## return a non-nil descriptor or throw an exception.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2024-03-18 19:40:23 +00:00
|
|
|
ctx.setTrackNewApi CtxGetMptFn
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = ctx.methods.newColFn(colType, EMPTY_ROOT_HASH, address).value
|
2024-06-05 20:52:04 +00:00
|
|
|
result = ctx.methods.getMptFn(col).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-06-05 20:52:04 +00:00
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, colType, elapsed
|
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
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
proc getMpt*(acc: CoreDxAccRef): CoreDxMptRef =
|
|
|
|
## Variant of `getMpt()`, 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
|
|
|
##
|
2024-03-18 19:40:23 +00:00
|
|
|
## The needed sub-trie information is taken/implied from the current `acc`
|
|
|
|
## argument.
|
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
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
acc.setTrackNewApi AccToMptFn
|
2024-03-18 19:40:23 +00:00
|
|
|
result = acc.methods.getMptFn().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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let colState = result.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, colState
|
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
|
|
|
|
2024-03-22 17:31:56 +00:00
|
|
|
proc getAcc*(
|
2024-03-18 19:40:23 +00:00
|
|
|
ctx: CoreDbCtxRef;
|
2024-04-19 18:37:27 +00:00
|
|
|
col: CoreDbColRef;
|
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-06-05 20:52:04 +00:00
|
|
|
## Accounts trie constructor, will defect on failure.
|
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-04-19 18:37:27 +00:00
|
|
|
## let col = db.getColumn(CtAccounts,<some-hash>).valueOr:
|
2024-03-22 17:31:56 +00:00
|
|
|
## ... # No node available with <some-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
|
|
|
## return
|
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
## let acc = db.getAccMpt(col)
|
|
|
|
## ... # Was not the state root for the accounts column
|
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
|
|
|
## return
|
|
|
|
##
|
2024-03-18 19:40:23 +00:00
|
|
|
## This function works similar to `getMpt()` for handling accounts. Although
|
2024-04-19 18:37:27 +00:00
|
|
|
## one can emulate this function by means of `getMpt(..).toPhk()`, it is
|
|
|
|
## recommended using `CoreDxAccRef` methods for accounts.
|
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-03-22 17:31:56 +00:00
|
|
|
ctx.setTrackNewApi CtxGetAccFn
|
2024-06-05 20:52:04 +00:00
|
|
|
result = ctx.methods.getAccFn col
|
|
|
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, 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
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Replaces the pre-hashed argument column `phk` by the non pre-hashed *MPT*.
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
phk.setTrackNewApi PhkToMptFn
|
2024-04-19 18:37:27 +00:00
|
|
|
result = phk.toMpt
|
2024-02-02 20:23:04 +00:00
|
|
|
phk.ifTrackNewApi:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = result.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col
|
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-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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = result.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col
|
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
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc getColumn*(acc: CoreDxAccRef): CoreDbColRef =
|
2023-10-11 19:09:11 +00:00
|
|
|
## Getter, result is not `nil`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
acc.setTrackNewApi AccGetColFn
|
|
|
|
result = acc.methods.getColFn()
|
2024-03-18 19:40:23 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc getColumn*(mpt: CoreDxMptRef): CoreDbColRef =
|
|
|
|
## Variant of `getColumn()`
|
|
|
|
##
|
|
|
|
mpt.setTrackNewApi MptGetColFn
|
|
|
|
result = mpt.methods.getColFn()
|
2024-03-18 19:40:23 +00:00
|
|
|
mpt.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2023-12-12 17:47:41 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc getColumn*(phk: CoreDxPhkRef): CoreDbColRef =
|
|
|
|
## Variant of `getColumn()`
|
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-04-19 18:37:27 +00:00
|
|
|
phk.setTrackNewApi PhkGetColFn
|
|
|
|
result = phk.methods.getColFn()
|
|
|
|
phk.ifTrackNewApi: debug newApiTxt, api, elapsed, 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] =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Fetch data from the argument `mpt`. The function always returns a
|
2023-11-08 12:18:32 +00:00
|
|
|
## 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = mpt.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = phk.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = mpt.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = phk.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = mpt.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = phk.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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-04-19 18:37:27 +00:00
|
|
|
let col = mpt.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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-04-19 18:37:27 +00:00
|
|
|
let col = phk.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = mpt.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let col = phk.methods.getColFn()
|
|
|
|
debug newApiTxt, api, elapsed, col, 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:
|
2024-04-19 18:37:27 +00:00
|
|
|
let storage = if result.isErr: "n/a" else: result.value.storage.prettyText()
|
|
|
|
debug newApiTxt, api, elapsed, address, storage, result
|
2024-03-18 19:40:23 +00:00
|
|
|
|
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
|
2024-03-18 19:40:23 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2024-06-14 11:19:48 +00:00
|
|
|
proc stoDelete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
2024-02-12 19:37:00 +00:00
|
|
|
## 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.
|
|
|
|
##
|
2024-03-18 19:40:23 +00:00
|
|
|
## Caveat:
|
|
|
|
## This function has 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.
|
2024-02-12 19:37:00 +00:00
|
|
|
##
|
2024-06-14 11:19:48 +00:00
|
|
|
acc.setTrackNewApi AccStoDeleteFn
|
|
|
|
result = acc.methods.stoDeleteFn address
|
2024-03-18 19:40:23 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
|
|
|
|
2024-02-12 19:37:00 +00:00
|
|
|
|
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
|
2024-03-18 19:40:23 +00:00
|
|
|
debug newApiTxt, api, 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
|
2024-03-18 19:40:23 +00:00
|
|
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
|
|
|
|
|
|
|
|
|
|
|
proc recast*(statement: CoreDbAccount): CoreDbRc[Account] =
|
|
|
|
## Convert the argument `statement` to the portable Ethereum representation
|
2024-04-19 18:37:27 +00:00
|
|
|
## of an account statement. This conversion may fail if the storage colState
|
2024-03-18 19:40:23 +00:00
|
|
|
## hash (see `hash()` above) is currently unavailable.
|
|
|
|
##
|
|
|
|
## Note:
|
|
|
|
## With the legacy backend, this function always succeeds.
|
|
|
|
##
|
2024-04-19 18:37:27 +00:00
|
|
|
let storage = statement.storage
|
|
|
|
storage.setTrackNewApi EthAccRecastFn
|
2024-03-18 19:40:23 +00:00
|
|
|
let rc =
|
2024-04-19 18:37:27 +00:00
|
|
|
if storage.isNil or not storage.ready: CoreDbRc[Hash256].ok(EMPTY_ROOT_HASH)
|
|
|
|
else: storage.parent.methods.colStateFn storage
|
2024-03-18 19:40:23 +00:00
|
|
|
result =
|
|
|
|
if rc.isOk:
|
|
|
|
ok Account(
|
|
|
|
nonce: statement.nonce,
|
|
|
|
balance: statement.balance,
|
|
|
|
codeHash: statement.codeHash,
|
|
|
|
storageRoot: rc.value)
|
|
|
|
else:
|
|
|
|
err(rc.error)
|
2024-04-19 18:37:27 +00:00
|
|
|
storage.ifTrackNewApi: debug newApiTxt, api, elapsed, storage, result
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public transaction related methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc level*(db: CoreDbRef): int =
|
|
|
|
## Retrieve transaction level (zero if there is no pending transaction).
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BaseLevelFn
|
|
|
|
result = db.methods.levelFn()
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
|
|
|
|
2024-04-29 20:17:17 +00:00
|
|
|
proc persistent*(
|
|
|
|
db: CoreDbRef;
|
2024-06-13 18:15:11 +00:00
|
|
|
): CoreDbRc[void] =
|
2024-04-19 18:37:27 +00:00
|
|
|
## For the legacy database, this function has no effect and succeeds always.
|
|
|
|
## It will nevertheless return a discardable error if there is a pending
|
|
|
|
## transaction (i.e. `db.level() == 0`.)
|
|
|
|
##
|
|
|
|
## Otherwise, cached data from the `Kvt`, `Mpt`, and `Acc` descriptors are
|
|
|
|
## stored on the persistent database (if any). This requires that that there
|
|
|
|
## is no transaction pending.
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BasePersistentFn
|
2024-06-14 07:31:08 +00:00
|
|
|
result = db.methods.persistentFn Opt.none(BlockNumber)
|
2024-04-19 18:37:27 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
|
|
|
|
2024-04-29 20:17:17 +00:00
|
|
|
proc persistent*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
blockNumber: BlockNumber;
|
|
|
|
): CoreDbRc[void] {.discardable.} =
|
|
|
|
## Variant of `persistent()` which stores a block number within the recovery
|
|
|
|
## journal record. This recoed will be addressable by the `blockNumber` (e.g.
|
|
|
|
## for recovery.) The argument block number `blockNumber` must be greater
|
|
|
|
## than all previously stored block numbers.
|
|
|
|
##
|
|
|
|
## The function is intended to be used in a way so hat the argument block
|
|
|
|
## number `blockNumber` is associated with the state root to be recovered
|
|
|
|
## from a particular journal entry. This means that the correct block number
|
|
|
|
## will be the one of the state *before* a state change takes place. Using
|
|
|
|
## it that way, `pesistent()` must only be run after some blocks were fully
|
|
|
|
## executed.
|
|
|
|
##
|
|
|
|
## Example:
|
|
|
|
## ::
|
|
|
|
## # Save block number for the current state
|
|
|
|
## let stateBlockNumber = db.getCanonicalHead().blockNumber
|
|
|
|
## ..
|
|
|
|
## # Process blocks
|
|
|
|
## ..
|
|
|
|
## db.persistent(stateBlockNumber)
|
|
|
|
##
|
|
|
|
db.setTrackNewApi BasePersistentFn
|
2024-06-14 07:31:08 +00:00
|
|
|
result = db.methods.persistentFn Opt.some(blockNumber)
|
2024-04-29 20:17:17 +00:00
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, blockNumber, result
|
|
|
|
|
2024-06-05 20:52:04 +00:00
|
|
|
proc newTransaction*(db: CoreDbRef): 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:
|
2024-06-05 20:52:04 +00:00
|
|
|
debug newApiTxt, api, elapsed, newLevel=db.methods.levelFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
proc level*(tx: CoreDxTxRef): int =
|
2024-04-19 18:37:27 +00:00
|
|
|
## Print positive transaction level for argument `tx`
|
2023-11-24 22:16:21 +00:00
|
|
|
##
|
2023-12-12 17:47:41 +00:00
|
|
|
tx.setTrackNewApi TxLevelFn
|
2023-11-24 22:16:21 +00:00
|
|
|
result = tx.methods.levelFn()
|
2024-03-18 19:40:23 +00:00
|
|
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2024-06-05 20:52:04 +00:00
|
|
|
proc commit*(tx: CoreDxTxRef) =
|
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()
|
2024-06-05 20:52:04 +00:00
|
|
|
tx.methods.commitFn()
|
|
|
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2024-06-05 20:52:04 +00:00
|
|
|
proc rollback*(tx: CoreDxTxRef) =
|
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()
|
2024-06-05 20:52:04 +00:00
|
|
|
tx.methods.rollbackFn()
|
|
|
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
2023-07-31 13:43:38 +00:00
|
|
|
|
2024-06-05 20:52:04 +00:00
|
|
|
proc dispose*(tx: CoreDxTxRef) =
|
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()
|
2024-06-05 20:52:04 +00:00
|
|
|
tx.methods.disposeFn()
|
|
|
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
2023-08-02 20:46:41 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public tracer methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-18 11:14:02 +00:00
|
|
|
when false: # currently disabled
|
|
|
|
proc newCapture*(
|
|
|
|
db: CoreDbRef;
|
|
|
|
flags: set[CoreDbCaptFlags] = {};
|
|
|
|
): CoreDbRc[CoreDxCaptRef] =
|
|
|
|
## 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
|
|
|
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
|
|
|
|
|
|
|
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, api, elapsed
|
|
|
|
|
|
|
|
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.
|
|
|
|
##
|
|
|
|
cp.setTrackNewApi CptLogDbFn
|
|
|
|
result = cp.methods.logDbFn()
|
|
|
|
cp.ifTrackNewApi: debug newApiTxt, api, elapsed
|
|
|
|
|
|
|
|
proc flags*(cp: CoreDxCaptRef):set[CoreDbCaptFlags] =
|
|
|
|
## Getter
|
|
|
|
##
|
|
|
|
cp.setTrackNewApi CptFlagsFn
|
|
|
|
result = cp.methods.getFlagsFn()
|
|
|
|
cp.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
|
|
|
|
|
|
|
proc forget*(cp: CoreDxCaptRef) =
|
|
|
|
## Explicitely stop recording the current tracer instance and reset to
|
|
|
|
## previous level.
|
|
|
|
##
|
|
|
|
cp.setTrackNewApi CptForgetFn
|
|
|
|
cp.methods.forgetFn()
|
|
|
|
cp.ifTrackNewApi: debug newApiTxt, api, elapsed
|
2024-03-07 19:24:05 +00:00
|
|
|
|
2023-07-31 13:43:38 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|