diff --git a/nimbus/db/aristo/aristo_delete/delete_subtree.nim b/nimbus/db/aristo/aristo_delete/delete_subtree.nim index 996703e775..e0afa2bcaa 100644 --- a/nimbus/db/aristo/aristo_delete/delete_subtree.nim +++ b/nimbus/db/aristo/aristo_delete/delete_subtree.nim @@ -12,7 +12,6 @@ import eth/common, - results, ".."/[aristo_desc, aristo_get, aristo_layers], ./delete_helpers @@ -20,13 +19,34 @@ import # Private heplers # ------------------------------------------------------------------------------ -proc collectStoTreeLazily( - db: AristoDbRef; # Database, top layer - rvid: RootedVertexID; # Root vertex - accPath: Hash256; # Accounts cache designator - stoPath: NibblesBuf; # Current storage path +proc delSubTreeNow( + db: AristoDbRef; + rvid: RootedVertexID; + ): Result[void,AristoError] = + ## Delete sub-tree now + let (vtx, _) = db.getVtxRc(rvid).valueOr: + if error == GetVtxNotFound: + return ok() + return err(error) + + if vtx.vType == Branch: + for n in 0..15: + if vtx.bVid[n].isValid: + ? db.delSubTreeNow((rvid.root,vtx.bVid[n])) + + db.disposeOfVtx(rvid) + + ok() + + +proc delStoTreeNow( + db: AristoDbRef; # Database, top layer + rvid: RootedVertexID; # Root vertex + accPath: Hash256; # Accounts cache designator + stoPath: NibblesBuf; # Current storage path ): Result[void,AristoError] = - ## Collect vertex/vid and delete cache entries. + ## Implementation of *delete* sub-trie. + let (vtx, _) = db.getVtxRc(rvid).valueOr: if error == GetVtxNotFound: return ok() @@ -36,7 +56,7 @@ proc collectStoTreeLazily( of Branch: for i in 0..15: if vtx.bVid[i].isValid: - ? db.collectStoTreeLazily( + ? db.delStoTreeNow( (rvid.root, vtx.bVid[i]), accPath, stoPath & vtx.ePfx & NibblesBuf.nibble(byte i)) @@ -44,54 +64,19 @@ proc collectStoTreeLazily( let stoPath = Hash256(data: (stoPath & vtx.lPfx).getBytes()) db.layersPutStoLeaf(AccountKey.mixUp(accPath, stoPath), nil) - # There is no useful approach avoiding to walk the whole tree for updating - # the storage data access cache. - # - # The alternative of stopping here and clearing the whole cache did degrade - # performance significantly in some tests on mainnet when importing `era1`. - # - # The cache it was seen - # * filled up to maximum size most of the time - # * at the same time having no `stoPath` hit at all (so there was nothing - # to be cleared.) - # - ok() - - -proc disposeOfSubTree( - db: AristoDbRef; # Database, top layer - rvid: RootedVertexID; # Root vertex - ) = - ## Evaluate results from `collectSubTreeLazyImpl()` or ftom - ## `collectStoTreeLazyImpl)`. - ## - let vtx = db.getVtxRc(rvid).value[0] - if vtx.vType == Branch: - for n in 0..15: - if vtx.bVid[n].isValid: - db.top.delTree.add (rvid.root,vtx.bVid[n]) - - # Delete top of tree now. db.disposeOfVtx(rvid) + ok() + # ------------------------------------------------------------------------------ # Public functions # ------------------------------------------------------------------------------ proc delSubTreeImpl*( - db: AristoDbRef; # Database, top layer - root: VertexID; # Root vertex + db: AristoDbRef; + root: VertexID; ): Result[void,AristoError] = - ## Delete all the `subRoots`if there are a few, only. Otherwise - ## mark it for deleting later. - discard db.getVtxRc((root,root)).valueOr: - if error == GetVtxNotFound: - return ok() - return err(error) - - db.disposeOfSubTree((root,root)) - - ok() + db.delSubTreeNow (root,root) proc delStoTreeImpl*( @@ -99,17 +84,8 @@ proc delStoTreeImpl*( rvid: RootedVertexID; # Root vertex accPath: Hash256; ): Result[void,AristoError] = - ## Collect vertex/vid and cache entry. - discard db.getVtxRc(rvid).valueOr: - if error == GetVtxNotFound: - return ok() - return err(error) - - ? db.collectStoTreeLazily(rvid, accPath, NibblesBuf()) - - db.disposeOfSubTree(rvid) - - ok() + ## Implementation of *delete* sub-trie. + db.delStoTreeNow(rvid, accPath, NibblesBuf()) # ------------------------------------------------------------------------------ # End diff --git a/nimbus/db/aristo/aristo_delta.nim b/nimbus/db/aristo/aristo_delta.nim index cec172c985..f408a394c9 100644 --- a/nimbus/db/aristo/aristo_delta.nim +++ b/nimbus/db/aristo/aristo_delta.nim @@ -24,26 +24,6 @@ import logScope: topics = "aristo-delta" -# ------------------------------------------------------------------------------ -# Private functions -# ------------------------------------------------------------------------------ - -proc toStr(rvid: RootedVertexID): string = - "$" & rvid.root.uint64.toHex & ":" & rvid.vid.uint64.toHex - -proc delSubTree(db: AristoDbRef; writer: PutHdlRef; rvid: RootedVertexID) = - ## Collect subtrees marked for deletion - let (vtx,_) = db.getVtxRc(rvid).valueOr: - notice "Descending for deletion stopped", rvid=(rvid.toStr), error - return - for vid in vtx.subVids: - db.delSubTree(writer, (rvid.root, vid)) - db.backend.putVtxFn(writer, rvid, VertexRef(nil)) - db.backend.putKeyFn(writer, rvid, VOID_HASH_KEY) - # Make sure the `rvid` is not mentioned here, anymore for further update. - db.balancer.sTab.del rvid - db.balancer.kMap.del rvid - # ------------------------------------------------------------------------------ # Public functions, save to backend # ------------------------------------------------------------------------------ @@ -109,12 +89,6 @@ proc deltaPersistent*( # Store structural single trie entries let writeBatch = ? be.putBegFn() - # This one must come first in order to avoid duplicate `sTree[]` or - # `kMap[]` instructions, in the worst case overwiting previously deleted - # entries. - for rvid in db.balancer.delTree: - db.delSubTree(writeBatch, rvid) - # Now the standard `sTree[]` and `kMap[]` instructions. for rvid, vtx in db.balancer.sTab: be.putVtxFn(writeBatch, rvid, vtx) for rvid, key in db.balancer.kMap: diff --git a/nimbus/db/aristo/aristo_delta/delta_merge.nim b/nimbus/db/aristo/aristo_delta/delta_merge.nim index 8f9c7265d1..c2dc3119ac 100644 --- a/nimbus/db/aristo/aristo_delta/delta_merge.nim +++ b/nimbus/db/aristo/aristo_delta/delta_merge.nim @@ -48,7 +48,6 @@ proc deltaMerge*( result = LayerRef( sTab: lower.sTab, # shallow copy (entries will not be modified) kMap: lower.kMap, - delTree: lower.delTree, accLeaves: lower.accLeaves, stoLeaves: lower.stoLeaves, vTop: upper.vTop) @@ -68,9 +67,6 @@ proc deltaMerge*( if not upper.kMap.hasKey(rvid): upper.kMap[rvid] = key - for rvid in lower.delTree: - upper.delTree.add rvid - for (accPath,leafVtx) in lower.accLeaves.pairs: if not upper.accLeaves.hasKey(accPath): upper.accLeaves[accPath] = leafVtx diff --git a/nimbus/db/aristo/aristo_delta/delta_reverse.nim b/nimbus/db/aristo/aristo_delta/delta_reverse.nim index 2650075584..308e54089d 100644 --- a/nimbus/db/aristo/aristo_delta/delta_reverse.nim +++ b/nimbus/db/aristo/aristo_delta/delta_reverse.nim @@ -97,10 +97,6 @@ proc revFilter*( else: return err((rvid.vid,rc.error)) - # Reverse changes for `delTree[]` list. - for rvid in filter.delTree: - ? db.revSubTree(rev, rvid) - ok(rev) # ------------------------------------------------------------------------------ diff --git a/nimbus/db/aristo/aristo_desc/desc_structural.nim b/nimbus/db/aristo/aristo_desc/desc_structural.nim index a6b58b0647..b1e277ac50 100644 --- a/nimbus/db/aristo/aristo_desc/desc_structural.nim +++ b/nimbus/db/aristo/aristo_desc/desc_structural.nim @@ -124,8 +124,6 @@ type kMap*: Table[RootedVertexID,HashKey] ## Merkle hash key mapping vTop*: VertexID ## Last used vertex ID - delTree*: seq[RootedVertexID] ## Not yet fully deleted sub-trees - accLeaves*: Table[Hash256, VertexRef] ## Account path -> VertexRef stoLeaves*: Table[Hash256, VertexRef] ## Storage path -> VertexRef diff --git a/nimbus/db/aristo/aristo_layers.nim b/nimbus/db/aristo/aristo_layers.nim index 03eb9884ce..b4d8a33dd4 100644 --- a/nimbus/db/aristo/aristo_layers.nim +++ b/nimbus/db/aristo/aristo_layers.nim @@ -171,7 +171,6 @@ func isEmpty*(ly: LayerRef): bool = ## tables are empty. The field `txUid` is ignored, here. ly.sTab.len == 0 and ly.kMap.len == 0 and - ly.delTree.len == 0 and ly.accLeaves.len == 0 and ly.stoLeaves.len == 0 @@ -187,8 +186,6 @@ func layersMergeOnto*(src: LayerRef; trg: var LayerObj) = for (vid,key) in src.kMap.pairs: trg.kMap[vid] = key trg.vTop = src.vTop - for rvid in src.delTree: - trg.delTree.add rvid for (accPath,leafVtx) in src.accLeaves.pairs: trg.accLeaves[accPath] = leafVtx for (mixPath,leafVtx) in src.stoLeaves.pairs: @@ -207,7 +204,6 @@ func layersCc*(db: AristoDbRef; level = high(int)): LayerRef = sTab: layers[0].sTab.dup, # explicit dup for ref values kMap: layers[0].kMap, vTop: layers[^1].vTop, - delTree: layers[0].delTree, accLeaves: layers[0].accLeaves, stoLeaves: layers[0].stoLeaves) @@ -217,8 +213,6 @@ func layersCc*(db: AristoDbRef; level = high(int)): LayerRef = result.sTab[vid] = vtx for (vid,key) in layers[n].kMap.pairs: result.kMap[vid] = key - for rvid in layers[n].delTree: - result.delTree.add rvid for (accPath,vtx) in layers[n].accLeaves.pairs: result.accLeaves[accPath] = vtx for (mixPath,vtx) in layers[n].stoLeaves.pairs: