2023-09-11 20:38:49 +00:00
|
|
|
# nimbus-eth1
|
2024-04-26 13:43:52 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-09-11 20:38:49 +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.
|
|
|
|
|
|
|
|
import
|
|
|
|
std/tables,
|
2024-06-03 20:10:35 +00:00
|
|
|
eth/common,
|
2023-09-11 20:38:49 +00:00
|
|
|
results,
|
|
|
|
".."/[aristo_desc, aristo_get]
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc revFilter*(
|
|
|
|
db: AristoDbRef; # Database
|
2024-06-03 20:10:35 +00:00
|
|
|
filter: LayerDeltaRef; # Filter to revert
|
|
|
|
): Result[LayerDeltaRef,(VertexID,AristoError)] =
|
2023-09-11 20:38:49 +00:00
|
|
|
## 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
|
2024-06-28 18:43:04 +00:00
|
|
|
let rev = LayerDeltaRef()
|
2023-09-11 20:38:49 +00:00
|
|
|
|
|
|
|
# Get vid generator state on backend
|
|
|
|
block:
|
2024-06-04 15:05:13 +00:00
|
|
|
let rc = db.getTuvUbe()
|
2023-09-11 20:38:49 +00:00
|
|
|
if rc.isOk:
|
2024-06-04 15:05:13 +00:00
|
|
|
rev.vTop = rc.value
|
|
|
|
elif rc.error != GetTuvNotFound:
|
2023-09-11 20:38:49 +00:00
|
|
|
return err((VertexID(0), rc.error))
|
|
|
|
|
|
|
|
# Calculate reverse changes for the `sTab[]` structural table
|
2024-07-04 13:46:52 +00:00
|
|
|
for rvid in filter.sTab.keys:
|
|
|
|
let rc = db.getVtxUbe rvid
|
2023-09-11 20:38:49 +00:00
|
|
|
if rc.isOk:
|
2024-07-04 13:46:52 +00:00
|
|
|
rev.sTab[rvid] = rc.value
|
2023-09-11 20:38:49 +00:00
|
|
|
elif rc.error == GetVtxNotFound:
|
2024-07-04 13:46:52 +00:00
|
|
|
rev.sTab[rvid] = VertexRef(nil)
|
2023-09-11 20:38:49 +00:00
|
|
|
else:
|
2024-07-04 13:46:52 +00:00
|
|
|
return err((rvid.vid,rc.error))
|
2023-09-11 20:38:49 +00:00
|
|
|
|
|
|
|
# Calculate reverse changes for the `kMap` sequence.
|
2024-07-04 13:46:52 +00:00
|
|
|
for rvid in filter.kMap.keys:
|
|
|
|
let rc = db.getKeyUbe rvid
|
2023-09-11 20:38:49 +00:00
|
|
|
if rc.isOk:
|
2024-07-04 13:46:52 +00:00
|
|
|
rev.kMap[rvid] = rc.value
|
2023-09-11 20:38:49 +00:00
|
|
|
elif rc.error == GetKeyNotFound:
|
2024-07-04 13:46:52 +00:00
|
|
|
rev.kMap[rvid] = VOID_HASH_KEY
|
2023-09-11 20:38:49 +00:00
|
|
|
else:
|
2024-07-04 13:46:52 +00:00
|
|
|
return err((rvid.vid,rc.error))
|
2023-09-11 20:38:49 +00:00
|
|
|
|
|
|
|
ok(rev)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|