Some helpers for tracing and debugging Trie issues (the code is no-op by default)
This commit is contained in:
parent
f84b3c337c
commit
409d875beb
|
@ -1,4 +1,4 @@
|
||||||
import os, rocksdb, ranges
|
import os, rocksdb, ranges, eth_trie/db_tracing
|
||||||
import ../storage_types
|
import ../storage_types
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -22,13 +22,15 @@ proc newChainDB*(basePath: string): ChainDB =
|
||||||
proc get*(db: ChainDB, key: openarray[byte]): seq[byte] =
|
proc get*(db: ChainDB, key: openarray[byte]): seq[byte] =
|
||||||
let s = db.store.getBytes(key)
|
let s = db.store.getBytes(key)
|
||||||
if s.ok:
|
if s.ok:
|
||||||
return s.value
|
result = s.value
|
||||||
|
traceGet key, result
|
||||||
elif s.error.len == 0:
|
elif s.error.len == 0:
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
raiseKeyReadError(key)
|
raiseKeyReadError(key)
|
||||||
|
|
||||||
proc put*(db: ChainDB, key, value: openarray[byte]) =
|
proc put*(db: ChainDB, key, value: openarray[byte]) =
|
||||||
|
tracePut key, value
|
||||||
let s = db.store.put(key, value)
|
let s = db.store.put(key, value)
|
||||||
if not s.ok: raiseKeyWriteError(key)
|
if not s.ok: raiseKeyWriteError(key)
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ proc contains*(db: ChainDB, key: openarray[byte]): bool =
|
||||||
return s.value
|
return s.value
|
||||||
|
|
||||||
proc del*(db: ChainDB, key: openarray[byte]) =
|
proc del*(db: ChainDB, key: openarray[byte]) =
|
||||||
|
traceDel key
|
||||||
let s = db.store.del(key)
|
let s = db.store.del(key)
|
||||||
if not s.ok: raiseKeyDeletionError(key)
|
if not s.ok: raiseKeyDeletionError(key)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import
|
import
|
||||||
sqlite3, ranges, ranges/ptr_arith, ../storage_types
|
sqlite3, ranges, ranges/ptr_arith, eth_trie/db_tracing,
|
||||||
|
../storage_types
|
||||||
|
|
||||||
type
|
type
|
||||||
SqliteChainDB* = ref object of RootObj
|
SqliteChainDB* = ref object of RootObj
|
||||||
|
@ -71,12 +72,15 @@ proc get*(db: ChainDB, key: openarray[byte]): seq[byte] =
|
||||||
resLen = columnBytes(db.selectStmt, 0)
|
resLen = columnBytes(db.selectStmt, 0)
|
||||||
result = newSeq[byte](resLen)
|
result = newSeq[byte](resLen)
|
||||||
copyMem(result.baseAddr, resStart, resLen)
|
copyMem(result.baseAddr, resStart, resLen)
|
||||||
|
traceGet key, result
|
||||||
of SQLITE_DONE:
|
of SQLITE_DONE:
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
raiseKeyReadError(key)
|
raiseKeyReadError(key)
|
||||||
|
|
||||||
proc put*(db: ChainDB, key, value: openarray[byte]) =
|
proc put*(db: ChainDB, key, value: openarray[byte]) =
|
||||||
|
tracePut key, value
|
||||||
|
|
||||||
template check(op) =
|
template check(op) =
|
||||||
let status = op
|
let status = op
|
||||||
if status != SQLITE_OK: raiseKeyWriteError(key)
|
if status != SQLITE_OK: raiseKeyWriteError(key)
|
||||||
|
@ -104,6 +108,8 @@ proc contains*(db: ChainDB, key: openarray[byte]): bool =
|
||||||
else: raiseKeySearchError(key)
|
else: raiseKeySearchError(key)
|
||||||
|
|
||||||
proc del*(db: ChainDB, key: openarray[byte]) =
|
proc del*(db: ChainDB, key: openarray[byte]) =
|
||||||
|
traceDel key
|
||||||
|
|
||||||
template check(op) =
|
template check(op) =
|
||||||
let status = op
|
let status = op
|
||||||
if status != SQLITE_OK: raiseKeyDeletionError(key)
|
if status != SQLITE_OK: raiseKeyDeletionError(key)
|
||||||
|
|
Loading…
Reference in New Issue