avoid closure environment for mpt methods (#2408)

An instance of `CoreDbMptRef` is created for and stored in every account
- when we are processing blocks and have many accounts in memory, this
closure environment takes up hundreds of mb of memory (around block 5M,
it is the 4:th largest memory consumer!) - incidentally, this also
removes a circular reference in the setup that causes the
`AristoCodeDbMptRef` to linger in memory much longer than it
has to which is the core reason why it takes so much.

The real solution here is to remove the methods indirection entirely,
but this PR provides relief until that has been done.

Similar treatment is given to some of the other core api functions to
avoid circulars there too.
This commit is contained in:
Jacek Sieka 2024-06-24 07:56:41 +02:00 committed by GitHub
parent 99ff8dc876
commit 9521582005
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 131 additions and 125 deletions

View File

@ -183,20 +183,19 @@ func toVoidRc[T](
# ------------------------------------------------------------------------------
# Private `MPT` call back functions
# ------------------------------------------------------------------------------
proc mptMethods(): CoreDbMptFns =
# These templates are a hack to remove a closure environment that was using
# hundreds of mb of memory to have this syntactic convenience
# TODO remove methods / abstraction entirely - it is no longer needed
template base: untyped = cMpt.base
template db: untyped = base.parent # Ditto
template api: untyped = base.api # Ditto
template mpt: untyped = base.ctx.mpt # Ditto
proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
## Generic columns database handlers
let
cMpt = cMpt # So it can savely be captured
base = cMpt.base # Will not change and can be captured
db = base.parent # Ditto
api = base.api # Ditto
mpt = base.ctx.mpt # Ditto
proc mptBackend(): CoreDbMptBackendRef =
proc mptBackend(cMpt: AristoCoreDbMptRef): CoreDbMptBackendRef =
db.bless AristoCoreDbMptBE(adb: mpt)
proc mptColFn(): CoreDbColRef =
proc mptColFn(cMpt: AristoCoreDbMptRef): CoreDbColRef =
if cMpt.mptRoot.distinctBase < LEAST_FREE_VID:
return db.bless(AristoColRef(
base: base,
@ -219,7 +218,7 @@ proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
stoRoot: cMpt.mptRoot,
stoAddr: cMpt.address)
proc mptFetch(key: openArray[byte]): CoreDbRc[Blob] =
proc mptFetch(cMpt: AristoCoreDbMptRef, key: openArray[byte]): CoreDbRc[Blob] =
const info = "fetchFn()"
let rc = block:
@ -241,7 +240,7 @@ proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
else:
err(rc.error.toError(base, info, MptNotFound))
proc mptMerge(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
proc mptMerge(cMpt: AristoCoreDbMptRef, k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
const info = "mergeFn()"
if cMpt.accPath.isValid:
@ -257,7 +256,7 @@ proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
ok()
proc mptDelete(key: openArray[byte]): CoreDbRc[void] =
proc mptDelete(cMpt: AristoCoreDbMptRef, key: openArray[byte]): CoreDbRc[void] =
const info = "deleteFn()"
let rc = block:
@ -281,7 +280,7 @@ proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
ok()
proc mptHasPath(key: openArray[byte]): CoreDbRc[bool] =
proc mptHasPath(cMpt: AristoCoreDbMptRef, key: openArray[byte]): CoreDbRc[bool] =
const info = "hasPathFn()"
let rc = block:
@ -295,52 +294,50 @@ proc mptMethods(cMpt: AristoCoreDbMptRef): CoreDbMptFns =
return err(rc.error.toError(base, info))
ok(rc.value)
## Generic columns database handlers
CoreDbMptFns(
backendFn: proc(): CoreDbMptBackendRef =
mptBackend(),
backendFn: proc(cMpt: CoreDbMptRef): CoreDbMptBackendRef =
mptBackend(AristoCoreDbMptRef(cMpt)),
fetchFn: proc(k: openArray[byte]): CoreDbRc[Blob] =
mptFetch(k),
fetchFn: proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[Blob] =
mptFetch(AristoCoreDbMptRef(cMpt), k),
deleteFn: proc(k: openArray[byte]): CoreDbRc[void] =
mptDelete(k),
deleteFn: proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[void] =
mptDelete(AristoCoreDbMptRef(cMpt), k),
mergeFn: proc(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
mptMerge(k, v),
mergeFn: proc(cMpt: CoreDbMptRef, k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] =
mptMerge(AristoCoreDbMptRef(cMpt), k, v),
hasPathFn: proc(k: openArray[byte]): CoreDbRc[bool] =
mptHasPath(k),
hasPathFn: proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[bool] =
mptHasPath(AristoCoreDbMptRef(cMpt), k),
getColFn: proc(): CoreDbColRef =
mptColFn())
getColFn: proc(cMpt: CoreDbMptRef): CoreDbColRef =
mptColFn(AristoCoreDbMptRef(cMpt)))
# ------------------------------------------------------------------------------
# Private account call back functions
# ------------------------------------------------------------------------------
proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
proc accMethods(): CoreDbAccFns =
## Account columns database handlers
let
cAcc = cAcc # So it can savely be captured
base = cAcc.base # Will not change and can be captured
db = base.parent # Ditto
api = base.api # Ditto
mpt = base.ctx.mpt # Ditto
template base: untyped = cAcc.base
template db: untyped = base.parent
template api: untyped = base.api
template mpt: untyped = base.ctx.mpt
proc getColFn(): CoreDbColRef =
proc getColFn(cAcc: AristoCoreDbAccRef): CoreDbColRef =
db.bless AristoColRef(
base: base,
colType: CtAccounts)
proc accCloneMpt(): CoreDbRc[CoreDbMptRef] =
proc accCloneMpt(cAcc: AristoCoreDbAccRef): CoreDbRc[CoreDbMptRef] =
var xpt = AristoCoreDbMptRef(
base: base,
mptRoot: AccountsVID)
xpt.methods = xpt.mptMethods
xpt.methods = mptMethods()
ok(db.bless xpt)
proc accFetch(address: EthAddress): CoreDbRc[CoreDbAccount] =
proc accFetch(cAcc: AristoCoreDbAccRef, address: EthAddress): CoreDbRc[CoreDbAccount] =
const info = "acc/fetchFn()"
let
@ -352,7 +349,7 @@ proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
ok cAcc.toCoreDbAccount(acc, address)
proc accMerge(account: CoreDbAccount): CoreDbRc[void] =
proc accMerge(cAcc: AristoCoreDbAccRef, account: CoreDbAccount): CoreDbRc[void] =
const info = "acc/mergeFn()"
let
@ -363,7 +360,7 @@ proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
return err(rc.error.toError(base, info))
ok()
proc accDelete(address: EthAddress): CoreDbRc[void] =
proc accDelete(cAcc: AristoCoreDbAccRef, address: EthAddress): CoreDbRc[void] =
const info = "acc/deleteFn()"
let key = address.keccakHash.data
@ -374,7 +371,7 @@ proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
ok()
proc accStoDelete(address: EthAddress): CoreDbRc[void] =
proc accStoDelete(cAcc: AristoCoreDbAccRef, address: EthAddress): CoreDbRc[void] =
const info = "stoDeleteFn()"
let rc = api.deleteStorageTree(mpt, address.to(PathID))
@ -383,7 +380,7 @@ proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
ok()
proc accHasPath(address: EthAddress): CoreDbRc[bool] =
proc accHasPath(cAcc: AristoCoreDbAccRef, address: EthAddress): CoreDbRc[bool] =
const info = "hasPathFn()"
let
@ -394,40 +391,39 @@ proc accMethods(cAcc: AristoCoreDbAccRef): CoreDbAccFns =
CoreDbAccFns(
getMptFn: proc(): CoreDbRc[CoreDbMptRef] =
accCloneMpt(),
getMptFn: proc(cAcc: CoreDbAccRef): CoreDbRc[CoreDbMptRef] =
accCloneMpt(AristoCoreDbAccRef(cAcc)),
fetchFn: proc(address: EthAddress): CoreDbRc[CoreDbAccount] =
accFetch(address),
fetchFn: proc(cAcc: CoreDbAccRef, address: EthAddress): CoreDbRc[CoreDbAccount] =
accFetch(AristoCoreDbAccRef(cAcc), address),
deleteFn: proc(address: EthAddress): CoreDbRc[void] =
accDelete(address),
deleteFn: proc(cAcc: CoreDbAccRef, address: EthAddress): CoreDbRc[void] =
accDelete(AristoCoreDbAccRef(cAcc), address),
stoDeleteFn: proc(address: EthAddress): CoreDbRc[void] =
accStoDelete(address),
stoDeleteFn: proc(cAcc: CoreDbAccRef, address: EthAddress): CoreDbRc[void] =
accStoDelete(AristoCoreDbAccRef(cAcc), address),
mergeFn: proc(acc: CoreDbAccount): CoreDbRc[void] =
accMerge(acc),
mergeFn: proc(cAcc: CoreDbAccRef, acc: CoreDbAccount): CoreDbRc[void] =
accMerge(AristoCoreDbAccRef(cAcc), acc),
hasPathFn: proc(address: EthAddress): CoreDbRc[bool] =
accHasPath(address),
hasPathFn: proc(cAcc: CoreDbAccRef, address: EthAddress): CoreDbRc[bool] =
accHasPath(AristoCoreDbAccRef(cAcc), address),
getColFn: proc(): CoreDbColRef =
getColFn())
getColFn: proc(cAcc: CoreDbAccRef): CoreDbColRef =
getColFn(AristoCoreDbAccRef(cAcc)))
# ------------------------------------------------------------------------------
# Private context call back functions
# ------------------------------------------------------------------------------
proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
let
cCtx = cCtx # So it can savely be captured
base = cCtx.base # Will not change and can be captured
db = base.parent # Ditto
api = base.api # Ditto
mpt = cCtx.mpt # Ditto
template base: untyped = cCtx.base
template db: untyped = base.parent
template api: untyped = base.api
template mpt: untyped = cCtx.mpt
proc ctxNewCol(
cCtx: AristoCoreDbCtxRef,
colType: CoreDbColType;
colState: Hash256;
address: Opt[EthAddress];
@ -463,7 +459,7 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
err(aristo.GenericError.toError(base, info, RootNotFound))
proc ctxGetMpt(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
proc ctxGetMpt(cCtx: AristoCoreDbCtxRef, col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
const
info = "ctx/getMptFn()"
let
@ -505,10 +501,10 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
col.reset = false
newMpt.base = base
newMpt.methods = newMpt.mptMethods()
newMpt.methods = mptMethods()
ok(db.bless newMpt)
proc ctxGetAcc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
proc ctxGetAcc(cCtx: AristoCoreDbCtxRef, col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
const info = "getAccFn()"
let col = AristoColRef(col)
@ -517,31 +513,32 @@ proc ctxMethods(cCtx: AristoCoreDbCtxRef): CoreDbCtxFns =
return err(error.toError(base, info, RootUnacceptable))
let acc = AristoCoreDbAccRef(base: base)
acc.methods = acc.accMethods()
acc.methods = accMethods()
ok(db.bless acc)
proc ctxForget() =
proc ctxForget(cCtx: AristoCoreDbCtxRef) =
api.forget(mpt).isOkOr:
raiseAssert "forgetFn(): " & $error
CoreDbCtxFns(
newColFn: proc(
cCtx: CoreDbCtxRef;
col: CoreDbColType;
colState: Hash256;
address: Opt[EthAddress];
): CoreDbRc[CoreDbColRef] =
ctxNewCol(col, colState, address),
ctxNewCol(AristoCoreDbCtxRef(cCtx), col, colState, address),
getMptFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
ctxGetMpt(col),
getMptFn: proc(cCtx: CoreDbCtxRef, col: CoreDbColRef): CoreDbRc[CoreDbMptRef] =
ctxGetMpt(AristoCoreDbCtxRef(cCtx), col),
getAccFn: proc(col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
ctxGetAcc(col),
getAccFn: proc(cCtx: CoreDbCtxRef, col: CoreDbColRef): CoreDbRc[CoreDbAccRef] =
ctxGetAcc(AristoCoreDbCtxRef(cCtx), col),
forgetFn: proc() =
ctxForget())
forgetFn: proc(cCtx: CoreDbCtxRef) =
ctxForget(AristoCoreDbCtxRef(cCtx)))
# ------------------------------------------------------------------------------
# Public handlers and helpers

View File

@ -11,7 +11,6 @@
{.push raises: [].}
import
chronicles,
eth/common,
"../.."/[constants, errors],
./base/[api_tracking, base_desc]
@ -205,13 +204,20 @@ proc parent*[T: CoreDbKvtRef |
##
result = child.parent
proc backend*(dsc: CoreDbKvtRef | CoreDbMptRef): auto =
proc backend*(dsc: CoreDbKvtRef): auto =
## Getter, retrieves the *raw* backend object for special/localised support.
##
dsc.setTrackNewApi AnyBackendFn
result = dsc.methods.backendFn()
dsc.ifTrackNewApi: debug newApiTxt, api, elapsed
proc backend*(mpt: CoreDbMptRef): auto =
## Getter, retrieves the *raw* backend object for special/localised support.
##
mpt.setTrackNewApi AnyBackendFn
result = mpt.methods.backendFn(mpt)
mpt.ifTrackNewApi: debug newApiTxt, api, elapsed
proc finish*(db: CoreDbRef; eradicate = false) =
## Database destructor. If the argument `eradicate` is set `false`, the
## database is left as-is and only the in-memory handlers are cleaned up.
@ -337,7 +343,7 @@ proc forget*(ctx: CoreDbCtxRef) =
## context. This function fails if `ctx` is the default context.
##
ctx.setTrackNewApi CtxForgetFn
ctx.methods.forgetFn()
ctx.methods.forgetFn(ctx)
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed
# ------------------------------------------------------------------------------
@ -381,7 +387,7 @@ proc newColumn*(
## db.getAcc col
##
ctx.setTrackNewApi CtxNewColFn
result = ctx.methods.newColFn(colType, colState, address)
result = ctx.methods.newColFn(ctx, colType, colState, address)
ctx.ifTrackNewApi:
debug newApiTxt, api, elapsed, colType, colState, address, result
@ -393,7 +399,7 @@ proc newColumn*(
## Shortcut for `ctx.newColumn(CtStorage,colState,some(address))`.
##
ctx.setTrackNewApi CtxNewColFn
result = ctx.methods.newColFn(CtStorage, colState, Opt.some(address))
result = ctx.methods.newColFn(ctx, CtStorage, colState, Opt.some(address))
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, colState, address, result
proc newColumn*(
@ -406,7 +412,7 @@ proc newColumn*(
##
ctx.setTrackNewApi CtxNewColFn
result = ctx.methods.newColFn(
CtStorage, EMPTY_ROOT_HASH, Opt.some(address)).valueOr:
ctx, CtStorage, EMPTY_ROOT_HASH, Opt.some(address)).valueOr:
raiseAssert error.prettyText()
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
@ -474,7 +480,7 @@ proc getMpt*(
## function `getColumn()`.
##
ctx.setTrackNewApi CtxGetMptFn
result = ctx.methods.getMptFn col
result = ctx.methods.getMptFn(ctx, col)
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
proc getMpt*(
@ -487,8 +493,8 @@ proc getMpt*(
## return a non-nil descriptor or throw an exception.
##
ctx.setTrackNewApi CtxGetMptFn
let col = ctx.methods.newColFn(colType, EMPTY_ROOT_HASH, address).value
result = ctx.methods.getMptFn(col).valueOr:
let col = ctx.methods.newColFn(ctx, colType, EMPTY_ROOT_HASH, address).value
result = ctx.methods.getMptFn(ctx, col).valueOr:
raiseAssert error.prettyText()
ctx.ifTrackNewApi: debug newApiTxt, api, colType, elapsed
@ -500,7 +506,7 @@ proc getMpt*(acc: CoreDbAccRef): CoreDbMptRef =
## argument.
##
acc.setTrackNewApi AccToMptFn
result = acc.methods.getMptFn().valueOr:
result = acc.methods.getMptFn(acc).valueOr:
raiseAssert error.prettyText()
acc.ifTrackNewApi:
let colState = result.methods.getColFn()
@ -526,7 +532,7 @@ proc getAcc*(
## This function works similar to `getMpt()` for handling accounts.
##
ctx.setTrackNewApi CtxGetAccFn
result = ctx.methods.getAccFn col
result = ctx.methods.getAccFn(ctx, col)
ctx.ifTrackNewApi: debug newApiTxt, api, elapsed, col, result
# ------------------------------------------------------------------------------
@ -537,14 +543,14 @@ proc getColumn*(acc: CoreDbAccRef): CoreDbColRef =
## Getter, result is not `nil`
##
acc.setTrackNewApi AccGetColFn
result = acc.methods.getColFn()
result = acc.methods.getColFn(acc)
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, result
proc getColumn*(mpt: CoreDbMptRef): CoreDbColRef =
## Variant of `getColumn()`
##
mpt.setTrackNewApi MptGetColFn
result = mpt.methods.getColFn()
result = mpt.methods.getColFn(mpt)
mpt.ifTrackNewApi: debug newApiTxt, api, elapsed, result
# ------------------------------------------------------------------------------
@ -556,9 +562,9 @@ proc fetch*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[Blob] =
## non-empty `Blob` or an error code.
##
mpt.setTrackNewApi MptFetchFn
result = mpt.methods.fetchFn key
result = mpt.methods.fetchFn(mpt, key)
mpt.ifTrackNewApi:
let col = mpt.methods.getColFn()
let col = mpt.methods.getColFn(mpt)
debug newApiTxt, api, elapsed, col, key=key.toStr, result
proc fetchOrEmpty*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[Blob] =
@ -566,16 +572,16 @@ proc fetchOrEmpty*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[Blob] =
## on the database.
##
mpt.setTrackNewApi MptFetchOrEmptyFn
result = mpt.methods.fetchFn key
result = mpt.methods.fetchFn(mpt, key)
if result.isErr and result.error.error == MptNotFound:
result = CoreDbRc[Blob].ok(EmptyBlob)
mpt.ifTrackNewApi:
let col = mpt.methods.getColFn()
let col = mpt.methods.getColFn(mpt)
debug newApiTxt, api, elapsed, col, key=key.toStr, result
proc delete*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[void] =
mpt.setTrackNewApi MptDeleteFn
result = mpt.methods.deleteFn key
result = mpt.methods.deleteFn(mpt, key)
mpt.ifTrackNewApi:
let col = mpt.methods.getColFn()
debug newApiTxt, api, elapsed, col, key=key.toStr, result
@ -586,9 +592,9 @@ proc merge*(
val: openArray[byte];
): CoreDbRc[void] =
mpt.setTrackNewApi MptMergeFn
result = mpt.methods.mergeFn(key, val)
result = mpt.methods.mergeFn(mpt, key, val)
mpt.ifTrackNewApi:
let col = mpt.methods.getColFn()
let col = mpt.methods.getColFn(mpt)
debug newApiTxt, api, elapsed, col, key=key.toStr, val=val.toLenStr, result
proc hasPath*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[bool] =
@ -596,9 +602,9 @@ proc hasPath*(mpt: CoreDbMptRef; key: openArray[byte]): CoreDbRc[bool] =
## than a `Result[]`.
##
mpt.setTrackNewApi MptHasPathFn
result = mpt.methods.hasPathFn key
result = mpt.methods.hasPathFn(mpt, key)
mpt.ifTrackNewApi:
let col = mpt.methods.getColFn()
let col = mpt.methods.getColFn(mpt)
debug newApiTxt, api, elapsed, col, key=key.toStr, result
# ------------------------------------------------------------------------------
@ -609,7 +615,7 @@ proc fetch*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
## Fetch data from the argument `acc`.
##
acc.setTrackNewApi AccFetchFn
result = acc.methods.fetchFn address
result = acc.methods.fetchFn(acc, address)
acc.ifTrackNewApi:
let storage = if result.isErr: "n/a" else: result.value.storage.prettyText()
debug newApiTxt, api, elapsed, address, storage, result
@ -617,7 +623,7 @@ proc fetch*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
proc delete*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[void] =
acc.setTrackNewApi AccDeleteFn
result = acc.methods.deleteFn address
result = acc.methods.deleteFn(acc, address)
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
proc stoDelete*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[void] =
@ -632,7 +638,7 @@ proc stoDelete*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[void] =
## backend.
##
acc.setTrackNewApi AccStoDeleteFn
result = acc.methods.stoDeleteFn address
result = acc.methods.stoDeleteFn(acc, address)
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result
@ -641,7 +647,7 @@ proc merge*(
account: CoreDbAccount;
): CoreDbRc[void] =
acc.setTrackNewApi AccMergeFn
result = acc.methods.mergeFn account
result = acc.methods.mergeFn(acc, account)
acc.ifTrackNewApi:
let address = account.address
debug newApiTxt, api, elapsed, address, result
@ -651,7 +657,7 @@ proc hasPath*(acc: CoreDbAccRef; address: EthAddress): CoreDbRc[bool] =
## Would be named `contains` if it returned `bool` rather than `Result[]`.
##
acc.setTrackNewApi AccHasPathFn
result = acc.methods.hasPathFn address
result = acc.methods.hasPathFn(acc, address)
acc.ifTrackNewApi: debug newApiTxt, api, elapsed, address, result

View File

@ -160,16 +160,14 @@ type
# --------------------------------------------------
# Sub-descriptor: MPT context methods
# --------------------------------------------------
CoreDbCtxFromTxFn* =
proc(root: Hash256; kind: CoreDbColType): CoreDbRc[CoreDbCtxRef] {.noRaise.}
CoreDbCtxNewColFn* = proc(
colType: CoreDbColType; colState: Hash256; address: Opt[EthAddress];
cCtx: CoreDbCtxRef; colType: CoreDbColType; colState: Hash256; address: Opt[EthAddress];
): CoreDbRc[CoreDbColRef] {.noRaise.}
CoreDbCtxGetMptFn* = proc(
root: CoreDbColRef): CoreDbRc[CoreDbMptRef] {.noRaise.}
cCtx: CoreDbCtxRef; root: CoreDbColRef): CoreDbRc[CoreDbMptRef] {.noRaise.}
CoreDbCtxGetAccFn* = proc(
root: CoreDbColRef): CoreDbRc[CoreDbAccRef] {.noRaise.}
CoreDbCtxForgetFn* = proc() {.noRaise.}
cCtx: CoreDbCtxRef; root: CoreDbColRef): CoreDbRc[CoreDbAccRef] {.noRaise.}
CoreDbCtxForgetFn* = proc(cCtx: CoreDbCtxRef) {.noRaise.}
CoreDbCtxFns* = object
## Methods for context maniulation
@ -181,20 +179,20 @@ type
# --------------------------------------------------
# Sub-descriptor: generic Mpt/hexary trie methods
# --------------------------------------------------
CoreDbMptBackendFn* = proc(): CoreDbMptBackendRef {.noRaise.}
CoreDbMptBackendFn* = proc(cMpt: CoreDbMptRef): CoreDbMptBackendRef {.noRaise.}
CoreDbMptFetchFn* =
proc(k: openArray[byte]): CoreDbRc[Blob] {.noRaise.}
proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[Blob] {.noRaise.}
CoreDbMptFetchAccountFn* =
proc(k: openArray[byte]): CoreDbRc[CoreDbAccount] {.noRaise.}
proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[CoreDbAccount] {.noRaise.}
CoreDbMptDeleteFn* =
proc(k: openArray[byte]): CoreDbRc[void] {.noRaise.}
proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[void] {.noRaise.}
CoreDbMptMergeFn* =
proc(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] {.noRaise.}
proc(cMpt: CoreDbMptRef, k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] {.noRaise.}
CoreDbMptMergeAccountFn* =
proc(k: openArray[byte]; v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
CoreDbMptHasPathFn* = proc(k: openArray[byte]): CoreDbRc[bool] {.noRaise.}
CoreDbMptGetColFn* = proc(): CoreDbColRef {.noRaise.}
CoreDbMptForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
proc(cMpt: CoreDbMptRef, k: openArray[byte]; v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
CoreDbMptHasPathFn* = proc(cMpt: CoreDbMptRef, k: openArray[byte]): CoreDbRc[bool] {.noRaise.}
CoreDbMptGetColFn* = proc(cMpt: CoreDbMptRef): CoreDbColRef {.noRaise.}
CoreDbMptForgetFn* = proc(cMpt: CoreDbMptRef): CoreDbRc[void] {.noRaise.}
CoreDbMptFns* = object
## Methods for trie objects
@ -209,14 +207,13 @@ type
# ----------------------------------------------------
# Sub-descriptor: Mpt/hexary trie methods for accounts
# ------------------------------------------------------
CoreDbAccGetMptFn* = proc(): CoreDbRc[CoreDbMptRef] {.noRaise.}
CoreDbAccFetchFn* = proc(k: EthAddress): CoreDbRc[CoreDbAccount] {.noRaise.}
CoreDbAccDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
CoreDbAccStoDeleteFn* = proc(k: EthAddress): CoreDbRc[void] {.noRaise.}
CoreDbAccMergeFn* = proc(v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
CoreDbAccHasPathFn* = proc(k: EthAddress): CoreDbRc[bool] {.noRaise.}
CoreDbAccGetColFn* = proc(): CoreDbColRef {.noRaise.}
CoreDbAccForgetFn* = proc(): CoreDbRc[void] {.noRaise.}
CoreDbAccGetMptFn* = proc(cAcc: CoreDbAccRef): CoreDbRc[CoreDbMptRef] {.noRaise.}
CoreDbAccFetchFn* = proc(cAcc: CoreDbAccRef, k: EthAddress): CoreDbRc[CoreDbAccount] {.noRaise.}
CoreDbAccDeleteFn* = proc(cAcc: CoreDbAccRef, k: EthAddress): CoreDbRc[void] {.noRaise.}
CoreDbAccStoDeleteFn* = proc(cAcc: CoreDbAccRef,k: EthAddress): CoreDbRc[void] {.noRaise.}
CoreDbAccMergeFn* = proc(cAcc: CoreDbAccRef, v: CoreDbAccount): CoreDbRc[void] {.noRaise.}
CoreDbAccHasPathFn* = proc(cAcc: CoreDbAccRef, k: EthAddress): CoreDbRc[bool] {.noRaise.}
CoreDbAccGetColFn* = proc(cAcc: CoreDbAccRef): CoreDbColRef {.noRaise.}
CoreDbAccFns* = object
## Methods for trie objects

View File

@ -21,6 +21,9 @@ import
./db/era1_db,
beacon_chain/era_db
declareGauge nec_import_block_number,
"Latest imported block number"
declareCounter nec_imported_blocks,
"Blocks processed during import"
@ -105,6 +108,8 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
if csv != nil:
close(csv)
nec_import_block_number.set(start.int64)
template blockNumber(): uint64 =
start + imported
@ -155,6 +160,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
avgMGps = f(gas.float / 1000000 / diff0),
elapsed = shortLog(time2 - time0, 3)
metrics.set(nec_import_block_number, int64(blockNumber))
nec_imported_blocks.inc(blocks.len)
nec_imported_transactions.inc(statsRes[].txs)
nec_imported_gas.inc(statsRes[].gas)