Merge pull request #502 from status-im/fix_accounts_cache

fix accounts cache init API
This commit is contained in:
andri lim 2020-05-01 11:26:39 +07:00 committed by GitHub
commit eb29b305e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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)

View File

@ -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()