mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-25 03:28:57 +00:00
605739ef4c
* Experimental MP-trie why: Deleting records is a infeasible with the current structure * Added vertex ID recycling management Todo: Provide some unit tests * DB layout update why: Main news is the separation of `Merkel` hashes into an extra table. details: The code fragments cover conversion between compact MPT records and Aristo DB records as well as some rudimentary cache handling for the `Merkel` hashes (i.e. the extra table entries.) todo: Add some simple unit test for the descriptor record (currently used for vertex ID management, only.) * Updated vertex ID recycling management details: added simple unit tests (mainly testing ABI) * docu update
74 lines
2.2 KiB
Nim
74 lines
2.2 KiB
Nim
# Nimbus - Types, data structures and shared utilities used in network sync
|
|
#
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
# http://opensource.org/licenses/MIT)
|
|
# at your option. This file may not be copied, modified, or
|
|
# distributed except according to those terms.
|
|
|
|
import
|
|
std/sequtils,
|
|
eth/common,
|
|
rocksdb,
|
|
../../nimbus/db/kvstore_rocksdb,
|
|
../../nimbus/sync/snap/constants,
|
|
../replay/pp
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public helpers
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc say*(noisy = false; pfx = "***"; args: varargs[string, `$`]) =
|
|
if noisy:
|
|
if args.len == 0:
|
|
echo "*** ", pfx
|
|
elif 0 < pfx.len and pfx[^1] != ' ':
|
|
echo pfx, " ", args.toSeq.join
|
|
else:
|
|
echo pfx, args.toSeq.join
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public iterators
|
|
# ------------------------------------------------------------------------------
|
|
|
|
iterator walkAllDb*(rocky: RocksStoreRef): (int,Blob,Blob) =
|
|
## Walk over all key-value pairs of the database (`RocksDB` only.)
|
|
let
|
|
rop = rocky.store.readOptions
|
|
rit = rocky.store.db.rocksdb_create_iterator(rop)
|
|
defer:
|
|
rit.rocksdb_iter_destroy()
|
|
|
|
rit.rocksdb_iter_seek_to_first()
|
|
var count = -1
|
|
|
|
while rit.rocksdb_iter_valid() != 0:
|
|
count .inc
|
|
|
|
# Read key-value pair
|
|
var
|
|
kLen, vLen: csize_t
|
|
let
|
|
kData = rit.rocksdb_iter_key(addr kLen)
|
|
vData = rit.rocksdb_iter_value(addr vLen)
|
|
|
|
# Fetch data
|
|
let
|
|
key = if kData.isNil: EmptyBlob
|
|
else: kData.toOpenArrayByte(0,int(kLen)-1).toSeq
|
|
value = if vData.isNil: EmptyBlob
|
|
else: vData.toOpenArrayByte(0,int(vLen)-1).toSeq
|
|
|
|
yield (count, key, value)
|
|
|
|
# Update Iterator (might overwrite kData/vdata)
|
|
rit.rocksdb_iter_next()
|
|
# End while
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|