Some helpers for tracing and debugging Trie issues (the code is no-op by default)

This commit is contained in:
Zahary Karadjov 2018-09-16 00:20:20 +03:00
parent f84b3c337c
commit 409d875beb
2 changed files with 12 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import os, rocksdb, ranges
import os, rocksdb, ranges, eth_trie/db_tracing
import ../storage_types
type
@ -22,13 +22,15 @@ proc newChainDB*(basePath: string): ChainDB =
proc get*(db: ChainDB, key: openarray[byte]): seq[byte] =
let s = db.store.getBytes(key)
if s.ok:
return s.value
result = s.value
traceGet key, result
elif s.error.len == 0:
discard
else:
raiseKeyReadError(key)
proc put*(db: ChainDB, key, value: openarray[byte]) =
tracePut key, value
let s = db.store.put(key, value)
if not s.ok: raiseKeyWriteError(key)
@ -38,6 +40,7 @@ proc contains*(db: ChainDB, key: openarray[byte]): bool =
return s.value
proc del*(db: ChainDB, key: openarray[byte]) =
traceDel key
let s = db.store.del(key)
if not s.ok: raiseKeyDeletionError(key)

View File

@ -1,5 +1,6 @@
import
sqlite3, ranges, ranges/ptr_arith, ../storage_types
sqlite3, ranges, ranges/ptr_arith, eth_trie/db_tracing,
../storage_types
type
SqliteChainDB* = ref object of RootObj
@ -71,12 +72,15 @@ proc get*(db: ChainDB, key: openarray[byte]): seq[byte] =
resLen = columnBytes(db.selectStmt, 0)
result = newSeq[byte](resLen)
copyMem(result.baseAddr, resStart, resLen)
traceGet key, result
of SQLITE_DONE:
discard
else:
raiseKeyReadError(key)
proc put*(db: ChainDB, key, value: openarray[byte]) =
tracePut key, value
template check(op) =
let status = op
if status != SQLITE_OK: raiseKeyWriteError(key)
@ -104,6 +108,8 @@ proc contains*(db: ChainDB, key: openarray[byte]): bool =
else: raiseKeySearchError(key)
proc del*(db: ChainDB, key: openarray[byte]) =
traceDel key
template check(op) =
let status = op
if status != SQLITE_OK: raiseKeyDeletionError(key)