diff --git a/nimbus/db/accounts_cache.nim b/nimbus/db/accounts_cache.nim index bbc450d82..7d104cb94 100644 --- a/nimbus/db/accounts_cache.nim +++ b/nimbus/db/accounts_cache.nim @@ -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) diff --git a/tests/test_state_db.nim b/tests/test_state_db.nim index a5bd0c3f0..0d2df8b00 100644 --- a/tests/test_state_db.nim +++ b/tests/test_state_db.nim @@ -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()