Skip to content

Commit 6135980

Browse files
authored
Make the max snapshots database parameter configurable (#3808)
* Log the number of snapshots in memory. * Make max snapshots configurable.
1 parent 786aacb commit 6135980

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

execution_chain/conf.nim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ type
356356
desc: "Rewrite selected network config hash to database"
357357
name: "debug-rewrite-datadir-id".}: bool
358358

359+
aristoDbMaxSnapshots* {.
360+
hidden
361+
defaultValue: defaultMaxSnapshots
362+
defaultValueDesc: $defaultMaxSnapshots
363+
name: "debug-aristo-db-max-snapshots" .}: int
364+
359365
eagerStateRootCheck* {.
360366
hidden
361367
desc: "Eagerly check state roots when syncing finalized blocks"
@@ -780,8 +786,8 @@ func dbOptions*(config: ExecutionClientConf, noKeyCache = false): DbOptions =
780786
# The import command does not use the key cache - better give it to branch
781787
if noKeyCache: config.rdbKeyCacheSize + config.rdbBranchCacheSize
782788
else: config.rdbBranchCacheSize,
783-
784789
rdbPrintStats = config.rdbPrintStats,
790+
maxSnapshots = config.aristoDbMaxSnapshots,
785791
)
786792

787793
{.pop.}

execution_chain/core/chain/forked_chain.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import
2828
block_quarantine]
2929

3030
from std/sequtils import mapIt
31+
from std/heapqueue import len
3132
from web3/engine_api_types import ExecutionPayloadBodyV1
3233

3334
logScope:
@@ -400,15 +401,17 @@ proc processUpdateBase(c: ForkedChainRef): Future[Result[void, string]] {.async:
400401
base = c.base.number,
401402
baseHash = c.base.hash.short,
402403
pendingFCU = c.pendingFCU.short,
403-
resolvedFin= c.latestFinalizedBlockNumber
404+
resolvedFin = c.latestFinalizedBlockNumber,
405+
dbSnapshotsCount = c.baseTxFrame.aTx.db.snapshots.len()
404406
else:
405407
debug "Finalized blocks persisted",
406408
nBlocks = c.persistedCount,
407409
target = c.base.hash.short,
408410
base = c.base.number,
409411
baseHash = c.base.hash.short,
410412
pendingFCU = c.pendingFCU.short,
411-
resolvedFin= c.latestFinalizedBlockNumber
413+
resolvedFin = c.latestFinalizedBlockNumber,
414+
dbSnapshotsCount = c.baseTxFrame.aTx.db.snapshots.len()
412415
c.lastBaseLogTime = time
413416
c.persistedCount = 0
414417
return ok()
@@ -506,8 +509,6 @@ proc validateBlock(c: ForkedChainRef,
506509
parentTxFrame=cast[uint](parentFrame),
507510
txFrame=cast[uint](txFrame)
508511

509-
510-
511512
var receipts = c.processBlock(parent, txFrame, blk, blkHash, finalized).valueOr:
512513
txFrame.dispose()
513514
return err(error)

execution_chain/db/aristo/aristo_init/init_common.nim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import
1313
../aristo_desc,
1414
../aristo_desc/desc_backend
1515

16+
from ../../opts import defaultMaxSnapshots
17+
1618
const
1719
verifyIxId = true # and false
1820
## Enforce session tracking
@@ -81,12 +83,13 @@ proc finishSession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
8183
doAssert db.txId == hdl.txId
8284
db.txId = 0
8385

84-
proc initInstance*(db: AristoDbRef): Result[void, AristoError] =
86+
proc initInstance*(db: AristoDbRef, maxSnapshots = defaultMaxSnapshots): Result[void, AristoError] =
87+
doAssert maxSnapshots > 0
8588
let vTop = (?db.getLstFn()).vTop
8689
db.txRef = AristoTxRef(db: db, vTop: vTop, snapshot: Snapshot(level: Opt.some(0)))
8790
db.accLeaves = LruCache[Hash32, AccLeafRef].init(ACC_LRU_SIZE)
8891
db.stoLeaves = LruCache[Hash32, StoLeafRef].init(ACC_LRU_SIZE)
89-
db.maxSnapshots = 10
92+
db.maxSnapshots = maxSnapshots
9093
ok()
9194

9295
proc finish*(db: AristoDbRef; eradicate = false) =

execution_chain/db/aristo/aristo_init/persistent.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ proc init*(
4343
baseDb: RocksDbInstanceRef;
4444
): Result[T, AristoError] =
4545
let db = rocksDbBackend(opts, baseDb)
46-
db.initInstance().isOkOr:
46+
db.initInstance(opts.maxSnapshots).isOkOr:
4747
db.closeFn(eradicate = false)
4848
return err(error)
4949
ok db

execution_chain/db/opts.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const
3939
## Hashes of the above
4040
defaultRdbBranchCacheSize* = 1024 * 1024 * 1024
4141
## Cache of branches and leaves in the state MPTs (world and account)
42+
defaultMaxSnapshots* = 5
43+
## The max number of snapshots to store in the aristo database.
4244

4345

4446
type DbOptions* = object # Options that are transported to the database layer
@@ -50,6 +52,7 @@ type DbOptions* = object # Options that are transported to the database layer
5052
rdbKeyCacheSize*: int
5153
rdbBranchCacheSize*: int
5254
rdbPrintStats*: bool
55+
maxSnapshots*: int
5356

5457
func init*(
5558
T: type DbOptions,
@@ -61,6 +64,7 @@ func init*(
6164
rdbKeyCacheSize = defaultRdbKeyCacheSize,
6265
rdbBranchCacheSize = defaultRdbBranchCacheSize,
6366
rdbPrintStats = false,
67+
maxSnapshots = defaultMaxSnapshots,
6468
): T =
6569
T(
6670
maxOpenFiles: maxOpenFiles,
@@ -71,4 +75,5 @@ func init*(
7175
rdbKeyCacheSize: rdbKeyCacheSize,
7276
rdbBranchCacheSize: rdbBranchCacheSize,
7377
rdbPrintStats: rdbPrintStats,
78+
maxSnapshots: maxSnapshots,
7479
)

0 commit comments

Comments
 (0)