mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-30 05:55:30 +00:00
5ac362fe6f
* Aristo: Merge `delta_siblings` module into `deltaPersistent()` * Aristo: Add `isEmpty()` for canonical checking whether a layer is empty * Aristo: Merge `LayerDeltaRef` into `LayerObj` why: No need to maintain nested object refs anymore. Previously the `LayerDeltaRef` object had a companion `LayerFinalRef` which held non-delta layer information. * Kvt: Merge `LayerDeltaRef` into `LayerRef` why: No need to maintain nested object refs (as with `Aristo`) * Kvt: Re-write balancer logic similar to `Aristo` why: Although `Kvt` was a cheap copy of `Aristo` it sort of got out of sync and the balancer code was wrong. * Update iterator over forked peers why: Yield additional field `isLast` indicating that the last iteration cycle was approached. * Optimise balancer calculation. why: One can often avoid providing a new object containing the merge of two layers for the balancer. This avoids copying tables. In some cases this is replaced by `hasKey()` look ups though. One uses one of the two to combine and merges the other into the first. Of course, this needs some checks for making sure that none of the components to merge is eventually shared with something else. * Fix copyright year
66 lines
2.1 KiB
Nim
66 lines
2.1 KiB
Nim
# nimbus-eth1
|
|
# 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.
|
|
|
|
import
|
|
std/tables,
|
|
eth/common,
|
|
results,
|
|
".."/[aristo_desc, aristo_get]
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public functions
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc revFilter*(
|
|
db: AristoDbRef; # Database
|
|
filter: LayerRef; # Filter to revert
|
|
): Result[LayerRef,(VertexID,AristoError)] =
|
|
## Assemble reverse filter for the `filter` argument, i.e. changes to the
|
|
## backend that reverse the effect of applying the this read-only filter.
|
|
##
|
|
## This read-only filter is calculated against the current unfiltered
|
|
## backend (excluding optionally installed read-only filter.)
|
|
##
|
|
let rev = LayerRef()
|
|
|
|
# Get vid generator state on backend
|
|
block:
|
|
let rc = db.getTuvUbe()
|
|
if rc.isOk:
|
|
rev.vTop = rc.value
|
|
elif rc.error != GetTuvNotFound:
|
|
return err((VertexID(0), rc.error))
|
|
|
|
# Calculate reverse changes for the `sTab[]` structural table
|
|
for rvid in filter.sTab.keys:
|
|
let rc = db.getVtxUbe rvid
|
|
if rc.isOk:
|
|
rev.sTab[rvid] = rc.value
|
|
elif rc.error == GetVtxNotFound:
|
|
rev.sTab[rvid] = VertexRef(nil)
|
|
else:
|
|
return err((rvid.vid,rc.error))
|
|
|
|
# Calculate reverse changes for the `kMap` sequence.
|
|
for rvid in filter.kMap.keys:
|
|
let rc = db.getKeyUbe rvid
|
|
if rc.isOk:
|
|
rev.kMap[rvid] = rc.value
|
|
elif rc.error == GetKeyNotFound:
|
|
rev.kMap[rvid] = VOID_HASH_KEY
|
|
else:
|
|
return err((rvid.vid,rc.error))
|
|
|
|
ok(rev)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|