nimbus-eth1/nimbus/db/core_db
Jordan Hrycaj 6dc2773957
Only use pre hashed addresses as account keys (#2424)
* Normalised storage tree addressing in function prototypes

detail:
  Argument list is always `<db> <account-path> <slot-path> ..` with
  both path arguments as `openArray[]`

* Remove cruft

* CoreDb internally Use full account paths rather than addresses

* Update API logging

* Use hashed account address only in prototypes

why:
  This avoids unnecessary repeated hashing of the same account address.
  The burden of doing that is upon the application. In the case here,
  the ledger caches all kinds of stuff anyway so it is common sense to
  exploit that for account address hashes.

caveat:
  Using `openArray[byte]` argument types for hashed accounts is inherently
  fragile. In non-release mode, a length verification `doAssert` is
  enabled by default.

* No accPath in data record (use `AristoAccount` as `CoreDbAccount`)

* Remove now unused `eAddr` field from ledger `AccountRef` type

why:
  Is duplicate of lookup key

* Avoid merging the account record/statement in the ledger twice.
2024-06-27 19:21:01 +00:00
..
backend Only use pre hashed addresses as account keys (#2424) 2024-06-27 19:21:01 +00:00
base Only use pre hashed addresses as account keys (#2424) 2024-06-27 19:21:01 +00:00
README.md
TODO.md Aristo resume off line syncing on pre loaded database (#2203) 2024-05-22 13:41:14 +00:00
base.nim Only use pre hashed addresses as account keys (#2424) 2024-06-27 19:21:01 +00:00
base_iterators.nim Only use pre hashed addresses as account keys (#2424) 2024-06-27 19:21:01 +00:00
base_iterators_persistent.nim Only use pre hashed addresses as account keys (#2424) 2024-06-27 19:21:01 +00:00
core_apps.nim Update storage tree admin (#2419) 2024-06-27 09:01:26 +00:00
memory_only.nim Coeredb related clean up and maint fixes (#2360) 2024-06-14 11:19:48 +00:00
persistent.nim Coeredb related clean up and maint fixes (#2360) 2024-06-14 11:19:48 +00: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
     | | |
     | | +--- CoreDbCtxRef           -- MPT context 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 legacy 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