Skip to content

Commit 9c7cac7

Browse files
authored
Correctly pass RuntimeConfig when initializing database in ncli_db (#7612)
In ncli_db, some operations did not pass the RuntimeConfig to BeaconChainDB.new. Fix these instances, and make RuntimeConfig required when initializing BeaconChainDB to avoid this problem in the future.
1 parent b8716f1 commit 9c7cac7

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

beacon_chain/beacon_chain_db.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ proc new*(T: type BeaconChainDBV0,
503503

504504
proc new*(T: type BeaconChainDB,
505505
db: SqStoreRef,
506-
cfg: RuntimeConfig = defaultRuntimeConfig
506+
cfg: RuntimeConfig
507507
): BeaconChainDB =
508508
if not db.readOnly:
509509
# Remove the deposits table we used before we switched
@@ -653,7 +653,7 @@ proc new*(T: type BeaconChainDB,
653653

654654
proc new*(T: type BeaconChainDB,
655655
dir: string,
656-
cfg: RuntimeConfig = defaultRuntimeConfig,
656+
cfg: RuntimeConfig,
657657
inMemory = false,
658658
readOnly = false
659659
): BeaconChainDB =

ncli/ncli_db.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
227227

228228
echo "Opening database..."
229229
let
230-
db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
231-
dbBenchmark = BeaconChainDB.new("benchmark")
230+
db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
231+
dbBenchmark = BeaconChainDB.new("benchmark", cfg)
232232
defer:
233233
db.close()
234234
dbBenchmark.close()
@@ -390,8 +390,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
390390
processBlocks(blocks[i])
391391
printTimers(false, timers)
392392

393-
proc cmdDumpState(conf: DbConf) =
394-
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
393+
proc cmdDumpState(conf: DbConf, cfg: RuntimeConfig) =
394+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
395395
defer: db.close()
396396

397397
let
@@ -428,7 +428,7 @@ proc cmdDumpState(conf: DbConf) =
428428
echo "Couldn't load ", stateRoot
429429

430430
proc cmdPutState(conf: DbConf, cfg: RuntimeConfig) =
431-
let db = BeaconChainDB.new(conf.databaseDir.string)
431+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg)
432432
defer: db.close()
433433

434434
for file in conf.stateFile:
@@ -448,8 +448,8 @@ proc cmdPutState(conf: DbConf, cfg: RuntimeConfig) =
448448
withState(state[]):
449449
db.putState(forkyState)
450450

451-
proc cmdDumpBlock(conf: DbConf) =
452-
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
451+
proc cmdDumpBlock(conf: DbConf, cfg: RuntimeConfig) =
452+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
453453
defer: db.close()
454454

455455
for blockRoot in conf.blockRootx:
@@ -469,7 +469,7 @@ proc cmdDumpBlock(conf: DbConf) =
469469
echo "Couldn't load ", blockRoot, ": ", e.msg
470470

471471
proc cmdPutBlock(conf: DbConf, cfg: RuntimeConfig) =
472-
let db = BeaconChainDB.new(conf.databaseDir.string)
472+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg)
473473
defer: db.close()
474474

475475
for file in conf.blckFile:
@@ -521,7 +521,7 @@ proc cmdPutBlob(conf: DbConf, cfg: RuntimeConfig) =
521521

522522
proc cmdRewindState(conf: DbConf, cfg: RuntimeConfig) =
523523
echo "Opening database..."
524-
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
524+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
525525
defer: db.close()
526526

527527
if (let v = ChainDAGRef.isInitialized(db); v.isErr()):
@@ -557,7 +557,7 @@ proc cmdVerifyEra(conf: DbConf, cfg: RuntimeConfig) =
557557
echo root
558558

559559
proc cmdExportEra(conf: DbConf, cfg: RuntimeConfig) =
560-
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
560+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
561561
defer: db.close()
562562

563563
if (let v = ChainDAGRef.isInitialized(db); v.isErr()):
@@ -676,7 +676,7 @@ proc cmdExportEra(conf: DbConf, cfg: RuntimeConfig) =
676676
quit QuitFailure
677677

678678
proc cmdImportEra(conf: DbConf, cfg: RuntimeConfig) =
679-
let db = BeaconChainDB.new(conf.databaseDir.string)
679+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg)
680680
defer: db.close()
681681

682682
type Timers = enum
@@ -741,7 +741,7 @@ type
741741
proc cmdValidatorPerf(conf: DbConf, cfg: RuntimeConfig) =
742742
echo "Opening database..."
743743
let
744-
db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
744+
db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
745745
defer:
746746
db.close()
747747

@@ -978,7 +978,7 @@ proc insertValidators(db: SqStoreRef, state: ForkedHashedBeaconState,
978978
proc cmdValidatorDb(conf: DbConf, cfg: RuntimeConfig) =
979979
# Create a database with performance information for every epoch
980980
info "Opening database..."
981-
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
981+
let db = BeaconChainDB.new(conf.databaseDir.string, cfg, readOnly = true)
982982
defer: db.close()
983983

984984
if (let v = ChainDAGRef.isInitialized(db); v.isErr()):
@@ -1214,11 +1214,11 @@ when isMainModule:
12141214
of DbCmd.bench:
12151215
cmdBench(conf, cfg)
12161216
of DbCmd.dumpState:
1217-
cmdDumpState(conf)
1217+
cmdDumpState(conf, cfg)
12181218
of DbCmd.putState:
12191219
cmdPutState(conf, cfg)
12201220
of DbCmd.dumpBlock:
1221-
cmdDumpBlock(conf)
1221+
cmdDumpBlock(conf, cfg)
12221222
of DbCmd.putBlock:
12231223
cmdPutBlock(conf, cfg)
12241224
of DbCmd.putBlob:

tests/consensus_spec/test_fixture_light_client_data_collection.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ proc runTest(suiteName, path: string, consensusFork: static ConsensusFork) =
133133
(cfg, _) = readRuntimeConfig(path/"config.yaml")
134134
initial_state = loadForkedState(
135135
path/"initial_state.ssz_snappy", consensusFork)
136-
db = BeaconChainDB.new("", cfg = cfg, inMemory = true)
136+
db = BeaconChainDB.new("", cfg, inMemory = true)
137137
defer: db.close()
138138
ChainDAGRef.preInit(db, initial_state[])
139139

tests/test_quarantine.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ suite "BlobQuarantine data structure test suite " & preset():
166166
setup:
167167
let
168168
cfg {.used.} = defaultRuntimeConfig
169-
db {.used.} = BeaconChainDB.new("", inMemory = true, cfg = cfg)
169+
db {.used.} = BeaconChainDB.new("", cfg, inMemory = true)
170170
quarantine {.used.} = db.getQuarantineDB()
171171

172172
teardown:
@@ -1065,7 +1065,7 @@ suite "ColumnQuarantine data structure test suite " & preset():
10651065
setup:
10661066
let
10671067
cfg {.used.} = defaultRuntimeConfig
1068-
db {.used.} = BeaconChainDB.new("", inMemory = true, cfg = cfg)
1068+
db {.used.} = BeaconChainDB.new("", cfg, inMemory = true)
10691069
quarantine {.used.} = db.getQuarantineDB()
10701070

10711071
teardown:

0 commit comments

Comments
 (0)