Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Feb 8, 2025
1 parent 67b8dd7 commit 10bc875
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions nimbus/db/aristo/aristo_desc/desc_identifiers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func `$`*(vid: VertexID): string =
func `$`*(rvid: RootedVertexID): string =
$rvid.root & "/" & $rvid.vid

func hash*(rvid: RootedVertexID): Hash {.inline.} =
hash(rvid.vid.uint64) # No need to waste cycles on mixing in root!

func `==`*(a: VertexID; b: static[uint]): bool = (a == VertexID(b))

# Scalar model extension as in `IntervalSetRef[VertexID,uint64]`
Expand Down
6 changes: 5 additions & 1 deletion nimbus/db/aristo/aristo_desc/desc_structural.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import
std/[hashes as std_hashes, tables],
stint,
eth/common/[accounts, base, hashes],
./desc_identifiers
./desc_identifiers,
minilru

export stint, tables, accounts, base, hashes

Expand Down Expand Up @@ -122,6 +123,9 @@ type
kMap*: Table[RootedVertexID,HashKey] ## Merkle hash key mapping
vTop*: VertexID ## Last used vertex ID

pTab*: LruCache[RootedVertexID,(VertexRef, int)]
pMap*: LruCache[RootedVertexID,(HashKey, int)]

accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef

Expand Down
23 changes: 23 additions & 0 deletions nimbus/db/aristo/aristo_layers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ func layersGetVtx*(db: AristoTxRef; rvid: RootedVertexID): Opt[(VertexRef, int)]
##
for w, level in db.rstack:
w.sTab.withValue(rvid, item):
if level > 0:
db.layer.pTab.put(rvid, (item[], level))
return Opt.some((item[], level))

if level == 0:
let p = w.pTab.get(rvid)
if p.isSome():
return p

Opt.none((VertexRef, int))

func layersGetKey*(db: AristoTxRef; rvid: RootedVertexID): Opt[(HashKey, int)] =
Expand All @@ -38,10 +45,20 @@ func layersGetKey*(db: AristoTxRef; rvid: RootedVertexID): Opt[(HashKey, int)] =

for w, level in db.rstack:
w.kMap.withValue(rvid, item):
if level > 0:
w.pMap.put(rvid, (item[], level))
return ok((item[], level))

if rvid in w.sTab:
if level > 0:
db.layer.pMap.put(rvid, (VOID_HASH_KEY, level))
return Opt.some((VOID_HASH_KEY, level))

if level == 0:
let p = w.pMap.get(rvid)
if p.isSome():
return p

Opt.none((HashKey, int))

func layersGetKeyOrVoid*(db: AristoTxRef; rvid: RootedVertexID): HashKey =
Expand Down Expand Up @@ -135,6 +152,12 @@ proc mergeAndReset*(trg, src: var Layer) =
mergeAndReset(trg.accLeaves, src.accLeaves)
mergeAndReset(trg.stoLeaves, src.stoLeaves)

swap(trg.pTab, src.pTab)
swap(trg.pMap, src.pMap)

src.pTab = LruCache[RootedVertexID,(VertexRef, int)].init(ACC_LRU_SIZE)
src.pMap = LruCache[RootedVertexID,(HashKey, int)].init(ACC_LRU_SIZE)

# func layersCc*(db: AristoDbRef; level = high(int)): LayerRef =
# ## Provide a collapsed copy of layers up to a particular transaction level.
# ## If the `level` argument is too large, the maximum transaction level is
Expand Down
12 changes: 10 additions & 2 deletions nimbus/db/aristo/aristo_tx/tx_frame.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ proc txFrameBegin*(db: AristoDbRef, parent: AristoTxRef): Result[AristoTxRef,Ari

let
vTop = parent.layer.vTop
layer = LayerRef(vTop: vTop, cTop: vTop)
layer = LayerRef(
vTop: vTop, cTop: vTop,
pTab: LruCache[RootedVertexID,(VertexRef, int)].init(ACC_LRU_SIZE),
pMap: LruCache[RootedVertexID,(HashKey, int)].init(ACC_LRU_SIZE),
)

ok AristoTxRef(
db: db,
Expand All @@ -59,7 +63,11 @@ proc rollback*(
# TODO Everyone using this txref should repoint their parent field

let vTop = tx.layer[].cTop
tx.layer[] = Layer(vTop: vTop, cTop: vTop)
tx.layer[] = Layer(
vTop: vTop, cTop: vTop,
pTab: LruCache[RootedVertexID,(VertexRef, int)].init(ACC_LRU_SIZE),
pMap: LruCache[RootedVertexID,(HashKey, int)].init(ACC_LRU_SIZE),
)

ok()

Expand Down

0 comments on commit 10bc875

Please sign in to comment.