From d1ab073aad19fbc6264df82f2d6699c31588ffef Mon Sep 17 00:00:00 2001 From: advaita-saha Date: Mon, 6 May 2024 23:18:09 +0530 Subject: [PATCH] upstream verkle to ledger backend --- nimbus/db/ledger/backend/accounts_cache.nim | 10 +++++----- nimbus/db/ledger/backend/accounts_cache_desc.nim | 2 +- nimbus/db/ledger/verkle_accounts_cache.nim | 14 +++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/nimbus/db/ledger/backend/accounts_cache.nim b/nimbus/db/ledger/backend/accounts_cache.nim index f3822860a..04db8abdb 100644 --- a/nimbus/db/ledger/backend/accounts_cache.nim +++ b/nimbus/db/ledger/backend/accounts_cache.nim @@ -14,7 +14,7 @@ import eth/common, ../../../../stateless/multi_keys, "../.."/[core_db, distinct_tries], - ../accounts_cache as impl, + ../verkle_accounts_cache as impl, ".."/[base, base/base_desc], ./accounts_cache_desc as wrp @@ -51,7 +51,7 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns = lc.addLogEntry(log), beginSavepointFn: proc(): LedgerSpRef = - wrp.SavePoint(sp: lc.beginSavepoint()), + wrp.SavePoint(sp: lc.beginSavePoint()), clearStorageFn: proc(eAddr: EthAddress) = lc.clearStorage(eAddr), @@ -184,7 +184,7 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns = proc ledgerExtras(lc: impl.AccountsCache): LedgerExtras = LedgerExtras( getMptFn: proc(): CoreDbMptRef = - lc.rawTrie.mpt, + lc.rawTrie.mpt, # -----------> needs to be fixed, MPT doesn't exist anymore rawRootHashFn: proc(): Hash256 = lc.rawTrie.rootHash()) @@ -195,7 +195,7 @@ proc newLegacyAccountsCache( root: Hash256; pruneTrie: bool): LedgerRef = ## Constructor - let lc = impl.AccountsCache.init(db, root, pruneTrie) + let lc = impl.AccountsCache.init() wrp.AccountsCache( ldgType: LegacyAccountsCache, ac: lc, @@ -231,7 +231,7 @@ iterator storageIt*( ): (UInt256,UInt256) {.gcsafe, raises: [CoreDbApiError].} = 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 # ------------------------------------------------------------------------------ diff --git a/nimbus/db/ledger/backend/accounts_cache_desc.nim b/nimbus/db/ledger/backend/accounts_cache_desc.nim index 2e9d026d9..624b5054f 100644 --- a/nimbus/db/ledger/backend/accounts_cache_desc.nim +++ b/nimbus/db/ledger/backend/accounts_cache_desc.nim @@ -9,7 +9,7 @@ # according to those terms. import - ../accounts_cache as impl, + ../verkle_accounts_cache as impl, ../base/base_desc type diff --git a/nimbus/db/ledger/verkle_accounts_cache.nim b/nimbus/db/ledger/verkle_accounts_cache.nim index 280f387ed..349cfdc11 100644 --- a/nimbus/db/ledger/verkle_accounts_cache.nim +++ b/nimbus/db/ledger/verkle_accounts_cache.nim @@ -119,7 +119,7 @@ proc rawTrie*(ac: AccountsCache): VerkleTrie {.inline.} = ac.trie proc init*(x: typedesc[AccountsCache]): AccountsCache = new result result.trie = initVerkleTrie() - result.witnessCache = initTable[EthAddress, WitnessData] + result.witnessCache = initTable[EthAddress, WitnessData]() discard result.beginSavePoint proc rootHash*(ac: AccountsCache): KeccakHash = @@ -261,6 +261,18 @@ proc storageValue(acc: RefAccount, address: EthAddress, slot: UInt256, db: Verkl do: 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) = acc.flags.excl Alive acc.overlayStorage.clear()