Merge pull request #502 from status-im/fix_accounts_cache
fix accounts cache init API
This commit is contained in:
commit
eb29b305e1
|
@ -45,12 +45,15 @@ proc beginSavepoint*(ac: var AccountsCache): SavePoint {.gcsafe.}
|
|||
|
||||
# The AccountsCache is modeled after TrieDatabase for it's transaction style
|
||||
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef,
|
||||
root: KeccakHash, pruneTrie: bool): AccountsCache =
|
||||
root: KeccakHash, pruneTrie: bool = true): AccountsCache =
|
||||
result.db = db
|
||||
result.trie = initSecureHexaryTrie(db, root, pruneTrie)
|
||||
result.unrevertablyTouched = initHashSet[EthAddress]()
|
||||
discard result.beginSavepoint
|
||||
|
||||
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef, pruneTrie: bool = true): AccountsCache =
|
||||
init(x, db, emptyRlpHash, pruneTrie)
|
||||
|
||||
proc rootHash*(ac: AccountsCache): KeccakHash =
|
||||
# make sure all savepoint already committed
|
||||
doAssert(ac.savePoint.parentSavePoint.isNil)
|
||||
|
|
|
@ -141,5 +141,14 @@ proc stateDBMain*() =
|
|||
# state trie at all
|
||||
check ac.rootHash == rootHash
|
||||
|
||||
test "accounts cache code retrieval after persist called":
|
||||
var ac = init(AccountsCache, acDB)
|
||||
var addr2 = initAddr(2)
|
||||
ac.setCode(addr2, code)
|
||||
ac.persist()
|
||||
check ac.getCode(addr2) == code
|
||||
let key = contractHashKey(hexary.keccak(code))
|
||||
check acDB.get(key.toOpenArray) == code
|
||||
|
||||
when isMainModule:
|
||||
stateDBMain()
|
||||
|
|
Loading…
Reference in New Issue