diff --git a/execution_chain/db/aristo/aristo_desc.nim b/execution_chain/db/aristo/aristo_desc.nim index a9ece6787..8970669e6 100644 --- a/execution_chain/db/aristo/aristo_desc.nim +++ b/execution_chain/db/aristo/aristo_desc.nim @@ -73,8 +73,7 @@ type accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef - cTop*: VertexID ## Last committed vertex ID - blockNumber*: Opt[uint64] ## Block number set when freezing the frame + blockNumber*: Opt[uint64] ## Block number set when checkpointing the frame AristoDbRef* = ref object ## 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 yield (tx, level) tx = tx.parent + i += 1 proc deltaAtLevel*(db: AristoTxRef, level: int): AristoTxRef = if level == -2: diff --git a/execution_chain/db/aristo/aristo_layers.nim b/execution_chain/db/aristo/aristo_layers.nim index 675f0b22a..14c0eb2bb 100644 --- a/execution_chain/db/aristo/aristo_layers.nim +++ b/execution_chain/db/aristo/aristo_layers.nim @@ -124,6 +124,7 @@ func isEmpty*(ly: AristoTxRef): bool = proc mergeAndReset*(trg, src: AristoTxRef) = ## Merges the argument `src` into the argument `trg` and clears `src`. trg.vTop = src.vTop + trg.blockNumber = src.blockNumber if trg.kMap.len > 0: # Invalidate cached keys in the lower layer diff --git a/execution_chain/db/aristo/aristo_tx_frame.nim b/execution_chain/db/aristo/aristo_tx_frame.nim index 4b67f7d1c..13dbf2035 100644 --- a/execution_chain/db/aristo/aristo_tx_frame.nim +++ b/execution_chain/db/aristo/aristo_tx_frame.nim @@ -73,7 +73,6 @@ proc txFramePersist*( if frame == db.txRef: continue mergeAndReset(db.txRef, frame) - db.txRef.blockNumber = frame.blockNumber frame.dispose() # This will also dispose `txFrame` itself! @@ -82,7 +81,7 @@ proc txFramePersist*( db.txRef = txFrame # Store structural single trie entries - for rvid, vtx in db.txRef.sTab: + for rvid, vtx in txFrame.sTab: txFrame.kMap.withValue(rvid, key) do: be.putVtxFn(batch, rvid, vtx, key[]) do: @@ -107,6 +106,7 @@ proc txFramePersist*( txFrame.kMap.clear() txFrame.accLeaves.clear() txFrame.stoLeaves.clear() + txFrame.blockNumber.reset() # ------------------------------------------------------------------------------ # End diff --git a/execution_chain/db/core_db/core_apps.nim b/execution_chain/db/core_db/core_apps.nim index abf6fe76a..7d4a4f258 100644 --- a/execution_chain/db/core_db/core_apps.nim +++ b/execution_chain/db/core_db/core_apps.nim @@ -221,13 +221,6 @@ proc getScore*( warn info, data = data.toHex(), error=exc.msg 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*( db: CoreDbTxRef; ): UInt256 = diff --git a/tests/test_aristo/test_tx_frame.nim b/tests/test_aristo/test_tx_frame.nim index 137d298fb..5acfbbd17 100644 --- a/tests/test_aristo/test_tx_frame.nim +++ b/tests/test_aristo/test_tx_frame.nim @@ -19,11 +19,13 @@ import aristo_delete, aristo_desc, aristo_fetch, - aristo_tx_frame, + aristo_hike, aristo_init, aristo_init/memory_db, + aristo_layers, aristo_merge, aristo_persist, + aristo_tx_frame, ] proc makeAccount(i: uint64): (Hash32, AristoAccount) = @@ -34,6 +36,7 @@ proc makeAccount(i: uint64): (Hash32, AristoAccount) = const acc1 = makeAccount(1) acc2 = makeAccount(2) + acc3 = makeAccount(3) suite "Aristo TxFrame": setup: @@ -47,12 +50,14 @@ suite "Aristo TxFrame": tx1 = db.txFrameBegin(tx0) tx2 = db.txFrameBegin(tx1) tx2b = db.txFrameBegin(tx1) + tx2c = db.txFrameBegin(tx1) check: tx0.mergeAccountRecord(acc1[0], acc1[1]).isOk() tx1.mergeAccountRecord(acc2[0], acc2[1]).isOk() tx2.deleteAccountRecord(acc2[0]).isOk() tx2b.deleteAccountRecord(acc1[0]).isOk() + tx2c.mergeAccountRecord(acc2[0], acc3[1]).isOk() check: tx0.fetchAccountRecord(acc1[0]).isOk() @@ -68,6 +73,15 @@ suite "Aristo TxFrame": tx0.fetchStateRoot() != tx1.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) let batch = db.backend.putBegFn().expect("working batch") db.persist(batch, tx2)