mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 22:04:52 +00:00
fix accounts cache init API
This commit is contained in:
parent
ff028982d6
commit
c9e49bf68a
@ -45,12 +45,15 @@ proc beginSavepoint*(ac: var AccountsCache): SavePoint {.gcsafe.}
|
|||||||
|
|
||||||
# The AccountsCache is modeled after TrieDatabase for it's transaction style
|
# The AccountsCache is modeled after TrieDatabase for it's transaction style
|
||||||
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef,
|
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef,
|
||||||
root: KeccakHash, pruneTrie: bool): AccountsCache =
|
root: KeccakHash, pruneTrie: bool = true): AccountsCache =
|
||||||
result.db = db
|
result.db = db
|
||||||
result.trie = initSecureHexaryTrie(db, root, pruneTrie)
|
result.trie = initSecureHexaryTrie(db, root, pruneTrie)
|
||||||
result.unrevertablyTouched = initHashSet[EthAddress]()
|
result.unrevertablyTouched = initHashSet[EthAddress]()
|
||||||
discard result.beginSavepoint
|
discard result.beginSavepoint
|
||||||
|
|
||||||
|
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef, pruneTrie: bool = true): AccountsCache =
|
||||||
|
init(x, db, emptyRlpHash, pruneTrie)
|
||||||
|
|
||||||
proc rootHash*(ac: AccountsCache): KeccakHash =
|
proc rootHash*(ac: AccountsCache): KeccakHash =
|
||||||
# make sure all savepoint already committed
|
# make sure all savepoint already committed
|
||||||
doAssert(ac.savePoint.parentSavePoint.isNil)
|
doAssert(ac.savePoint.parentSavePoint.isNil)
|
||||||
|
@ -141,5 +141,14 @@ proc stateDBMain*() =
|
|||||||
# state trie at all
|
# state trie at all
|
||||||
check ac.rootHash == rootHash
|
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:
|
when isMainModule:
|
||||||
stateDBMain()
|
stateDBMain()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user