cleanly close kvstore databases and bump nim-eth (#1630)
* cleanly close kvstore databases * close databases for all subcommands and during error conditions
This commit is contained in:
parent
5fff800cf8
commit
aca1a318f2
|
@ -128,6 +128,9 @@ proc get[T](db: BeaconChainDB, key: openArray[byte], output: var T): GetResult =
|
|||
|
||||
status
|
||||
|
||||
proc close*(db: BeaconChainDB) =
|
||||
discard db.backend.close()
|
||||
|
||||
proc putBlock*(db: BeaconChainDB, value: SignedBeaconBlock) =
|
||||
db.put(subkey(type value, value.root), value)
|
||||
proc putBlock*(db: BeaconChainDB, value: TrustedSignedBeaconBlock) =
|
||||
|
|
|
@ -796,6 +796,8 @@ proc stop*(node: BeaconNode) =
|
|||
if not node.config.inProcessValidators:
|
||||
node.vcProcess.close()
|
||||
waitFor node.network.stop()
|
||||
node.db.close()
|
||||
info "Database closed"
|
||||
|
||||
proc run*(node: BeaconNode) =
|
||||
if status == BeaconNodeStatus.Starting:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import
|
||||
tables, strutils, json, streams,
|
||||
tables, json, streams,
|
||||
chronos, chronicles,
|
||||
spec/[datatypes, crypto, digest, signatures, helpers],
|
||||
beacon_node_types,
|
||||
|
|
|
@ -89,6 +89,7 @@ proc cmdBench(conf: DbConf, runtimePreset: RuntimePreset) =
|
|||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||
dbBenchmark = BeaconChainDB.init(
|
||||
kvStore SqStoreRef.init(".", "benchmark").tryGet())
|
||||
defer: db.close()
|
||||
|
||||
if not ChainDAGRef.isInitialized(db):
|
||||
echo "Database not initialized"
|
||||
|
@ -142,6 +143,7 @@ proc cmdDumpState(conf: DbConf) =
|
|||
let
|
||||
db = BeaconChainDB.init(
|
||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||
defer: db.close()
|
||||
|
||||
for stateRoot in conf.stateRoot:
|
||||
try:
|
||||
|
@ -158,6 +160,7 @@ proc cmdDumpBlock(conf: DbConf) =
|
|||
let
|
||||
db = BeaconChainDB.init(
|
||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||
defer: db.close()
|
||||
|
||||
for blockRoot in conf.blockRootx:
|
||||
try:
|
||||
|
@ -246,6 +249,10 @@ proc cmdPrune(conf: DbConf) =
|
|||
copyDb = BeaconChainDB.init(
|
||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc_pruned").tryGet())
|
||||
|
||||
defer:
|
||||
db.close()
|
||||
copyDb.close()
|
||||
|
||||
db.copyPrunedDatabase(copyDb, conf.dryRun, conf.verbose, conf.keepOldStates)
|
||||
|
||||
proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
||||
|
@ -253,6 +260,7 @@ proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
|||
let
|
||||
db = BeaconChainDB.init(
|
||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||
defer: db.close()
|
||||
|
||||
if not ChainDAGRef.isInitialized(db):
|
||||
echo "Database not initialized"
|
||||
|
|
|
@ -66,6 +66,8 @@ suiteReport "Beacon chain DB" & preset():
|
|||
db.getStateRoot(root, signedBlock.message.slot).get() == root
|
||||
db.getStateRoot(root, signedBlock.message.slot + 1).get() == root2
|
||||
|
||||
db.close()
|
||||
|
||||
wrappedTimedTest "sanity check states" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
|
@ -80,6 +82,8 @@ suiteReport "Beacon chain DB" & preset():
|
|||
db.containsState(root)
|
||||
hash_tree_root(db.getStateRef(root)[]) == root
|
||||
|
||||
db.close()
|
||||
|
||||
wrappedTimedTest "find ancestors" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
|
@ -128,6 +132,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||
|
||||
check db.containsState(root)
|
||||
let state2 = db.getStateRef(root)
|
||||
db.close()
|
||||
|
||||
check:
|
||||
hash_tree_root(state2[]) == root
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c9caafb2a4a0e69471bf1335188c54aad27536df
|
||||
Subproject commit ea0dbb256e7f911a1ea39d8f53597c947923acae
|
Loading…
Reference in New Issue