2023-06-02 19:21:46 +00:00
|
|
|
# nimbus-eth1
|
2024-02-01 21:27:48 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-06-02 19:21:46 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
## Aristo DB -- Patricia Trie delete funcionality
|
|
|
|
## ==============================================
|
|
|
|
##
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2024-07-03 20:21:57 +00:00
|
|
|
std/typetraits,
|
2024-06-22 20:33:37 +00:00
|
|
|
eth/common,
|
2023-09-12 18:45:12 +00:00
|
|
|
results,
|
2024-08-14 08:54:44 +00:00
|
|
|
./aristo_delete/[delete_helpers, delete_subtree],
|
2024-06-27 09:01:26 +00:00
|
|
|
"."/[aristo_desc, aristo_fetch, aristo_get, aristo_hike, aristo_layers,
|
2024-08-12 20:56:15 +00:00
|
|
|
aristo_utils]
|
2023-06-02 19:21:46 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-06-30 22:22:33 +00:00
|
|
|
# Private heplers
|
2023-06-02 19:21:46 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc branchStillNeeded(vtx: VertexRef): Result[int,void] =
|
|
|
|
## Returns the nibble if there is only one reference left.
|
|
|
|
var nibble = -1
|
2023-06-02 19:21:46 +00:00
|
|
|
for n in 0 .. 15:
|
2023-06-12 13:48:47 +00:00
|
|
|
if vtx.bVid[n].isValid:
|
2023-06-30 22:22:33 +00:00
|
|
|
if 0 <= nibble:
|
|
|
|
return ok(-1)
|
|
|
|
nibble = n
|
|
|
|
if 0 <= nibble:
|
|
|
|
return ok(nibble)
|
|
|
|
# Oops, degenerated branch node
|
|
|
|
err()
|
2023-06-02 19:21:46 +00:00
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-06-02 19:21:46 +00:00
|
|
|
proc deleteImpl(
|
2023-07-04 18:24:03 +00:00
|
|
|
db: AristoDbRef; # Database, top layer
|
2023-06-02 19:21:46 +00:00
|
|
|
hike: Hike; # Fully expanded path
|
2024-07-14 17:12:10 +00:00
|
|
|
): Result[void,AristoError] =
|
2023-06-02 19:21:46 +00:00
|
|
|
## Implementation of *delete* functionality.
|
2023-12-12 17:47:41 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
# Remove leaf entry
|
2023-06-30 22:22:33 +00:00
|
|
|
let lf = hike.legs[^1].wp
|
|
|
|
if lf.vtx.vType != Leaf:
|
2024-07-14 17:12:10 +00:00
|
|
|
return err(DelLeafExpexted)
|
2023-08-07 17:45:23 +00:00
|
|
|
|
2024-07-04 13:46:52 +00:00
|
|
|
db.disposeOfVtx((hike.root, lf.vid))
|
2023-06-30 22:22:33 +00:00
|
|
|
|
|
|
|
if 1 < hike.legs.len:
|
|
|
|
# Get current `Branch` vertex `br`
|
2023-11-08 12:18:32 +00:00
|
|
|
let br = block:
|
|
|
|
var wp = hike.legs[^2].wp
|
|
|
|
wp.vtx = wp.vtx.dup # make sure that layers are not impliciteley modified
|
|
|
|
wp
|
2023-06-30 22:22:33 +00:00
|
|
|
if br.vtx.vType != Branch:
|
2024-07-14 17:12:10 +00:00
|
|
|
return err(DelBranchExpexted)
|
2023-06-30 22:22:33 +00:00
|
|
|
|
|
|
|
# Unlink child vertex from structural table
|
|
|
|
br.vtx.bVid[hike.legs[^2].nibble] = VertexID(0)
|
2024-07-04 13:46:52 +00:00
|
|
|
db.layersPutVtx((hike.root, br.vid), br.vtx)
|
2023-06-30 22:22:33 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
# Clear all Merkle hash keys up to the root key
|
2023-06-30 22:22:33 +00:00
|
|
|
for n in 0 .. hike.legs.len - 2:
|
|
|
|
let vid = hike.legs[n].wp.vid
|
2024-07-04 13:46:52 +00:00
|
|
|
db.layersResKey((hike.root, vid))
|
2023-06-30 22:22:33 +00:00
|
|
|
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
let nbl = block:
|
2023-06-30 22:22:33 +00:00
|
|
|
let rc = br.vtx.branchStillNeeded()
|
|
|
|
if rc.isErr:
|
2024-07-14 17:12:10 +00:00
|
|
|
return err(DelBranchWithoutRefs)
|
2023-06-30 22:22:33 +00:00
|
|
|
rc.value
|
|
|
|
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
if 0 <= nbl:
|
|
|
|
# Branch has only one entry - convert it to a leaf or join with parent
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
# Get child vertex (there must be one after a `Branch` node)
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
let
|
|
|
|
vid = br.vtx.bVid[nbl]
|
|
|
|
nxt = db.getVtx (hike.root, vid)
|
|
|
|
if not nxt.isValid:
|
2024-07-14 17:12:10 +00:00
|
|
|
return err(DelVidStaleVtx)
|
2023-06-30 22:22:33 +00:00
|
|
|
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
db.disposeOfVtx((hike.root, vid))
|
|
|
|
|
|
|
|
let vtx =
|
|
|
|
case nxt.vType
|
|
|
|
of Leaf:
|
|
|
|
VertexRef(
|
|
|
|
vType: Leaf,
|
2024-09-13 16:55:17 +00:00
|
|
|
pfx: br.vtx.pfx & NibblesBuf.nibble(nbl.byte) & nxt.pfx,
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
lData: nxt.lData)
|
|
|
|
of Branch:
|
|
|
|
VertexRef(
|
|
|
|
vType: Branch,
|
2024-09-13 16:55:17 +00:00
|
|
|
pfx: br.vtx.pfx & NibblesBuf.nibble(nbl.byte) & nxt.pfx,
|
No ext update (#2494)
* Imported/rebase from `no-ext`, PR #2485
Store extension nodes together with the branch
Extension nodes must be followed by a branch - as such, it makes sense
to store the two together both in the database and in memory:
* fewer reads, writes and updates to traverse the tree
* simpler logic for maintaining the node structure
* less space used, both memory and storage, because there are fewer
nodes overall
There is also a downside: hashes can no longer be cached for an
extension - instead, only the extension+branch hash can be cached - this
seems like a fine tradeoff since computing it should be fast.
TODO: fix commented code
* Fix merge functions and `toNode()`
* Update `merkleSignCommit()` prototype
why:
Result is always a 32bit hash
* Update short Merkle hash key generation
details:
Ethereum reference MPTs use Keccak hashes as node links if the size of
an RLP encoded node is at least 32 bytes. Otherwise, the RLP encoded
node value is used as a pseudo node link (rather than a hash.) This is
specified in the yellow paper, appendix D.
Different to the `Aristo` implementation, the reference MPT would not
store such a node on the key-value database. Rather the RLP encoded node value is stored instead of a node link in a parent node
is stored as a node link on the parent database.
Only for the root hash, the top level node is always referred to by the
hash.
* Fix/update `Extension` sections
why:
Were commented out after removal of a dedicated `Extension` type which
left the system disfunctional.
* Clean up unused error codes
* Update unit tests
* Update docu
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
2024-07-16 19:47:59 +00:00
|
|
|
bVid: nxt.bVid)
|
|
|
|
|
|
|
|
# Put the new vertex at the id of the obsolete branch
|
|
|
|
db.layersPutVtx((hike.root, br.vid), vtx)
|
2023-06-22 11:13:24 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
ok()
|
2023-06-02 19:21:46 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-27 09:01:26 +00:00
|
|
|
proc deleteAccountRecord*(
|
2024-06-18 19:30:01 +00:00
|
|
|
db: AristoDbRef;
|
2024-07-03 08:14:26 +00:00
|
|
|
accPath: Hash256;
|
2024-06-18 19:30:01 +00:00
|
|
|
): Result[void,AristoError] =
|
|
|
|
## Delete the account leaf entry addressed by the argument `path`. If this
|
|
|
|
## leaf entry referres to a storage tree, this one will be deleted as well.
|
2024-02-01 21:27:48 +00:00
|
|
|
##
|
2024-06-18 19:30:01 +00:00
|
|
|
let
|
2024-06-27 19:21:01 +00:00
|
|
|
hike = accPath.hikeUp(VertexID(1), db).valueOr:
|
2024-06-18 19:30:01 +00:00
|
|
|
if error[1] in HikeAcceptableStopsNotFound:
|
|
|
|
return err(DelPathNotFound)
|
|
|
|
return err(error[1])
|
2024-06-27 09:01:26 +00:00
|
|
|
stoID = hike.legs[^1].wp.vtx.lData.stoID
|
2024-02-01 21:27:48 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
# Delete storage tree if present
|
|
|
|
if stoID.isValid:
|
2024-08-14 08:54:44 +00:00
|
|
|
? db.delStoTreeImpl((stoID.vid, stoID.vid), accPath)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
2024-07-14 17:12:10 +00:00
|
|
|
?db.deleteImpl(hike)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
2024-07-14 10:02:05 +00:00
|
|
|
db.layersPutAccLeaf(accPath, nil)
|
2024-07-12 13:08:26 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
ok()
|
|
|
|
|
|
|
|
|
|
|
|
proc deleteGenericData*(
|
|
|
|
db: AristoDbRef;
|
|
|
|
root: VertexID;
|
|
|
|
path: openArray[byte];
|
|
|
|
): Result[bool,AristoError] =
|
|
|
|
## Delete the leaf data entry addressed by the argument `path`. The MPT
|
|
|
|
## sub-tree the leaf data entry is subsumed under is passed as argument
|
|
|
|
## `root` which must be greater than `VertexID(1)` and smaller than
|
|
|
|
## `LEAST_FREE_VID`.
|
2024-02-08 16:32:16 +00:00
|
|
|
##
|
2024-06-18 19:30:01 +00:00
|
|
|
## The return value is `true` if the argument `path` deleted was the last
|
|
|
|
## one and the tree does not exist anymore.
|
2023-09-15 15:23:53 +00:00
|
|
|
##
|
2024-06-18 19:30:01 +00:00
|
|
|
# Verify that `root` is neither an accounts tree nor a strorage tree.
|
|
|
|
if not root.isValid:
|
|
|
|
return err(DelRootVidMissing)
|
|
|
|
elif root == VertexID(1):
|
|
|
|
return err(DelAccRootNotAccepted)
|
|
|
|
elif LEAST_FREE_VID <= root.distinctBase:
|
|
|
|
return err(DelStoRootNotAccepted)
|
|
|
|
|
2024-06-27 19:21:01 +00:00
|
|
|
let hike = path.hikeUp(root, db).valueOr:
|
2024-06-18 19:30:01 +00:00
|
|
|
if error[1] in HikeAcceptableStopsNotFound:
|
|
|
|
return err(DelPathNotFound)
|
|
|
|
return err(error[1])
|
2023-06-02 19:21:46 +00:00
|
|
|
|
2024-07-14 17:12:10 +00:00
|
|
|
?db.deleteImpl(hike)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
2024-07-04 13:46:52 +00:00
|
|
|
ok(not db.getVtx((root, root)).isValid)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
|
|
|
proc deleteGenericTree*(
|
2023-07-04 18:24:03 +00:00
|
|
|
db: AristoDbRef; # Database, top layer
|
2024-06-18 19:30:01 +00:00
|
|
|
root: VertexID; # Root vertex
|
|
|
|
): Result[void,AristoError] =
|
|
|
|
## Variant of `deleteGenericData()` for purging the whole MPT sub-tree.
|
2023-09-15 15:23:53 +00:00
|
|
|
##
|
2024-06-18 19:30:01 +00:00
|
|
|
# Verify that `root` is neither an accounts tree nor a strorage tree.
|
|
|
|
if not root.isValid:
|
|
|
|
return err(DelRootVidMissing)
|
|
|
|
elif root == VertexID(1):
|
|
|
|
return err(DelAccRootNotAccepted)
|
|
|
|
elif LEAST_FREE_VID <= root.distinctBase:
|
|
|
|
return err(DelStoRootNotAccepted)
|
|
|
|
|
|
|
|
db.delSubTreeImpl root
|
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
|
2024-06-18 19:30:01 +00:00
|
|
|
proc deleteStorageData*(
|
2023-09-15 15:23:53 +00:00
|
|
|
db: AristoDbRef;
|
2024-07-03 08:14:26 +00:00
|
|
|
accPath: Hash256; # Implies storage data tree
|
2024-07-04 23:48:45 +00:00
|
|
|
stoPath: Hash256;
|
2024-06-18 19:30:01 +00:00
|
|
|
): Result[bool,AristoError] =
|
|
|
|
## For a given account argument `accPath`, this function deletes the
|
2024-06-27 19:21:01 +00:00
|
|
|
## argument `stoPath` from the associated storage tree (if any, at all.) If
|
|
|
|
## the if the argument `stoPath` deleted was the last one on the storage tree,
|
2024-06-18 19:30:01 +00:00
|
|
|
## account leaf referred to by `accPath` will be updated so that it will
|
|
|
|
## not refer to a storage tree anymore. In the latter case only the function
|
|
|
|
## will return `true`.
|
2023-09-15 15:23:53 +00:00
|
|
|
##
|
2024-06-18 19:30:01 +00:00
|
|
|
let
|
2024-06-27 09:01:26 +00:00
|
|
|
accHike = db.fetchAccountHike(accPath).valueOr:
|
|
|
|
if error == FetchAccInaccessible:
|
|
|
|
return err(DelStoAccMissing)
|
|
|
|
return err(error)
|
2024-06-18 19:30:01 +00:00
|
|
|
wpAcc = accHike.legs[^1].wp
|
2024-06-27 09:01:26 +00:00
|
|
|
stoID = wpAcc.vtx.lData.stoID
|
2024-06-18 19:30:01 +00:00
|
|
|
|
|
|
|
if not stoID.isValid:
|
|
|
|
return err(DelStoRootMissing)
|
|
|
|
|
2024-08-07 13:28:01 +00:00
|
|
|
let stoHike = stoPath.hikeUp(stoID.vid, db).valueOr:
|
2024-06-18 19:30:01 +00:00
|
|
|
if error[1] in HikeAcceptableStopsNotFound:
|
|
|
|
return err(DelPathNotFound)
|
|
|
|
return err(error[1])
|
|
|
|
|
2024-06-28 18:43:04 +00:00
|
|
|
# Mark account path Merkle keys for update
|
2024-06-18 19:30:01 +00:00
|
|
|
db.updateAccountForHasher accHike
|
|
|
|
|
2024-07-14 17:12:10 +00:00
|
|
|
?db.deleteImpl(stoHike)
|
|
|
|
|
2024-09-13 13:47:50 +00:00
|
|
|
db.layersPutStoLeaf(mixUp(accPath, stoPath), nil)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
|
|
|
# Make sure that an account leaf has no dangling sub-trie
|
2024-08-07 13:28:01 +00:00
|
|
|
if db.getVtx((stoID.vid, stoID.vid)).isValid:
|
2024-06-18 19:30:01 +00:00
|
|
|
return ok(false)
|
|
|
|
|
|
|
|
# De-register the deleted storage tree from the account record
|
|
|
|
let leaf = wpAcc.vtx.dup # Dup on modify
|
2024-08-07 13:28:01 +00:00
|
|
|
leaf.lData.stoID.isValid = false
|
2024-07-14 10:02:05 +00:00
|
|
|
db.layersPutAccLeaf(accPath, leaf)
|
2024-07-04 13:46:52 +00:00
|
|
|
db.layersPutVtx((accHike.root, wpAcc.vid), leaf)
|
2024-06-18 19:30:01 +00:00
|
|
|
ok(true)
|
|
|
|
|
|
|
|
proc deleteStorageTree*(
|
|
|
|
db: AristoDbRef; # Database, top layer
|
2024-07-03 08:14:26 +00:00
|
|
|
accPath: Hash256; # Implies storage data tree
|
2024-06-18 19:30:01 +00:00
|
|
|
): Result[void,AristoError] =
|
|
|
|
## Variant of `deleteStorageData()` for purging the whole storage tree
|
|
|
|
## associated to the account argument `accPath`.
|
|
|
|
##
|
|
|
|
let
|
2024-06-27 09:01:26 +00:00
|
|
|
accHike = db.fetchAccountHike(accPath).valueOr:
|
|
|
|
if error == FetchAccInaccessible:
|
2024-06-18 19:30:01 +00:00
|
|
|
return err(DelStoAccMissing)
|
|
|
|
return err(error)
|
|
|
|
wpAcc = accHike.legs[^1].wp
|
2024-06-27 09:01:26 +00:00
|
|
|
stoID = wpAcc.vtx.lData.stoID
|
2024-06-18 19:30:01 +00:00
|
|
|
|
|
|
|
if not stoID.isValid:
|
|
|
|
return err(DelStoRootMissing)
|
|
|
|
|
2024-06-28 18:43:04 +00:00
|
|
|
# Mark account path Merkle keys for update
|
2024-06-18 19:30:01 +00:00
|
|
|
db.updateAccountForHasher accHike
|
|
|
|
|
2024-08-14 08:54:44 +00:00
|
|
|
? db.delStoTreeImpl((stoID.vid, stoID.vid), accPath)
|
2024-06-18 19:30:01 +00:00
|
|
|
|
|
|
|
# De-register the deleted storage tree from the accounts record
|
|
|
|
let leaf = wpAcc.vtx.dup # Dup on modify
|
2024-08-07 13:28:01 +00:00
|
|
|
leaf.lData.stoID.isValid = false
|
2024-07-14 10:02:05 +00:00
|
|
|
db.layersPutAccLeaf(accPath, leaf)
|
2024-07-04 13:46:52 +00:00
|
|
|
db.layersPutVtx((accHike.root, wpAcc.vid), leaf)
|
2024-06-18 19:30:01 +00:00
|
|
|
ok()
|
2023-06-02 19:21:46 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|