From b3917ea4b051cc542bd9f8ea0f49491bf7d131a7 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 20 Dec 2024 15:06:12 +0100 Subject: [PATCH] fix layer vtop after rollback --- nimbus/db/aristo/aristo_delta.nim | 1 + nimbus/db/aristo/aristo_desc/desc_structural.nim | 6 ++---- nimbus/db/aristo/aristo_init/memory_only.nim | 4 ++-- nimbus/db/aristo/aristo_init/persistent.nim | 2 +- nimbus/db/aristo/aristo_tx/tx_frame.nim | 13 +++++++++---- nimbus/db/kvt/kvt_tx/tx_frame.nim | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nimbus/db/aristo/aristo_delta.nim b/nimbus/db/aristo/aristo_delta.nim index 142e2a882a..b10ec811d1 100644 --- a/nimbus/db/aristo/aristo_delta.nim +++ b/nimbus/db/aristo/aristo_delta.nim @@ -83,6 +83,7 @@ proc deltaPersistent*( db.stoLeaves.put(mixPath, vtx) # Done with txRef, all saved to backend + db.txRef.layer.cTop = db.txRef.layer.vTop db.txRef.layer.sTab.clear() db.txRef.layer.kMap.clear() db.txRef.layer.accLeaves.clear() diff --git a/nimbus/db/aristo/aristo_desc/desc_structural.nim b/nimbus/db/aristo/aristo_desc/desc_structural.nim index e2fa26d2e6..1522d2127a 100644 --- a/nimbus/db/aristo/aristo_desc/desc_structural.nim +++ b/nimbus/db/aristo/aristo_desc/desc_structural.nim @@ -125,6 +125,8 @@ type accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef + cTop*: VertexID ## Last committed vertex ID + GetVtxFlag* = enum PeekCache ## Peek into, but don't update cache - useful on work loads that are @@ -148,10 +150,6 @@ func setUsed*(vtx: VertexRef, nibble: uint8, used: static bool): VertexID = vtx.used and (not (1'u16 shl nibble)) vtx.bVid(nibble) -func init*(T: type LayerRef): T = - ## Constructor, returns empty layer - T() - func hash*(node: NodeRef): Hash = ## Table/KeyedQueue/HashSet mixin cast[pointer](node).hash diff --git a/nimbus/db/aristo/aristo_init/memory_only.nim b/nimbus/db/aristo/aristo_init/memory_only.nim index b55320b42b..f3ff5257d2 100644 --- a/nimbus/db/aristo/aristo_init/memory_only.nim +++ b/nimbus/db/aristo/aristo_init/memory_only.nim @@ -56,10 +56,10 @@ proc init*( let db = when B is VoidBackendRef: - AristoDbRef(txRef: AristoTxRef(layer: LayerRef.init())) + AristoDbRef(txRef: AristoTxRef(layer: LayerRef())) elif B is MemBackendRef: - AristoDbRef(txRef: AristoTxRef(layer: LayerRef.init()), backend: memoryBackend()) + AristoDbRef(txRef: AristoTxRef(layer: LayerRef()), backend: memoryBackend()) db.txRef.db = db db diff --git a/nimbus/db/aristo/aristo_init/persistent.nim b/nimbus/db/aristo/aristo_init/persistent.nim index e6a6f14a26..4f214302e5 100644 --- a/nimbus/db/aristo/aristo_init/persistent.nim +++ b/nimbus/db/aristo/aristo_init/persistent.nim @@ -52,7 +52,7 @@ proc newAristoRdbDbRef( return err(rc.error) rc.value db = (AristoDbRef( - txRef: AristoTxRef(layer: LayerRef(vTop: vTop)), + txRef: AristoTxRef(layer: LayerRef(vTop: vTop, cTop: vTop)), backend: be, accLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE), stoLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE), diff --git a/nimbus/db/aristo/aristo_tx/tx_frame.nim b/nimbus/db/aristo/aristo_tx/tx_frame.nim index a67059ccc0..2cd061a390 100644 --- a/nimbus/db/aristo/aristo_tx/tx_frame.nim +++ b/nimbus/db/aristo/aristo_tx/tx_frame.nim @@ -40,8 +40,7 @@ proc txFrameBegin*(db: AristoDbRef, parent: AristoTxRef): Result[AristoTxRef,Ari let vTop = parent.layer.vTop - layer = LayerRef( - vTop: vTop) + layer = LayerRef(vTop: vTop, cTop: vTop) ok AristoTxRef( db: db, @@ -58,7 +57,10 @@ proc rollback*( ## performed for this transactio. The previous transaction is returned if ## there was any. # TODO Everyone using this txref should repoint their parent field - tx.layer = LayerRef() + + let vTop = tx.layer[].cTop + tx.layer[] = Layer(vTop: vTop, cTop: vTop) + ok() @@ -69,8 +71,11 @@ proc commit*( ## # TODO Everyone using this txref should repoint their parent field doAssert tx.parent != nil, "should not commit the base tx" - mergeAndReset(tx.parent.layer[], tx.layer[]) + # A rollback after commit should reset to the new vTop! + tx.layer[].cTop = tx.layer[].vTop + + mergeAndReset(tx.parent.layer[], tx.layer[]) ok() diff --git a/nimbus/db/kvt/kvt_tx/tx_frame.nim b/nimbus/db/kvt/kvt_tx/tx_frame.nim index 597fe47097..bed04badc1 100644 --- a/nimbus/db/kvt/kvt_tx/tx_frame.nim +++ b/nimbus/db/kvt/kvt_tx/tx_frame.nim @@ -52,7 +52,7 @@ proc rollback*( ## there was any. ## - tx.layer = LayerRef() + tx.layer[] = Layer() ok() proc commit*(