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
|
|
|
# Copyright (c) 2023 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
|
|
|
|
./base_desc
|
|
|
|
|
|
|
|
type
|
|
|
|
EphemMethodsDesc =
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDbBackendRef | CoreDbKvtBackendRef | CoreDbMptBackendRef |
|
|
|
|
CoreDbAccBackendRef | CoreDbVidRef
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
MethodsDesc =
|
2023-10-11 19:09:11 +00:00
|
|
|
CoreDxKvtRef |
|
|
|
|
CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
|
|
|
CoreDxTxRef | CoreDxTxID |
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDxCaptRef
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
ValidateDesc* = MethodsDesc | EphemMethodsDesc | CoreDbErrorRef
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc validateMethodsDesc(base: CoreDbBaseFns) =
|
|
|
|
doAssert not base.backendFn.isNil
|
|
|
|
doAssert not base.destroyFn.isNil
|
|
|
|
doAssert not base.vidHashFn.isNil
|
|
|
|
doAssert not base.errorPrintFn.isNil
|
|
|
|
doAssert not base.legacySetupFn.isNil
|
|
|
|
doAssert not base.getRootFn.isNil
|
|
|
|
doAssert not base.newKvtFn.isNil
|
|
|
|
doAssert not base.newMptFn.isNil
|
|
|
|
doAssert not base.newAccFn.isNil
|
|
|
|
doAssert not base.getIdFn.isNil
|
|
|
|
doAssert not base.beginFn.isNil
|
|
|
|
doAssert not base.captureFn.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
proc validateMethodsDesc(kvt: CoreDbKvtFns) =
|
|
|
|
doAssert not kvt.backendFn.isNil
|
|
|
|
doAssert not kvt.getFn.isNil
|
|
|
|
doAssert not kvt.delFn.isNil
|
|
|
|
doAssert not kvt.putFn.isNil
|
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
|
|
|
doAssert not kvt.destroyFn.isNil
|
2023-11-08 12:18:32 +00:00
|
|
|
doAssert not kvt.hasKeyFn.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
doAssert not kvt.pairsIt.isNil
|
|
|
|
|
|
|
|
proc validateMethodsDesc(fns: CoreDbMptFns) =
|
|
|
|
doAssert not fns.backendFn.isNil
|
2023-10-11 19:09:11 +00:00
|
|
|
doAssert not fns.fetchFn.isNil
|
|
|
|
doAssert not fns.deleteFn.isNil
|
|
|
|
doAssert not fns.mergeFn.isNil
|
2023-11-08 12:18:32 +00:00
|
|
|
doAssert not fns.hasPathFn.isNil
|
2023-10-11 19:09:11 +00:00
|
|
|
doAssert not fns.rootVidFn.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
doAssert not fns.isPruningFn.isNil
|
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
|
|
|
doAssert not fns.destroyFn.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
doAssert not fns.pairsIt.isNil
|
|
|
|
doAssert not fns.replicateIt.isNil
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc validateMethodsDesc(fns: CoreDbAccFns) =
|
|
|
|
doAssert not fns.backendFn.isNil
|
|
|
|
doAssert not fns.fetchFn.isNil
|
|
|
|
doAssert not fns.deleteFn.isNil
|
|
|
|
doAssert not fns.mergeFn.isNil
|
2023-11-08 12:18:32 +00:00
|
|
|
doAssert not fns.hasPathFn.isNil
|
2023-10-11 19:09:11 +00:00
|
|
|
doAssert not fns.rootVidFn.isNil
|
|
|
|
doAssert not fns.isPruningFn.isNil
|
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
|
|
|
doAssert not fns.destroyFn.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
# ------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc validateMethodsDesc(vid: CoreDbVidRef) =
|
|
|
|
doAssert not vid.isNil
|
|
|
|
doAssert not vid.parent.isNil
|
|
|
|
doAssert vid.ready == true
|
|
|
|
|
2023-10-02 18:05:17 +00:00
|
|
|
proc validateMethodsDesc(e: CoreDbErrorRef) =
|
2023-11-08 12:18:32 +00:00
|
|
|
doAssert e.error != CoreDbErrorCode(0)
|
2023-10-02 18:05:17 +00:00
|
|
|
doAssert not e.isNil
|
2023-09-26 09:21:13 +00:00
|
|
|
doAssert not e.parent.isNil
|
|
|
|
|
|
|
|
proc validateMethodsDesc(eph: EphemMethodsDesc) =
|
|
|
|
doAssert not eph.isNil
|
|
|
|
doAssert not eph.parent.isNil
|
2023-10-11 19:09:11 +00:00
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc validateMethodsDesc(kvt: CoreDxKvtRef) =
|
|
|
|
doAssert not kvt.isNil
|
|
|
|
doAssert not kvt.parent.isNil
|
|
|
|
kvt.methods.validateMethodsDesc
|
|
|
|
|
|
|
|
proc validateMethodsDesc(mpt: CoreDxMptRef) =
|
|
|
|
doAssert not mpt.isNil
|
|
|
|
doAssert not mpt.parent.isNil
|
|
|
|
mpt.methods.validateMethodsDesc
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc validateMethodsDesc(acc: CoreDxAccRef) =
|
|
|
|
doAssert not acc.isNil
|
|
|
|
doAssert not acc.parent.isNil
|
|
|
|
acc.methods.validateMethodsDesc
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc validateMethodsDesc(phk: CoreDxPhkRef) =
|
|
|
|
doAssert not phk.isNil
|
|
|
|
doAssert not phk.fromMpt.isNil
|
|
|
|
phk.methods.validateMethodsDesc
|
|
|
|
|
|
|
|
proc validateMethodsDesc(cpt: CoreDxCaptRef) =
|
|
|
|
doAssert not cpt.isNil
|
|
|
|
doAssert not cpt.parent.isNil
|
|
|
|
doAssert not cpt.methods.recorderFn.isNil
|
|
|
|
doAssert not cpt.methods.getFlagsFn.isNil
|
|
|
|
|
|
|
|
proc validateMethodsDesc(tx: CoreDxTxRef) =
|
|
|
|
doAssert not tx.isNil
|
|
|
|
doAssert not tx.parent.isNil
|
|
|
|
doAssert not tx.methods.commitFn.isNil
|
|
|
|
doAssert not tx.methods.rollbackFn.isNil
|
|
|
|
doAssert not tx.methods.disposeFn.isNil
|
|
|
|
doAssert not tx.methods.safeDisposeFn.isNil
|
|
|
|
|
|
|
|
proc validateMethodsDesc(id: CoreDxTxID) =
|
|
|
|
doAssert not id.isNil
|
|
|
|
doAssert not id.parent.isNil
|
|
|
|
doAssert not id.methods.roWrapperFn.isNil
|
|
|
|
|
|
|
|
proc validateMethodsDesc(db: CoreDbRef) =
|
|
|
|
doAssert not db.isNil
|
|
|
|
doAssert db.dbType != CoreDbType(0)
|
|
|
|
db.methods.validateMethodsDesc
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public debugging helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-11 19:09:11 +00:00
|
|
|
proc validate*(dsc: ValidateDesc) =
|
|
|
|
dsc.validateMethodsDesc
|
2023-09-26 09:21:13 +00:00
|
|
|
|
|
|
|
proc validate*(db: CoreDbRef) =
|
|
|
|
db.validateMethodsDesc
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|