mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-19 17:58:23 +00:00
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
|
status
|
||||||
|
|
||||||
|
proc close*(db: BeaconChainDB) =
|
||||||
|
discard db.backend.close()
|
||||||
|
|
||||||
proc putBlock*(db: BeaconChainDB, value: SignedBeaconBlock) =
|
proc putBlock*(db: BeaconChainDB, value: SignedBeaconBlock) =
|
||||||
db.put(subkey(type value, value.root), value)
|
db.put(subkey(type value, value.root), value)
|
||||||
proc putBlock*(db: BeaconChainDB, value: TrustedSignedBeaconBlock) =
|
proc putBlock*(db: BeaconChainDB, value: TrustedSignedBeaconBlock) =
|
||||||
|
@ -796,6 +796,8 @@ proc stop*(node: BeaconNode) =
|
|||||||
if not node.config.inProcessValidators:
|
if not node.config.inProcessValidators:
|
||||||
node.vcProcess.close()
|
node.vcProcess.close()
|
||||||
waitFor node.network.stop()
|
waitFor node.network.stop()
|
||||||
|
node.db.close()
|
||||||
|
info "Database closed"
|
||||||
|
|
||||||
proc run*(node: BeaconNode) =
|
proc run*(node: BeaconNode) =
|
||||||
if status == BeaconNodeStatus.Starting:
|
if status == BeaconNodeStatus.Starting:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
tables, strutils, json, streams,
|
tables, json, streams,
|
||||||
chronos, chronicles,
|
chronos, chronicles,
|
||||||
spec/[datatypes, crypto, digest, signatures, helpers],
|
spec/[datatypes, crypto, digest, signatures, helpers],
|
||||||
beacon_node_types,
|
beacon_node_types,
|
||||||
|
@ -89,6 +89,7 @@ proc cmdBench(conf: DbConf, runtimePreset: RuntimePreset) =
|
|||||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||||
dbBenchmark = BeaconChainDB.init(
|
dbBenchmark = BeaconChainDB.init(
|
||||||
kvStore SqStoreRef.init(".", "benchmark").tryGet())
|
kvStore SqStoreRef.init(".", "benchmark").tryGet())
|
||||||
|
defer: db.close()
|
||||||
|
|
||||||
if not ChainDAGRef.isInitialized(db):
|
if not ChainDAGRef.isInitialized(db):
|
||||||
echo "Database not initialized"
|
echo "Database not initialized"
|
||||||
@ -142,6 +143,7 @@ proc cmdDumpState(conf: DbConf) =
|
|||||||
let
|
let
|
||||||
db = BeaconChainDB.init(
|
db = BeaconChainDB.init(
|
||||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||||
|
defer: db.close()
|
||||||
|
|
||||||
for stateRoot in conf.stateRoot:
|
for stateRoot in conf.stateRoot:
|
||||||
try:
|
try:
|
||||||
@ -158,6 +160,7 @@ proc cmdDumpBlock(conf: DbConf) =
|
|||||||
let
|
let
|
||||||
db = BeaconChainDB.init(
|
db = BeaconChainDB.init(
|
||||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||||
|
defer: db.close()
|
||||||
|
|
||||||
for blockRoot in conf.blockRootx:
|
for blockRoot in conf.blockRootx:
|
||||||
try:
|
try:
|
||||||
@ -246,6 +249,10 @@ proc cmdPrune(conf: DbConf) =
|
|||||||
copyDb = BeaconChainDB.init(
|
copyDb = BeaconChainDB.init(
|
||||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc_pruned").tryGet())
|
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc_pruned").tryGet())
|
||||||
|
|
||||||
|
defer:
|
||||||
|
db.close()
|
||||||
|
copyDb.close()
|
||||||
|
|
||||||
db.copyPrunedDatabase(copyDb, conf.dryRun, conf.verbose, conf.keepOldStates)
|
db.copyPrunedDatabase(copyDb, conf.dryRun, conf.verbose, conf.keepOldStates)
|
||||||
|
|
||||||
proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
||||||
@ -253,6 +260,7 @@ proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
|||||||
let
|
let
|
||||||
db = BeaconChainDB.init(
|
db = BeaconChainDB.init(
|
||||||
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
kvStore SqStoreRef.init(conf.databaseDir.string, "nbc").tryGet())
|
||||||
|
defer: db.close()
|
||||||
|
|
||||||
if not ChainDAGRef.isInitialized(db):
|
if not ChainDAGRef.isInitialized(db):
|
||||||
echo "Database not initialized"
|
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).get() == root
|
||||||
db.getStateRoot(root, signedBlock.message.slot + 1).get() == root2
|
db.getStateRoot(root, signedBlock.message.slot + 1).get() == root2
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
wrappedTimedTest "sanity check states" & preset():
|
wrappedTimedTest "sanity check states" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||||
@ -80,6 +82,8 @@ suiteReport "Beacon chain DB" & preset():
|
|||||||
db.containsState(root)
|
db.containsState(root)
|
||||||
hash_tree_root(db.getStateRef(root)[]) == root
|
hash_tree_root(db.getStateRef(root)[]) == root
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
wrappedTimedTest "find ancestors" & preset():
|
wrappedTimedTest "find ancestors" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||||
@ -128,6 +132,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||||||
|
|
||||||
check db.containsState(root)
|
check db.containsState(root)
|
||||||
let state2 = db.getStateRef(root)
|
let state2 = db.getStateRef(root)
|
||||||
|
db.close()
|
||||||
|
|
||||||
check:
|
check:
|
||||||
hash_tree_root(state2[]) == root
|
hash_tree_root(state2[]) == root
|
||||||
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit c9caafb2a4a0e69471bf1335188c54aad27536df
|
Subproject commit ea0dbb256e7f911a1ea39d8f53597c947923acae
|
Loading…
x
Reference in New Issue
Block a user