2023-06-20 13:26:25 +00:00
|
|
|
# nimbus-eth1
|
2024-03-14 22:17:43 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-06-20 13:26:25 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2023-06-30 22:22:33 +00:00
|
|
|
../aristo_desc,
|
2023-08-25 22:53:59 +00:00
|
|
|
../aristo_desc/desc_backend
|
2023-06-20 13:26:25 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
verifyIxId = true # and false
|
|
|
|
## Enforce session tracking
|
|
|
|
|
|
|
|
type
|
2023-08-18 19:46:55 +00:00
|
|
|
BackendType* = enum
|
2023-09-15 15:23:53 +00:00
|
|
|
BackendVoid = 0 ## For providing backend-less constructor
|
2023-06-20 13:26:25 +00:00
|
|
|
BackendMemory
|
|
|
|
BackendRocksDB
|
2024-06-13 18:15:11 +00:00
|
|
|
BackendRdbHosting ## Allowed piggybacking write session
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2023-08-18 19:46:55 +00:00
|
|
|
StorageType* = enum
|
|
|
|
## Storage types, key prefix
|
|
|
|
Oops = 0
|
2023-08-21 14:58:30 +00:00
|
|
|
AdmPfx = 1 ## Admin data, e.g. ID generator
|
2023-08-18 19:46:55 +00:00
|
|
|
VtxPfx = 2 ## Vertex data
|
|
|
|
KeyPfx = 3 ## Key/hash data
|
|
|
|
|
2023-08-21 14:58:30 +00:00
|
|
|
AdminTabID* = distinct uint64
|
|
|
|
## Access keys for admin table records. When exposed (e.g. when itereating
|
|
|
|
## over the tables), this data type is to be used.
|
|
|
|
|
2024-04-16 20:39:11 +00:00
|
|
|
GuestDbRef* = ref object of RootRef
|
|
|
|
## Object returned from `GuestDbFn` (if any)
|
|
|
|
beKind*: BackendType ## Backend type identifier
|
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
TypedBackendRef* = ref TypedBackendObj
|
|
|
|
TypedBackendObj* = object of BackendObj
|
2023-09-05 13:57:20 +00:00
|
|
|
beKind*: BackendType ## Backend type identifier
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
txGen: uint ## Transaction ID generator (for debugging)
|
|
|
|
txId: uint ## Active transaction ID (for debugging)
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
TypedPutHdlErrRef* = ref object of RootRef
|
2023-08-18 19:46:55 +00:00
|
|
|
case pfx*: StorageType ## Error sub-table
|
|
|
|
of VtxPfx, KeyPfx:
|
|
|
|
vid*: VertexID ## Vertex ID where the error occured
|
2024-04-16 20:39:11 +00:00
|
|
|
of AdmPfx:
|
|
|
|
aid*: AdminTabID
|
|
|
|
of Oops:
|
2023-08-18 19:46:55 +00:00
|
|
|
discard
|
2023-06-30 22:22:33 +00:00
|
|
|
code*: AristoError ## Error code (if any)
|
2024-04-16 20:39:11 +00:00
|
|
|
info*: string ## Error description (if any)
|
2023-06-30 22:22:33 +00:00
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
TypedPutHdlRef* = ref object of PutHdlRef
|
2023-06-30 22:22:33 +00:00
|
|
|
error*: TypedPutHdlErrRef ## Track error while collecting transaction
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
txId: uint ## Transaction ID (for debugging)
|
|
|
|
|
2023-08-21 14:58:30 +00:00
|
|
|
const
|
2024-06-04 15:05:13 +00:00
|
|
|
AdmTabIdTuv* = AdminTabID(0) ## Access key for vertex ID generator state
|
2024-05-31 17:32:22 +00:00
|
|
|
AdmTabIdLst* = AdminTabID(2) ## Access key for last state
|
2023-08-21 14:58:30 +00:00
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc beginSession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == 0
|
|
|
|
if db.txGen == 0:
|
|
|
|
db.txGen = 1
|
|
|
|
db.txId = db.txGen
|
|
|
|
hdl.txId = db.txGen
|
|
|
|
db.txGen.inc
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc verifySession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == hdl.txId
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc finishSession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == hdl.txId
|
|
|
|
db.txId = 0
|
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
proc init*(trg: var TypedBackendObj; src: TypedBackendObj) =
|
|
|
|
desc_backend.init(trg, src)
|
|
|
|
trg.beKind = src.beKind
|
|
|
|
when verifyIxId:
|
|
|
|
trg.txGen = src.txGen
|
|
|
|
trg.txId = src.txId
|
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|