2023-06-12 13:48:47 +00:00
|
|
|
# nimbus-eth1
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
2023-09-12 18:45:12 +00:00
|
|
|
## Aristo DB -- Patricia Trie backend data access
|
|
|
|
## ==============================================
|
2023-06-12 13:48:47 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2023-08-10 20:01:28 +00:00
|
|
|
results,
|
2023-08-25 22:53:59 +00:00
|
|
|
"."/[desc_error, desc_identifiers, desc_structural]
|
2023-06-12 13:48:47 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
GetVtxFn* =
|
|
|
|
proc(vid: VertexID): Result[VertexRef,AristoError] {.gcsafe, raises: [].}
|
2023-06-20 13:26:25 +00:00
|
|
|
## Generic backend database retrieval function for a single structural
|
|
|
|
## `Aristo DB` data record.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
|
|
|
GetKeyFn* =
|
2023-06-12 18:16:03 +00:00
|
|
|
proc(vid: VertexID): Result[HashKey,AristoError] {.gcsafe, raises: [].}
|
2023-06-20 13:26:25 +00:00
|
|
|
## Generic backend database retrieval function for a single
|
|
|
|
## `Aristo DB` hash lookup value.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
2023-08-22 18:44:54 +00:00
|
|
|
GetFilFn* =
|
2023-08-25 22:53:59 +00:00
|
|
|
proc(qid: QueueID): Result[FilterRef,AristoError]
|
2023-08-22 18:44:54 +00:00
|
|
|
{.gcsafe, raises: [].}
|
|
|
|
## Generic backend database retrieval function for a filter record.
|
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
GetIdgFn* =
|
|
|
|
proc(): Result[seq[VertexID],AristoError] {.gcsafe, raises: [].}
|
2023-06-20 13:26:25 +00:00
|
|
|
## Generic backend database retrieval function for a the ID generator
|
|
|
|
## `Aristo DB` state record.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
2023-08-25 22:53:59 +00:00
|
|
|
GetFqsFn* =
|
|
|
|
proc(): Result[seq[(QueueID,QueueID)],AristoError] {.gcsafe, raises: [].}
|
|
|
|
## Generic backend database retrieval function for some filter queue
|
|
|
|
## administration data (e.g. the bottom/top ID.)
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
# -------------
|
|
|
|
|
|
|
|
PutHdlRef* = ref object of RootRef
|
|
|
|
## Persistent database transaction frame handle. This handle is used to
|
|
|
|
## wrap any of `PutVtxFn`, `PutKeyFn`, and `PutIdgFn` into and atomic
|
|
|
|
## transaction frame. These transaction frames must not be interleaved
|
|
|
|
## by any library function using the backend.
|
|
|
|
|
|
|
|
PutBegFn* =
|
|
|
|
proc(): PutHdlRef {.gcsafe, raises: [].}
|
|
|
|
## Generic transaction initialisation function
|
|
|
|
|
|
|
|
PutVtxFn* =
|
|
|
|
proc(hdl: PutHdlRef; vrps: openArray[(VertexID,VertexRef)])
|
|
|
|
{.gcsafe, raises: [].}
|
2023-06-20 13:26:25 +00:00
|
|
|
## Generic backend database bulk storage function, `VertexRef(nil)`
|
|
|
|
## values indicate that records should be deleted.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
|
|
|
PutKeyFn* =
|
2023-06-12 18:16:03 +00:00
|
|
|
proc(hdl: PutHdlRef; vkps: openArray[(VertexID,HashKey)])
|
2023-06-12 13:48:47 +00:00
|
|
|
{.gcsafe, raises: [].}
|
2023-06-20 13:26:25 +00:00
|
|
|
## Generic backend database bulk storage function, `VOID_HASH_KEY`
|
|
|
|
## values indicate that records should be deleted.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
2023-08-22 18:44:54 +00:00
|
|
|
PutFilFn* =
|
2023-08-25 22:53:59 +00:00
|
|
|
proc(hdl: PutHdlRef; qf: openArray[(QueueID,FilterRef)])
|
2023-08-22 18:44:54 +00:00
|
|
|
{.gcsafe, raises: [].}
|
|
|
|
## Generic backend database storage function for filter records.
|
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
PutIdgFn* =
|
2023-06-20 13:26:25 +00:00
|
|
|
proc(hdl: PutHdlRef; vs: openArray[VertexID])
|
|
|
|
{.gcsafe, raises: [].}
|
|
|
|
## Generic backend database ID generator state storage function. This
|
|
|
|
## function replaces the current generator state.
|
2023-06-12 13:48:47 +00:00
|
|
|
|
2023-08-25 22:53:59 +00:00
|
|
|
PutFqsFn* =
|
|
|
|
proc(hdl: PutHdlRef; vs: openArray[(QueueID,QueueID)])
|
2023-08-22 18:44:54 +00:00
|
|
|
{.gcsafe, raises: [].}
|
|
|
|
## Generic backend database filter ID state storage function. This
|
2023-08-25 22:53:59 +00:00
|
|
|
## function replaces the current filter ID list.
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
PutEndFn* =
|
2023-09-12 18:45:12 +00:00
|
|
|
proc(hdl: PutHdlRef): Result[void,AristoError] {.gcsafe, raises: [].}
|
2023-06-12 13:48:47 +00:00
|
|
|
## Generic transaction termination function
|
|
|
|
|
|
|
|
# -------------
|
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
CloseFn* =
|
|
|
|
proc(flush: bool) {.gcsafe, raises: [].}
|
|
|
|
## Generic destructor for the `Aristo DB` backend. The argument `flush`
|
|
|
|
## indicates that a full database deletion is requested. If passed
|
|
|
|
## `false` the outcome might differ depending on the type of backend
|
|
|
|
## (e.g. in-memory backends would flush on close.)
|
2023-06-12 13:48:47 +00:00
|
|
|
|
2023-08-10 20:01:28 +00:00
|
|
|
# -------------
|
|
|
|
|
2023-08-18 19:46:55 +00:00
|
|
|
BackendRef* = ref object of RootRef
|
2023-06-12 13:48:47 +00:00
|
|
|
## Backend interface.
|
2023-09-05 13:57:20 +00:00
|
|
|
filters*: QidSchedRef ## Filter slot queue state
|
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
getVtxFn*: GetVtxFn ## Read vertex record
|
|
|
|
getKeyFn*: GetKeyFn ## Read Merkle hash/key
|
2023-08-22 18:44:54 +00:00
|
|
|
getFilFn*: GetFilFn ## Read back log filter
|
|
|
|
getIdgFn*: GetIdgFn ## Read vertex ID generator state
|
2023-08-25 22:53:59 +00:00
|
|
|
getFqsFn*: GetFqsFn ## Read filter ID state
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2023-06-12 13:48:47 +00:00
|
|
|
putBegFn*: PutBegFn ## Start bulk store session
|
|
|
|
putVtxFn*: PutVtxFn ## Bulk store vertex records
|
|
|
|
putKeyFn*: PutKeyFn ## Bulk store vertex hashes
|
2023-08-22 18:44:54 +00:00
|
|
|
putFilFn*: PutFilFn ## Store back log filter
|
2023-06-12 13:48:47 +00:00
|
|
|
putIdgFn*: PutIdgFn ## Store ID generator state
|
2023-08-25 22:53:59 +00:00
|
|
|
putFqsFn*: PutFqsFn ## Store filter ID state
|
2023-06-12 13:48:47 +00:00
|
|
|
putEndFn*: PutEndFn ## Commit bulk store session
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
closeFn*: CloseFn ## Generic destructor
|
2023-06-12 13:48:47 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|