From 503dcd40c462328dd65f1aa8032d758f1632bfc8 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Sun, 20 Oct 2024 17:25:12 +0200 Subject: [PATCH] aristo: remove `replicate` (#2758) Not used, not tested, mostly obsolete due to how key table has become a cache --- nimbus/db/aristo/aristo_walk/memory_only.nim | 8 -- nimbus/db/aristo/aristo_walk/persistent.nim | 8 -- nimbus/db/aristo/aristo_walk/walk_private.nim | 13 ---- .../db/core_db/backend/aristo_replicate.nim | 74 ------------------- nimbus/db/core_db/base/api_tracking.nim | 1 - nimbus/db/core_db/base_iterators.nim | 59 ++++++++++----- .../db/core_db/base_iterators_persistent.nim | 61 --------------- nimbus/db/core_db/persistent.nim | 4 +- 8 files changed, 40 insertions(+), 188 deletions(-) delete mode 100644 nimbus/db/core_db/backend/aristo_replicate.nim delete mode 100644 nimbus/db/core_db/base_iterators_persistent.nim diff --git a/nimbus/db/aristo/aristo_walk/memory_only.nim b/nimbus/db/aristo/aristo_walk/memory_only.nim index 08f459af6..377d75701 100644 --- a/nimbus/db/aristo/aristo_walk/memory_only.nim +++ b/nimbus/db/aristo/aristo_walk/memory_only.nim @@ -54,14 +54,6 @@ iterator walkPairs*[T: MemBackendRef|VoidBackendRef]( for (rvid,vtx) in walkPairsImpl[T](db): yield (rvid,vtx) -iterator replicate*[T: MemBackendRef|VoidBackendRef]( - _: type T; - db: AristoDbRef; - ): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] = - ## Variant of `walkPairsImpl()` for legacy applications. - for (rvid,key,vtx,node) in replicateImpl[T](db): - yield (rvid,key,vtx,node) - # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/db/aristo/aristo_walk/persistent.nim b/nimbus/db/aristo/aristo_walk/persistent.nim index 1a2451d73..ced41cac7 100644 --- a/nimbus/db/aristo/aristo_walk/persistent.nim +++ b/nimbus/db/aristo/aristo_walk/persistent.nim @@ -59,14 +59,6 @@ iterator walkPairs*[T: RdbBackendRef]( for (rvid,vtx) in walkPairsImpl[T](db): yield (rvid,vtx) -iterator replicate*[T: RdbBackendRef]( - _: type T; - db: AristoDbRef; - ): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] = - ## Variant of `walkPairsImpl()` for legacy applications. - for (rvid,key,vtx,node) in replicateImpl[T](db): - yield (rvid,key,vtx,node) - # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/db/aristo/aristo_walk/walk_private.nim b/nimbus/db/aristo/aristo_walk/walk_private.nim index c065d661d..110c4bc4b 100644 --- a/nimbus/db/aristo/aristo_walk/walk_private.nim +++ b/nimbus/db/aristo/aristo_walk/walk_private.nim @@ -90,19 +90,6 @@ iterator walkPairsImpl*[T]( if rvid.vid notin seen: yield (rvid,vtx) -iterator replicateImpl*[T]( - db: AristoDbRef; # Database with top layer & backend filter - ): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] = - ## Variant of `walkPairsImpl()` for legacy applications. - for (rvid,vtx) in walkPairsImpl[T](db): - let node = block: - let rc = vtx.toNode(rvid.root, db) - if rc.isOk: - rc.value - else: - NodeRef(nil) - yield (rvid, db.getKey rvid, vtx, node) - # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/db/core_db/backend/aristo_replicate.nim b/nimbus/db/core_db/backend/aristo_replicate.nim deleted file mode 100644 index 950b9bf22..000000000 --- a/nimbus/db/core_db/backend/aristo_replicate.nim +++ /dev/null @@ -1,74 +0,0 @@ -# Nimbus -# Copyright (c) 2023-2024 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. - -## Generic iterator, prototype to be included (rather than imported). Using -## an include file avoids duplicating code because the `T` argument is not -## bound to any object type. Otherwise all object types would be required -## when providing this iterator for import. -## -## This is not wanted here, because the import of a **pesistent** object -## would always require extra linking. - -template valueOrApiError[U,V](rc: Result[U,V]; info: static[string]): U = - rc.valueOr: raise (ref CoreDbApiError)(msg: info) - -template dbType(dsc: CoreDbKvtRef | CoreDbMptRef | CoreDbAccRef): CoreDbType = - dsc.distinctBase.parent.dbType - -# --------------- - -template kvt(dsc: CoreDbKvtRef): KvtDbRef = - dsc.distinctBase.kvt - -template call(api: KvtApiRef; fn: untyped; args: varArgs[untyped]): untyped = - when CoreDbEnableApiJumpTable: - api.fn(args) - else: - fn(args) - -template call(kvt: CoreDbKvtRef; fn: untyped; args: varArgs[untyped]): untyped = - kvt.distinctBase.parent.kvtApi.call(fn, args) - -# --------------- - -template mpt(dsc: CoreDbAccRef | CoreDbMptRef): AristoDbRef = - dsc.distinctBase.mpt - -template call(api: AristoApiRef; fn: untyped; args: varArgs[untyped]): untyped = - when CoreDbEnableApiJumpTable: - api.fn(args) - else: - fn(args) - -template call( - acc: CoreDbAccRef | CoreDbMptRef; - fn: untyped; - args: varArgs[untyped]; - ): untyped = - acc.distinctBase.parent.ariApi.call(fn, args) - -# --------------- - -iterator aristoReplicate[T]( - mpt: CoreDbMptRef; - ): (seq[byte],seq[byte]) - {.gcsafe, raises: [CoreDbApiError].} = - ## Generic iterator used for building dedicated backend iterators. - ## - let p = mpt.call(forkTx, mpt.mpt, 0).valueOrApiError "aristoReplicate()" - defer: discard mpt.call(forget, p) - for (rVid,key,vtx,node) in T.replicate(p): - let w = node.to(seq[seq[byte]]) - yield (@(key.data),w[0]) - if 1 < w.len: - # Was an extension merged into a branch - yield (@(w[1].digestTo(HashKey).data),w[1]) - -# End diff --git a/nimbus/db/core_db/base/api_tracking.nim b/nimbus/db/core_db/base/api_tracking.nim index 8f354bdbb..e33375722 100644 --- a/nimbus/db/core_db/base/api_tracking.nim +++ b/nimbus/db/core_db/base/api_tracking.nim @@ -87,7 +87,6 @@ type MptMergeFn = "mpt/merge" MptProofFn = "mpt/proof" MptPairsIt = "mpt/pairs" - MptReplicateIt = "mpt/replicate" MptStateFn = "mpt/state" TxCommitFn = "commit" diff --git a/nimbus/db/core_db/base_iterators.nim b/nimbus/db/core_db/base_iterators.nim index 996ff5139..d4e3c168a 100644 --- a/nimbus/db/core_db/base_iterators.nim +++ b/nimbus/db/core_db/base_iterators.nim @@ -15,7 +15,6 @@ import eth/common, ../../errors, ../aristo as use_ari, - ../aristo/[aristo_walk, aristo_serialise], ../kvt as use_kvt, ../kvt/[kvt_init/memory_only, kvt_walk], ./base/[api_tracking, base_config, base_desc] @@ -24,12 +23,9 @@ when CoreDbEnableApiJumpTable: discard else: import - ../aristo/[aristo_desc, aristo_path, aristo_tx], + ../aristo/[aristo_desc, aristo_path], ../kvt/[kvt_desc, kvt_tx] -include - ./backend/aristo_replicate - when CoreDbEnableApiTracking: import chronicles @@ -41,6 +37,44 @@ when CoreDbEnableApiTracking: # Annotation helper(s) {.pragma: apiRaise, gcsafe, raises: [CoreDbApiError].} +template valueOrApiError[U,V](rc: Result[U,V]; info: static[string]): U = + rc.valueOr: raise (ref CoreDbApiError)(msg: info) + +template dbType(dsc: CoreDbKvtRef | CoreDbMptRef | CoreDbAccRef): CoreDbType = + dsc.distinctBase.parent.dbType + +# --------------- + +template kvt(dsc: CoreDbKvtRef): KvtDbRef = + dsc.distinctBase.kvt + +template call(api: KvtApiRef; fn: untyped; args: varArgs[untyped]): untyped = + when CoreDbEnableApiJumpTable: + api.fn(args) + else: + fn(args) + +template call(kvt: CoreDbKvtRef; fn: untyped; args: varArgs[untyped]): untyped = + kvt.distinctBase.parent.kvtApi.call(fn, args) + +# --------------- + +template mpt(dsc: CoreDbAccRef | CoreDbMptRef): AristoDbRef = + dsc.distinctBase.mpt + +template call(api: AristoApiRef; fn: untyped; args: varArgs[untyped]): untyped = + when CoreDbEnableApiJumpTable: + api.fn(args) + else: + fn(args) + +template call( + acc: CoreDbAccRef | CoreDbMptRef; + fn: untyped; + args: varArgs[untyped]; + ): untyped = + acc.distinctBase.parent.ariApi.call(fn, args) + # ------------------------------------------------------------------------------ # Public iterators # ------------------------------------------------------------------------------ @@ -89,21 +123,6 @@ iterator slotPairs*(acc: CoreDbAccRef; accPath: Hash32): (seq[byte], UInt256) = acc.ifTrackNewApi: debug logTxt, api, elapsed -iterator replicate*(mpt: CoreDbMptRef): (seq[byte], seq[byte]) {.apiRaise.} = - ## Low level trie dump, only supported for non persistent `CoreDbMptRef` - ## - mpt.setTrackNewApi MptReplicateIt - case mpt.dbType: - of AristoDbMemory: - for k,v in aristoReplicate[use_ari.MemBackendRef](mpt): - yield (k,v) - of AristoDbVoid: - for k,v in aristoReplicate[use_ari.VoidBackendRef](mpt): - yield (k,v) - of Ooops, AristoDbRocks: - raiseAssert: "Unsupported database type: " & $mpt.dbType - mpt.ifTrackNewApi: debug logTxt, api, elapsed - # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/db/core_db/base_iterators_persistent.nim b/nimbus/db/core_db/base_iterators_persistent.nim deleted file mode 100644 index df2b157ec..000000000 --- a/nimbus/db/core_db/base_iterators_persistent.nim +++ /dev/null @@ -1,61 +0,0 @@ -# Nimbus -# Copyright (c) 2024 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. - -{.push raises: [].} - -import - std/typetraits, - eth/common, - ../../errors, - ../aristo as use_ari, - ../aristo/aristo_init/rocks_db, - ../aristo/[aristo_desc, aristo_walk/persistent, aristo_serialise, aristo_tx], - ../kvt, # needed for `aristo_replicate` - ./base/[api_tracking, base_config, base_desc], ./base - -include - ./backend/aristo_replicate - -when CoreDbEnableApiTracking: - import - chronicles - logScope: - topics = "core_db" - const - logTxt = "API" - -# Annotation helper(s) -{.pragma: rlpRaise, gcsafe, raises: [CoreDbApiError].} - -# ------------------------------------------------------------------------------ -# Public iterators -# ------------------------------------------------------------------------------ - -iterator replicatePersistent*(mpt: CoreDbMptRef): (seq[byte], seq[byte]) {.rlpRaise.} = - ## Extended version of `replicate()` for `Aristo` persistent backend. - ## - mpt.setTrackNewApi MptReplicateIt - case mpt.dbType: - of AristoDbMemory: - for k,v in aristoReplicate[use_ari.MemBackendRef](mpt): - yield (k,v) - of AristoDbVoid: - for k,v in aristoReplicate[use_ari.VoidBackendRef](mpt): - yield (k,v) - of AristoDbRocks: - for k, v in aristoReplicate[rocks_db.RdbBackendRef](mpt): - yield (k, v) - else: - raiseAssert: "Unsupported database type: " & $mpt.dbType - mpt.ifTrackNewApi: debug logTxt, api, elapsed - -# ------------------------------------------------------------------------------ -# End -# ------------------------------------------------------------------------------ diff --git a/nimbus/db/core_db/persistent.nim b/nimbus/db/core_db/persistent.nim index c2d2a4092..4f68b556f 100644 --- a/nimbus/db/core_db/persistent.nim +++ b/nimbus/db/core_db/persistent.nim @@ -24,13 +24,11 @@ import ../aristo, ./memory_only, - base_iterators_persistent, ./backend/aristo_rocksdb, ../opts export - memory_only, - base_iterators_persistent + memory_only proc newCoreDbRef*( dbType: static[CoreDbType]; # Database type symbol