mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-30 14:05:23 +00:00
f926222fec
* Remove all journal related stuff * Refactor function names journal*() => delta*(), filter*() => delta*() * remove `trg` fileld from `FilterRef` why: Same as `kMap[$1]` * Re-type FilterRef.src as `HashKey` why: So it is directly comparable to `kMap[$1]` * Moved `vGen[]` field from `LayerFinalRef` to `LayerDeltaRef` why: Then a separate `FilterRef` type is not needed, anymore * Rename `roFilter` field in `AristoDbRef` => `balancer` why: New name more appropriate. * Replace `FilterRef` by `LayerDeltaRef` type why: This allows to avoid copying into the `balancer` (see next patch set) most of the time. Typically, only one instance is running on the backend and the `balancer` is only used as a stage before saving data. * Refactor way how to store data persistently why: Avoid useless copy when staging `top` layer for persistently saving to backend. * Fix copyright header?
67 lines
2.2 KiB
Nim
67 lines
2.2 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: LayerDeltaRef; # Filter to revert
|
|
): Result[LayerDeltaRef,(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.)
|
|
##
|
|
# Register MPT state roots for reverting back
|
|
let rev = LayerDeltaRef(src: filter.kMap.getOrVoid(VertexID 1))
|
|
|
|
# Get vid generator state on backend
|
|
block:
|
|
let rc = db.getIdgUbe()
|
|
if rc.isOk:
|
|
rev.vGen = rc.value
|
|
elif rc.error != GetIdgNotFound:
|
|
return err((VertexID(0), rc.error))
|
|
|
|
# Calculate reverse changes for the `sTab[]` structural table
|
|
for vid in filter.sTab.keys:
|
|
let rc = db.getVtxUbe vid
|
|
if rc.isOk:
|
|
rev.sTab[vid] = rc.value
|
|
elif rc.error == GetVtxNotFound:
|
|
rev.sTab[vid] = VertexRef(nil)
|
|
else:
|
|
return err((vid,rc.error))
|
|
|
|
# Calculate reverse changes for the `kMap` sequence.
|
|
for vid in filter.kMap.keys:
|
|
let rc = db.getKeyUbe vid
|
|
if rc.isOk:
|
|
rev.kMap[vid] = rc.value
|
|
elif rc.error == GetKeyNotFound:
|
|
rev.kMap[vid] = VOID_HASH_KEY
|
|
else:
|
|
return err((vid,rc.error))
|
|
|
|
ok(rev)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|