mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-02 23:35:31 +00:00
Remove vertex ID recycle function (#2558)
why: It is not safe in general to recycle vertex IDs while the `RocksDb` cache has `VertexID` rather than `RootedVertexID` where the former type seems preferable. In some fringe cases one might remove a vertex with key `(root1,vid)` and insert another vertex with key `(root2,vid)` while re-using the vertex ID `vid`. Without knowledge of `root1` and `root2`, the LRU cache will return the same vertex for `(root2,vid)` also for `(root1,vid)`.
This commit is contained in:
parent
8723a79225
commit
7becf4e389
@ -20,7 +20,7 @@ import
|
|||||||
eth/common,
|
eth/common,
|
||||||
results,
|
results,
|
||||||
"."/[aristo_desc, aristo_fetch, aristo_get, aristo_hike, aristo_layers,
|
"."/[aristo_desc, aristo_fetch, aristo_get, aristo_hike, aristo_layers,
|
||||||
aristo_utils, aristo_vid]
|
aristo_utils]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private heplers
|
# Private heplers
|
||||||
@ -48,7 +48,6 @@ proc disposeOfVtx(
|
|||||||
# Remove entry
|
# Remove entry
|
||||||
db.layersResVtx(rvid)
|
db.layersResVtx(rvid)
|
||||||
db.layersResKey(rvid)
|
db.layersResKey(rvid)
|
||||||
db.vidDispose rvid.vid # Recycle ID
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private functions
|
# Private functions
|
||||||
|
@ -38,6 +38,20 @@ type
|
|||||||
vtxCol*: ColFamilyReadWrite ## Vertex column family handler
|
vtxCol*: ColFamilyReadWrite ## Vertex column family handler
|
||||||
keyCol*: ColFamilyReadWrite ## Hash key column family handler
|
keyCol*: ColFamilyReadWrite ## Hash key column family handler
|
||||||
session*: WriteBatchRef ## For batched `put()`
|
session*: WriteBatchRef ## For batched `put()`
|
||||||
|
|
||||||
|
# Note that the key type `VertexID` for LRU caches requires that there is
|
||||||
|
# strictly no vertex ID re-use.
|
||||||
|
#
|
||||||
|
# Otherwise, in some fringe cases one might remove a vertex with key
|
||||||
|
# `(root1,vid)` and insert another vertex with key `(root2,vid)` while
|
||||||
|
# re-using the vertex ID `vid`. Without knowledge of `root1` and `root2`,
|
||||||
|
# the LRU cache will return the same vertex for `(root2,vid)` also for
|
||||||
|
# `(root1,vid)`.
|
||||||
|
#
|
||||||
|
# The other alternaive would be to use the key type `RootedVertexID` which
|
||||||
|
# is less memory and time efficient (the latter one due to internal LRU
|
||||||
|
# handling of the longer key.)
|
||||||
|
#
|
||||||
rdKeyLru*: KeyedQueue[VertexID,HashKey] ## Read cache
|
rdKeyLru*: KeyedQueue[VertexID,HashKey] ## Read cache
|
||||||
rdVtxLru*: KeyedQueue[VertexID,VertexRef] ## Read cache
|
rdVtxLru*: KeyedQueue[VertexID,VertexRef] ## Read cache
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ import
|
|||||||
std/sets,
|
std/sets,
|
||||||
eth/common,
|
eth/common,
|
||||||
results,
|
results,
|
||||||
".."/[aristo_desc, aristo_get, aristo_hike, aristo_layers, aristo_utils,
|
".."/[aristo_desc, aristo_get, aristo_hike, aristo_layers, aristo_utils],
|
||||||
aristo_vid],
|
|
||||||
#./part_debug,
|
#./part_debug,
|
||||||
./part_desc
|
./part_desc
|
||||||
|
|
||||||
@ -112,7 +111,6 @@ proc ctxAcceptChange(psc: PartStateCtx): Result[bool,AristoError] =
|
|||||||
let key = ps.move(psc.fromVid, toVid)
|
let key = ps.move(psc.fromVid, toVid)
|
||||||
doAssert key.isValid
|
doAssert key.isValid
|
||||||
ps.changed.incl key
|
ps.changed.incl key
|
||||||
db.vidDispose psc.fromVid # typically no action
|
|
||||||
|
|
||||||
# Remove parent vertex it it has become complete.
|
# Remove parent vertex it it has become complete.
|
||||||
ps.removeCompletedNodes(psc.location)
|
ps.removeCompletedNodes(psc.location)
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/typetraits,
|
|
||||||
./aristo_desc
|
./aristo_desc
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -30,11 +29,6 @@ proc vidFetch*(db: AristoDbRef): VertexID =
|
|||||||
db.top.vTop.inc
|
db.top.vTop.inc
|
||||||
db.top.vTop
|
db.top.vTop
|
||||||
|
|
||||||
proc vidDispose*(db: AristoDbRef; vid: VertexID) =
|
|
||||||
## Only top vertexIDs are disposed
|
|
||||||
if vid == db.top.vTop and LEAST_FREE_VID < db.top.vTop.distinctBase:
|
|
||||||
db.top.vTop.dec
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user