Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified database frontend #1661

Merged
merged 8 commits into from
Jul 31, 2023
Merged
Prev Previous commit
Next Next commit
Allow pairs() iterator on all memory based key-value tables
why:
  Previously only available for capture recorder.
  • Loading branch information
mjfh committed Jul 31, 2023
commit bd289b0a9db3ee46862ccadae2fc8a8346009640
14 changes: 7 additions & 7 deletions nimbus/db/core_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ logScope:
template logTxt(info: static[string]): static[string] =
"ChainDB " & info

proc itNotImplemented(db: CoreDbRef, name: string) {.used.} =
proc itNotImplemented(db: CoreDbRef|CoreDbKvtRef, name: string) {.used.} =
debug logTxt "iterator not implemented", dbType=db.dbType, meth=name

proc tmplNotImplemented*(db: CoreDbRef, name: string) {.used.} =
Expand Down Expand Up @@ -136,15 +136,15 @@ template shortTimeReadOnly*(db: CoreDbRef; id: CoreDbTxID; body: untyped) =
# ------------------------------------------------------------------------------

iterator pairs*(
db: CoreDbCaptRef;
db: CoreDbKvtRef;
): (Blob, Blob)
{.gcsafe, raises: [RlpError].} =
case db.parent.dbType:
of LegacyDbMemory, LegacyDbPersistent:
for k,v in db.LegacyCoreDbCaptRef:
{.gcsafe.} =
case db.dbType:
of LegacyDbMemory:
for k,v in db.LegacyCoreDbKvtRef:
yield (k,v)
else:
db.parent.itNotImplemented "pairs/capt"
db.itNotImplemented "pairs/kvt"

iterator pairs*(
db: CoreDbMptRef;
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/core_db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ Usage of the replacement wrapper
db = capture.recorder # use the recorder in place of db
...

for key,value in capture: # process recorded data
...
for key,value in capture.recorder.kvt:
... # process recorded data
18 changes: 7 additions & 11 deletions nimbus/db/core_db/legacy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@

import
std/options,
chronicles,
eth/[common, rlp, trie/db, trie/hexary],
results,
../../constants,
../select_backend,
./base

logScope:
topics = "core_db-legacy"

type
LegacyCoreDbRef* = ref object of CoreDbRef
backend: ChainDB
Expand Down Expand Up @@ -147,13 +143,6 @@ method recorder*(
): CoreDbRef =
db.appDb

iterator pairs*(
db: LegacyCoreDbCaptRef;
): (Blob, Blob)
{.gcsafe, raises: [RlpError].} =
for k,v in db.recorder.pairsInMemoryDB:
yield (k,v)

# ------------------------------------------------------------------------------
# Public key-value table methods
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -189,6 +178,13 @@ method contains*(
): bool =
db.db.contains key

iterator pairs*(
db: LegacyCoreDbKvtRef;
): (Blob, Blob)
{.gcsafe.} =
for k,v in db.db.pairsInMemoryDB:
yield (k,v)

# ------------------------------------------------------------------------------
# Public hexary trie methods
# ------------------------------------------------------------------------------
Expand Down
Loading