2023-09-26 09:21:13 +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-09-26 09:21:13 +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
|
2024-03-07 19:24:05 +00:00
|
|
|
std/tables,
|
2023-09-26 09:21:13 +00:00
|
|
|
eth/common,
|
2024-02-29 21:10:24 +00:00
|
|
|
results,
|
|
|
|
../../aristo/aristo_profile
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# Annotation helpers
|
|
|
|
{.pragma: noRaise, gcsafe, raises: [].}
|
|
|
|
{.pragma: apiRaise, gcsafe, raises: [CoreDbApiError].}
|
|
|
|
|
|
|
|
type
|
|
|
|
CoreDbType* = enum
|
|
|
|
Ooops
|
|
|
|
LegacyDbMemory
|
|
|
|
LegacyDbPersistent
|
2023-11-16 20:53:44 +00:00
|
|
|
AristoDbMemory ## Memory backend emulator
|
|
|
|
AristoDbRocks ## RocksDB backend
|
|
|
|
AristoDbVoid ## No backend
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
const
|
2023-11-16 20:53:44 +00:00
|
|
|
CoreDbPersistentTypes* = {LegacyDbPersistent, AristoDbRocks}
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
type
|
2024-02-29 21:10:24 +00:00
|
|
|
CoreDbProfListRef* = AristoDbProfListRef
|
|
|
|
## Borrowed from `aristo_profile`, only used in profiling mode
|
|
|
|
|
|
|
|
CoreDbProfData* = AristoDbProfData
|
|
|
|
## Borrowed from `aristo_profile`, only used in profiling mode
|
|
|
|
|
2023-10-02 18:05:17 +00:00
|
|
|
CoreDbRc*[T] = Result[T,CoreDbErrorRef]
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbAccount* = object
|
|
|
|
## Generic account representation referencing an *MPT* sub-trie
|
2024-02-02 20:23:04 +00:00
|
|
|
address*: EthAddress ## Reverse reference for storage trie path
|
|
|
|
nonce*: AccountNonce ## Some `uint64` type
|
|
|
|
balance*: UInt256
|
|
|
|
stoTrie*: CoreDbTrieRef ## Implies storage root sub-MPT
|
|
|
|
codeHash*: Hash256
|
2023-10-11 19:09:11 +00:00
|
|
|
|
|
|
|
CoreDbErrorCode* = enum
|
2023-11-08 12:18:32 +00:00
|
|
|
Unset = 0
|
|
|
|
Unspecified
|
2024-03-18 19:40:23 +00:00
|
|
|
|
|
|
|
AccAddrMissing
|
|
|
|
AccNotFound
|
|
|
|
AccTxPending
|
|
|
|
AutoFlushFailed
|
|
|
|
CtxNotFound
|
|
|
|
HashNotAvailable
|
2023-10-11 19:09:11 +00:00
|
|
|
KvtNotFound
|
2023-11-24 22:16:21 +00:00
|
|
|
KvtTxPending
|
2023-10-11 19:09:11 +00:00
|
|
|
MptNotFound
|
2023-11-24 22:16:21 +00:00
|
|
|
MptTxPending
|
2024-03-18 19:40:23 +00:00
|
|
|
NotImplemented
|
|
|
|
RlpException
|
2023-10-11 19:09:11 +00:00
|
|
|
RootNotFound
|
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
|
|
|
RootUnacceptable
|
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
|
|
|
StorageFailed
|
2024-03-18 19:40:23 +00:00
|
|
|
TrieLocked
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbSubTrie* = enum
|
|
|
|
StorageTrie = 0
|
|
|
|
AccountsTrie
|
|
|
|
GenericTrie
|
|
|
|
ReceiptsTrie
|
|
|
|
TxTrie
|
|
|
|
WithdrawalsTrie
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbCaptFlags* {.pure.} = enum
|
|
|
|
PersistPut
|
|
|
|
PersistDel
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
# Sub-descriptor: Misc methods for main descriptor
|
2023-09-26 09:21:13 +00:00
|
|
|
# --------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbBaseBackendFn* = proc(): CoreDbBackendRef {.noRaise.}
|
|
|
|
CoreDbBaseDestroyFn* = proc(flush = true) {.noRaise.}
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbBaseRootHashFn* = proc(
|
|
|
|
trie: CoreDbTrieRef): CoreDbRc[Hash256] {.noRaise.}
|
|
|
|
CoreDbBaseTriePrintFn* = proc(vid: CoreDbTrieRef): string {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbBaseErrorPrintFn* = proc(e: CoreDbErrorRef): string {.noRaise.}
|
|
|
|
CoreDbBaseInitLegaSetupFn* = proc() {.noRaise.}
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDbBaseLevelFn* = proc(): int {.noRaise.}
|
2024-03-18 19:40:23 +00:00
|
|
|
CoreDbBaseNewKvtFn* =
|
|
|
|
proc(sharedTable: bool): CoreDbRc[CoreDxKvtRef] {.noRaise.}
|
|
|
|
CoreDbBaseGetCtxFn* = proc(): CoreDbCtxRef {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbBaseTxBeginFn* = proc(): CoreDbRc[CoreDxTxRef] {.noRaise.}
|
2024-03-07 19:24:05 +00:00
|
|
|
CoreDbBaseNewCaptFn* =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(flgs: set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] {.noRaise.}
|
2024-03-07 19:24:05 +00:00
|
|
|
CoreDbBaseGetCaptFn* = proc(): CoreDbRc[CoreDxCaptRef] {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbBaseFns* = object
|
|
|
|
backendFn*: CoreDbBaseBackendFn
|
|
|
|
destroyFn*: CoreDbBaseDestroyFn
|
2024-02-02 20:23:04 +00:00
|
|
|
rootHashFn*: CoreDbBaseRootHashFn
|
|
|
|
triePrintFn*: CoreDbBaseTriePrintFn
|
2023-10-11 19:09:11 +00:00
|
|
|
errorPrintFn*: CoreDbBaseErrorPrintFn
|
|
|
|
legacySetupFn*: CoreDbBaseInitLegaSetupFn
|
2023-11-24 22:16:21 +00:00
|
|
|
levelFn*: CoreDbBaseLevelFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
# Kvt constructor
|
2024-03-18 19:40:23 +00:00
|
|
|
newKvtFn*: CoreDbBaseNewKvtFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
# MPT context constructor
|
|
|
|
getCtxFn*: CoreDbBaseGetCtxFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
# Transactions constructors
|
|
|
|
beginFn*: CoreDbBaseTxBeginFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
# capture/tracer constructors
|
2024-03-07 19:24:05 +00:00
|
|
|
newCaptureFn*: CoreDbBaseNewCaptFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
# Sub-descriptor: KVT methods
|
|
|
|
# --------------------------------------------------
|
|
|
|
CoreDbKvtBackendFn* = proc(): CoreDbKvtBackendRef {.noRaise.}
|
|
|
|
CoreDbKvtGetFn* = proc(k: openArray[byte]): CoreDbRc[Blob] {.noRaise.}
|
|
|
|
CoreDbKvtDelFn* = proc(k: openArray[byte]): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbKvtPutFn* =
|
|
|
|
proc(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] {.noRaise.}
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDbKvtPersistentFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbKvtForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
|
2023-11-08 12:18:32 +00:00
|
|
|
CoreDbKvtHasKeyFn* = proc(k: openArray[byte]): CoreDbRc[bool] {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
CoreDbKvtFns* = object
|
|
|
|
## Methods for key-value table
|
2023-11-24 22:16:21 +00:00
|
|
|
backendFn*: CoreDbKvtBackendFn
|
|
|
|
getFn*: CoreDbKvtGetFn
|
|
|
|
delFn*: CoreDbKvtDelFn
|
|
|
|
putFn*: CoreDbKvtPutFn
|
|
|
|
hasKeyFn*: CoreDbKvtHasKeyFn
|
|
|
|
persistentFn*: CoreDbKvtPersistentFn
|
|
|
|
forgetFn*: CoreDbKvtForgetFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
# --------------------------------------------------
|
|
|
|
# Sub-descriptor: MPT context methods
|
|
|
|
# --------------------------------------------------
|
|
|
|
CoreDbCtxFromTxFn* =
|
|
|
|
proc(root: Hash256; kind: CoreDbSubTrie): CoreDbRc[CoreDbCtxRef] {.noRaise.}
|
|
|
|
CoreDbCtxSwapFn* = proc(ctx: CoreDbCtxRef): CoreDbCtxRef {.noRaise.}
|
|
|
|
CoreDbCtxNewTrieFn* = proc(
|
|
|
|
trie: CoreDbSubTrie; root: Hash256; address: Option[EthAddress];
|
|
|
|
): CoreDbRc[CoreDbTrieRef] {.noRaise.}
|
|
|
|
CoreDbCtxGetMptFn* = proc(
|
|
|
|
root: CoreDbTrieRef; prune: bool): CoreDbRc[CoreDxMptRef] {.noRaise.}
|
|
|
|
CoreDbCtxGetAccFn* = proc(
|
|
|
|
root: CoreDbTrieRef; prune: bool): CoreDbRc[CoreDxAccRef] {.noRaise.}
|
|
|
|
CoreDbCtxForgetFn* = proc() {.noRaise.}
|
|
|
|
|
|
|
|
CoreDbCtxFns* = object
|
|
|
|
## Methods for context maniulation
|
|
|
|
fromTxFn*: CoreDbCtxFromTxFn
|
|
|
|
swapFn*: CoreDbCtxSwapFn
|
|
|
|
newTrieFn*: CoreDbCtxNewTrieFn
|
|
|
|
getMptFn*: CoreDbCtxGetMptFn
|
|
|
|
getAccFn*: CoreDbCtxGetAccFn
|
|
|
|
forgetFn*: CoreDbCtxForgetFn
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
# Sub-descriptor: MPT context methods
|
|
|
|
# --------------------------------------------------
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# --------------------------------------------------
|
2023-10-11 19:09:11 +00:00
|
|
|
# Sub-descriptor: generic Mpt/hexary trie methods
|
2023-09-26 09:21:13 +00:00
|
|
|
# --------------------------------------------------
|
|
|
|
CoreDbMptBackendFn* = proc(): CoreDbMptBackendRef {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbMptFetchFn* =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[Blob] {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbMptFetchAccountFn* =
|
|
|
|
proc(k: openArray[byte]): CoreDbRc[CoreDbAccount] {.noRaise.}
|
|
|
|
CoreDbMptDeleteFn* =
|
2023-09-26 09:21:13 +00:00
|
|
|
proc(k: openArray[byte]): CoreDbRc[void] {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbMptMergeFn* =
|
|
|
|
proc(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbMptMergeAccountFn* =
|
|
|
|
proc(k: openArray[byte]; v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
|
2023-11-08 12:18:32 +00:00
|
|
|
CoreDbMptHasPathFn* = proc(k: openArray[byte]): CoreDbRc[bool] {.noRaise.}
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbMptGetTrieFn* = proc(): CoreDbTrieRef {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbMptIsPruningFn* = proc(): bool {.noRaise.}
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDbMptPersistentFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbMptForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
CoreDbMptFns* = object
|
|
|
|
## Methods for trie objects
|
2023-10-11 19:09:11 +00:00
|
|
|
backendFn*: CoreDbMptBackendFn
|
|
|
|
fetchFn*: CoreDbMptFetchFn
|
|
|
|
deleteFn*: CoreDbMptDeleteFn
|
|
|
|
mergeFn*: CoreDbMptMergeFn
|
2023-11-08 12:18:32 +00:00
|
|
|
hasPathFn*: CoreDbMptHasPathFn
|
2024-02-02 20:23:04 +00:00
|
|
|
getTrieFn*: CoreDbMptGetTrieFn
|
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
|
|
|
isPruningFn*: CoreDbMptIsPruningFn
|
2023-11-24 22:16:21 +00:00
|
|
|
persistentFn*: CoreDbMptPersistentFn
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
|
|
|
|
# ----------------------------------------------------
|
|
|
|
# Sub-descriptor: Mpt/hexary trie methods for accounts
|
|
|
|
# ------------------------------------------------------
|
|
|
|
CoreDbAccBackendFn* = proc(): CoreDbAccBackendRef {.noRaise.}
|
2024-03-18 19:40:23 +00:00
|
|
|
CoreDbAccGetMptFn* = proc(): CoreDbRc[CoreDxMptRef] {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbAccFetchFn* = proc(k: EthAddress): CoreDbRc[CoreDbAccount] {.noRaise.}
|
|
|
|
CoreDbAccDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
2024-02-12 19:37:00 +00:00
|
|
|
CoreDbAccStoFlushFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbAccMergeFn* = proc(v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
|
2023-11-08 12:18:32 +00:00
|
|
|
CoreDbAccHasPathFn* = proc(k: EthAddress): CoreDbRc[bool] {.noRaise.}
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbAccGetTrieFn* = proc(): CoreDbTrieRef {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbAccIsPruningFn* = proc(): bool {.noRaise.}
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDbAccPersistentFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbAccForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
|
2023-10-11 19:09:11 +00:00
|
|
|
|
|
|
|
CoreDbAccFns* = object
|
|
|
|
## Methods for trie objects
|
|
|
|
backendFn*: CoreDbAccBackendFn
|
2024-03-18 19:40:23 +00:00
|
|
|
getMptFn*: CoreDbAccGetMptFn
|
2023-10-11 19:09:11 +00:00
|
|
|
fetchFn*: CoreDbAccFetchFn
|
|
|
|
deleteFn*: CoreDbAccDeleteFn
|
2024-02-12 19:37:00 +00:00
|
|
|
stoFlushFn*: CoreDbAccStoFlushFn
|
2023-10-11 19:09:11 +00:00
|
|
|
mergeFn*: CoreDbAccMergeFn
|
2023-11-08 12:18:32 +00:00
|
|
|
hasPathFn*: CoreDbAccHasPathFn
|
2024-02-02 20:23:04 +00:00
|
|
|
getTrieFn*: CoreDbAccGetTrieFn
|
2023-10-11 19:09:11 +00:00
|
|
|
isPruningFn*: CoreDbAccIsPruningFn
|
2023-11-24 22:16:21 +00:00
|
|
|
persistentFn*: CoreDbAccPersistentFn
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
# Sub-descriptor: Transaction frame management
|
|
|
|
# --------------------------------------------------
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDbTxLevelFn* = proc(): int {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbTxCommitFn* = proc(applyDeletes: bool): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbTxRollbackFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbTxDisposeFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
CoreDbTxSafeDisposeFn* = proc(): CoreDbRc[void] {.noRaise.}
|
|
|
|
|
|
|
|
CoreDbTxFns* = object
|
2023-11-24 22:16:21 +00:00
|
|
|
levelFn*: CoreDbTxLevelFn
|
2023-09-26 09:21:13 +00:00
|
|
|
commitFn*: CoreDbTxCommitFn
|
|
|
|
rollbackFn*: CoreDbTxRollbackFn
|
|
|
|
disposeFn*: CoreDbTxDisposeFn
|
|
|
|
safeDisposeFn*: CoreDbTxSafeDisposeFn
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
# Sub-descriptor: capture recorder methods
|
|
|
|
# --------------------------------------------------
|
2024-03-07 19:24:05 +00:00
|
|
|
CoreDbCaptRecorderFn* = proc(): CoreDbRef {.noRaise.}
|
|
|
|
CoreDbCaptLogDbFn* = proc(): TableRef[Blob,Blob] {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbCaptFlagsFn* = proc(): set[CoreDbCaptFlags] {.noRaise.}
|
2024-03-07 19:24:05 +00:00
|
|
|
CoreDbCaptForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
CoreDbCaptFns* = object
|
|
|
|
recorderFn*: CoreDbCaptRecorderFn
|
2023-10-11 19:09:11 +00:00
|
|
|
logDbFn*: CoreDbCaptLogDbFn
|
2023-09-26 09:21:13 +00:00
|
|
|
getFlagsFn*: CoreDbCaptFlagsFn
|
2024-03-07 19:24:05 +00:00
|
|
|
forgetFn*: CoreDbCaptForgetFn
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
# --------------------------------------------------
|
|
|
|
# Production descriptors
|
|
|
|
# --------------------------------------------------
|
|
|
|
CoreDbRef* = ref object of RootRef
|
|
|
|
## Database descriptor
|
2024-02-29 21:10:24 +00:00
|
|
|
dbType*: CoreDbType ## Type of database backend
|
|
|
|
trackLegaApi*: bool ## Debugging, support
|
|
|
|
trackNewApi*: bool ## Debugging, support
|
|
|
|
trackLedgerApi*: bool ## Debugging, suggestion for subsequent ledger
|
|
|
|
localDbOnly*: bool ## Debugging, suggestion to ignore async fetch
|
|
|
|
profTab*: CoreDbProfListRef ## Profiling data (if any)
|
|
|
|
ledgerHook*: RootRef ## Debugging/profiling, to be used by ledger
|
2023-10-11 19:09:11 +00:00
|
|
|
methods*: CoreDbBaseFns
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-10-02 18:05:17 +00:00
|
|
|
CoreDbErrorRef* = ref object of RootRef
|
2023-09-26 09:21:13 +00:00
|
|
|
## Generic error object
|
2023-10-11 19:09:11 +00:00
|
|
|
error*: CoreDbErrorCode
|
2023-09-26 09:21:13 +00:00
|
|
|
parent*: CoreDbRef
|
|
|
|
|
|
|
|
CoreDbBackendRef* = ref object of RootRef
|
|
|
|
## Backend wrapper for direct backend access
|
|
|
|
parent*: CoreDbRef
|
|
|
|
|
|
|
|
CoreDbKvtBackendRef* = ref object of RootRef
|
|
|
|
## Backend wrapper for direct backend access
|
|
|
|
parent*: CoreDbRef
|
|
|
|
|
|
|
|
CoreDbMptBackendRef* = ref object of RootRef
|
|
|
|
## Backend wrapper for direct backend access
|
|
|
|
parent*: CoreDbRef
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbAccBackendRef* = ref object of RootRef
|
|
|
|
## Backend wrapper for direct backend access
|
|
|
|
parent*: CoreDbRef
|
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
CoreDxKvtRef* = ref CoreDxKvtObj
|
|
|
|
CoreDxKvtObj* = object of RootObj
|
2023-09-26 09:21:13 +00:00
|
|
|
## Statically initialised Key-Value pair table living in `CoreDbRef`
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbKvtFns
|
|
|
|
|
2024-03-18 19:40:23 +00:00
|
|
|
CoreDbCtxRef* = ref object of RootRef
|
|
|
|
## Context for `CoreDxMptRef` and `CoreDxAccRef`
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbCtxFns
|
|
|
|
|
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
|
|
|
CoreDxMptRef* = ref object of RootRef
|
2023-09-26 09:21:13 +00:00
|
|
|
## Hexary/Merkle-Patricia tree derived from `CoreDbRef`, will be
|
|
|
|
## initialised on-the-fly.
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbMptFns
|
|
|
|
|
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
|
|
|
CoreDxAccRef* = ref object of RootRef
|
2023-10-11 19:09:11 +00:00
|
|
|
## Similar to `CoreDxKvtRef`, only dealing with `CoreDbAccount` data
|
|
|
|
## rather than `Blob` values.
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbAccFns
|
|
|
|
|
2024-02-02 20:23:04 +00:00
|
|
|
CoreDbTrieRef* = ref object of RootRef
|
2023-10-11 19:09:11 +00:00
|
|
|
## Generic state root: `Hash256` for legacy, `VertexID` for Aristo. This
|
|
|
|
## object makes only sense in the context od an *MPT*.
|
|
|
|
parent*: CoreDbRef
|
|
|
|
ready*: bool ## Must be set `true` to enable
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDxPhkRef* = ref object
|
|
|
|
## Similar to `CoreDbMptRef` but with pre-hashed keys. That is, any
|
2023-10-11 19:09:11 +00:00
|
|
|
## argument key for `merge()`, `fetch()` etc. will be hashed first
|
|
|
|
## before being applied.
|
2023-09-26 09:21:13 +00:00
|
|
|
fromMpt*: CoreDxMptRef
|
|
|
|
methods*: CoreDbMptFns
|
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
CoreDxTxRef* = ref object of RootRef
|
2023-09-26 09:21:13 +00:00
|
|
|
## Transaction descriptor derived from `CoreDbRef`
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbTxFns
|
|
|
|
|
|
|
|
CoreDxCaptRef* = ref object
|
|
|
|
## Db transaction tracer derived from `CoreDbRef`
|
|
|
|
parent*: CoreDbRef
|
|
|
|
methods*: CoreDbCaptFns
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|