mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-29 21:45:16 +00:00
0d4ef023ed
* Aristo: Code cosmetics, e.g. update some CamelCase names * CoreDb+Aristo: Provide oldest known state root implied details: The Aristo journal allows to recover earlier but not all state roots. * Aristo: Fix journal backward index operator, e.g. `[^1]` * Aristo: Fix journal updater why: The `fifosStore()` store function slightly misinterpreted the update instructions when translation is to database `put()` functions. The effect was that the journal was ever growing due to stale entries which were never deleted. * CoreDb+Aristo: Provide utils for purging stale data from the KVT details: See earlier patch, not all state roots are available. This patch provides a mapping from some state root to a block number and allows to remove all KVT data related to a particular block number * Aristo+Kvt: Implement a clean up schedule for expired data in KVT why: For a single state ledger like `Aristo`, there is only a limited backlog of states. So KVT data (i.e. headers etc.) are cleaned up regularly * Fix copyright year
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