mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-28 20:00:43 +00:00
fix level reporting (#3085)
Oops, level 0 was always used which needlessly increases mem usage - comes with an assortment of simplifications
This commit is contained in:
parent
816ce73a2a
commit
3732b3f95e
@ -73,8 +73,7 @@ type
|
|||||||
accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
|
accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
|
||||||
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef
|
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef
|
||||||
|
|
||||||
cTop*: VertexID ## Last committed vertex ID
|
blockNumber*: Opt[uint64] ## Block number set when checkpointing the frame
|
||||||
blockNumber*: Opt[uint64] ## Block number set when freezing the frame
|
|
||||||
|
|
||||||
AristoDbRef* = ref object
|
AristoDbRef* = ref object
|
||||||
## Three tier database object supporting distributed instances.
|
## Three tier database object supporting distributed instances.
|
||||||
@ -202,6 +201,7 @@ iterator rstack*(tx: AristoTxRef): (AristoTxRef, int) =
|
|||||||
let level = if tx.parent == nil: -1 else: i
|
let level = if tx.parent == nil: -1 else: i
|
||||||
yield (tx, level)
|
yield (tx, level)
|
||||||
tx = tx.parent
|
tx = tx.parent
|
||||||
|
i += 1
|
||||||
|
|
||||||
proc deltaAtLevel*(db: AristoTxRef, level: int): AristoTxRef =
|
proc deltaAtLevel*(db: AristoTxRef, level: int): AristoTxRef =
|
||||||
if level == -2:
|
if level == -2:
|
||||||
|
@ -124,6 +124,7 @@ func isEmpty*(ly: AristoTxRef): bool =
|
|||||||
proc mergeAndReset*(trg, src: AristoTxRef) =
|
proc mergeAndReset*(trg, src: AristoTxRef) =
|
||||||
## Merges the argument `src` into the argument `trg` and clears `src`.
|
## Merges the argument `src` into the argument `trg` and clears `src`.
|
||||||
trg.vTop = src.vTop
|
trg.vTop = src.vTop
|
||||||
|
trg.blockNumber = src.blockNumber
|
||||||
|
|
||||||
if trg.kMap.len > 0:
|
if trg.kMap.len > 0:
|
||||||
# Invalidate cached keys in the lower layer
|
# Invalidate cached keys in the lower layer
|
||||||
|
@ -73,7 +73,6 @@ proc txFramePersist*(
|
|||||||
if frame == db.txRef:
|
if frame == db.txRef:
|
||||||
continue
|
continue
|
||||||
mergeAndReset(db.txRef, frame)
|
mergeAndReset(db.txRef, frame)
|
||||||
db.txRef.blockNumber = frame.blockNumber
|
|
||||||
|
|
||||||
frame.dispose() # This will also dispose `txFrame` itself!
|
frame.dispose() # This will also dispose `txFrame` itself!
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ proc txFramePersist*(
|
|||||||
db.txRef = txFrame
|
db.txRef = txFrame
|
||||||
|
|
||||||
# Store structural single trie entries
|
# Store structural single trie entries
|
||||||
for rvid, vtx in db.txRef.sTab:
|
for rvid, vtx in txFrame.sTab:
|
||||||
txFrame.kMap.withValue(rvid, key) do:
|
txFrame.kMap.withValue(rvid, key) do:
|
||||||
be.putVtxFn(batch, rvid, vtx, key[])
|
be.putVtxFn(batch, rvid, vtx, key[])
|
||||||
do:
|
do:
|
||||||
@ -107,6 +106,7 @@ proc txFramePersist*(
|
|||||||
txFrame.kMap.clear()
|
txFrame.kMap.clear()
|
||||||
txFrame.accLeaves.clear()
|
txFrame.accLeaves.clear()
|
||||||
txFrame.stoLeaves.clear()
|
txFrame.stoLeaves.clear()
|
||||||
|
txFrame.blockNumber.reset()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -221,13 +221,6 @@ proc getScore*(
|
|||||||
warn info, data = data.toHex(), error=exc.msg
|
warn info, data = data.toHex(), error=exc.msg
|
||||||
Opt.none(UInt256)
|
Opt.none(UInt256)
|
||||||
|
|
||||||
proc setScore*(db: CoreDbTxRef; blockHash: Hash32, score: UInt256) =
|
|
||||||
## for testing purpose
|
|
||||||
let scoreKey = blockHashToScoreKey blockHash
|
|
||||||
db.put(scoreKey.toOpenArray, rlp.encode(score)).isOkOr:
|
|
||||||
warn "setScore()", scoreKey, error=($$error)
|
|
||||||
return
|
|
||||||
|
|
||||||
proc headTotalDifficulty*(
|
proc headTotalDifficulty*(
|
||||||
db: CoreDbTxRef;
|
db: CoreDbTxRef;
|
||||||
): UInt256 =
|
): UInt256 =
|
||||||
|
@ -19,11 +19,13 @@ import
|
|||||||
aristo_delete,
|
aristo_delete,
|
||||||
aristo_desc,
|
aristo_desc,
|
||||||
aristo_fetch,
|
aristo_fetch,
|
||||||
aristo_tx_frame,
|
aristo_hike,
|
||||||
aristo_init,
|
aristo_init,
|
||||||
aristo_init/memory_db,
|
aristo_init/memory_db,
|
||||||
|
aristo_layers,
|
||||||
aristo_merge,
|
aristo_merge,
|
||||||
aristo_persist,
|
aristo_persist,
|
||||||
|
aristo_tx_frame,
|
||||||
]
|
]
|
||||||
|
|
||||||
proc makeAccount(i: uint64): (Hash32, AristoAccount) =
|
proc makeAccount(i: uint64): (Hash32, AristoAccount) =
|
||||||
@ -34,6 +36,7 @@ proc makeAccount(i: uint64): (Hash32, AristoAccount) =
|
|||||||
const
|
const
|
||||||
acc1 = makeAccount(1)
|
acc1 = makeAccount(1)
|
||||||
acc2 = makeAccount(2)
|
acc2 = makeAccount(2)
|
||||||
|
acc3 = makeAccount(3)
|
||||||
|
|
||||||
suite "Aristo TxFrame":
|
suite "Aristo TxFrame":
|
||||||
setup:
|
setup:
|
||||||
@ -47,12 +50,14 @@ suite "Aristo TxFrame":
|
|||||||
tx1 = db.txFrameBegin(tx0)
|
tx1 = db.txFrameBegin(tx0)
|
||||||
tx2 = db.txFrameBegin(tx1)
|
tx2 = db.txFrameBegin(tx1)
|
||||||
tx2b = db.txFrameBegin(tx1)
|
tx2b = db.txFrameBegin(tx1)
|
||||||
|
tx2c = db.txFrameBegin(tx1)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
tx0.mergeAccountRecord(acc1[0], acc1[1]).isOk()
|
tx0.mergeAccountRecord(acc1[0], acc1[1]).isOk()
|
||||||
tx1.mergeAccountRecord(acc2[0], acc2[1]).isOk()
|
tx1.mergeAccountRecord(acc2[0], acc2[1]).isOk()
|
||||||
tx2.deleteAccountRecord(acc2[0]).isOk()
|
tx2.deleteAccountRecord(acc2[0]).isOk()
|
||||||
tx2b.deleteAccountRecord(acc1[0]).isOk()
|
tx2b.deleteAccountRecord(acc1[0]).isOk()
|
||||||
|
tx2c.mergeAccountRecord(acc2[0], acc3[1]).isOk()
|
||||||
|
|
||||||
check:
|
check:
|
||||||
tx0.fetchAccountRecord(acc1[0]).isOk()
|
tx0.fetchAccountRecord(acc1[0]).isOk()
|
||||||
@ -68,6 +73,15 @@ suite "Aristo TxFrame":
|
|||||||
tx0.fetchStateRoot() != tx1.fetchStateRoot()
|
tx0.fetchStateRoot() != tx1.fetchStateRoot()
|
||||||
tx0.fetchStateRoot() == tx2.fetchStateRoot()
|
tx0.fetchStateRoot() == tx2.fetchStateRoot()
|
||||||
|
|
||||||
|
var acc1Hike: Hike
|
||||||
|
check:
|
||||||
|
tx2c.fetchAccountHike(acc1[0], acc1Hike).isOk()
|
||||||
|
|
||||||
|
# The vid for acc1 gets created in tx1 because it has to move to a new
|
||||||
|
# mpt node from the root - tx2c updates only data, so the level at which
|
||||||
|
# we find the vtx should be one below tx2c!
|
||||||
|
tx2c.layersGetVtx((VertexID(1), acc1Hike.legs[^1].wp.vid)).value()[1] == 1
|
||||||
|
|
||||||
tx2.checkpoint(1)
|
tx2.checkpoint(1)
|
||||||
let batch = db.backend.putBegFn().expect("working batch")
|
let batch = db.backend.putBegFn().expect("working batch")
|
||||||
db.persist(batch, tx2)
|
db.persist(batch, tx2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user