2023-05-14 17:43:01 +00:00
|
|
|
# nimbus-eth1
|
2024-02-01 21:27:48 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-05-14 17:43:01 +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.
|
|
|
|
|
|
|
|
## Handle vertex IDs on the layered Aristo DB delta architecture
|
|
|
|
## =============================================================
|
2024-06-04 15:05:13 +00:00
|
|
|
##
|
2023-05-14 17:43:01 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2024-06-04 15:05:13 +00:00
|
|
|
std/typetraits,
|
|
|
|
./aristo_desc
|
2023-05-14 17:43:01 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
proc vidFetch*(db: AristoDbRef): VertexID =
|
2024-06-04 15:05:13 +00:00
|
|
|
## Fetch next vertex ID.
|
2024-02-29 21:10:24 +00:00
|
|
|
##
|
2024-06-04 15:05:13 +00:00
|
|
|
if db.top.delta.vTop == 0:
|
|
|
|
db.top.delta.vTop = VertexID(LEAST_FREE_VID)
|
2023-05-14 17:43:01 +00:00
|
|
|
else:
|
2024-06-04 15:05:13 +00:00
|
|
|
db.top.delta.vTop.inc
|
|
|
|
db.top.delta.vTop
|
2023-05-14 17:43:01 +00:00
|
|
|
|
2023-07-04 18:24:03 +00:00
|
|
|
proc vidDispose*(db: AristoDbRef; vid: VertexID) =
|
2024-06-04 15:05:13 +00:00
|
|
|
## Only top vertexIDs are disposed
|
|
|
|
if vid == db.top.delta.vTop and
|
|
|
|
LEAST_FREE_VID < db.top.delta.vTop.distinctBase:
|
|
|
|
db.top.delta.vTop.dec
|
2023-06-09 11:17:37 +00:00
|
|
|
|
2023-05-14 17:43:01 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|