Coredb maintenance (#2398)
* CoreDb: remove PHK tries why: There is no general use anymore for an MPT with a pre-hashed key. It was used to resemble the `SecureHexaryTrie` logic from the legacy DB. The only pace where this is needed is the `Leger` which uses a a distinct MPT version anyway (see `distinct_ledgers.nim`.) * Rename `CoreDx*` -> `CoreDb*` why: The naming `CoreDx*` was used to differentiate the new CoreDb API from the legacy API which had descriptors named `CoreDb*`.
This commit is contained in:
parent
e7be0d185c
commit
081cb15493
|
@ -357,7 +357,7 @@ proc consensus*(com: CommonRef, header: BlockHeader): ConsensusType =
|
||||||
|
|
||||||
proc initializeEmptyDb*(com: CommonRef) =
|
proc initializeEmptyDb*(com: CommonRef) =
|
||||||
let kvt = com.db.newKvt()
|
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"
|
kvt.hasKey(key).expect "valid bool"
|
||||||
if canonicalHeadHashKey().toOpenArray notin kvt:
|
if canonicalHeadHashKey().toOpenArray notin kvt:
|
||||||
info "Writing genesis to DB"
|
info "Writing genesis to DB"
|
||||||
|
|
|
@ -36,7 +36,7 @@ type
|
||||||
|
|
||||||
TxPackerStateRef = ref object
|
TxPackerStateRef = ref object
|
||||||
xp: TxPoolRef
|
xp: TxPoolRef
|
||||||
tr: CoreDxMptRef
|
tr: CoreDbMptRef
|
||||||
cleanState: bool
|
cleanState: bool
|
||||||
balance: UInt256
|
balance: UInt256
|
||||||
blobGasUsed: uint64
|
blobGasUsed: uint64
|
||||||
|
|
|
@ -127,13 +127,13 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
|
||||||
kBase = db.kdbBase
|
kBase = db.kdbBase
|
||||||
|
|
||||||
when false: # currently disabled
|
when false: # currently disabled
|
||||||
proc tracerSetup(flags: set[CoreDbCaptFlags]): CoreDxCaptRef =
|
proc tracerSetup(flags: set[CoreDbCaptFlags]): CoreDbCaptRef =
|
||||||
if db.tracer.isNil:
|
if db.tracer.isNil:
|
||||||
db.tracer = AristoTracerRef(parent: db)
|
db.tracer = AristoTracerRef(parent: db)
|
||||||
db.tracer.init(kBase, aBase, flags)
|
db.tracer.init(kBase, aBase, flags)
|
||||||
else:
|
else:
|
||||||
db.tracer.push(flags)
|
db.tracer.push(flags)
|
||||||
CoreDxCaptRef(methods: db.tracer.cptMethods)
|
CoreDbCaptRef(methods: db.tracer.cptMethods)
|
||||||
|
|
||||||
proc persistent(bn: Opt[BlockNumber]): CoreDbRc[void] =
|
proc persistent(bn: Opt[BlockNumber]): CoreDbRc[void] =
|
||||||
const info = "persistentFn()"
|
const info = "persistentFn()"
|
||||||
|
@ -164,7 +164,7 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
|
||||||
errorPrintFn: proc(e: CoreDbErrorRef): string =
|
errorPrintFn: proc(e: CoreDbErrorRef): string =
|
||||||
e.errorPrint(),
|
e.errorPrint(),
|
||||||
|
|
||||||
newKvtFn: proc(): CoreDbRc[CoreDxKvtRef] =
|
newKvtFn: proc(): CoreDbRc[CoreDbKvtRef] =
|
||||||
kBase.newKvtHandler("newKvtFn()"),
|
kBase.newKvtHandler("newKvtFn()"),
|
||||||
|
|
||||||
newCtxFn: proc(): CoreDbCtxRef =
|
newCtxFn: proc(): CoreDbCtxRef =
|
||||||
|
@ -176,16 +176,16 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns =
|
||||||
swapCtxFn: proc(ctx: CoreDbCtxRef): CoreDbCtxRef =
|
swapCtxFn: proc(ctx: CoreDbCtxRef): CoreDbCtxRef =
|
||||||
aBase.swapCtx(ctx),
|
aBase.swapCtx(ctx),
|
||||||
|
|
||||||
beginFn: proc(): CoreDxTxRef =
|
beginFn: proc(): CoreDbTxRef =
|
||||||
const info = "beginFn()"
|
const info = "beginFn()"
|
||||||
let
|
let
|
||||||
aTx = aBase.txBegin info
|
aTx = aBase.txBegin info
|
||||||
kTx = kBase.txBegin info
|
kTx = kBase.txBegin info
|
||||||
dsc = CoreDxTxRef(methods: db.txMethods(aTx, kTx))
|
dsc = CoreDbTxRef(methods: db.txMethods(aTx, kTx))
|
||||||
db.bless(dsc),
|
db.bless(dsc),
|
||||||
|
|
||||||
# # currently disabled
|
# # currently disabled
|
||||||
# newCaptureFn: proc(flags:set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] =
|
# newCaptureFn: proc(flags:set[CoreDbCaptFlags]): CoreDbRc[CoreDbCaptRef] =
|
||||||
# ok(db.bless flags.tracerSetup()),
|
# ok(db.bless flags.tracerSetup()),
|
||||||
|
|
||||||
persistentFn: proc(bn: Opt[BlockNumber]): CoreDbRc[void] =
|
persistentFn: proc(bn: Opt[BlockNumber]): CoreDbRc[void] =
|
||||||
|
@ -230,11 +230,11 @@ func toAristoProfData*(
|
||||||
result.aristo = db.AristoCoreDbRef.adbBase.api.AristoApiProfRef.data
|
result.aristo = db.AristoCoreDbRef.adbBase.api.AristoApiProfRef.data
|
||||||
result.kvt = db.AristoCoreDbRef.kdbBase.api.KvtApiProfRef.data
|
result.kvt = db.AristoCoreDbRef.kdbBase.api.KvtApiProfRef.data
|
||||||
|
|
||||||
func toAristoApi*(kvt: CoreDxKvtRef): KvtApiRef =
|
func toAristoApi*(kvt: CoreDbKvtRef): KvtApiRef =
|
||||||
if kvt.parent.isAristo:
|
if kvt.parent.isAristo:
|
||||||
return AristoCoreDbRef(kvt.parent).kdbBase.api
|
return AristoCoreDbRef(kvt.parent).kdbBase.api
|
||||||
|
|
||||||
func toAristoApi*(mpt: CoreDxMptRef): AristoApiRef =
|
func toAristoApi*(mpt: CoreDbMptRef): AristoApiRef =
|
||||||
if mpt.parent.isAristo:
|
if mpt.parent.isAristo:
|
||||||
return mpt.to(AristoApiRef)
|
return mpt.to(AristoApiRef)
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ include
|
||||||
|
|
||||||
# ------------------------
|
# ------------------------
|
||||||
|
|
||||||
iterator aristoKvtPairsVoid*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
iterator aristoKvtPairsVoid*(dsc: CoreDbKvtRef): (Blob,Blob) {.rlpRaise.} =
|
||||||
let
|
let
|
||||||
api = dsc.toAristoApi()
|
api = dsc.toAristoApi()
|
||||||
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
|
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
|
||||||
|
@ -272,7 +272,7 @@ iterator aristoKvtPairsVoid*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
||||||
for (k,v) in use_kvt.VoidBackendRef.walkPairs p:
|
for (k,v) in use_kvt.VoidBackendRef.walkPairs p:
|
||||||
yield (k,v)
|
yield (k,v)
|
||||||
|
|
||||||
iterator aristoKvtPairsMem*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
iterator aristoKvtPairsMem*(dsc: CoreDbKvtRef): (Blob,Blob) {.rlpRaise.} =
|
||||||
let
|
let
|
||||||
api = dsc.toAristoApi()
|
api = dsc.toAristoApi()
|
||||||
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
|
p = api.forkTx(dsc.to(KvtDbRef),0).valueOrApiError "aristoKvtPairs()"
|
||||||
|
@ -280,19 +280,19 @@ iterator aristoKvtPairsMem*(dsc: CoreDxKvtRef): (Blob,Blob) {.rlpRaise.} =
|
||||||
for (k,v) in use_kvt.MemBackendRef.walkPairs p:
|
for (k,v) in use_kvt.MemBackendRef.walkPairs p:
|
||||||
yield (k,v)
|
yield (k,v)
|
||||||
|
|
||||||
iterator aristoMptPairs*(dsc: CoreDxMptRef): (Blob,Blob) {.noRaise.} =
|
iterator aristoMptPairs*(dsc: CoreDbMptRef): (Blob,Blob) {.noRaise.} =
|
||||||
let
|
let
|
||||||
api = dsc.to(AristoApiRef)
|
api = dsc.to(AristoApiRef)
|
||||||
mpt = dsc.to(AristoDbRef)
|
mpt = dsc.to(AristoDbRef)
|
||||||
for (k,v) in mpt.rightPairs LeafTie(root: dsc.rootID):
|
for (k,v) in mpt.rightPairs LeafTie(root: dsc.rootID):
|
||||||
yield (api.pathAsBlob(k.path), api.serialise(mpt, v).valueOr(EmptyBlob))
|
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`
|
## Instantiation for `MemBackendRef`
|
||||||
for k,v in aristoReplicate[use_ari.MemBackendRef](dsc):
|
for k,v in aristoReplicate[use_ari.MemBackendRef](dsc):
|
||||||
yield (k,v)
|
yield (k,v)
|
||||||
|
|
||||||
iterator aristoReplicateVoid*(dsc: CoreDxMptRef): (Blob,Blob) {.rlpRaise.} =
|
iterator aristoReplicateVoid*(dsc: CoreDbMptRef): (Blob,Blob) {.rlpRaise.} =
|
||||||
## Instantiation for `VoidBackendRef`
|
## Instantiation for `VoidBackendRef`
|
||||||
for k,v in aristoReplicate[use_ari.VoidBackendRef](dsc):
|
for k,v in aristoReplicate[use_ari.VoidBackendRef](dsc):
|
||||||
yield (k,v)
|
yield (k,v)
|
||||||
|
|
|
@ -20,7 +20,7 @@ template valueOrApiError[U,V](rc: Result[U,V]; info: static[string]): U =
|
||||||
rc.valueOr: raise (ref AristoApiRlpError)(msg: info)
|
rc.valueOr: raise (ref AristoApiRlpError)(msg: info)
|
||||||
|
|
||||||
iterator aristoReplicate[T](
|
iterator aristoReplicate[T](
|
||||||
dsc: CoreDxMptRef;
|
dsc: CoreDbMptRef;
|
||||||
): (Blob,Blob)
|
): (Blob,Blob)
|
||||||
{.gcsafe, raises: [AristoApiRlpError].} =
|
{.gcsafe, raises: [AristoApiRlpError].} =
|
||||||
## Generic iterator used for building dedicated backend iterators.
|
## Generic iterator used for building dedicated backend iterators.
|
||||||
|
|
|
@ -31,10 +31,10 @@ type
|
||||||
base: AristoBaseRef ## Local base descriptor
|
base: AristoBaseRef ## Local base descriptor
|
||||||
mpt*: AristoDbRef ## Aristo MPT database
|
mpt*: AristoDbRef ## Aristo MPT database
|
||||||
|
|
||||||
AristoCoreDxAccRef = ref object of CoreDxAccRef
|
AristoCoreDbAccRef = ref object of CoreDbAccRef
|
||||||
base: AristoBaseRef ## Local base descriptor
|
base: AristoBaseRef ## Local base descriptor
|
||||||
|
|
||||||
AristoCoreDxMptRef = ref object of CoreDxMptRef
|
AristoCoreDbMptRef = ref object of CoreDbMptRef
|
||||||
base: AristoBaseRef ## Local base descriptor
|
base: AristoBaseRef ## Local base descriptor
|
||||||
mptRoot: VertexID ## State root, may be zero unless account
|
mptRoot: VertexID ## State root, may be zero unless account
|
||||||
accPath: PathID ## Needed for storage tree/columns
|
accPath: PathID ## Needed for storage tree/columns
|
||||||
|
@ -94,7 +94,7 @@ func resetCol(colType: CoreDbColType): bool =
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
func toCoreDbAccount(
|
func toCoreDbAccount(
|
||||||
cAcc: AristoCoreDxAccRef;
|
cAcc: AristoCoreDbAccRef;
|
||||||
acc: AristoAccount;
|
acc: AristoAccount;
|
||||||
address: EthAddress;
|
address: EthAddress;
|
||||||
): CoreDbAccount =
|
): CoreDbAccount =
|
||||||
|
@ -184,7 +184,7 @@ func toVoidRc[T](
|
||||||
# Private `MPT` call back functions
|
# Private `MPT` call back functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc mptMethods(cMpt: AristoCoreDxMptRef): CoreDbMptFns =
|
proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
|
||||||
## Generic columns database handlers
|
## Generic columns database handlers
|
||||||
let
|
let
|
||||||
cMpt = cMpt # So it can savely be captured
|
cMpt = cMpt # So it can savely be captured
|
||||||
|
@ -319,7 +319,7 @@ proc mptMethods(cMpt: AristoCoreDxMptRef): CoreDbMptFns =
|
||||||
# Private account call back functions
|
# Private account call back functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =
|
proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
|
||||||
## Account columns database handlers
|
## Account columns database handlers
|
||||||
let
|
let
|
||||||
cAcc = cAcc # So it can savely be captured
|
cAcc = cAcc # So it can savely be captured
|
||||||
|
@ -333,8 +333,8 @@ proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =
|
||||||
base: base,
|
base: base,
|
||||||
colType: CtAccounts)
|
colType: CtAccounts)
|
||||||
|
|
||||||
proc accCloneMpt(): CoreDbRc[CoreDxMptRef] =
|
proc accCloneMpt(): CoreDbRc[CoreDbMptRef] =
|
||||||
var xpt = AristoCoreDxMptRef(
|
var xpt = AristoCoreDbMptRef(
|
||||||
base: base,
|
base: base,
|
||||||
mptRoot: AccountsVID)
|
mptRoot: AccountsVID)
|
||||||
xpt.methods = xpt.mptMethods
|
xpt.methods = xpt.mptMethods
|
||||||
|
@ -394,7 +394,7 @@ proc accMethods(cAcc: AristoCoreDxAccRef): CoreDbAccFns =
|
||||||
|
|
||||||
|
|
||||||
CoreDbAccFns(
|
CoreDbAccFns(
|
||||||
getMptFn: proc(): CoreDbRc[CoreDxMptRef] =
|
getMptFn: proc(): CoreDbRc[CoreDbMptRef] =
|
||||||
accCloneMpt(),
|
accCloneMpt(),
|
||||||
|
|
||||||
fetchFn: proc(address: EthAddress): CoreDbRc[CoreDbAccount] =
|
fetchFn: proc(address: EthAddress): CoreDbRc[CoreDbAccount] =
|
||||||
|
@ -463,22 +463,22 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
|
||||||
err(aristo.GenericError.toError(base, info, RootNotFound))
|
err(aristo.GenericError.toError(base, info, RootNotFound))
|
||||||
|
|
||||||
|
|
||||||
proc ctxGetMpt(col: CoreDbColRef): CoreDbRc[CoreDxMptRef] =
|
proc ctxGetMpt(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
|
||||||
const
|
const
|
||||||
info = "ctx/getMptFn()"
|
info = "ctx/getMptFn()"
|
||||||
let
|
let
|
||||||
col = AristoColRef(col)
|
col = AristoColRef(col)
|
||||||
var
|
var
|
||||||
reset = false
|
reset = false
|
||||||
newMpt: AristoCoreDxMptRef
|
newMpt: AristoCoreDbMptRef
|
||||||
if not col.isValid:
|
if not col.isValid:
|
||||||
reset = true
|
reset = true
|
||||||
newMpt = AristoCoreDxMptRef(
|
newMpt = AristoCoreDbMptRef(
|
||||||
mptRoot: GenericVID,
|
mptRoot: GenericVID,
|
||||||
accPath: VOID_PATH_ID)
|
accPath: VOID_PATH_ID)
|
||||||
|
|
||||||
elif col.colType == CtStorage:
|
elif col.colType == CtStorage:
|
||||||
newMpt = AristoCoreDxMptRef(
|
newMpt = AristoCoreDbMptRef(
|
||||||
mptRoot: col.stoRoot,
|
mptRoot: col.stoRoot,
|
||||||
accPath: col.stoAddr.to(PathID),
|
accPath: col.stoAddr.to(PathID),
|
||||||
address: col.stoAddr)
|
address: col.stoAddr)
|
||||||
|
@ -492,7 +492,7 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
|
||||||
return err(rc.error[1].toError(base, info, AccNotFound))
|
return err(rc.error[1].toError(base, info, AccNotFound))
|
||||||
else:
|
else:
|
||||||
reset = col.colType.resetCol()
|
reset = col.colType.resetCol()
|
||||||
newMpt = AristoCoreDxMptRef(
|
newMpt = AristoCoreDbMptRef(
|
||||||
mptRoot: VertexID(col.colType),
|
mptRoot: VertexID(col.colType),
|
||||||
accPath: VOID_PATH_ID)
|
accPath: VOID_PATH_ID)
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
|
||||||
newMpt.methods = newMpt.mptMethods()
|
newMpt.methods = newMpt.mptMethods()
|
||||||
ok(db.bless newMpt)
|
ok(db.bless newMpt)
|
||||||
|
|
||||||
proc ctxGetAcc(col: CoreDbColRef): CoreDbRc[CoreDxAccRef] =
|
proc ctxGetAcc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
|
||||||
const info = "getAccFn()"
|
const info = "getAccFn()"
|
||||||
|
|
||||||
let col = AristoColRef(col)
|
let col = AristoColRef(col)
|
||||||
|
@ -516,7 +516,7 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
|
||||||
let error = (AccountsVID, AccRootUnacceptable)
|
let error = (AccountsVID, AccRootUnacceptable)
|
||||||
return err(error.toError(base, info, RootUnacceptable))
|
return err(error.toError(base, info, RootUnacceptable))
|
||||||
|
|
||||||
let acc = AristoCoreDxAccRef(base: base)
|
let acc = AristoCoreDbAccRef(base: base)
|
||||||
acc.methods = acc.accMethods()
|
acc.methods = acc.accMethods()
|
||||||
|
|
||||||
ok(db.bless acc)
|
ok(db.bless acc)
|
||||||
|
@ -534,10 +534,10 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
|
||||||
): CoreDbRc[CoreDbColRef] =
|
): CoreDbRc[CoreDbColRef] =
|
||||||
ctxNewCol(col, colState, address),
|
ctxNewCol(col, colState, address),
|
||||||
|
|
||||||
getMptFn: proc(col: CoreDbColRef): CoreDbRc[CoreDxMptRef] =
|
getMptFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
|
||||||
ctxGetMpt(col),
|
ctxGetMpt(col),
|
||||||
|
|
||||||
getAccFn: proc(col: CoreDbColRef): CoreDbRc[CoreDxAccRef] =
|
getAccFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
|
||||||
ctxGetAcc(col),
|
ctxGetAcc(col),
|
||||||
|
|
||||||
forgetFn: proc() =
|
forgetFn: proc() =
|
||||||
|
@ -579,14 +579,14 @@ proc getSavedState*(base: AristoBaseRef): Result[SavedState,void] =
|
||||||
|
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
func to*(dsc: CoreDxMptRef, T: type AristoDbRef): T =
|
func to*(dsc: CoreDbMptRef, T: type AristoDbRef): T =
|
||||||
AristoCoreDxMptRef(dsc).base.ctx.mpt
|
AristoCoreDbMptRef(dsc).base.ctx.mpt
|
||||||
|
|
||||||
func to*(dsc: CoreDxMptRef, T: type AristoApiRef): T =
|
func to*(dsc: CoreDbMptRef, T: type AristoApiRef): T =
|
||||||
AristoCoreDxMptRef(dsc).base.api
|
AristoCoreDbMptRef(dsc).base.api
|
||||||
|
|
||||||
func rootID*(dsc: CoreDxMptRef): VertexID =
|
func rootID*(dsc: CoreDbMptRef): VertexID =
|
||||||
AristoCoreDxMptRef(dsc).mptRoot
|
AristoCoreDbMptRef(dsc).mptRoot
|
||||||
|
|
||||||
func txTop*(
|
func txTop*(
|
||||||
base: AristoBaseRef;
|
base: AristoBaseRef;
|
||||||
|
|
|
@ -24,9 +24,9 @@ type
|
||||||
parent: CoreDbRef ## Opaque top level descriptor
|
parent: CoreDbRef ## Opaque top level descriptor
|
||||||
kdb: KvtDbRef ## Shared key-value table
|
kdb: KvtDbRef ## Shared key-value table
|
||||||
api*: KvtApiRef ## Api functions can be re-directed
|
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
|
base: KvtBaseRef ## Local base descriptor
|
||||||
kvt: KvtDbRef ## In most cases different from `base.kdb`
|
kvt: KvtDbRef ## In most cases different from `base.kdb`
|
||||||
|
|
||||||
|
@ -68,16 +68,16 @@ func toRc[T](
|
||||||
# Private `kvt` call back functions
|
# Private `kvt` call back functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
|
proc kvtMethods(cKvt: KvtCoreDbKvtRef): CoreDbKvtFns =
|
||||||
## Key-value database table handlers
|
## Key-value database table handlers
|
||||||
|
|
||||||
proc kvtBackend(
|
proc kvtBackend(
|
||||||
cKvt:KvtCoreDxKvtRef;
|
cKvt:KvtCoreDbKvtRef;
|
||||||
): CoreDbKvtBackendRef =
|
): CoreDbKvtBackendRef =
|
||||||
cKvt.base.parent.bless AristoCoreDbKvtBE(kdb: cKvt.kvt)
|
cKvt.base.parent.bless AristoCoreDbKvtBE(kdb: cKvt.kvt)
|
||||||
|
|
||||||
proc kvtForget(
|
proc kvtForget(
|
||||||
cKvt: KvtCoreDxKvtRef;
|
cKvt: KvtCoreDbKvtRef;
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): CoreDbRc[void] =
|
): CoreDbRc[void] =
|
||||||
let
|
let
|
||||||
|
@ -95,7 +95,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc kvtGet(
|
proc kvtGet(
|
||||||
cKvt: KvtCoreDxKvtRef;
|
cKvt: KvtCoreDbKvtRef;
|
||||||
k: openArray[byte];
|
k: openArray[byte];
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): CoreDbRc[Blob] =
|
): CoreDbRc[Blob] =
|
||||||
|
@ -108,7 +108,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
|
||||||
rc.toRc(cKvt.base, info)
|
rc.toRc(cKvt.base, info)
|
||||||
|
|
||||||
proc kvtPut(
|
proc kvtPut(
|
||||||
cKvt: KvtCoreDxKvtRef;
|
cKvt: KvtCoreDbKvtRef;
|
||||||
k: openArray[byte];
|
k: openArray[byte];
|
||||||
v: openArray[byte];
|
v: openArray[byte];
|
||||||
info: static[string];
|
info: static[string];
|
||||||
|
@ -120,7 +120,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
|
||||||
err(rc.error.toError(cKvt.base, info))
|
err(rc.error.toError(cKvt.base, info))
|
||||||
|
|
||||||
proc kvtDel(
|
proc kvtDel(
|
||||||
cKvt: KvtCoreDxKvtRef;
|
cKvt: KvtCoreDbKvtRef;
|
||||||
k: openArray[byte];
|
k: openArray[byte];
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): CoreDbRc[void] =
|
): CoreDbRc[void] =
|
||||||
|
@ -131,7 +131,7 @@ proc kvtMethods(cKvt: KvtCoreDxKvtRef): CoreDbKvtFns =
|
||||||
err(rc.error.toError(cKvt.base, info))
|
err(rc.error.toError(cKvt.base, info))
|
||||||
|
|
||||||
proc kvtHasKey(
|
proc kvtHasKey(
|
||||||
cKvt: KvtCoreDxKvtRef;
|
cKvt: KvtCoreDbKvtRef;
|
||||||
k: openArray[byte];
|
k: openArray[byte];
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): CoreDbRc[bool] =
|
): CoreDbRc[bool] =
|
||||||
|
@ -176,8 +176,8 @@ func toVoidRc*[T](
|
||||||
|
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
func to*(dsc: CoreDxKvtRef; T: type KvtDbRef): T =
|
func to*(dsc: CoreDbKvtRef; T: type KvtDbRef): T =
|
||||||
KvtCoreDxKvtRef(dsc).kvt
|
KvtCoreDbKvtRef(dsc).kvt
|
||||||
|
|
||||||
func txTop*(
|
func txTop*(
|
||||||
base: KvtBaseRef;
|
base: KvtBaseRef;
|
||||||
|
@ -219,7 +219,7 @@ proc persistent*(
|
||||||
proc newKvtHandler*(
|
proc newKvtHandler*(
|
||||||
base: KvtBaseRef;
|
base: KvtBaseRef;
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): CoreDbRc[CoreDxKvtRef] =
|
): CoreDbRc[CoreDbKvtRef] =
|
||||||
ok(base.cache)
|
ok(base.cache)
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ func init*(T: type KvtBaseRef; db: CoreDbRef; kdb: KvtDbRef): T =
|
||||||
kdb: kdb)
|
kdb: kdb)
|
||||||
|
|
||||||
# Preallocated shared descriptor
|
# Preallocated shared descriptor
|
||||||
let dsc = KvtCoreDxKvtRef(
|
let dsc = KvtCoreDbKvtRef(
|
||||||
base: result,
|
base: result,
|
||||||
kvt: kdb)
|
kvt: kdb)
|
||||||
dsc.methods = dsc.kvtMethods()
|
dsc.methods = dsc.kvtMethods()
|
||||||
|
|
|
@ -170,7 +170,7 @@ proc newAristoDualRocksDbCoreDbRef*(path: string, opts: DbOptions): CoreDbRef =
|
||||||
# Public aristo iterators
|
# Public aristo iterators
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
iterator aristoReplicateRdb*(dsc: CoreDxMptRef): (Blob, Blob) {.rlpRaise.} =
|
iterator aristoReplicateRdb*(dsc: CoreDbMptRef): (Blob, Blob) {.rlpRaise.} =
|
||||||
## Instantiation for `VoidBackendRef`
|
## Instantiation for `VoidBackendRef`
|
||||||
for k, v in aristoReplicate[use_ari.RdbBackendRef](dsc):
|
for k, v in aristoReplicate[use_ari.RdbBackendRef](dsc):
|
||||||
yield (k, v)
|
yield (k, v)
|
||||||
|
|
|
@ -23,7 +23,7 @@ const
|
||||||
EnableApiTracking = false
|
EnableApiTracking = false
|
||||||
## When enabled, functions using this tracking facility need to import
|
## When enabled, functions using this tracking facility need to import
|
||||||
## `chronicles`, as well. Tracking is enabled by setting `true` the flags
|
## `chronicles`, as well. Tracking is enabled by setting `true` the flags
|
||||||
## `trackLegaApi` and/or `trackNewApi` in the `CoreDxTxRef` descriptor.
|
## `trackLegaApi` and/or `trackNewApi` in the `CoreDbTxRef` descriptor.
|
||||||
|
|
||||||
EnableApiProfiling = true
|
EnableApiProfiling = true
|
||||||
## Enables functions profiling if `EnableApiTracking` is also set `true`.
|
## Enables functions profiling if `EnableApiTracking` is also set `true`.
|
||||||
|
@ -49,12 +49,11 @@ export
|
||||||
CoreDbProfListRef,
|
CoreDbProfListRef,
|
||||||
CoreDbRef,
|
CoreDbRef,
|
||||||
CoreDbType,
|
CoreDbType,
|
||||||
CoreDxAccRef,
|
CoreDbAccRef,
|
||||||
CoreDxCaptRef,
|
CoreDbCaptRef,
|
||||||
CoreDxKvtRef,
|
CoreDbKvtRef,
|
||||||
CoreDxMptRef,
|
CoreDbMptRef,
|
||||||
CoreDxPhkRef,
|
CoreDbTxRef,
|
||||||
CoreDxTxRef,
|
|
||||||
PayloadRef
|
PayloadRef
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -94,7 +93,7 @@ when EnableApiTracking:
|
||||||
proc `$`(h: Hash256): string = h.toStr
|
proc `$`(h: Hash256): string = h.toStr
|
||||||
|
|
||||||
template setTrackNewApi(
|
template setTrackNewApi(
|
||||||
w: CoreDxApiTrackRef;
|
w: CoreDbApiTrackRef;
|
||||||
s: static[CoreDbFnInx];
|
s: static[CoreDbFnInx];
|
||||||
code: untyped;
|
code: untyped;
|
||||||
) =
|
) =
|
||||||
|
@ -106,48 +105,17 @@ template setTrackNewApi(
|
||||||
const api {.inject,used.} = s
|
const api {.inject,used.} = s
|
||||||
|
|
||||||
template setTrackNewApi*(
|
template setTrackNewApi*(
|
||||||
w: CoreDxApiTrackRef;
|
w: CoreDbApiTrackRef;
|
||||||
s: static[CoreDbFnInx];
|
s: static[CoreDbFnInx];
|
||||||
) =
|
) =
|
||||||
w.setTrackNewApi(s):
|
w.setTrackNewApi(s):
|
||||||
discard
|
discard
|
||||||
|
|
||||||
template ifTrackNewApi*(w: CoreDxApiTrackRef; code: untyped) =
|
template ifTrackNewApi*(w: CoreDbApiTrackRef; code: untyped) =
|
||||||
when EnableApiTracking:
|
when EnableApiTracking:
|
||||||
w.endNewApiIf:
|
w.endNewApiIf:
|
||||||
code
|
code
|
||||||
|
|
||||||
# ---------
|
|
||||||
|
|
||||||
func toCoreDxPhkRef(mpt: CoreDxMptRef): CoreDxPhkRef =
|
|
||||||
## MPT => pre-hashed MPT (aka PHK)
|
|
||||||
result = CoreDxPhkRef(
|
|
||||||
toMpt: mpt,
|
|
||||||
methods: mpt.methods)
|
|
||||||
|
|
||||||
result.methods.fetchFn =
|
|
||||||
proc(k: openArray[byte]): CoreDbRc[Blob] =
|
|
||||||
mpt.methods.fetchFn(k.keccakHash.data)
|
|
||||||
|
|
||||||
result.methods.deleteFn =
|
|
||||||
proc(k: openArray[byte]): CoreDbRc[void] =
|
|
||||||
mpt.methods.deleteFn(k.keccakHash.data)
|
|
||||||
|
|
||||||
result.methods.mergeFn =
|
|
||||||
proc(k:openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
|
|
||||||
mpt.methods.mergeFn(k.keccakHash.data, v)
|
|
||||||
|
|
||||||
result.methods.hasPathFn =
|
|
||||||
proc(k: openArray[byte]): CoreDbRc[bool] =
|
|
||||||
mpt.methods.hasPathFn(k.keccakHash.data)
|
|
||||||
|
|
||||||
when AutoValidateDescriptors:
|
|
||||||
result.validate
|
|
||||||
|
|
||||||
|
|
||||||
func parent(phk: CoreDxPhkRef): CoreDbRef =
|
|
||||||
phk.toMpt.parent
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public constructor helper
|
# Public constructor helper
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -168,16 +136,16 @@ proc bless*(db: CoreDbRef; col: CoreDbColRef): CoreDbColRef =
|
||||||
col.validate
|
col.validate
|
||||||
col
|
col
|
||||||
|
|
||||||
proc bless*(db: CoreDbRef; kvt: CoreDxKvtRef): CoreDxKvtRef =
|
proc bless*(db: CoreDbRef; kvt: CoreDbKvtRef): CoreDbKvtRef =
|
||||||
## Complete sub-module descriptor, fill in `parent`.
|
## Complete sub-module descriptor, fill in `parent`.
|
||||||
kvt.parent = db
|
kvt.parent = db
|
||||||
when AutoValidateDescriptors:
|
when AutoValidateDescriptors:
|
||||||
kvt.validate
|
kvt.validate
|
||||||
kvt
|
kvt
|
||||||
|
|
||||||
proc bless*[T: CoreDxKvtRef |
|
proc bless*[T: CoreDbKvtRef |
|
||||||
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
CoreDbCtxRef | CoreDbMptRef | CoreDbAccRef |
|
||||||
CoreDxTxRef | CoreDxCaptRef |
|
CoreDbTxRef | CoreDbCaptRef |
|
||||||
CoreDbKvtBackendRef | CoreDbMptBackendRef](
|
CoreDbKvtBackendRef | CoreDbMptBackendRef](
|
||||||
db: CoreDbRef;
|
db: CoreDbRef;
|
||||||
dsc: T;
|
dsc: T;
|
||||||
|
@ -226,18 +194,18 @@ proc dbType*(db: CoreDbRef): CoreDbType =
|
||||||
result = db.dbType
|
result = db.dbType
|
||||||
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc parent*[T: CoreDxKvtRef |
|
proc parent*[T: CoreDbKvtRef |
|
||||||
CoreDbColRef |
|
CoreDbColRef |
|
||||||
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
CoreDbCtxRef | CoreDbMptRef | CoreDbAccRef |
|
||||||
CoreDxTxRef |
|
CoreDbTxRef |
|
||||||
CoreDxCaptRef |
|
CoreDbCaptRef |
|
||||||
CoreDbErrorRef](
|
CoreDbErrorRef](
|
||||||
child: T): CoreDbRef =
|
child: T): CoreDbRef =
|
||||||
## Getter, common method for all sub-modules
|
## Getter, common method for all sub-modules
|
||||||
##
|
##
|
||||||
result = child.parent
|
result = child.parent
|
||||||
|
|
||||||
proc backend*(dsc: CoreDxKvtRef | CoreDxMptRef): auto =
|
proc backend*(dsc: CoreDbKvtRef | CoreDbMptRef): auto =
|
||||||
## Getter, retrieves the *raw* backend object for special/localised support.
|
## Getter, retrieves the *raw* backend object for special/localised support.
|
||||||
##
|
##
|
||||||
dsc.setTrackNewApi AnyBackendFn
|
dsc.setTrackNewApi AnyBackendFn
|
||||||
|
@ -268,7 +236,7 @@ proc `$$`*(e: CoreDbErrorRef): string =
|
||||||
# Public key-value table methods
|
# Public key-value table methods
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc newKvt*(db: CoreDbRef): CoreDxKvtRef =
|
proc newKvt*(db: CoreDbRef): CoreDbKvtRef =
|
||||||
## Constructor, will defect on failure.
|
## Constructor, will defect on failure.
|
||||||
##
|
##
|
||||||
## This function subscribes to the common base object shared with other
|
## This function subscribes to the common base object shared with other
|
||||||
|
@ -281,13 +249,13 @@ proc newKvt*(db: CoreDbRef): CoreDxKvtRef =
|
||||||
raiseAssert error.prettyText()
|
raiseAssert error.prettyText()
|
||||||
db.ifTrackNewApi: debug newApiTxt, api, elapsed
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed
|
||||||
|
|
||||||
proc get*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
proc get*(kvt: CoreDbKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
## This function always returns a non-empty `Blob` or an error code.
|
## This function always returns a non-empty `Blob` or an error code.
|
||||||
kvt.setTrackNewApi KvtGetFn
|
kvt.setTrackNewApi KvtGetFn
|
||||||
result = kvt.methods.getFn key
|
result = kvt.methods.getFn key
|
||||||
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
||||||
|
|
||||||
proc getOrEmpty*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
proc getOrEmpty*(kvt: CoreDbKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
## This function sort of mimics the behaviour of the legacy database
|
## This function sort of mimics the behaviour of the legacy database
|
||||||
## returning an empty `Blob` if the argument `key` is not found on the
|
## returning an empty `Blob` if the argument `key` is not found on the
|
||||||
## database.
|
## database.
|
||||||
|
@ -298,13 +266,13 @@ proc getOrEmpty*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
result = CoreDbRc[Blob].ok(EmptyBlob)
|
result = CoreDbRc[Blob].ok(EmptyBlob)
|
||||||
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
||||||
|
|
||||||
proc del*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[void] =
|
proc del*(kvt: CoreDbKvtRef; key: openArray[byte]): CoreDbRc[void] =
|
||||||
kvt.setTrackNewApi KvtDelFn
|
kvt.setTrackNewApi KvtDelFn
|
||||||
result = kvt.methods.delFn key
|
result = kvt.methods.delFn key
|
||||||
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed, key=key.toStr, result
|
||||||
|
|
||||||
proc put*(
|
proc put*(
|
||||||
kvt: CoreDxKvtRef;
|
kvt: CoreDbKvtRef;
|
||||||
key: openArray[byte];
|
key: openArray[byte];
|
||||||
val: openArray[byte];
|
val: openArray[byte];
|
||||||
): CoreDbRc[void] =
|
): CoreDbRc[void] =
|
||||||
|
@ -313,7 +281,7 @@ proc put*(
|
||||||
kvt.ifTrackNewApi:
|
kvt.ifTrackNewApi:
|
||||||
debug newApiTxt, api, elapsed, key=key.toStr, val=val.toLenStr, result
|
debug newApiTxt, api, elapsed, key=key.toStr, val=val.toLenStr, result
|
||||||
|
|
||||||
proc hasKey*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[bool] =
|
proc hasKey*(kvt: CoreDbKvtRef; key: openArray[byte]): CoreDbRc[bool] =
|
||||||
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
||||||
##
|
##
|
||||||
kvt.setTrackNewApi KvtHasKeyFn
|
kvt.setTrackNewApi KvtHasKeyFn
|
||||||
|
@ -400,7 +368,7 @@ proc newColumn*(
|
||||||
##
|
##
|
||||||
## This function is intended to open a column on the database as in:
|
## This function is intended to open a column on the database as in:
|
||||||
## ::
|
## ::
|
||||||
## proc openAccountLedger(db: CoreDbRef, colState: Hash256): CoreDxMptRef =
|
## proc openAccountLedger(db: CoreDbRef, colState: Hash256): CoreDbMptRef =
|
||||||
## let col = db.ctx.newColumn(CtAccounts, colState).valueOr:
|
## let col = db.ctx.newColumn(CtAccounts, colState).valueOr:
|
||||||
## # some error handling
|
## # some error handling
|
||||||
## return
|
## return
|
||||||
|
@ -490,7 +458,7 @@ proc stateEmptyOrVoid*(col: CoreDbColRef): bool =
|
||||||
proc getMpt*(
|
proc getMpt*(
|
||||||
ctx: CoreDbCtxRef;
|
ctx: CoreDbCtxRef;
|
||||||
col: CoreDbColRef;
|
col: CoreDbColRef;
|
||||||
): CoreDbRc[CoreDxMptRef] =
|
): CoreDbRc[CoreDbMptRef] =
|
||||||
## Get an MPT sub-trie view.
|
## Get an MPT sub-trie view.
|
||||||
##
|
##
|
||||||
## If the `col` argument descriptor was created for an `EMPTY_ROOT_HASH`
|
## If the `col` argument descriptor was created for an `EMPTY_ROOT_HASH`
|
||||||
|
@ -507,7 +475,7 @@ proc getMpt*(
|
||||||
ctx: CoreDbCtxRef;
|
ctx: CoreDbCtxRef;
|
||||||
colType: CoreDbColType;
|
colType: CoreDbColType;
|
||||||
address = Opt.none(EthAddress);
|
address = Opt.none(EthAddress);
|
||||||
): CoreDxMptRef =
|
): CoreDbMptRef =
|
||||||
## Shortcut for `getMpt(col)` where the `col` argument is
|
## Shortcut for `getMpt(col)` where the `col` argument is
|
||||||
## `db.getColumn(colType,EMPTY_ROOT_HASH).value`. This function will always
|
## `db.getColumn(colType,EMPTY_ROOT_HASH).value`. This function will always
|
||||||
## return a non-nil descriptor or throw an exception.
|
## return a non-nil descriptor or throw an exception.
|
||||||
|
@ -519,7 +487,7 @@ proc getMpt*(
|
||||||
ctx.ifTrackNewApi: debug newApiTxt, api, colType, elapsed
|
ctx.ifTrackNewApi: debug newApiTxt, api, colType, elapsed
|
||||||
|
|
||||||
|
|
||||||
proc getMpt*(acc: CoreDxAccRef): CoreDxMptRef =
|
proc getMpt*(acc: CoreDbAccRef): CoreDbMptRef =
|
||||||
## Variant of `getMpt()`, will defect on failure.
|
## Variant of `getMpt()`, will defect on failure.
|
||||||
##
|
##
|
||||||
## The needed sub-trie information is taken/implied from the current `acc`
|
## The needed sub-trie information is taken/implied from the current `acc`
|
||||||
|
@ -536,7 +504,7 @@ proc getMpt*(acc: CoreDxAccRef): CoreDxMptRef =
|
||||||
proc getAcc*(
|
proc getAcc*(
|
||||||
ctx: CoreDbCtxRef;
|
ctx: CoreDbCtxRef;
|
||||||
col: CoreDbColRef;
|
col: CoreDbColRef;
|
||||||
): CoreDbRc[CoreDxAccRef] =
|
): CoreDbRc[CoreDbAccRef] =
|
||||||
## Accounts trie constructor, will defect on failure.
|
## Accounts trie constructor, will defect on failure.
|
||||||
##
|
##
|
||||||
## Example:
|
## Example:
|
||||||
|
@ -549,62 +517,35 @@ proc getAcc*(
|
||||||
## ... # Was not the state root for the accounts column
|
## ... # Was not the state root for the accounts column
|
||||||
## return
|
## return
|
||||||
##
|
##
|
||||||
## This function works similar to `getMpt()` for handling accounts. Although
|
## This function works similar to `getMpt()` for handling accounts.
|
||||||
## one can emulate this function by means of `getMpt(..).toPhk()`, it is
|
|
||||||
## recommended using `CoreDxAccRef` methods for accounts.
|
|
||||||
##
|
##
|
||||||
ctx.setTrackNewApi CtxGetAccFn
|
ctx.setTrackNewApi CtxGetAccFn
|
||||||
result = ctx.methods.getAccFn col
|
result = ctx.methods.getAccFn col
|
||||||
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
|
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
|
||||||
|
|
||||||
proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
|
|
||||||
## Replaces the pre-hashed argument column `phk` by the non pre-hashed *MPT*.
|
|
||||||
##
|
|
||||||
phk.setTrackNewApi PhkToMptFn
|
|
||||||
result = phk.toMpt
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = result.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col
|
|
||||||
|
|
||||||
proc toPhk*(mpt: CoreDxMptRef): CoreDxPhkRef =
|
|
||||||
## Replaces argument `mpt` by a pre-hashed *MPT*.
|
|
||||||
##
|
|
||||||
mpt.setTrackNewApi MptToPhkFn
|
|
||||||
result = mpt.toCoreDxPhkRef
|
|
||||||
mpt.ifTrackNewApi:
|
|
||||||
let col = result.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public common methods for all hexary trie databases (`mpt`, `phk`, or `acc`)
|
# Public common methods for all hexary trie databases (`mpt`, or `acc`)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc getColumn*(acc: CoreDxAccRef): CoreDbColRef =
|
proc getColumn*(acc: CoreDbAccRef): CoreDbColRef =
|
||||||
## Getter, result is not `nil`
|
## Getter, result is not `nil`
|
||||||
##
|
##
|
||||||
acc.setTrackNewApi AccGetColFn
|
acc.setTrackNewApi AccGetColFn
|
||||||
result = acc.methods.getColFn()
|
result = acc.methods.getColFn()
|
||||||
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc getColumn*(mpt: CoreDxMptRef): CoreDbColRef =
|
proc getColumn*(mpt: CoreDbMptRef): CoreDbColRef =
|
||||||
## Variant of `getColumn()`
|
## Variant of `getColumn()`
|
||||||
##
|
##
|
||||||
mpt.setTrackNewApi MptGetColFn
|
mpt.setTrackNewApi MptGetColFn
|
||||||
result = mpt.methods.getColFn()
|
result = mpt.methods.getColFn()
|
||||||
mpt.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
mpt.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc getColumn*(phk: CoreDxPhkRef): CoreDbColRef =
|
|
||||||
## Variant of `getColumn()`
|
|
||||||
##
|
|
||||||
phk.setTrackNewApi PhkGetColFn
|
|
||||||
result = phk.methods.getColFn()
|
|
||||||
phk.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public generic hexary trie database methods (`mpt` or `phk`)
|
# Public generic hexary trie database methods
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc fetch*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
proc fetch*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
## Fetch data from the argument `mpt`. The function always returns a
|
## Fetch data from the argument `mpt`. The function always returns a
|
||||||
## non-empty `Blob` or an error code.
|
## non-empty `Blob` or an error code.
|
||||||
##
|
##
|
||||||
|
@ -614,16 +555,7 @@ proc fetch*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
let col = mpt.methods.getColFn()
|
let col = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
||||||
|
|
||||||
proc fetch*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
|
proc fetchOrEmpty*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
## Variant of `fetch()"
|
|
||||||
phk.setTrackNewApi PhkFetchFn
|
|
||||||
result = phk.methods.fetchFn key
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = phk.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
|
||||||
|
|
||||||
|
|
||||||
proc fetchOrEmpty*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
|
||||||
## This function returns an empty `Blob` if the argument `key` is not found
|
## This function returns an empty `Blob` if the argument `key` is not found
|
||||||
## on the database.
|
## on the database.
|
||||||
##
|
##
|
||||||
|
@ -635,34 +567,15 @@ proc fetchOrEmpty*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
|
||||||
let col = mpt.methods.getColFn()
|
let col = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
||||||
|
|
||||||
proc fetchOrEmpty*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
|
proc delete*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[void] =
|
||||||
## Variant of `fetchOrEmpty()`
|
|
||||||
phk.setTrackNewApi PhkFetchOrEmptyFn
|
|
||||||
result = phk.methods.fetchFn key
|
|
||||||
if result.isErr and result.error.error == MptNotFound:
|
|
||||||
result = CoreDbRc[Blob].ok(EmptyBlob)
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = phk.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
|
||||||
|
|
||||||
|
|
||||||
proc delete*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[void] =
|
|
||||||
mpt.setTrackNewApi MptDeleteFn
|
mpt.setTrackNewApi MptDeleteFn
|
||||||
result = mpt.methods.deleteFn key
|
result = mpt.methods.deleteFn key
|
||||||
mpt.ifTrackNewApi:
|
mpt.ifTrackNewApi:
|
||||||
let col = mpt.methods.getColFn()
|
let col = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
||||||
|
|
||||||
proc delete*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[void] =
|
|
||||||
phk.setTrackNewApi PhkDeleteFn
|
|
||||||
result = phk.methods.deleteFn key
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = phk.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
|
||||||
|
|
||||||
|
|
||||||
proc merge*(
|
proc merge*(
|
||||||
mpt: CoreDxMptRef;
|
mpt: CoreDbMptRef;
|
||||||
key: openArray[byte];
|
key: openArray[byte];
|
||||||
val: openArray[byte];
|
val: openArray[byte];
|
||||||
): CoreDbRc[void] =
|
): CoreDbRc[void] =
|
||||||
|
@ -672,19 +585,7 @@ proc merge*(
|
||||||
let col = mpt.methods.getColFn()
|
let col = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, val=val.toLenStr, result
|
debug newApiTxt, api, elapsed, col, key=key.toStr, val=val.toLenStr, result
|
||||||
|
|
||||||
proc merge*(
|
proc hasPath*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[bool] =
|
||||||
phk: CoreDxPhkRef;
|
|
||||||
key: openArray[byte];
|
|
||||||
val: openArray[byte];
|
|
||||||
): CoreDbRc[void] =
|
|
||||||
phk.setTrackNewApi PhkMergeFn
|
|
||||||
result = phk.methods.mergeFn(key, val)
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = phk.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, val=val.toLenStr, result
|
|
||||||
|
|
||||||
|
|
||||||
proc hasPath*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
||||||
## This function would be named `contains()` if it returned `bool` rather
|
## This function would be named `contains()` if it returned `bool` rather
|
||||||
## than a `Result[]`.
|
## than a `Result[]`.
|
||||||
##
|
##
|
||||||
|
@ -694,19 +595,11 @@ proc hasPath*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[bool] =
|
||||||
let col = mpt.methods.getColFn()
|
let col = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
||||||
|
|
||||||
proc hasPath*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[bool] =
|
|
||||||
## Variant of `hasPath()`
|
|
||||||
phk.setTrackNewApi PhkHasPathFn
|
|
||||||
result = phk.methods.hasPathFn key
|
|
||||||
phk.ifTrackNewApi:
|
|
||||||
let col = phk.methods.getColFn()
|
|
||||||
debug newApiTxt, api, elapsed, col, key=key.toStr, result
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public trie database methods for accounts
|
# Public trie database methods for accounts
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc fetch*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
|
proc fetch*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
|
||||||
## Fetch data from the argument `acc`.
|
## Fetch data from the argument `acc`.
|
||||||
##
|
##
|
||||||
acc.setTrackNewApi AccFetchFn
|
acc.setTrackNewApi AccFetchFn
|
||||||
|
@ -716,12 +609,12 @@ proc fetch*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
|
||||||
debug newApiTxt, api, elapsed, address, storage, result
|
debug newApiTxt, api, elapsed, address, storage, result
|
||||||
|
|
||||||
|
|
||||||
proc delete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
proc delete*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[void] =
|
||||||
acc.setTrackNewApi AccDeleteFn
|
acc.setTrackNewApi AccDeleteFn
|
||||||
result = acc.methods.deleteFn address
|
result = acc.methods.deleteFn address
|
||||||
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
|
||||||
|
|
||||||
proc stoDelete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
proc stoDelete*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[void] =
|
||||||
## Recursively delete all data elements from the storage trie associated to
|
## Recursively delete all data elements from the storage trie associated to
|
||||||
## the account identified by the argument `address`. After successful run,
|
## the account identified by the argument `address`. After successful run,
|
||||||
## the storage trie will be empty.
|
## the storage trie will be empty.
|
||||||
|
@ -738,7 +631,7 @@ proc stoDelete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
|
||||||
|
|
||||||
|
|
||||||
proc merge*(
|
proc merge*(
|
||||||
acc: CoreDxAccRef;
|
acc: CoreDbAccRef;
|
||||||
account: CoreDbAccount;
|
account: CoreDbAccount;
|
||||||
): CoreDbRc[void] =
|
): CoreDbRc[void] =
|
||||||
acc.setTrackNewApi AccMergeFn
|
acc.setTrackNewApi AccMergeFn
|
||||||
|
@ -748,7 +641,7 @@ proc merge*(
|
||||||
debug newApiTxt, api, elapsed, address, result
|
debug newApiTxt, api, elapsed, address, result
|
||||||
|
|
||||||
|
|
||||||
proc hasPath*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[bool] =
|
proc hasPath*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[bool] =
|
||||||
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
## Would be named `contains` if it returned `bool` rather than `Result[]`.
|
||||||
##
|
##
|
||||||
acc.setTrackNewApi AccHasPathFn
|
acc.setTrackNewApi AccHasPathFn
|
||||||
|
@ -835,7 +728,7 @@ proc persistent*(
|
||||||
result = db.methods.persistentFn Opt.some(blockNumber)
|
result = db.methods.persistentFn Opt.some(blockNumber)
|
||||||
db.ifTrackNewApi: debug newApiTxt, api, elapsed, blockNumber, result
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, blockNumber, result
|
||||||
|
|
||||||
proc newTransaction*(db: CoreDbRef): CoreDxTxRef =
|
proc newTransaction*(db: CoreDbRef): CoreDbTxRef =
|
||||||
## Constructor
|
## Constructor
|
||||||
##
|
##
|
||||||
db.setTrackNewApi BaseNewTxFn
|
db.setTrackNewApi BaseNewTxFn
|
||||||
|
@ -844,26 +737,26 @@ proc newTransaction*(db: CoreDbRef): CoreDxTxRef =
|
||||||
debug newApiTxt, api, elapsed, newLevel=db.methods.levelFn()
|
debug newApiTxt, api, elapsed, newLevel=db.methods.levelFn()
|
||||||
|
|
||||||
|
|
||||||
proc level*(tx: CoreDxTxRef): int =
|
proc level*(tx: CoreDbTxRef): int =
|
||||||
## Print positive transaction level for argument `tx`
|
## Print positive transaction level for argument `tx`
|
||||||
##
|
##
|
||||||
tx.setTrackNewApi TxLevelFn
|
tx.setTrackNewApi TxLevelFn
|
||||||
result = tx.methods.levelFn()
|
result = tx.methods.levelFn()
|
||||||
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc commit*(tx: CoreDxTxRef) =
|
proc commit*(tx: CoreDbTxRef) =
|
||||||
tx.setTrackNewApi TxCommitFn:
|
tx.setTrackNewApi TxCommitFn:
|
||||||
let prvLevel {.used.} = tx.methods.levelFn()
|
let prvLevel {.used.} = tx.methods.levelFn()
|
||||||
tx.methods.commitFn()
|
tx.methods.commitFn()
|
||||||
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
||||||
|
|
||||||
proc rollback*(tx: CoreDxTxRef) =
|
proc rollback*(tx: CoreDbTxRef) =
|
||||||
tx.setTrackNewApi TxRollbackFn:
|
tx.setTrackNewApi TxRollbackFn:
|
||||||
let prvLevel {.used.} = tx.methods.levelFn()
|
let prvLevel {.used.} = tx.methods.levelFn()
|
||||||
tx.methods.rollbackFn()
|
tx.methods.rollbackFn()
|
||||||
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
tx.ifTrackNewApi: debug newApiTxt, api, elapsed, prvLevel
|
||||||
|
|
||||||
proc dispose*(tx: CoreDxTxRef) =
|
proc dispose*(tx: CoreDbTxRef) =
|
||||||
tx.setTrackNewApi TxDisposeFn:
|
tx.setTrackNewApi TxDisposeFn:
|
||||||
let prvLevel {.used.} = tx.methods.levelFn()
|
let prvLevel {.used.} = tx.methods.levelFn()
|
||||||
tx.methods.disposeFn()
|
tx.methods.disposeFn()
|
||||||
|
@ -877,7 +770,7 @@ when false: # currently disabled
|
||||||
proc newCapture*(
|
proc newCapture*(
|
||||||
db: CoreDbRef;
|
db: CoreDbRef;
|
||||||
flags: set[CoreDbCaptFlags] = {};
|
flags: set[CoreDbCaptFlags] = {};
|
||||||
): CoreDbRc[CoreDxCaptRef] =
|
): CoreDbRc[CoreDbCaptRef] =
|
||||||
## Trace constructor providing an overlay on top of the argument database
|
## Trace constructor providing an overlay on top of the argument database
|
||||||
## `db`. This overlay provides a replacement database handle that can be
|
## `db`. This overlay provides a replacement database handle that can be
|
||||||
## retrieved via `db.recorder()` (which can in turn be ovelayed.) While
|
## retrieved via `db.recorder()` (which can in turn be ovelayed.) While
|
||||||
|
@ -893,7 +786,7 @@ when false: # currently disabled
|
||||||
result = db.methods.newCaptureFn flags
|
result = db.methods.newCaptureFn flags
|
||||||
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
db.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc recorder*(cpt: CoreDxCaptRef): CoreDbRef =
|
proc recorder*(cpt: CoreDbCaptRef): CoreDbRef =
|
||||||
## Getter, returns a tracer replacement handle to be used as new database.
|
## Getter, returns a tracer replacement handle to be used as new database.
|
||||||
## It records every action like fetch, store, hasKey, hasPath and delete.
|
## It records every action like fetch, store, hasKey, hasPath and delete.
|
||||||
## This descriptor can be superseded by a new overlay tracer (using
|
## This descriptor can be superseded by a new overlay tracer (using
|
||||||
|
@ -908,7 +801,7 @@ when false: # currently disabled
|
||||||
result = cpt.methods.recorderFn()
|
result = cpt.methods.recorderFn()
|
||||||
cpt.ifTrackNewApi: debug newApiTxt, api, elapsed
|
cpt.ifTrackNewApi: debug newApiTxt, api, elapsed
|
||||||
|
|
||||||
proc logDb*(cp: CoreDxCaptRef): TableRef[Blob,Blob] =
|
proc logDb*(cp: CoreDbCaptRef): TableRef[Blob,Blob] =
|
||||||
## Getter, returns the logger table for the overlay tracer database.
|
## Getter, returns the logger table for the overlay tracer database.
|
||||||
##
|
##
|
||||||
## Caveat:
|
## Caveat:
|
||||||
|
@ -920,14 +813,14 @@ when false: # currently disabled
|
||||||
result = cp.methods.logDbFn()
|
result = cp.methods.logDbFn()
|
||||||
cp.ifTrackNewApi: debug newApiTxt, api, elapsed
|
cp.ifTrackNewApi: debug newApiTxt, api, elapsed
|
||||||
|
|
||||||
proc flags*(cp: CoreDxCaptRef):set[CoreDbCaptFlags] =
|
proc flags*(cp: CoreDbCaptRef):set[CoreDbCaptFlags] =
|
||||||
## Getter
|
## Getter
|
||||||
##
|
##
|
||||||
cp.setTrackNewApi CptFlagsFn
|
cp.setTrackNewApi CptFlagsFn
|
||||||
result = cp.methods.getFlagsFn()
|
result = cp.methods.getFlagsFn()
|
||||||
cp.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
cp.ifTrackNewApi: debug newApiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc forget*(cp: CoreDxCaptRef) =
|
proc forget*(cp: CoreDbCaptRef) =
|
||||||
## Explicitely stop recording the current tracer instance and reset to
|
## Explicitely stop recording the current tracer instance and reset to
|
||||||
## previous level.
|
## previous level.
|
||||||
##
|
##
|
||||||
|
|
|
@ -19,10 +19,10 @@ import
|
||||||
./base_desc
|
./base_desc
|
||||||
|
|
||||||
type
|
type
|
||||||
CoreDxApiTrackRef* =
|
CoreDbApiTrackRef* =
|
||||||
CoreDbRef | CoreDxKvtRef | CoreDbColRef |
|
CoreDbRef | CoreDbKvtRef | CoreDbColRef |
|
||||||
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
CoreDbCtxRef | CoreDbMptRef | CoreDbAccRef |
|
||||||
CoreDxTxRef | CoreDxCaptRef | CoreDbErrorRef
|
CoreDbTxRef | CoreDbCaptRef | CoreDbErrorRef
|
||||||
|
|
||||||
CoreDbFnInx* = enum
|
CoreDbFnInx* = enum
|
||||||
## Profiling table index
|
## Profiling table index
|
||||||
|
@ -84,16 +84,6 @@ type
|
||||||
MptMergeFn = "mpt/merge"
|
MptMergeFn = "mpt/merge"
|
||||||
MptPairsIt = "mpt/pairs"
|
MptPairsIt = "mpt/pairs"
|
||||||
MptReplicateIt = "mpt/replicate"
|
MptReplicateIt = "mpt/replicate"
|
||||||
MptToPhkFn = "mpt/toPhk"
|
|
||||||
|
|
||||||
PhkDeleteFn = "phk/delete"
|
|
||||||
PhkFetchFn = "phk/fetch"
|
|
||||||
PhkFetchOrEmptyFn = "phk/fetchOrEmpty"
|
|
||||||
PhkForgetFn = "phk/forget"
|
|
||||||
PhkGetColFn = "phk/getColumn"
|
|
||||||
PhkHasPathFn = "phk/hasPath"
|
|
||||||
PhkMergeFn = "phk/merge"
|
|
||||||
PhkToMptFn = "phk/toMpt"
|
|
||||||
|
|
||||||
TxCommitFn = "commit"
|
TxCommitFn = "commit"
|
||||||
TxDisposeFn = "dispose"
|
TxDisposeFn = "dispose"
|
||||||
|
@ -165,12 +155,12 @@ proc toStr[T](rc: CoreDbRc[T]; ifOk: static[string]): string =
|
||||||
|
|
||||||
proc toStr*(rc: CoreDbRc[CoreDbRef]): string = rc.toStr "db"
|
proc toStr*(rc: CoreDbRc[CoreDbRef]): string = rc.toStr "db"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDbAccount]): string = rc.toStr "acc"
|
proc toStr*(rc: CoreDbRc[CoreDbAccount]): string = rc.toStr "acc"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDxKvtRef]): string = rc.toStr "kvt"
|
proc toStr*(rc: CoreDbRc[CoreDbKvtRef]): string = rc.toStr "kvt"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDxTxRef]): string = rc.toStr "tx"
|
proc toStr*(rc: CoreDbRc[CoreDbTxRef]): string = rc.toStr "tx"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDxCaptRef]): string = rc.toStr "capt"
|
proc toStr*(rc: CoreDbRc[CoreDbCaptRef]): string = rc.toStr "capt"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDbCtxRef]): string = rc.toStr "ctx"
|
proc toStr*(rc: CoreDbRc[CoreDbCtxRef]): string = rc.toStr "ctx"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDxMptRef]): string = rc.toStr "mpt"
|
proc toStr*(rc: CoreDbRc[CoreDbMptRef]): string = rc.toStr "mpt"
|
||||||
proc toStr*(rc: CoreDbRc[CoreDxAccRef]): string = rc.toStr "acc"
|
proc toStr*(rc: CoreDbRc[CoreDbAccRef]): string = rc.toStr "acc"
|
||||||
|
|
||||||
func toStr*(ela: Duration): string =
|
func toStr*(ela: Duration): string =
|
||||||
aristo_profile.toStr(ela)
|
aristo_profile.toStr(ela)
|
||||||
|
@ -179,12 +169,12 @@ func toStr*(ela: Duration): string =
|
||||||
# Public new API logging framework
|
# Public new API logging framework
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
template beginNewApi*(w: CoreDxApiTrackRef; s: static[CoreDbFnInx]) =
|
template beginNewApi*(w: CoreDbApiTrackRef; s: static[CoreDbFnInx]) =
|
||||||
when CoreDbEnableApiProfiling:
|
when CoreDbEnableApiProfiling:
|
||||||
const bnaCtx {.inject.} = s # Local use only
|
const bnaCtx {.inject.} = s # Local use only
|
||||||
let bnaStart {.inject.} = getTime() # Local use only
|
let bnaStart {.inject.} = getTime() # Local use only
|
||||||
|
|
||||||
template endNewApiIf*(w: CoreDxApiTrackRef; code: untyped) =
|
template endNewApiIf*(w: CoreDbApiTrackRef; code: untyped) =
|
||||||
block:
|
block:
|
||||||
when typeof(w) is CoreDbRef:
|
when typeof(w) is CoreDbRef:
|
||||||
let db = w
|
let db = w
|
||||||
|
|
|
@ -97,15 +97,15 @@ type
|
||||||
CoreDbBaseColPrintFn* = proc(vid: CoreDbColRef): string {.noRaise.}
|
CoreDbBaseColPrintFn* = proc(vid: CoreDbColRef): string {.noRaise.}
|
||||||
CoreDbBaseErrorPrintFn* = proc(e: CoreDbErrorRef): string {.noRaise.}
|
CoreDbBaseErrorPrintFn* = proc(e: CoreDbErrorRef): string {.noRaise.}
|
||||||
CoreDbBaseLevelFn* = proc(): int {.noRaise.}
|
CoreDbBaseLevelFn* = proc(): int {.noRaise.}
|
||||||
CoreDbBaseNewKvtFn* = proc(): CoreDbRc[CoreDxKvtRef] {.noRaise.}
|
CoreDbBaseNewKvtFn* = proc(): CoreDbRc[CoreDbKvtRef] {.noRaise.}
|
||||||
CoreDbBaseNewCtxFn* = proc(): CoreDbCtxRef {.noRaise.}
|
CoreDbBaseNewCtxFn* = proc(): CoreDbCtxRef {.noRaise.}
|
||||||
CoreDbBaseNewCtxFromTxFn* = proc(
|
CoreDbBaseNewCtxFromTxFn* = proc(
|
||||||
colState: Hash256; kind: CoreDbColType): CoreDbRc[CoreDbCtxRef] {.noRaise.}
|
colState: Hash256; kind: CoreDbColType): CoreDbRc[CoreDbCtxRef] {.noRaise.}
|
||||||
CoreDbBaseSwapCtxFn* = proc(ctx: CoreDbCtxRef): CoreDbCtxRef {.noRaise.}
|
CoreDbBaseSwapCtxFn* = proc(ctx: CoreDbCtxRef): CoreDbCtxRef {.noRaise.}
|
||||||
CoreDbBaseTxBeginFn* = proc(): CoreDxTxRef {.noRaise.}
|
CoreDbBaseTxBeginFn* = proc(): CoreDbTxRef {.noRaise.}
|
||||||
CoreDbBaseNewCaptFn* =
|
CoreDbBaseNewCaptFn* =
|
||||||
proc(flgs: set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] {.noRaise.}
|
proc(flgs: set[CoreDbCaptFlags]): CoreDbRc[CoreDbCaptRef] {.noRaise.}
|
||||||
CoreDbBaseGetCaptFn* = proc(): CoreDbRc[CoreDxCaptRef] {.noRaise.}
|
CoreDbBaseGetCaptFn* = proc(): CoreDbRc[CoreDbCaptRef] {.noRaise.}
|
||||||
CoreDbBasePersistentFn* =
|
CoreDbBasePersistentFn* =
|
||||||
proc(bn: Opt[BlockNumber]): CoreDbRc[void] {.noRaise.}
|
proc(bn: Opt[BlockNumber]): CoreDbRc[void] {.noRaise.}
|
||||||
|
|
||||||
|
@ -164,9 +164,9 @@ type
|
||||||
colType: CoreDbColType; colState: Hash256; address: Opt[EthAddress];
|
colType: CoreDbColType; colState: Hash256; address: Opt[EthAddress];
|
||||||
): CoreDbRc[CoreDbColRef] {.noRaise.}
|
): CoreDbRc[CoreDbColRef] {.noRaise.}
|
||||||
CoreDbCtxGetMptFn* = proc(
|
CoreDbCtxGetMptFn* = proc(
|
||||||
root: CoreDbColRef): CoreDbRc[CoreDxMptRef] {.noRaise.}
|
root: CoreDbColRef): CoreDbRc[CoreDbMptRef] {.noRaise.}
|
||||||
CoreDbCtxGetAccFn* = proc(
|
CoreDbCtxGetAccFn* = proc(
|
||||||
root: CoreDbColRef): CoreDbRc[CoreDxAccRef] {.noRaise.}
|
root: CoreDbColRef): CoreDbRc[CoreDbAccRef] {.noRaise.}
|
||||||
CoreDbCtxForgetFn* = proc() {.noRaise.}
|
CoreDbCtxForgetFn* = proc() {.noRaise.}
|
||||||
|
|
||||||
CoreDbCtxFns* = object
|
CoreDbCtxFns* = object
|
||||||
|
@ -207,7 +207,7 @@ type
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
# Sub-descriptor: Mpt/hexary trie methods for accounts
|
# Sub-descriptor: Mpt/hexary trie methods for accounts
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
CoreDbAccGetMptFn* = proc(): CoreDbRc[CoreDxMptRef] {.noRaise.}
|
CoreDbAccGetMptFn* = proc(): CoreDbRc[CoreDbMptRef] {.noRaise.}
|
||||||
CoreDbAccFetchFn* = proc(k: EthAddress): CoreDbRc[CoreDbAccount] {.noRaise.}
|
CoreDbAccFetchFn* = proc(k: EthAddress): CoreDbRc[CoreDbAccount] {.noRaise.}
|
||||||
CoreDbAccDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
CoreDbAccDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
||||||
CoreDbAccStoDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
CoreDbAccStoDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
|
||||||
|
@ -283,25 +283,24 @@ type
|
||||||
## Backend wrapper for direct backend access
|
## Backend wrapper for direct backend access
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
|
|
||||||
CoreDxKvtRef* = ref CoreDxKvtObj
|
CoreDbKvtRef* = ref object of RootRef
|
||||||
CoreDxKvtObj* = object of RootObj
|
|
||||||
## Statically initialised Key-Value pair table living in `CoreDbRef`
|
## Statically initialised Key-Value pair table living in `CoreDbRef`
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbKvtFns
|
methods*: CoreDbKvtFns
|
||||||
|
|
||||||
CoreDbCtxRef* = ref object of RootRef
|
CoreDbCtxRef* = ref object of RootRef
|
||||||
## Context for `CoreDxMptRef` and `CoreDxAccRef`
|
## Context for `CoreDbMptRef` and `CoreDbAccRef`
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbCtxFns
|
methods*: CoreDbCtxFns
|
||||||
|
|
||||||
CoreDxMptRef* = ref object of RootRef
|
CoreDbMptRef* = ref object of RootRef
|
||||||
## Hexary/Merkle-Patricia tree derived from `CoreDbRef`, will be
|
## Hexary/Merkle-Patricia tree derived from `CoreDbRef`, will be
|
||||||
## initialised on-the-fly.
|
## initialised on-the-fly.
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbMptFns
|
methods*: CoreDbMptFns
|
||||||
|
|
||||||
CoreDxAccRef* = ref object of RootRef
|
CoreDbAccRef* = ref object of RootRef
|
||||||
## Similar to `CoreDxKvtRef`, only dealing with `CoreDbAccount` data
|
## Similar to `CoreDbKvtRef`, only dealing with `CoreDbAccount` data
|
||||||
## rather than `Blob` values.
|
## rather than `Blob` values.
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbAccFns
|
methods*: CoreDbAccFns
|
||||||
|
@ -312,19 +311,12 @@ type
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
ready*: bool ## Must be set `true` to enable
|
ready*: bool ## Must be set `true` to enable
|
||||||
|
|
||||||
CoreDxPhkRef* = ref object
|
CoreDbTxRef* = ref object of RootRef
|
||||||
## Similar to `CoreDbMptRef` but with pre-hashed keys. That is, any
|
|
||||||
## argument key for `merge()`, `fetch()` etc. will be hashed first
|
|
||||||
## before being applied.
|
|
||||||
toMpt*: CoreDxMptRef
|
|
||||||
methods*: CoreDbMptFns
|
|
||||||
|
|
||||||
CoreDxTxRef* = ref object of RootRef
|
|
||||||
## Transaction descriptor derived from `CoreDbRef`
|
## Transaction descriptor derived from `CoreDbRef`
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbTxFns
|
methods*: CoreDbTxFns
|
||||||
|
|
||||||
CoreDxCaptRef* = ref object
|
CoreDbCaptRef* = ref object
|
||||||
## Db transaction tracer derived from `CoreDbRef`
|
## Db transaction tracer derived from `CoreDbRef`
|
||||||
parent*: CoreDbRef
|
parent*: CoreDbRef
|
||||||
methods*: CoreDbCaptFns
|
methods*: CoreDbCaptFns
|
||||||
|
|
|
@ -16,10 +16,10 @@ type
|
||||||
EphemMethodsDesc = CoreDbKvtBackendRef | CoreDbMptBackendRef | CoreDbColRef
|
EphemMethodsDesc = CoreDbKvtBackendRef | CoreDbMptBackendRef | CoreDbColRef
|
||||||
|
|
||||||
MethodsDesc =
|
MethodsDesc =
|
||||||
CoreDxKvtRef |
|
CoreDbKvtRef |
|
||||||
CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef |
|
CoreDbCtxRef | CoreDbMptRef | CoreDbAccRef |
|
||||||
CoreDxTxRef |
|
CoreDbTxRef |
|
||||||
CoreDxCaptRef
|
CoreDbCaptRef
|
||||||
|
|
||||||
ValidateDesc* = MethodsDesc | EphemMethodsDesc | CoreDbErrorRef
|
ValidateDesc* = MethodsDesc | EphemMethodsDesc | CoreDbErrorRef
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ proc validateMethodsDesc(eph: EphemMethodsDesc) =
|
||||||
doAssert not eph.isNil
|
doAssert not eph.isNil
|
||||||
doAssert not eph.parent.isNil
|
doAssert not eph.parent.isNil
|
||||||
|
|
||||||
proc validateMethodsDesc(kvt: CoreDxKvtRef) =
|
proc validateMethodsDesc(kvt: CoreDbKvtRef) =
|
||||||
doAssert not kvt.isNil
|
doAssert not kvt.isNil
|
||||||
doAssert not kvt.parent.isNil
|
doAssert not kvt.parent.isNil
|
||||||
kvt.methods.validateMethodsDesc
|
kvt.methods.validateMethodsDesc
|
||||||
|
@ -98,30 +98,25 @@ proc validateMethodsDesc(ctx: CoreDbCtxRef) =
|
||||||
doAssert not ctx.parent.isNil
|
doAssert not ctx.parent.isNil
|
||||||
ctx.methods.validateMethodsDesc
|
ctx.methods.validateMethodsDesc
|
||||||
|
|
||||||
proc validateMethodsDesc(mpt: CoreDxMptRef) =
|
proc validateMethodsDesc(mpt: CoreDbMptRef) =
|
||||||
doAssert not mpt.isNil
|
doAssert not mpt.isNil
|
||||||
doAssert not mpt.parent.isNil
|
doAssert not mpt.parent.isNil
|
||||||
mpt.methods.validateMethodsDesc
|
mpt.methods.validateMethodsDesc
|
||||||
|
|
||||||
proc validateMethodsDesc(acc: CoreDxAccRef) =
|
proc validateMethodsDesc(acc: CoreDbAccRef) =
|
||||||
doAssert not acc.isNil
|
doAssert not acc.isNil
|
||||||
doAssert not acc.parent.isNil
|
doAssert not acc.parent.isNil
|
||||||
acc.methods.validateMethodsDesc
|
acc.methods.validateMethodsDesc
|
||||||
|
|
||||||
proc validateMethodsDesc(phk: CoreDxPhkRef) =
|
|
||||||
doAssert not phk.isNil
|
|
||||||
doAssert not phk.toMpt.isNil
|
|
||||||
phk.methods.validateMethodsDesc
|
|
||||||
|
|
||||||
when false: # currently disabled
|
when false: # currently disabled
|
||||||
proc validateMethodsDesc(cpt: CoreDxCaptRef) =
|
proc validateMethodsDesc(cpt: CoreDbCaptRef) =
|
||||||
doAssert not cpt.isNil
|
doAssert not cpt.isNil
|
||||||
doAssert not cpt.parent.isNil
|
doAssert not cpt.parent.isNil
|
||||||
doAssert not cpt.methods.recorderFn.isNil
|
doAssert not cpt.methods.recorderFn.isNil
|
||||||
doAssert not cpt.methods.getFlagsFn.isNil
|
doAssert not cpt.methods.getFlagsFn.isNil
|
||||||
doAssert not cpt.methods.forgetFn.isNil
|
doAssert not cpt.methods.forgetFn.isNil
|
||||||
|
|
||||||
proc validateMethodsDesc(tx: CoreDxTxRef) =
|
proc validateMethodsDesc(tx: CoreDbTxRef) =
|
||||||
doAssert not tx.isNil
|
doAssert not tx.isNil
|
||||||
doAssert not tx.parent.isNil
|
doAssert not tx.parent.isNil
|
||||||
doAssert not tx.methods.levelFn.isNil
|
doAssert not tx.methods.levelFn.isNil
|
||||||
|
|
|
@ -31,7 +31,7 @@ when CoreDbEnableApiTracking:
|
||||||
# Public iterators
|
# Public iterators
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
iterator pairs*(kvt: CoreDxKvtRef): (Blob, Blob) {.apiRaise.} =
|
iterator pairs*(kvt: CoreDbKvtRef): (Blob, Blob) {.apiRaise.} =
|
||||||
## Iterator supported on memory DB (otherwise implementation dependent)
|
## Iterator supported on memory DB (otherwise implementation dependent)
|
||||||
##
|
##
|
||||||
kvt.setTrackNewApi KvtPairsIt
|
kvt.setTrackNewApi KvtPairsIt
|
||||||
|
@ -46,8 +46,8 @@ iterator pairs*(kvt: CoreDxKvtRef): (Blob, Blob) {.apiRaise.} =
|
||||||
raiseAssert: "Unsupported database type: " & $kvt.parent.dbType
|
raiseAssert: "Unsupported database type: " & $kvt.parent.dbType
|
||||||
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed
|
kvt.ifTrackNewApi: debug newApiTxt, api, elapsed
|
||||||
|
|
||||||
iterator pairs*(mpt: CoreDxMptRef): (Blob, Blob) =
|
iterator pairs*(mpt: CoreDbMptRef): (Blob, Blob) =
|
||||||
## Trie traversal, only supported for `CoreDxMptRef` (not `Phk`)
|
## Trie traversal, only supported for `CoreDbMptRef`
|
||||||
##
|
##
|
||||||
mpt.setTrackNewApi MptPairsIt
|
mpt.setTrackNewApi MptPairsIt
|
||||||
case mpt.parent.dbType:
|
case mpt.parent.dbType:
|
||||||
|
@ -60,8 +60,8 @@ iterator pairs*(mpt: CoreDxMptRef): (Blob, Blob) =
|
||||||
let trie = mpt.methods.getColFn()
|
let trie = mpt.methods.getColFn()
|
||||||
debug newApiTxt, api, elapsed, trie
|
debug newApiTxt, api, elapsed, trie
|
||||||
|
|
||||||
iterator replicate*(mpt: CoreDxMptRef): (Blob, Blob) {.apiRaise.} =
|
iterator replicate*(mpt: CoreDbMptRef): (Blob, Blob) {.apiRaise.} =
|
||||||
## Low level trie dump, only supported for `CoreDxMptRef` (not `Phk`)
|
## Low level trie dump, only supported for `CoreDbMptRef`
|
||||||
##
|
##
|
||||||
mpt.setTrackNewApi MptReplicateIt
|
mpt.setTrackNewApi MptReplicateIt
|
||||||
case mpt.parent.dbType:
|
case mpt.parent.dbType:
|
||||||
|
|
|
@ -31,7 +31,7 @@ when CoreDbEnableApiTracking:
|
||||||
# Public iterators
|
# Public iterators
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
iterator replicatePersistent*(mpt: CoreDxMptRef): (Blob, Blob) {.rlpRaise.} =
|
iterator replicatePersistent*(mpt: CoreDbMptRef): (Blob, Blob) {.rlpRaise.} =
|
||||||
## Extended version of `replicate()` for `Aristo` persistent backend.
|
## Extended version of `replicate()` for `Aristo` persistent backend.
|
||||||
##
|
##
|
||||||
mpt.setTrackNewApi MptReplicateIt
|
mpt.setTrackNewApi MptReplicateIt
|
||||||
|
|
|
@ -64,7 +64,7 @@ type
|
||||||
|
|
||||||
AccountsLedgerRef* = ref object
|
AccountsLedgerRef* = ref object
|
||||||
ledger: AccountLedger
|
ledger: AccountLedger
|
||||||
kvt: CoreDxKvtRef
|
kvt: CoreDbKvtRef
|
||||||
savePoint: LedgerSavePoint
|
savePoint: LedgerSavePoint
|
||||||
witnessCache: Table[EthAddress, WitnessData]
|
witnessCache: Table[EthAddress, WitnessData]
|
||||||
isDirty: bool
|
isDirty: bool
|
||||||
|
@ -412,7 +412,7 @@ proc getNonce*(ac: AccountsLedgerRef, address: EthAddress): AccountNonce =
|
||||||
if acc.isNil: emptyEthAccount.nonce
|
if acc.isNil: emptyEthAccount.nonce
|
||||||
else: acc.statement.nonce
|
else: acc.statement.nonce
|
||||||
|
|
||||||
proc getCode(acc: AccountRef, kvt: CoreDxKvtRef): lent seq[byte] =
|
proc getCode(acc: AccountRef, kvt: CoreDbKvtRef): lent seq[byte] =
|
||||||
if CodeLoaded notin acc.flags and CodeChanged notin acc.flags:
|
if CodeLoaded notin acc.flags and CodeChanged notin acc.flags:
|
||||||
if acc.statement.codeHash != EMPTY_CODE_HASH:
|
if acc.statement.codeHash != EMPTY_CODE_HASH:
|
||||||
var rc = kvt.get(contractHashKey(acc.statement.codeHash).toOpenArray)
|
var rc = kvt.get(contractHashKey(acc.statement.codeHash).toOpenArray)
|
||||||
|
|
|
@ -351,9 +351,9 @@ proc getAccessList*(ldg: LedgerRef): AccessList =
|
||||||
proc rootHash*(ldg: LedgerRef): KeccakHash =
|
proc rootHash*(ldg: LedgerRef): KeccakHash =
|
||||||
ldg.state()
|
ldg.state()
|
||||||
|
|
||||||
proc getMpt*(ldg: LedgerRef): CoreDxMptRef =
|
proc getMpt*(ldg: LedgerRef): CoreDbMptRef =
|
||||||
ldg.beginTrackApi LdgGetMptFn
|
ldg.beginTrackApi LdgGetMptFn
|
||||||
result = ldg.ac.rawTrie.CoreDxAccRef.getMpt
|
result = ldg.ac.rawTrie.CoreDbAccRef.getMpt
|
||||||
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
||||||
|
|
||||||
proc getEthAccount*(ldg: LedgerRef, eAddr: EthAddress): Account =
|
proc getEthAccount*(ldg: LedgerRef, eAddr: EthAddress): Account =
|
||||||
|
|
|
@ -100,7 +100,7 @@ func toStr*(w: Hash256): string =
|
||||||
|
|
||||||
when declared(CoreDbMptRef):
|
when declared(CoreDbMptRef):
|
||||||
func toStr*(w: CoreDbMptRef): string =
|
func toStr*(w: CoreDbMptRef): string =
|
||||||
if w.CoreDxMptRef.isNil: "MptRef(nil)" else: "MptRef"
|
if w.CoreDbMptRef.isNil: "MptRef(nil)" else: "MptRef"
|
||||||
|
|
||||||
func toStr*(w: Blob): string =
|
func toStr*(w: Blob): string =
|
||||||
if 0 < w.len and w.len < 5: "<" & w.oaToStr & ">"
|
if 0 < w.len and w.len < 5: "<" & w.oaToStr & ">"
|
||||||
|
|
|
@ -32,8 +32,8 @@ import
|
||||||
".."/[core_db, storage_types]
|
".."/[core_db, storage_types]
|
||||||
|
|
||||||
type
|
type
|
||||||
AccountLedger* = distinct CoreDxAccRef
|
AccountLedger* = distinct CoreDbAccRef
|
||||||
StorageLedger* = distinct CoreDxPhkRef
|
StorageLedger* = distinct CoreDbMptRef
|
||||||
SomeLedger* = AccountLedger | StorageLedger
|
SomeLedger* = AccountLedger | StorageLedger
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -56,7 +56,7 @@ proc toSvp*(sl: StorageLedger): seq[(UInt256,UInt256)] =
|
||||||
let kvt = db.newKvt
|
let kvt = db.newKvt
|
||||||
var kvp: Table[UInt256,UInt256]
|
var kvp: Table[UInt256,UInt256]
|
||||||
try:
|
try:
|
||||||
for (slotHash,val) in sl.distinctBase.toMpt.pairs:
|
for (slotHash,val) in sl.distinctBase.pairs:
|
||||||
let rc = kvt.get(slotHashToSlotKey(slotHash).toOpenArray)
|
let rc = kvt.get(slotHashToSlotKey(slotHash).toOpenArray)
|
||||||
if rc.isErr:
|
if rc.isErr:
|
||||||
warn "StorageLedger.dump()", slotHash, error=($$rc.error)
|
warn "StorageLedger.dump()", slotHash, error=($$rc.error)
|
||||||
|
@ -186,22 +186,22 @@ proc init*(
|
||||||
if rc.isErr:
|
if rc.isErr:
|
||||||
raiseAssert info & $$rc.error
|
raiseAssert info & $$rc.error
|
||||||
rc.value
|
rc.value
|
||||||
mpt.toPhk.T
|
mpt.T
|
||||||
|
|
||||||
proc fetch*(sl: StorageLedger, slot: UInt256): Result[Blob,void] =
|
proc fetch*(sl: StorageLedger, slot: UInt256): Result[Blob,void] =
|
||||||
var rc = sl.distinctBase.fetch(slot.toBytesBE)
|
var rc = sl.distinctBase.fetch(slot.toBytesBE.keccakHash.data)
|
||||||
if rc.isErr:
|
if rc.isErr:
|
||||||
return err()
|
return err()
|
||||||
ok move(rc.value)
|
ok move(rc.value)
|
||||||
|
|
||||||
proc merge*(sl: StorageLedger, slot: UInt256, value: openArray[byte]) =
|
proc merge*(sl: StorageLedger, slot: UInt256, value: openArray[byte]) =
|
||||||
const info = "StorageLedger/merge(): "
|
const info = "StorageLedger/merge(): "
|
||||||
sl.distinctBase.merge(slot.toBytesBE, value).isOkOr:
|
sl.distinctBase.merge(slot.toBytesBE.keccakHash.data, value).isOkOr:
|
||||||
raiseAssert info & $$error
|
raiseAssert info & $$error
|
||||||
|
|
||||||
proc delete*(sl: StorageLedger, slot: UInt256) =
|
proc delete*(sl: StorageLedger, slot: UInt256) =
|
||||||
const info = "StorageLedger/delete(): "
|
const info = "StorageLedger/delete(): "
|
||||||
sl.distinctBase.delete(slot.toBytesBE).isOkOr:
|
sl.distinctBase.delete(slot.toBytesBE.keccakHash.data).isOkOr:
|
||||||
if error.error == MptNotFound:
|
if error.error == MptNotFound:
|
||||||
return
|
return
|
||||||
raiseAssert info & $$error
|
raiseAssert info & $$error
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except
|
# at your option. This file may not be copied, modified, or distributed except
|
||||||
# according to those terms.
|
# according to those terms.
|
||||||
|
|
||||||
# This implementation of getBranch on the CoreDbPhkRef type is a temporary solution
|
# This implementation of getBranch on the CoreDbMptRef type is a temporary solution
|
||||||
# which can be removed once we get an equivient proc defined on the CoreDbPhkRef type
|
# which can be removed once we get an equivient proc defined on the CoreDbMptRef type
|
||||||
# in the db layer.
|
# in the db layer.
|
||||||
|
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
@ -88,7 +88,12 @@ proc getBranchAux(
|
||||||
raise newException(RlpError, "node has an unexpected number of children")
|
raise newException(RlpError, "node has an unexpected number of children")
|
||||||
|
|
||||||
proc getBranch*(
|
proc getBranch*(
|
||||||
self: CoreDxPhkRef;
|
# self: CoreDxPhkRef;
|
||||||
|
# Note that PHK type has been removed. The difference PHK an MPT was that
|
||||||
|
# the keys of the PHK were pre-hased (as in the legacy `SecureHexaryTrie`
|
||||||
|
# object.) Can this code have worked at all? Looking at the `keyHash`
|
||||||
|
# below it would mean the `key` was double hashed? -- j
|
||||||
|
self: CoreDbMptRef;
|
||||||
key: openArray[byte]): seq[seq[byte]] {.raises: [RlpError].} =
|
key: openArray[byte]): seq[seq[byte]] {.raises: [RlpError].} =
|
||||||
let
|
let
|
||||||
keyHash = keccakHash(key).data
|
keyHash = keccakHash(key).data
|
||||||
|
|
|
@ -104,7 +104,7 @@ proc dumpMemoryDB*(node: JsonNode, kvt: TableRef[common.Blob, common.Blob]) =
|
||||||
n[k.toHex(false)] = %v
|
n[k.toHex(false)] = %v
|
||||||
node["state"] = n
|
node["state"] = n
|
||||||
|
|
||||||
proc dumpMemoryDB*(node: JsonNode, capture: CoreDxCaptRef) =
|
proc dumpMemoryDB*(node: JsonNode, capture: CoreDbCaptRef) =
|
||||||
node.dumpMemoryDB capture.logDb
|
node.dumpMemoryDB capture.logDb
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
|
@ -40,7 +40,7 @@ else:
|
||||||
template persistToDb(db: CoreDbRef, body: untyped) =
|
template persistToDb(db: CoreDbRef, body: untyped) =
|
||||||
block: body
|
block: body
|
||||||
|
|
||||||
proc contains(kvt: CoreDxKvtRef; key: openArray[byte]): bool =
|
proc contains(kvt: CoreDbKvtRef; key: openArray[byte]): bool =
|
||||||
kvt.hasKey(key).expect "valid bool"
|
kvt.hasKey(key).expect "valid bool"
|
||||||
|
|
||||||
proc main() {.used.} =
|
proc main() {.used.} =
|
||||||
|
|
Loading…
Reference in New Issue