mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-09 20:06:52 +00:00
5462c05dc6
* Fix copyright year * Show elapsed times with enabled `CoreDb` API tracking * Show elapsed times with enabled `LedgerRef` API tracking * Reorg `CoreDb` auto destructors for `Aristo` DB why: While `Aristo` supports some parallelism for concurrent database access, this comes with a price of management overhead. With a naive approach, the auto-destructor will slow down execution because the ledger and evm treat the database in a shared mode where a DB descriptor is just created and thrown away shortly after. This is reflected in the `Coredb` abstraction layer above `Aristo`/`Kvt` where a few `Shared` type descriptors are cached and a shared reference is returned rather than a disposable new object. * For `CoreDb` support transaction level tracking details: This is mainly an extra for the legacy DB as `Aristo` and `Kvt` support this already. Also return an error on the legacy DB backend when `persistent()` is called while there are transactions pending (the `persistent()` call does nothing otherwise on the legacy backend.) * Clear compiler warnings (remove unused variables etc.)
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