nimbus-eth1/nimbus/db/core_db
Jordan Hrycaj c47f021596
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
..
backend Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
base Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
.gitignore Unified database frontend (#1661) 2023-07-31 14:43:38 +01:00
README.md Unified database frontend integration (#1670) 2023-08-04 12:10:09 +01:00
base.nim Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
core_apps_legacy.nim Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
core_apps_newapi.nim Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
memory_only.nim Core db and aristo updates for destructor and tx logic (#1894) 2023-11-16 19:35:03 +00:00
persistent.nim Add check copyright year linter to CI 2023-11-01 10:41:20 +07:00

README.md

Core database replacement wrapper object

This wrapper replaces the TrieDatabaseRef and its derivatives by the new object CoreDbRef.

Relations to current TrieDatabaseRef implementation

Here are some incomplete translations for objects and constructors.

Object types:

Legacy notation CoreDbRef based replacement
ChainDB (don't use/avoid)
ChainDbRef CoreDbRef
TrieDatabaseRef CoreDbKvtRef
HexaryTrie CoreDbMptRef
SecureHexaryTrie CoreDbPhkRef
DbTransaction CoreDbTxRef
TransactionID CoreDbTxID

Constructors:

Legacy notation CoreDbRef based replacement
trieDB newChainDB("..") newCoreDbRef(LegacyDbPersistent,"..")
newMemoryDB() newCoreDbRef(LegacyDbMemory)
--
initHexaryTrie(db,..) db.mpt(..) (no pruning)
db.mptPrune(..) (w/pruning true/false)
--
initSecureHexaryTrie(db,..) db.phk(..) (no pruning)
db.phkPrune(..) (w/pruning true/false)
--
newCaptureDB(db,memDB) db.capture() (see below)

Usage of the replacement wrapper

Objects pedigree:

    CoreDbRef                   -- base descriptor
     | | | |
     | | | +-- CoreDbMptRef     -- hexary trie instance
     | | | |    :                    :
     | | | +-- CoreDbMptRef     -- hexary trie instance
     | | |
     | | |
     | | +---- CoreDbPhkRef     -- pre-hashed key hexary trie instance
     | | |      :                    :
     | | +---- CoreDbPhkRef     -- pre-hashed key hexary trie instance
     | |
     | |
     | +------ CoreDbKvtRef     -- single static key-value table
     |
     |
     +-------- CoreDbCaptRef    -- tracer support descriptor

Instantiating standard database object descriptors works as follows:

    let
      db = newCoreDbRef(..)           # new base descriptor
      mpt = db.mpt(..)                # hexary trie/Merkle Patricia Tree
      phk = db.phk(..)                # pre-hashed key hexary trie/MPT
      kvt = db.kvt                    # key-value table

Tracer support setup by hiding the current CoreDbRef behind a replacement:

    let
      capture = db.capture()
      db = capture.recorder           # use the recorder in place of db
    ...

    for key,value in capture.recorder.kvt:
     ...                              # process recorded data