mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 06:46:10 +00:00
better error message on disk / database issues (#2307)
bumps stew for better result defects as well
This commit is contained in:
parent
c13205035e
commit
f012d7060b
@ -152,7 +152,7 @@ proc init*[T](Seq: type DbSeq[T], db: SqStoreRef, name: string): Seq =
|
|||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
value BLOB
|
value BLOB
|
||||||
);
|
);
|
||||||
""").expect "working database"
|
""").expect "working database (disk broken/full?)"
|
||||||
|
|
||||||
let
|
let
|
||||||
insertStmt = db.prepareStmt(
|
insertStmt = db.prepareStmt(
|
||||||
@ -171,7 +171,7 @@ proc init*[T](Seq: type DbSeq[T], db: SqStoreRef, name: string): Seq =
|
|||||||
let countQueryRes = countStmt.exec do (res: int64):
|
let countQueryRes = countStmt.exec do (res: int64):
|
||||||
recordCount = res
|
recordCount = res
|
||||||
|
|
||||||
let found = countQueryRes.expect("working database")
|
let found = countQueryRes.expect("working database (disk broken/full?)")
|
||||||
if not found: panic()
|
if not found: panic()
|
||||||
|
|
||||||
Seq(insertStmt: insertStmt,
|
Seq(insertStmt: insertStmt,
|
||||||
@ -180,7 +180,7 @@ proc init*[T](Seq: type DbSeq[T], db: SqStoreRef, name: string): Seq =
|
|||||||
|
|
||||||
proc add*[T](s: var DbSeq[T], val: T) =
|
proc add*[T](s: var DbSeq[T], val: T) =
|
||||||
var bytes = SSZ.encode(val)
|
var bytes = SSZ.encode(val)
|
||||||
s.insertStmt.exec(bytes).expect "working database"
|
s.insertStmt.exec(bytes).expect "working database (disk broken/full?)"
|
||||||
inc s.recordCount
|
inc s.recordCount
|
||||||
|
|
||||||
template len*[T](s: DbSeq[T]): uint64 =
|
template len*[T](s: DbSeq[T]): uint64 =
|
||||||
@ -196,7 +196,7 @@ proc get*[T](s: DbSeq[T], idx: uint64): T =
|
|||||||
except SerializationError:
|
except SerializationError:
|
||||||
panic()
|
panic()
|
||||||
|
|
||||||
let found = queryRes.expect("working database")
|
let found = queryRes.expect("working database (disk broken/full?)")
|
||||||
if not found: panic()
|
if not found: panic()
|
||||||
|
|
||||||
proc createMap*(db: SqStoreRef, keyspace: int;
|
proc createMap*(db: SqStoreRef, keyspace: int;
|
||||||
@ -204,10 +204,10 @@ proc createMap*(db: SqStoreRef, keyspace: int;
|
|||||||
DbMap[K, V](db: db, keyspace: keyspace)
|
DbMap[K, V](db: db, keyspace: keyspace)
|
||||||
|
|
||||||
proc insert*[K, V](m: var DbMap[K, V], key: K, value: V) =
|
proc insert*[K, V](m: var DbMap[K, V], key: K, value: V) =
|
||||||
m.db.put(m.keyspace, SSZ.encode key, SSZ.encode value).expect("working database")
|
m.db.put(m.keyspace, SSZ.encode key, SSZ.encode value).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc contains*[K, V](m: DbMap[K, V], key: K): bool =
|
proc contains*[K, V](m: DbMap[K, V], key: K): bool =
|
||||||
contains(m.db, SSZ.encode key).expect("working database")
|
contains(m.db, SSZ.encode key).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
template insert*[K, V](t: var Table[K, V], key: K, value: V) =
|
template insert*[K, V](t: var Table[K, V], key: K, value: V) =
|
||||||
add(t, key, value)
|
add(t, key, value)
|
||||||
@ -228,7 +228,7 @@ proc init*(T: type BeaconChainDB,
|
|||||||
doAssert s.isOk # TODO(zah) Handle this in a better way
|
doAssert s.isOk # TODO(zah) Handle this in a better way
|
||||||
|
|
||||||
let sqliteStore = SqStoreRef.init(
|
let sqliteStore = SqStoreRef.init(
|
||||||
dir, "nbc", Keyspaces, manualCheckpoint = true).expect("working database")
|
dir, "nbc", Keyspaces, manualCheckpoint = true).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
# Remove the deposits table we used before we switched
|
# Remove the deposits table we used before we switched
|
||||||
# to storing only deposit contract checkpoints
|
# to storing only deposit contract checkpoints
|
||||||
@ -253,10 +253,10 @@ proc snappyEncode(inp: openArray[byte]): seq[byte] =
|
|||||||
raiseAssert err.msg
|
raiseAssert err.msg
|
||||||
|
|
||||||
proc put(db: BeaconChainDB, key: openArray[byte], v: Eth2Digest) =
|
proc put(db: BeaconChainDB, key: openArray[byte], v: Eth2Digest) =
|
||||||
db.backend.put(key, v.data).expect("working database")
|
db.backend.put(key, v.data).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc put(db: BeaconChainDB, key: openArray[byte], v: auto) =
|
proc put(db: BeaconChainDB, key: openArray[byte], v: auto) =
|
||||||
db.backend.put(key, snappyEncode(SSZ.encode(v))).expect("working database")
|
db.backend.put(key, snappyEncode(SSZ.encode(v))).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc get(db: BeaconChainDB, key: openArray[byte], T: type Eth2Digest): Opt[T] =
|
proc get(db: BeaconChainDB, key: openArray[byte], T: type Eth2Digest): Opt[T] =
|
||||||
var res: Opt[T]
|
var res: Opt[T]
|
||||||
@ -270,7 +270,7 @@ proc get(db: BeaconChainDB, key: openArray[byte], T: type Eth2Digest): Opt[T] =
|
|||||||
typ = name(T), dataLen = data.len
|
typ = name(T), dataLen = data.len
|
||||||
discard
|
discard
|
||||||
|
|
||||||
discard db.backend.get(key, decode).expect("working database")
|
discard db.backend.get(key, decode).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ proc get[T](db: BeaconChainDB, key: openArray[byte], output: var T): GetResult =
|
|||||||
err = e.msg, typ = name(T), dataLen = data.len
|
err = e.msg, typ = name(T), dataLen = data.len
|
||||||
status = GetResult.corrupted
|
status = GetResult.corrupted
|
||||||
|
|
||||||
discard db.backend.get(key, decode).expect("working database")
|
discard db.backend.get(key, decode).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
status
|
status
|
||||||
|
|
||||||
@ -342,17 +342,17 @@ proc putStateDiff*(db: BeaconChainDB, root: Eth2Digest, value: BeaconStateDiff)
|
|||||||
db.put(subkey(BeaconStateDiff, root), value)
|
db.put(subkey(BeaconStateDiff, root), value)
|
||||||
|
|
||||||
proc delBlock*(db: BeaconChainDB, key: Eth2Digest) =
|
proc delBlock*(db: BeaconChainDB, key: Eth2Digest) =
|
||||||
db.backend.del(subkey(SignedBeaconBlock, key)).expect("working database")
|
db.backend.del(subkey(SignedBeaconBlock, key)).expect("working database (disk broken/full?)")
|
||||||
db.backend.del(subkey(BeaconBlockSummary, key)).expect("working database")
|
db.backend.del(subkey(BeaconBlockSummary, key)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc delState*(db: BeaconChainDB, key: Eth2Digest) =
|
proc delState*(db: BeaconChainDB, key: Eth2Digest) =
|
||||||
db.backend.del(subkey(BeaconState, key)).expect("working database")
|
db.backend.del(subkey(BeaconState, key)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc delStateRoot*(db: BeaconChainDB, root: Eth2Digest, slot: Slot) =
|
proc delStateRoot*(db: BeaconChainDB, root: Eth2Digest, slot: Slot) =
|
||||||
db.backend.del(subkey(root, slot)).expect("working database")
|
db.backend.del(subkey(root, slot)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc delStateDiff*(db: BeaconChainDB, root: Eth2Digest) =
|
proc delStateDiff*(db: BeaconChainDB, root: Eth2Digest) =
|
||||||
db.backend.del(subkey(BeaconStateDiff, root)).expect("working database")
|
db.backend.del(subkey(BeaconStateDiff, root)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc putHeadBlock*(db: BeaconChainDB, key: Eth2Digest) =
|
proc putHeadBlock*(db: BeaconChainDB, key: Eth2Digest) =
|
||||||
db.put(subkey(kHeadBlock), key)
|
db.put(subkey(kHeadBlock), key)
|
||||||
@ -449,16 +449,16 @@ proc getSpeculativeDeposits*(db: BeaconChainDB): Opt[DepositContractSnapshot] =
|
|||||||
if r != found: result.err()
|
if r != found: result.err()
|
||||||
|
|
||||||
proc delSpeculativeDeposits*(db: BeaconChainDB) =
|
proc delSpeculativeDeposits*(db: BeaconChainDB) =
|
||||||
db.backend.del(subkey(kSpeculativeDeposits)).expect("working database")
|
db.backend.del(subkey(kSpeculativeDeposits)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool =
|
proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool =
|
||||||
db.backend.contains(subkey(SignedBeaconBlock, key)).expect("working database")
|
db.backend.contains(subkey(SignedBeaconBlock, key)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc containsState*(db: BeaconChainDB, key: Eth2Digest): bool =
|
proc containsState*(db: BeaconChainDB, key: Eth2Digest): bool =
|
||||||
db.backend.contains(subkey(BeaconState, key)).expect("working database")
|
db.backend.contains(subkey(BeaconState, key)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
proc containsStateDiff*(db: BeaconChainDB, key: Eth2Digest): bool =
|
proc containsStateDiff*(db: BeaconChainDB, key: Eth2Digest): bool =
|
||||||
db.backend.contains(subkey(BeaconStateDiff, key)).expect("working database")
|
db.backend.contains(subkey(BeaconStateDiff, key)).expect("working database (disk broken/full?)")
|
||||||
|
|
||||||
iterator getAncestors*(db: BeaconChainDB, root: Eth2Digest):
|
iterator getAncestors*(db: BeaconChainDB, root: Eth2Digest):
|
||||||
TrustedSignedBeaconBlock =
|
TrustedSignedBeaconBlock =
|
||||||
|
2
vendor/nim-stew
vendored
2
vendor/nim-stew
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 6d3e6a21caf4110d0d432b82f14e41e0271cd76b
|
Subproject commit a0e8ec451ecb4449657f0be7b49fc99641cf5bb6
|
Loading…
x
Reference in New Issue
Block a user