upstream verkle to ledger backend

This commit is contained in:
advaita-saha 2024-05-06 23:18:09 +05:30
parent 49a7f2c9c6
commit d1ab073aad
No known key found for this signature in database
GPG Key ID: 33CFA1C66B77807C
3 changed files with 19 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import
eth/common, eth/common,
../../../../stateless/multi_keys, ../../../../stateless/multi_keys,
"../.."/[core_db, distinct_tries], "../.."/[core_db, distinct_tries],
../accounts_cache as impl, ../verkle_accounts_cache as impl,
".."/[base, base/base_desc], ".."/[base, base/base_desc],
./accounts_cache_desc as wrp ./accounts_cache_desc as wrp
@ -51,7 +51,7 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns =
lc.addLogEntry(log), lc.addLogEntry(log),
beginSavepointFn: proc(): LedgerSpRef = beginSavepointFn: proc(): LedgerSpRef =
wrp.SavePoint(sp: lc.beginSavepoint()), wrp.SavePoint(sp: lc.beginSavePoint()),
clearStorageFn: proc(eAddr: EthAddress) = clearStorageFn: proc(eAddr: EthAddress) =
lc.clearStorage(eAddr), lc.clearStorage(eAddr),
@ -184,7 +184,7 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns =
proc ledgerExtras(lc: impl.AccountsCache): LedgerExtras = proc ledgerExtras(lc: impl.AccountsCache): LedgerExtras =
LedgerExtras( LedgerExtras(
getMptFn: proc(): CoreDbMptRef = getMptFn: proc(): CoreDbMptRef =
lc.rawTrie.mpt, lc.rawTrie.mpt, # -----------> needs to be fixed, MPT doesn't exist anymore
rawRootHashFn: proc(): Hash256 = rawRootHashFn: proc(): Hash256 =
lc.rawTrie.rootHash()) lc.rawTrie.rootHash())
@ -195,7 +195,7 @@ proc newLegacyAccountsCache(
root: Hash256; root: Hash256;
pruneTrie: bool): LedgerRef = pruneTrie: bool): LedgerRef =
## Constructor ## Constructor
let lc = impl.AccountsCache.init(db, root, pruneTrie) let lc = impl.AccountsCache.init()
wrp.AccountsCache( wrp.AccountsCache(
ldgType: LegacyAccountsCache, ldgType: LegacyAccountsCache,
ac: lc, ac: lc,
@ -231,7 +231,7 @@ iterator storageIt*(
): (UInt256,UInt256) ): (UInt256,UInt256)
{.gcsafe, raises: [CoreDbApiError].} = {.gcsafe, raises: [CoreDbApiError].} =
noRlpException "storage()": noRlpException "storage()":
for w in lc.ac.storage(eAddr): for w in lc.ac.storage(eAddr): # -----------> needs to be fixed, storage() doesn't exist yet
yield w yield w
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -9,7 +9,7 @@
# according to those terms. # according to those terms.
import import
../accounts_cache as impl, ../verkle_accounts_cache as impl,
../base/base_desc ../base/base_desc
type type

View File

@ -119,7 +119,7 @@ proc rawTrie*(ac: AccountsCache): VerkleTrie {.inline.} = ac.trie
proc init*(x: typedesc[AccountsCache]): AccountsCache = proc init*(x: typedesc[AccountsCache]): AccountsCache =
new result new result
result.trie = initVerkleTrie() result.trie = initVerkleTrie()
result.witnessCache = initTable[EthAddress, WitnessData] result.witnessCache = initTable[EthAddress, WitnessData]()
discard result.beginSavePoint discard result.beginSavePoint
proc rootHash*(ac: AccountsCache): KeccakHash = proc rootHash*(ac: AccountsCache): KeccakHash =
@ -261,6 +261,18 @@ proc storageValue(acc: RefAccount, address: EthAddress, slot: UInt256, db: Verkl
do: do:
result = acc.originalStorageValue(address, slot, db) result = acc.originalStorageValue(address, slot, db)
proc getCommittedStorage*(ac: AccountsCache, address: EthAddress, slot: UInt256): UInt256 {.inline.} =
let acc = ac.getAccount(address, false)
if acc.isNil:
return
acc.originalStorageValue(address, slot, ac.trie)
proc getStorage*(ac: AccountsCache, address: EthAddress, slot: UInt256): UInt256 {.inline.} =
let acc = ac.getAccount(address, false)
if acc.isNil:
return
acc.storageValue(address, slot, ac.trie)
proc kill(acc: RefAccount) = proc kill(acc: RefAccount) =
acc.flags.excl Alive acc.flags.excl Alive
acc.overlayStorage.clear() acc.overlayStorage.clear()