Skip to content

Commit

Permalink
Rename CoreDx* -> CoreDb*
Browse files Browse the repository at this point in the history
why:
  The naming `CoreDx*` was used to differentiate the new CoreDb API from
  the legacy API which had descriptors named `CoreDb*`.
  • Loading branch information
mjfh committed Jun 19, 2024
1 parent a841033 commit 29a775c
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 155 deletions.
2 changes: 1 addition & 1 deletion nimbus/common/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ proc consensus*(com: CommonRef, header: BlockHeader): ConsensusType =

proc initializeEmptyDb*(com: CommonRef) =
let kvt = com.db.newKvt()
proc contains(kvt: CoreDxKvtRef; key: openArray[byte]): bool =
proc contains(kvt: CoreDbKvtRef; key: openArray[byte]): bool =
kvt.hasKey(key).expect "valid bool"
if canonicalHeadHashKey().toOpenArray notin kvt:
info "Writing genesis to DB"
Expand Down
2 changes: 1 addition & 1 deletion nimbus/core/tx_pool/tx_tasks/tx_packer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type

TxPackerStateRef = ref object
xp: TxPoolRef
tr: CoreDxMptRef
tr: CoreDbMptRef
cleanState: bool
balance: UInt256
blobGasUsed: uint64
Expand Down
26 changes: 13 additions & 13 deletions nimbus/db/core_db/backend/aristo_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
kBase = db.kdbBase

when false: # currently disabled
proc tracerSetup(flags: set[CoreDbCaptFlags]): CoreDxCaptRef =
proc tracerSetup(flags: set[CoreDbCaptFlags]): CoreDbCaptRef =
if db.tracer.isNil:
db.tracer = AristoTracerRef(parent: db)
db.tracer.init(kBase, aBase, flags)
else:
db.tracer.push(flags)
CoreDxCaptRef(methods: db.tracer.cptMethods)
CoreDbCaptRef(methods: db.tracer.cptMethods)

proc persistent(bn: Opt[BlockNumber]): CoreDbRc[void] =
const info = "persistentFn()"
Expand Down Expand Up @@ -164,7 +164,7 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
errorPrintFn: proc(e: CoreDbErrorRef): string =
e.errorPrint(),

newKvtFn: proc(): CoreDbRc[CoreDxKvtRef] =
newKvtFn: proc(): CoreDbRc[CoreDbKvtRef] =
kBase.newKvtHandler("newKvtFn()"),

newCtxFn: proc(): CoreDbCtxRef =
Expand All @@ -176,16 +176,16 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
swapCtxFn: proc(ctx: CoreDbCtxRef): CoreDbCtxRef =
aBase.swapCtx(ctx),

beginFn: proc(): CoreDxTxRef =
beginFn: proc(): CoreDbTxRef =
const info = "beginFn()"
let
aTx = aBase.txBegin info
kTx = kBase.txBegin info
dsc = CoreDxTxRef(methods: db.txMethods(aTx, kTx))
dsc = CoreDbTxRef(methods: db.txMethods(aTx, kTx))
db.bless(dsc),

# # currently disabled
# newCaptureFn: proc(flags:set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] =
# newCaptureFn: proc(flags:set[CoreDbCaptFlags]): CoreDbRc[CoreDbCaptRef] =
# ok(db.bless flags.tracerSetup()),

persistentFn: proc(bn: Opt[BlockNumber]): CoreDbRc[void] =
Expand Down Expand Up @@ -230,11 +230,11 @@ func toAristoProfData*(
result.aristo = db.AristoCoreDbRef.adbBase.api.AristoApiProfRef.data
result.kvt = db.AristoCoreDbRef.kdbBase.api.KvtApiProfRef.data

func toAristoApi*(kvt: CoreDxKvtRef): KvtApiRef =
func toAristoApi*(kvt: CoreDbKvtRef): KvtApiRef =
if kvt.parent.isAristo:
return AristoCoreDbRef(kvt.parent).kdbBase.api

func toAristoApi*(mpt: CoreDxMptRef): AristoApiRef =
func toAristoApi*(mpt: CoreDbMptRef): AristoApiRef =
if mpt.parent.isAristo:
return mpt.to(AristoApiRef)

Expand Down Expand Up @@ -264,35 +264,35 @@ include

# ------------------------

iterator aristoKvtPairsVoid*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
iterator aristoKvtPairsVoid*(dsc: CoreDbKvtRef): (Blob,Blob) {.rlpRaise.} =
let
api = dsc.toAristoApi()
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
defer: discard api.forget(p)
for (k,v) in use_kvt.VoidBackendRef.walkPairs p:
yield (k,v)

iterator aristoKvtPairsMem*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
iterator aristoKvtPairsMem*(dsc: CoreDbKvtRef): (Blob,Blob) {.rlpRaise.} =
let
api = dsc.toAristoApi()
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
defer: discard api.forget(p)
for (k,v) in use_kvt.MemBackendRef.walkPairs p:
yield (k,v)

iterator aristoMptPairs*(dsc: CoreDxMptRef): (Blob,Blob) {.noRaise.} =
iterator aristoMptPairs*(dsc: CoreDbMptRef): (Blob,Blob) {.noRaise.} =
let
api = dsc.to(AristoApiRef)
mpt = dsc.to(AristoDbRef)
for (k,v) in mpt.rightPairs LeafTie(root: dsc.rootID):
yield (api.pathAsBlob(k.path), api.serialise(mpt, v).valueOr(EmptyBlob))

iterator aristoReplicateMem*(dsc: CoreDxMptRef): (Blob,Blob) {.rlpRaise.} =
iterator aristoReplicateMem*(dsc: CoreDbMptRef): (Blob,Blob) {.rlpRaise.} =
## Instantiation for `MemBackendRef`
for k,v in aristoReplicate[use_ari.MemBackendRef](dsc):
yield (k,v)

iterator aristoReplicateVoid*(dsc: CoreDxMptRef): (Blob,Blob) {.rlpRaise.} =
iterator aristoReplicateVoid*(dsc: CoreDbMptRef): (Blob,Blob) {.rlpRaise.} =
## Instantiation for `VoidBackendRef`
for k,v in aristoReplicate[use_ari.VoidBackendRef](dsc):
yield (k,v)
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/core_db/backend/aristo_db/aristo_replicate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template valueOrApiError[U,V](rc: Result[U,V]; info: static[string]): U =
rc.valueOr: raise (ref AristoApiRlpError)(msg: info)

iterator aristoReplicate[T](
dsc: CoreDxMptRef;
dsc: CoreDbMptRef;
): (Blob,Blob)
{.gcsafe, raises: [AristoApiRlpError].} =
## Generic iterator used for building dedicated backend iterators.
Expand Down
46 changes: 23 additions & 23 deletions nimbus/db/core_db/backend/aristo_db/handlers_aristo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type
base: AristoBaseRef ## Local base descriptor
mpt*: AristoDbRef ## Aristo MPT database

AristoCoreDxAccRef = ref object of CoreDxAccRef
AristoCoreDbAccRef = ref object of CoreDbAccRef
base: AristoBaseRef ## Local base descriptor

AristoCoreDxMptRef = ref object of CoreDxMptRef
AristoCoreDbMptRef = ref object of CoreDbMptRef
base: AristoBaseRef ## Local base descriptor
mptRoot: VertexID ## State root, may be zero unless account
accPath: PathID ## Needed for storage tree/columns
Expand Down Expand Up @@ -94,7 +94,7 @@ func resetCol(colType: CoreDbColType): bool =
# -------------------------------

func toCoreDbAccount(
cAcc: AristoCoreDxAccRef;
cAcc: AristoCoreDbAccRef;
acc: AristoAccount;
address: EthAddress;
): CoreDbAccount =
Expand Down Expand Up @@ -184,7 +184,7 @@ func toVoidRc[T](
# Private `MPT` call back functions
# ------------------------------------------------------------------------------

proc mptMethods(cMpt: AristoCoreDxMptRef): CoreDbMptFns =
proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
## Generic columns database handlers
let
cMpt = cMpt # So it can savely be captured
Expand Down Expand Up @@ -319,7 +319,7 @@ proc mptMethods(cMpt: AristoCoreDxMptRef): CoreDbMptFns =
# Private account call back functions
# ------------------------------------------------------------------------------

proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =
proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
## Account columns database handlers
let
cAcc = cAcc # So it can savely be captured
Expand All @@ -333,8 +333,8 @@ proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =
base: base,
colType: CtAccounts)

proc accCloneMpt(): CoreDbRc[CoreDxMptRef] =
var xpt = AristoCoreDxMptRef(
proc accCloneMpt(): CoreDbRc[CoreDbMptRef] =
var xpt = AristoCoreDbMptRef(
base: base,
mptRoot: AccountsVID)
xpt.methods = xpt.mptMethods
Expand Down Expand Up @@ -394,7 +394,7 @@ proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =


CoreDbAccFns(
getMptFn: proc(): CoreDbRc[CoreDxMptRef] =
getMptFn: proc(): CoreDbRc[CoreDbMptRef] =
accCloneMpt(),

fetchFn: proc(address: EthAddress): CoreDbRc[CoreDbAccount] =
Expand Down Expand Up @@ -463,22 +463,22 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
err(aristo.GenericError.toError(base, info, RootNotFound))


proc ctxGetMpt(col: CoreDbColRef): CoreDbRc[CoreDxMptRef] =
proc ctxGetMpt(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
const
info = "ctx/getMptFn()"
let
col = AristoColRef(col)
var
reset = false
newMpt: AristoCoreDxMptRef
newMpt: AristoCoreDbMptRef
if not col.isValid:
reset = true
newMpt = AristoCoreDxMptRef(
newMpt = AristoCoreDbMptRef(
mptRoot: GenericVID,
accPath: VOID_PATH_ID)

elif col.colType == CtStorage:
newMpt = AristoCoreDxMptRef(
newMpt = AristoCoreDbMptRef(
mptRoot: col.stoRoot,
accPath: col.stoAddr.to(PathID),
address: col.stoAddr)
Expand All @@ -492,7 +492,7 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
return err(rc.error[1].toError(base, info, AccNotFound))
else:
reset = col.colType.resetCol()
newMpt = AristoCoreDxMptRef(
newMpt = AristoCoreDbMptRef(
mptRoot: VertexID(col.colType),
accPath: VOID_PATH_ID)

Expand All @@ -508,15 +508,15 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
newMpt.methods = newMpt.mptMethods()
ok(db.bless newMpt)

proc ctxGetAcc(col: CoreDbColRef): CoreDbRc[CoreDxAccRef] =
proc ctxGetAcc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
const info = "getAccFn()"

let col = AristoColRef(col)
if col.colType != CtAccounts:
let error = (AccountsVID, AccRootUnacceptable)
return err(error.toError(base, info, RootUnacceptable))

let acc = AristoCoreDxAccRef(base: base)
let acc = AristoCoreDbAccRef(base: base)
acc.methods = acc.accMethods()

ok(db.bless acc)
Expand All @@ -534,10 +534,10 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
): CoreDbRc[CoreDbColRef] =
ctxNewCol(col, colState, address),

getMptFn: proc(col: CoreDbColRef): CoreDbRc[CoreDxMptRef] =
getMptFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
ctxGetMpt(col),

getAccFn: proc(col: CoreDbColRef): CoreDbRc[CoreDxAccRef] =
getAccFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
ctxGetAcc(col),

forgetFn: proc() =
Expand Down Expand Up @@ -579,14 +579,14 @@ proc getSavedState*(base: AristoBaseRef): Result[SavedState,void] =

# ---------------------

func to*(dsc: CoreDxMptRef, T: type AristoDbRef): T =
AristoCoreDxMptRef(dsc).base.ctx.mpt
func to*(dsc: CoreDbMptRef, T: type AristoDbRef): T =
AristoCoreDbMptRef(dsc).base.ctx.mpt

func to*(dsc: CoreDxMptRef, T: type AristoApiRef): T =
AristoCoreDxMptRef(dsc).base.api
func to*(dsc: CoreDbMptRef, T: type AristoApiRef): T =
AristoCoreDbMptRef(dsc).base.api

func rootID*(dsc: CoreDxMptRef): VertexID =
AristoCoreDxMptRef(dsc).mptRoot
func rootID*(dsc: CoreDbMptRef): VertexID =
AristoCoreDbMptRef(dsc).mptRoot

func txTop*(
base: AristoBaseRef;
Expand Down
26 changes: 13 additions & 13 deletions nimbus/db/core_db/backend/aristo_db/handlers_kvt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type
parent: CoreDbRef ## Opaque top level descriptor
kdb: KvtDbRef ## Shared key-value table
api*: KvtApiRef ## Api functions can be re-directed
cache: KvtCoreDxKvtRef ## Shared transaction table wrapper
cache: KvtCoreDbKvtRef ## Shared transaction table wrapper

KvtCoreDxKvtRef = ref object of CoreDxKvtRef
KvtCoreDbKvtRef = ref object of CoreDbKvtRef
base: KvtBaseRef ## Local base descriptor
kvt: KvtDbRef ## In most cases different from `base.kdb`

Expand Down Expand Up @@ -68,16 +68,16 @@ func toRc[T](
# Private `kvt` call back functions
# ------------------------------------------------------------------------------

proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
proc kvtMethods(cKvt: KvtCoreDbKvtRef): CoreDbKvtFns =
## Key-value database table handlers

proc kvtBackend(
cKvt:KvtCoreDxKvtRef;
cKvt:KvtCoreDbKvtRef;
): CoreDbKvtBackendRef =
cKvt.base.parent.bless AristoCoreDbKvtBE(kdb: cKvt.kvt)

proc kvtForget(
cKvt: KvtCoreDxKvtRef;
cKvt: KvtCoreDbKvtRef;
info: static[string];
): CoreDbRc[void] =
let
Expand All @@ -95,7 +95,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
ok()

proc kvtGet(
cKvt: KvtCoreDxKvtRef;
cKvt: KvtCoreDbKvtRef;
k: openArray[byte];
info: static[string];
): CoreDbRc[Blob] =
Expand All @@ -108,7 +108,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
rc.toRc(cKvt.base, info)

proc kvtPut(
cKvt: KvtCoreDxKvtRef;
cKvt: KvtCoreDbKvtRef;
k: openArray[byte];
v: openArray[byte];
info: static[string];
Expand All @@ -120,7 +120,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
err(rc.error.toError(cKvt.base, info))

proc kvtDel(
cKvt: KvtCoreDxKvtRef;
cKvt: KvtCoreDbKvtRef;
k: openArray[byte];
info: static[string];
): CoreDbRc[void] =
Expand All @@ -131,7 +131,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
err(rc.error.toError(cKvt.base, info))

proc kvtHasKey(
cKvt: KvtCoreDxKvtRef;
cKvt: KvtCoreDbKvtRef;
k: openArray[byte];
info: static[string];
): CoreDbRc[bool] =
Expand Down Expand Up @@ -176,8 +176,8 @@ func toVoidRc*[T](

# ---------------------

func to*(dsc: CoreDxKvtRef; T: type KvtDbRef): T =
KvtCoreDxKvtRef(dsc).kvt
func to*(dsc: CoreDbKvtRef; T: type KvtDbRef): T =
KvtCoreDbKvtRef(dsc).kvt

func txTop*(
base: KvtBaseRef;
Expand Down Expand Up @@ -219,7 +219,7 @@ proc persistent*(
proc newKvtHandler*(
base: KvtBaseRef;
info: static[string];
): CoreDbRc[CoreDxKvtRef] =
): CoreDbRc[CoreDbKvtRef] =
ok(base.cache)


Expand All @@ -234,7 +234,7 @@ func init*(T: type KvtBaseRef; db: CoreDbRef; kdb: KvtDbRef): T =
kdb: kdb)

# Preallocated shared descriptor
let dsc = KvtCoreDxKvtRef(
let dsc = KvtCoreDbKvtRef(
base: result,
kvt: kdb)
dsc.methods = dsc.kvtMethods()
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/core_db/backend/aristo_rocksdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ proc newAristoDualRocksDbCoreDbRef*(path: string, opts: DbOptions): CoreDbRef =
# Public aristo iterators
# ------------------------------------------------------------------------------

iterator aristoReplicateRdb*(dsc: CoreDxMptRef): (Blob, Blob) {.rlpRaise.} =
iterator aristoReplicateRdb*(dsc: CoreDbMptRef): (Blob, Blob) {.rlpRaise.} =
## Instantiation for `VoidBackendRef`
for k, v in aristoReplicate[use_ari.RdbBackendRef](dsc):
yield (k, v)
Expand Down
Loading

0 comments on commit 29a775c

Please sign in to comment.