mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-10 04:15:54 +00:00
6bc55d4e6f
* Kvt: Implemented multi-descriptor access on the same backend why: This behaviour mirrors the one of Aristo and can be used for simultaneous transactions on Aristo + Kvt * Kvt: Update database iterators why: Forgot to run on the top layer first * Kvt: Misc fixes * Aristo, use `openArray[byte]` rather than `Blob` in prototype * Aristo, by default hashify right after cloning descriptor why: Typically, a completed descriptor is expected after cloning. Hashing can be suppressed by argument flag. * Aristo provides `replicate()` iterator, similar to legacy `replicate()` * Aristo API fixes and updates * CoreDB: Rename `legacy_persistent` => `legacy_rocksdb` why: More systematic, will be in line with Aristo DB which might have more than one persistent backends * CoreDB: Prettify API sources why: Better to read and maintain details: Annotating with custom pragmas which cleans up the prototypes * CoreDB: Update MPT/put() prototype allowing `CatchableError` why: Will be needed for Aristo API (legacy is OK with `RlpError`)
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