diff --git a/hive_integration/nodocker/pyspec/test_env.nim b/hive_integration/nodocker/pyspec/test_env.nim index 1c418d652..b6adb4d06 100644 --- a/hive_integration/nodocker/pyspec/test_env.nim +++ b/hive_integration/nodocker/pyspec/test_env.nim @@ -53,7 +53,7 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) = ) t.chainRef = newChain(t.com, extraValidation = true) let - stateDB = LedgerCache.init(memDB, emptyRlpHash) + stateDB = LedgerRef.init(memDB, emptyRlpHash) genesisHeader = node.genesisHeader setupStateDB(node["pre"], stateDB) diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index f69526cb1..1f7228abe 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -94,9 +94,6 @@ type pos: CasperRef ## Proof Of Stake descriptor - ldgType: LedgerType - ## Optional suggestion for the ledger cache to be used as state DB - pruneHistory: bool ## Must not not set for a full node, might go away some time @@ -140,7 +137,6 @@ proc init(com : CommonRef, networkId : NetworkId, config : ChainConfig, genesis : Genesis, - ldgType : LedgerType, pruneHistory: bool, ) {.gcsafe, raises: [CatchableError].} = @@ -151,7 +147,6 @@ proc init(com : CommonRef, com.forkTransitionTable = config.toForkTransitionTable() com.networkId = networkId com.syncProgress= SyncProgress() - com.ldgType = (if ldgType == LedgerType(0): LedgerCache else: ldgType) com.pruneHistory= pruneHistory # Always initialise the PoW epoch cache even though it migh no be used @@ -177,7 +172,7 @@ proc init(com : CommonRef, # Must not overwrite the global state on the single state DB if not db.getBlockHeader(0.toBlockNumber, com.genesisHeader): com.genesisHeader = toGenesisHeader(genesis, - com.currentFork, com.db, com.ldgType) + com.currentFork, com.db) com.setForkId(com.genesisHeader) com.pos.timestamp = genesis.timestamp @@ -218,7 +213,6 @@ proc new*( db: CoreDbRef; networkId: NetworkId = MainNet; params = networkParams(MainNet); - ldgType = LedgerType(0); pruneHistory = false; ): CommonRef {.gcsafe, raises: [CatchableError].} = @@ -231,7 +225,6 @@ proc new*( networkId, params.config, params.genesis, - ldgType, pruneHistory) proc new*( @@ -239,7 +232,6 @@ proc new*( db: CoreDbRef; config: ChainConfig; networkId: NetworkId = MainNet; - ldgType = LedgerType(0); pruneHistory = false; ): CommonRef {.gcsafe, raises: [CatchableError].} = @@ -252,7 +244,6 @@ proc new*( networkId, config, nil, - ldgType, pruneHistory) proc clone*(com: CommonRef, db: CoreDbRef): CommonRef = @@ -271,7 +262,6 @@ proc clone*(com: CommonRef, db: CoreDbRef): CommonRef = consensusType: com.consensusType, pow : com.pow, pos : com.pos, - ldgType : com.ldgType, pruneHistory : com.pruneHistory) proc clone*(com: CommonRef): CommonRef = @@ -482,9 +472,6 @@ func syncHighest*(com: CommonRef): BlockNumber = func syncReqRelaxV2*(com: CommonRef): bool = com.syncReqRelaxV2 -func ledgerType*(com: CommonRef): LedgerType = - com.ldgType - # ------------------------------------------------------------------------------ # Setters # ------------------------------------------------------------------------------ diff --git a/nimbus/common/genesis.nim b/nimbus/common/genesis.nim index 40695186f..2c189c541 100644 --- a/nimbus/common/genesis.nim +++ b/nimbus/common/genesis.nim @@ -53,7 +53,7 @@ proc initAccountsLedgerRef( db: CoreDbRef; ): GenesisLedgerRef = ## Methods jump table - let ac = LedgerCache.init(db, EMPTY_ROOT_HASH) + let ac = LedgerRef.init(db, EMPTY_ROOT_HASH) GenesisLedgerRef( addAccount: proc( @@ -77,7 +77,7 @@ proc initAccountsLedgerRef( ac.persist(), rootHash: proc(): Hash256 = - ac.rootHash(), + ac.state(), getTrie: proc(): CoreDbMptRef = ac.getMpt()) @@ -88,10 +88,7 @@ proc initAccountsLedgerRef( proc newStateDB*( db: CoreDbRef; - ledgerType: LedgerType; ): GenesisLedgerRef = - ## Currently only `LedgerCache` supported for `ledgerType`. - doAssert ledgerType == LedgerCache db.initAccountsLedgerRef() proc getTrie*(sdb: GenesisLedgerRef): CoreDbMptRef = @@ -155,28 +152,25 @@ proc toGenesisHeader*( proc toGenesisHeader*( genesis: Genesis; fork: HardFork; - db = CoreDbRef(nil); - ledgerType = LedgerCache; - ): BlockHeader + db = CoreDbRef(nil)): BlockHeader {.gcsafe, raises: [CatchableError].} = ## Generate the genesis block header from the `genesis` and `config` ## argument value. let db = if db.isNil: AristoDbMemory.newCoreDbRef() else: db - sdb = db.newStateDB(ledgerType) + sdb = db.newStateDB() toGenesisHeader(genesis, sdb, fork) proc toGenesisHeader*( params: NetworkParams; - db = CoreDbRef(nil); - ledgerType = LedgerCache; + db = CoreDbRef(nil) ): BlockHeader {.raises: [CatchableError].} = ## Generate the genesis block header from the `genesis` and `config` ## argument value. let map = toForkTransitionTable(params.config) let fork = map.toHardFork(forkDeterminationInfo(0.toBlockNumber, params.genesis.timestamp)) - toGenesisHeader(params.genesis, fork, db, ledgerType) + toGenesisHeader(params.genesis, fork, db) # ------------------------------------------------------------------------------ # End diff --git a/nimbus/core/tx_pool/tx_chain.nim b/nimbus/core/tx_pool/tx_chain.nim index ec4759a24..e94da5961 100644 --- a/nimbus/core/tx_pool/tx_chain.nim +++ b/nimbus/core/tx_pool/tx_chain.nim @@ -123,7 +123,7 @@ proc update(dh: TxChainRef; parent: BlockHeader) let timestamp = dh.getTimestamp(parent) db = dh.com.db - acc = dh.com.ledgerType.init(db, parent.stateRoot) + acc = LedgerRef.init(db, parent.stateRoot) fee = if dh.com.isLondon(parent.blockNumber + 1, timestamp): some(dh.com.baseFeeGet(parent).uint64.u256) else: diff --git a/nimbus/db/ledger.nim b/nimbus/db/ledger.nim index 5604f8acc..e0dd6f4b4 100644 --- a/nimbus/db/ledger.nim +++ b/nimbus/db/ledger.nim @@ -18,15 +18,13 @@ import eth/common, ./core_db, - ./ledger/backend/[accounts_ledger, accounts_ledger_desc], - ./ledger/[base_iterators, distinct_ledgers] + ./ledger/[base_iterators, distinct_ledgers, accounts_ledger] import ./ledger/base except LedgerApiTxt, beginTrackApi, bless, ifTrackApi export AccountsLedgerRef, - LedgerType, base, base_iterators, distinct_ledgers, @@ -36,17 +34,8 @@ export # Public constructor # ------------------------------------------------------------------------------ -proc init*( - ldgType: LedgerType; - db: CoreDbRef; - root: Hash256; - ): LedgerRef = - case ldgType: - of LedgerCache: - AccountsLedgerRef.init(db, root) - - else: - raiseAssert: "Missing ledger type label" +proc init*(_: type LedgerRef, db: CoreDbRef; root: Hash256): LedgerRef = + LedgerRef(ac: AccountsLedgerRef.init(db, root)).bless(db) # ------------------------------------------------------------------------------ # End diff --git a/nimbus/db/ledger/backend/accounts_ledger.nim b/nimbus/db/ledger/backend/accounts_ledger.nim deleted file mode 100644 index b584def71..000000000 --- a/nimbus/db/ledger/backend/accounts_ledger.nim +++ /dev/null @@ -1,234 +0,0 @@ -# Nimbus -# Copyright (c) 2023-2024 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or -# http://www.apache.org/licenses/LICENSE-2.0) -# * MIT license ([LICENSE-MIT](LICENSE-MIT) or -# http://opensource.org/licenses/MIT) -# at your option. This file may not be copied, modified, or distributed except -# according to those terms. - -{.push raises: [].} - -import - eth/common, - ../../../../stateless/multi_keys, - ../../core_db, - ../base/base_desc, - ../accounts_ledger as impl, - ".."/[base, distinct_ledgers], - ./accounts_ledger_desc as wrp - -# ------------------------------------------------------------------------------ -# Private functions -# ------------------------------------------------------------------------------ - -func savePoint(sp: LedgerSpRef): impl.LedgerSavePoint = - if not sp.isNil: - wrp.LedgerSavePoint(sp).sp - else: - nil - -# ---------------- - -proc ledgerMethods(lc: impl.AccountsLedgerRef): LedgerFns = - LedgerFns( - accessListFn: proc(eAddr: EthAddress) = - lc.accessList(eAddr), - - accessList2Fn: proc(eAddr: EthAddress, slot: UInt256) = - lc.accessList(eAddr, slot), - - accountExistsFn: proc(eAddr: EthAddress): bool = - lc.accountExists(eAddr), - - addBalanceFn: proc(eAddr: EthAddress, delta: UInt256) = - lc.addBalance(eAddr, delta), - - addLogEntryFn: proc(log: Log) = - lc.addLogEntry(log), - - beginSavepointFn: proc(): LedgerSpRef = - wrp.LedgerSavePoint(sp: lc.beginSavepoint()), - - clearStorageFn: proc(eAddr: EthAddress) = - lc.clearStorage(eAddr), - - clearTransientStorageFn: proc() = - lc.clearTransientStorage(), - - collectWitnessDataFn: proc() = - lc.collectWitnessData(), - - commitFn: proc(sp: LedgerSpRef) = - lc.commit(sp.savePoint), - - deleteAccountFn: proc(eAddr: EthAddress) = - lc.deleteAccount(eAddr), - - disposeFn: proc(sp: LedgerSpRef) = - lc.dispose(sp.savePoint), - - getAndClearLogEntriesFn: proc(): seq[Log] = - lc.getAndClearLogEntries(), - - getBalanceFn: proc(eAddr: EthAddress): UInt256 = - lc.getBalance(eAddr), - - getCodeFn: proc(eAddr: EthAddress): Blob = - lc.getCode(eAddr), - - getCodeHashFn: proc(eAddr: EthAddress): Hash256 = - lc.getCodeHash(eAddr), - - getCodeSizeFn: proc(eAddr: EthAddress): int = - lc.getCodeSize(eAddr), - - getCommittedStorageFn: proc(eAddr: EthAddress, slot: UInt256): UInt256 = - lc.getCommittedStorage(eAddr, slot), - - getNonceFn: proc(eAddr: EthAddress): AccountNonce = - lc.getNonce(eAddr), - - getStorageFn: proc(eAddr: EthAddress, slot: UInt256): UInt256 = - lc.getStorage(eAddr, slot), - - getStorageRootFn: proc(eAddr: EthAddress): Hash256 = - lc.getStorageRoot(eAddr), - - getTransientStorageFn: proc(eAddr: EthAddress, slot: UInt256): UInt256 = - lc.getTransientStorage(eAddr, slot), - - contractCollisionFn: proc(eAddr: EthAddress): bool = - lc.contractCollision(eAddr), - - inAccessListFn: proc(eAddr: EthAddress): bool = - lc.inAccessList(eAddr), - - inAccessList2Fn: proc(eAddr: EthAddress, slot: UInt256): bool = - lc.inAccessList(eAddr, slot), - - incNonceFn: proc(eAddr: EthAddress) = - lc.incNonce(eAddr), - - isDeadAccountFn: proc(eAddr: EthAddress): bool = - lc.isDeadAccount(eAddr), - - isEmptyAccountFn: proc(eAddr: EthAddress): bool = - lc.isEmptyAccount(eAddr), - - isTopLevelCleanFn: proc(): bool = - lc.isTopLevelClean(), - - logEntriesFn: proc(): seq[Log] = - lc.logEntries(), - - makeMultiKeysFn: proc(): MultiKeysRef = - lc.makeMultiKeys(), - - persistFn: proc(clearEmptyAccount: bool, clearCache: bool) = - lc.persist(clearEmptyAccount, clearCache), - - ripemdSpecialFn: proc() = - lc.ripemdSpecial(), - - rollbackFn: proc(sp: LedgerSpRef) = - lc.rollback(sp.savePoint), - - safeDisposeFn: proc(sp: LedgerSpRef) = - lc.safeDispose(sp.savePoint), - - selfDestructFn: proc(eAddr: EthAddress) = - lc.selfDestruct(eAddr), - - selfDestruct6780Fn: proc(eAddr: EthAddress) = - lc.selfDestruct6780(eAddr), - - selfDestructLenFn: proc(): int = - lc.selfDestructLen(), - - setBalanceFn: proc(eAddr: EthAddress, balance: UInt256) = - lc.setBalance(eAddr, balance), - - setCodeFn: proc(eAddr: EthAddress, code: Blob) = - lc.setCode(eAddr, code), - - setNonceFn: proc(eAddr: EthAddress, nonce: AccountNonce) = - lc.setNonce(eAddr, nonce), - - setStorageFn: proc(eAddr: EthAddress, slot, val: UInt256) = - lc.setStorage(eAddr, slot, val), - - setTransientStorageFn: proc(eAddr: EthAddress, slot, val: UInt256) = - lc.setTransientStorage(eAddr, slot, val), - - stateFn: proc(): Hash256 = - lc.state(), - - subBalanceFn: proc(eAddr: EthAddress, delta: UInt256) = - lc.subBalance(eAddr, delta), - - getAccessListFn: proc(): common.AccessList = - lc.getAccessList()) - -proc ledgerExtras(lc: impl.AccountsLedgerRef): LedgerExtras = - LedgerExtras( - getMptFn: proc(): CoreDbMptRef = - lc.rawTrie.CoreDxAccRef.getMpt.CoreDbMptRef) - -proc newAccountsLedgerRef( - db: CoreDbRef; - root: Hash256; - ): LedgerRef = - let lc = impl.AccountsLedgerRef.init(db, root) - wrp.AccountsLedgerRef( - ldgType: LedgerCache, - ac: lc, - extras: lc.ledgerExtras(), - methods: lc.ledgerMethods()).bless db - -# ------------------------------------------------------------------------------ -# Public iterators -# ------------------------------------------------------------------------------ - -iterator accountsIt*(lc: wrp.AccountsLedgerRef): Account = - for w in lc.ac.accounts(): - yield w - -iterator addressesIt*(lc: wrp.AccountsLedgerRef): EthAddress = - for w in lc.ac.addresses(): - yield w - -iterator cachedStorageIt*( - lc: wrp.AccountsLedgerRef; - eAddr: EthAddress; - ): (UInt256,UInt256) = - for w in lc.ac.cachedStorage(eAddr): - yield w - -iterator pairsIt*(lc: wrp.AccountsLedgerRef): (EthAddress,Account) = - for w in lc.ac.pairs(): - yield w - -iterator storageIt*( - lc: wrp.AccountsLedgerRef; - eAddr: EthAddress; - ): (UInt256,UInt256) = - for w in lc.ac.storage(eAddr): - yield w - -# ------------------------------------------------------------------------------ -# Public constructor -# ------------------------------------------------------------------------------ - -proc init*( - T: type wrp.AccountsLedgerRef; - db: CoreDbRef; - root: Hash256; - pruneTrie = false; - ): LedgerRef = - db.newAccountsLedgerRef root - -# ------------------------------------------------------------------------------ -# End -# ------------------------------------------------------------------------------ diff --git a/nimbus/db/ledger/backend/accounts_ledger_desc.nim b/nimbus/db/ledger/backend/accounts_ledger_desc.nim deleted file mode 100644 index f8dd3f0f0..000000000 --- a/nimbus/db/ledger/backend/accounts_ledger_desc.nim +++ /dev/null @@ -1,22 +0,0 @@ -# Nimbus -# Copyright (c) 2023 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or -# http://www.apache.org/licenses/LICENSE-2.0) -# * MIT license ([LICENSE-MIT](LICENSE-MIT) or -# http://opensource.org/licenses/MIT) -# at your option. This file may not be copied, modified, or distributed except -# according to those terms. - -import - ../accounts_ledger as impl, - ../base/base_desc - -type - AccountsLedgerRef* = ref object of LedgerRef - ac*: impl.AccountsLedgerRef - - LedgerSavePoint* = ref object of LedgerSpRef - sp*: impl.LedgerSavePoint - -# End diff --git a/nimbus/db/ledger/base.nim b/nimbus/db/ledger/base.nim index f22221eb7..c56d47234 100644 --- a/nimbus/db/ledger/base.nim +++ b/nimbus/db/ledger/base.nim @@ -19,9 +19,6 @@ import ./base/[api_tracking, base_desc] const - AutoValidateDescriptors = defined(release).not - ## No validatinon needed for production suite. - EnableApiTracking = false ## When enabled, API functions are logged. Tracking is enabled by setting ## the `trackApi` flag to `true`. @@ -38,7 +35,6 @@ type export LedgerFnInx, LedgerProfListRef, - LedgerType, LedgerRef, LedgerSpRef @@ -47,9 +43,6 @@ const LedgerEnableApiProfiling* = EnableApiTracking and EnableApiProfiling LedgerApiTxt* = apiTxt -when AutoValidateDescriptors: - import ./base/validate - proc ldgProfData*(db: CoreDbRef): LedgerProfListRef {.gcsafe.} # ------------------------------------------------------------------------------ @@ -88,8 +81,6 @@ template ifTrackApi*(ldg: LedgerRef; code: untyped) = proc bless*(ldg: LedgerRef; db: CoreDbRef): LedgerRef = ldg.beginTrackApi LdgBlessFn - when AutoValidateDescriptors: - ldg.validate() when EnableApiTracking: ldg.trackApi = db.trackLedgerApi when LedgerEnableApiProfiling: @@ -116,87 +107,87 @@ proc ldgProfData*(db: CoreDbRef): LedgerProfListRef = proc accessList*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgAccessListFn - ldg.methods.accessListFn eAddr + ldg.ac.accessList(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr proc accessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256) = ldg.beginTrackApi LdgAccessListFn - ldg.methods.accessList2Fn(eAddr, slot) + ldg.ac.accessList(eAddr, slot) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot proc accountExists*(ldg: LedgerRef, eAddr: EthAddress): bool = ldg.beginTrackApi LdgAccountExistsFn - result = ldg.methods.accountExistsFn eAddr + result = ldg.ac.accountExists(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc addBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) = ldg.beginTrackApi LdgAddBalanceFn - ldg.methods.addBalanceFn(eAddr, delta) + ldg.ac.addBalance(eAddr, delta) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta proc addLogEntry*(ldg: LedgerRef, log: Log) = ldg.beginTrackApi LdgAddLogEntryFn - ldg.methods.addLogEntryFn log + ldg.ac.addLogEntry(log) ldg.ifTrackApi: debug apiTxt, api, elapsed proc beginSavepoint*(ldg: LedgerRef): LedgerSpRef = ldg.beginTrackApi LdgBeginSavepointFn - result = ldg.methods.beginSavepointFn() + result = ldg.ac.beginSavepoint() ldg.ifTrackApi: debug apiTxt, api, elapsed proc clearStorage*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgClearStorageFn - ldg.methods.clearStorageFn eAddr + ldg.ac.clearStorage(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr proc clearTransientStorage*(ldg: LedgerRef) = ldg.beginTrackApi LdgClearTransientStorageFn - ldg.methods.clearTransientStorageFn() + ldg.ac.clearTransientStorage() ldg.ifTrackApi: debug apiTxt, api, elapsed proc collectWitnessData*(ldg: LedgerRef) = ldg.beginTrackApi LdgCollectWitnessDataFn - ldg.methods.collectWitnessDataFn() + ldg.ac.collectWitnessData() ldg.ifTrackApi: debug apiTxt, api, elapsed proc commit*(ldg: LedgerRef, sp: LedgerSpRef) = ldg.beginTrackApi LdgCommitFn - ldg.methods.commitFn sp + ldg.ac.commit(sp) ldg.ifTrackApi: debug apiTxt, api, elapsed proc deleteAccount*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgDeleteAccountFn - ldg.methods.deleteAccountFn eAddr + ldg.ac.deleteAccount(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr proc dispose*(ldg: LedgerRef, sp: LedgerSpRef) = ldg.beginTrackApi LdgDisposeFn - ldg.methods.disposeFn sp + ldg.ac.dispose(sp) ldg.ifTrackApi: debug apiTxt, api, elapsed proc getAndClearLogEntries*(ldg: LedgerRef): seq[Log] = ldg.beginTrackApi LdgGetAndClearLogEntriesFn - result = ldg.methods.getAndClearLogEntriesFn() + result = ldg.ac.getAndClearLogEntries() ldg.ifTrackApi: debug apiTxt, api, elapsed proc getBalance*(ldg: LedgerRef, eAddr: EthAddress): UInt256 = ldg.beginTrackApi LdgGetBalanceFn - result = ldg.methods.getBalanceFn eAddr + result = ldg.ac.getBalance(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc getCode*(ldg: LedgerRef, eAddr: EthAddress): Blob = ldg.beginTrackApi LdgGetCodeFn - result = ldg.methods.getCodeFn eAddr + result = ldg.ac.getCode(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result=result.toStr proc getCodeHash*(ldg: LedgerRef, eAddr: EthAddress): Hash256 = ldg.beginTrackApi LdgGetCodeHashFn - result = ldg.methods.getCodeHashFn eAddr + result = ldg.ac.getCodeHash(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc getCodeSize*(ldg: LedgerRef, eAddr: EthAddress): int = ldg.beginTrackApi LdgGetCodeSizeFn - result = ldg.methods.getCodeSizeFn eAddr + result = ldg.ac.getCodeSize(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc getCommittedStorage*( @@ -205,22 +196,22 @@ proc getCommittedStorage*( slot: UInt256; ): UInt256 = ldg.beginTrackApi LdgGetCommittedStorageFn - result = ldg.methods.getCommittedStorageFn(eAddr, slot) + result = ldg.ac.getCommittedStorage(eAddr, slot) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result proc getNonce*(ldg: LedgerRef, eAddr: EthAddress): AccountNonce = ldg.beginTrackApi LdgGetNonceFn - result = ldg.methods.getNonceFn eAddr + result = ldg.ac.getNonce(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc getStorage*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): UInt256 = ldg.beginTrackApi LdgGetStorageFn - result = ldg.methods.getStorageFn(eAddr, slot) + result = ldg.ac.getStorage(eAddr, slot) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result proc getStorageRoot*(ldg: LedgerRef, eAddr: EthAddress): Hash256 = ldg.beginTrackApi LdgGetStorageRootFn - result = ldg.methods.getStorageRootFn eAddr + result = ldg.ac.getStorageRoot(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc getTransientStorage*( @@ -229,107 +220,107 @@ proc getTransientStorage*( slot: UInt256; ): UInt256 = ldg.beginTrackApi LdgGetTransientStorageFn - result = ldg.methods.getTransientStorageFn(eAddr, slot) + result = ldg.ac.getTransientStorage(eAddr, slot) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result proc contractCollision*(ldg: LedgerRef, eAddr: EthAddress): bool = ldg.beginTrackApi LdgContractCollisionFn - result = ldg.methods.contractCollisionFn eAddr + result = ldg.ac.contractCollision(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress): bool = ldg.beginTrackApi LdgInAccessListFn - result = ldg.methods.inAccessListFn eAddr + result = ldg.ac.inAccessList(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): bool = ldg.beginTrackApi LdgInAccessListFn - result = ldg.methods.inAccessList2Fn(eAddr, slot) + result = ldg.ac.inAccessList(eAddr, slot) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result proc incNonce*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgIncNonceFn - ldg.methods.incNonceFn eAddr + ldg.ac.incNonce(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr proc isDeadAccount*(ldg: LedgerRef, eAddr: EthAddress): bool = ldg.beginTrackApi LdgIsDeadAccountFn - result = ldg.methods.isDeadAccountFn eAddr + result = ldg.ac.isDeadAccount(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc isEmptyAccount*(ldg: LedgerRef, eAddr: EthAddress): bool = ldg.beginTrackApi LdgIsEmptyAccountFn - result = ldg.methods.isEmptyAccountFn eAddr + result = ldg.ac.isEmptyAccount(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result proc isTopLevelClean*(ldg: LedgerRef): bool = ldg.beginTrackApi LdgIsTopLevelCleanFn - result = ldg.methods.isTopLevelCleanFn() + result = ldg.ac.isTopLevelClean() ldg.ifTrackApi: debug apiTxt, api, elapsed, result proc logEntries*(ldg: LedgerRef): seq[Log] = ldg.beginTrackApi LdgLogEntriesFn - result = ldg.methods.logEntriesFn() + result = ldg.ac.logEntries() ldg.ifTrackApi: debug apiTxt, api, elapsed, result proc makeMultiKeys*(ldg: LedgerRef): MultiKeysRef = ldg.beginTrackApi LdgMakeMultiKeysFn - result = ldg.methods.makeMultiKeysFn() + result = ldg.ac.makeMultiKeys() ldg.ifTrackApi: debug apiTxt, api, elapsed proc persist*(ldg: LedgerRef, clearEmptyAccount = false, clearCache = true) = ldg.beginTrackApi LdgPersistFn - ldg.methods.persistFn(clearEmptyAccount, clearCache) + ldg.ac.persist(clearEmptyAccount, clearCache) ldg.ifTrackApi: debug apiTxt, api, elapsed, clearEmptyAccount, clearCache proc ripemdSpecial*(ldg: LedgerRef) = ldg.beginTrackApi LdgRipemdSpecialFn - ldg.methods.ripemdSpecialFn() + ldg.ac.ripemdSpecial() ldg.ifTrackApi: debug apiTxt, api, elapsed proc rollback*(ldg: LedgerRef, sp: LedgerSpRef) = ldg.beginTrackApi LdgRollbackFn - ldg.methods.rollbackFn sp + ldg.ac.rollback(sp) ldg.ifTrackApi: debug apiTxt, api, elapsed proc safeDispose*(ldg: LedgerRef, sp: LedgerSpRef) = ldg.beginTrackApi LdgSafeDisposeFn - ldg.methods.safeDisposeFn sp + ldg.ac.safeDispose(sp) ldg.ifTrackApi: debug apiTxt, api, elapsed proc selfDestruct*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgSelfDestructFn - ldg.methods.selfDestructFn eAddr + ldg.ac.selfDestruct(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed proc selfDestruct6780*(ldg: LedgerRef, eAddr: EthAddress) = ldg.beginTrackApi LdgSelfDestruct6780Fn - ldg.methods.selfDestruct6780Fn eAddr + ldg.ac.selfDestruct6780(eAddr) ldg.ifTrackApi: debug apiTxt, api, elapsed proc selfDestructLen*(ldg: LedgerRef): int = ldg.beginTrackApi LdgSelfDestructLenFn - result = ldg.methods.selfDestructLenFn() + result = ldg.ac.selfDestructLen() ldg.ifTrackApi: debug apiTxt, api, elapsed, result proc setBalance*(ldg: LedgerRef, eAddr: EthAddress, balance: UInt256) = ldg.beginTrackApi LdgSetBalanceFn - ldg.methods.setBalanceFn(eAddr, balance) + ldg.ac.setBalance(eAddr, balance) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, balance proc setCode*(ldg: LedgerRef, eAddr: EthAddress, code: Blob) = ldg.beginTrackApi LdgSetCodeFn - ldg.methods.setCodeFn(eAddr, code) + ldg.ac.setCode(eAddr, code) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, code=code.toStr proc setNonce*(ldg: LedgerRef, eAddr: EthAddress, nonce: AccountNonce) = ldg.beginTrackApi LdgSetNonceFn - ldg.methods.setNonceFn(eAddr, nonce) + ldg.ac.setNonce(eAddr, nonce) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, nonce proc setStorage*(ldg: LedgerRef, eAddr: EthAddress, slot, val: UInt256) = ldg.beginTrackApi LdgSetStorageFn - ldg.methods.setStorageFn(eAddr, slot, val) + ldg.ac.setStorage(eAddr, slot, val) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val proc setTransientStorage*( @@ -339,44 +330,37 @@ proc setTransientStorage*( val: UInt256; ) = ldg.beginTrackApi LdgSetTransientStorageFn - ldg.methods.setTransientStorageFn(eAddr, slot, val) + ldg.ac.setTransientStorage(eAddr, slot, val) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val proc state*(ldg: LedgerRef): Hash256 = ldg.beginTrackApi LdgStateFn - result = ldg.methods.stateFn() + result = ldg.ac.state() ldg.ifTrackApi: debug apiTxt, api, elapsed, result proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) = ldg.beginTrackApi LdgSubBalanceFn - ldg.methods.subBalanceFn(eAddr, delta) + ldg.ac.subBalance(eAddr, delta) ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta proc getAccessList*(ldg: LedgerRef): AccessList = ldg.beginTrackApi LdgGetAccessListFn - result = ldg.methods.getAccessListFn() + result = ldg.ac.getAccessList() ldg.ifTrackApi: debug apiTxt, api, elapsed -# ------------------------------------------------------------------------------ -# Public methods, extensions to go away -# ------------------------------------------------------------------------------ - -proc rootHash*(ldg: LedgerRef): Hash256 = - ## Replaced by `state()` - ldg.beginTrackApi LdgRootHashFn - result = ldg.methods.stateFn() - ldg.ifTrackApi: debug apiTxt, api, elapsed, result +proc rootHash*(ldg: LedgerRef): KeccakHash = + ldg.state() proc getMpt*(ldg: LedgerRef): CoreDbMptRef = ldg.beginTrackApi LdgGetMptFn - result = ldg.extras.getMptFn() + result = ldg.ac.rawTrie.CoreDxAccRef.getMpt.CoreDbMptRef ldg.ifTrackApi: debug apiTxt, api, elapsed, result # ------------------------------------------------------------------------------ # Public virtual read-only methods # ------------------------------------------------------------------------------ -proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.} +proc rootHash*(db: ReadOnlyStateDB): KeccakHash = db.LedgerRef.state() proc getCodeHash*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.} proc getStorageRoot*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.} proc getBalance*(db: ReadOnlyStateDB, eAddr: EthAddress): UInt256 {.borrow.} diff --git a/nimbus/db/ledger/base/base_desc.nim b/nimbus/db/ledger/base/base_desc.nim index 4e453bc0c..8127c3d46 100644 --- a/nimbus/db/ledger/base/base_desc.nim +++ b/nimbus/db/ledger/base/base_desc.nim @@ -11,13 +11,11 @@ {.push raises: [].} import - eth/common, - ../../core_db, - ../../../../stateless/multi_keys, - ../../aristo/aristo_profile + ../../aristo/aristo_profile, + ../accounts_ledger -# Annotation helpers -{.pragma: noRaise, gcsafe, raises: [].} +export + accounts_ledger type LedgerProfListRef* = AristoDbProfListRef @@ -26,122 +24,13 @@ type LedgerProfData* = AristoDbProfData ## Borrowed from `aristo_profile`, only used in profiling mode - LedgerType* = enum - Ooops = 0 - LedgerCache - - LedgerSpRef* = ref object of RootRef + LedgerSpRef* = LedgerSavePoint ## Object for check point or save point LedgerRef* = ref object of RootRef ## Root object with closures - ldgType*: LedgerType ## For debugging trackApi*: bool ## For debugging profTab*: LedgerProfListRef ## Profiling data (if any) - extras*: LedgerExtras ## Support might go away - methods*: LedgerFns - - GetMptFn* = proc(): CoreDbMptRef {.noRaise.} - - LedgerExtras* = object - getMptFn*: GetMptFn - - AccessListFn* = proc(eAddr: EthAddress) {.noRaise.} - AccessList2Fn* = proc(eAddr: EthAddress, slot: UInt256) {.noRaise.} - AccountExistsFn* = proc(eAddr: EthAddress): bool {.noRaise.} - AddBalanceFn* = proc(eAddr: EthAddress, delta: UInt256) {.noRaise.} - AddLogEntryFn* = proc(log: Log) {.noRaise.} - BeginSavepointFn* = proc(): LedgerSpRef {.noRaise.} - ClearStorageFn* = proc(eAddr: EthAddress) {.noRaise.} - ClearTransientStorageFn* = proc() {.noRaise.} - CollectWitnessDataFn* = proc() {.noRaise.} - CommitFn* = proc(sp: LedgerSpRef) {.noRaise.} - DeleteAccountFn* = proc(eAddr: EthAddress) {.noRaise.} - DisposeFn* = proc(sp: LedgerSpRef) {.noRaise.} - GetAndClearLogEntriesFn* = proc(): seq[Log] {.noRaise.} - GetBalanceFn* = proc(eAddr: EthAddress): UInt256 {.noRaise.} - GetCodeFn* = proc(eAddr: EthAddress): Blob {.noRaise.} - GetCodeHashFn* = proc(eAddr: EthAddress): Hash256 {.noRaise.} - GetCodeSizeFn* = proc(eAddr: EthAddress): int {.noRaise.} - GetCommittedStorageFn* = - proc(eAddr: EthAddress, slot: UInt256): UInt256 {.noRaise.} - GetNonceFn* = proc(eAddr: EthAddress): AccountNonce {.noRaise.} - GetStorageFn* = proc(eAddr: EthAddress, slot: UInt256): UInt256 {.noRaise.} - GetStorageRootFn* = proc(eAddr: EthAddress): Hash256 {.noRaise.} - GetTransientStorageFn* = - proc(eAddr: EthAddress, slot: UInt256): UInt256 {.noRaise.} - ContractCollisionFn* = proc(eAddr: EthAddress): bool {.noRaise.} - InAccessListFn* = proc(eAddr: EthAddress): bool {.noRaise.} - InAccessList2Fn* = proc(eAddr: EthAddress, slot: UInt256): bool {.noRaise.} - IncNonceFn* = proc(eAddr: EthAddress) {.noRaise.} - IsDeadAccountFn* = proc(eAddr: EthAddress): bool {.noRaise.} - IsEmptyAccountFn* = proc(eAddr: EthAddress): bool {.noRaise.} - IsTopLevelCleanFn* = proc(): bool {.noRaise.} - LogEntriesFn* = proc(): seq[Log] {.noRaise.} - MakeMultiKeysFn* = proc(): MultiKeysRef {.noRaise.} - PersistFn* = proc(clearEmptyAccount: bool, clearCache: bool) {.noRaise.} - RipemdSpecialFn* = proc() {.noRaise.} - RollbackFn* = proc(sp: LedgerSpRef) {.noRaise.} - SafeDisposeFn* = proc(sp: LedgerSpRef) {.noRaise.} - SelfDestructFn* = proc(eAddr: EthAddress) {.noRaise.} - SelfDestruct6780Fn* = proc(eAddr: EthAddress) {.noRaise.} - SelfDestructLenFn* = proc(): int {.noRaise.} - SetBalanceFn* = proc(eAddr: EthAddress, balance: UInt256) {.noRaise.} - SetCodeFn* = proc(eAddr: EthAddress, code: Blob) {.noRaise.} - SetNonceFn* = proc(eAddr: EthAddress, nonce: AccountNonce) {.noRaise.} - SetStorageFn* = proc(eAddr: EthAddress, slot, value: UInt256) {.noRaise.} - SetTransientStorageFn* = - proc(eAddr: EthAddress, slot, val: UInt256) {.noRaise.} - StateFn* = proc(): Hash256 {.noRaise.} - SubBalanceFn* = proc(eAddr: EthAddress, delta: UInt256) {.noRaise.} - GetAccessListFn* = proc(): AccessList {.noRaise.} - - LedgerFns* = object - accessListFn*: AccessListFn - accessList2Fn*: AccessList2Fn - accountExistsFn*: AccountExistsFn - addBalanceFn*: AddBalanceFn - addLogEntryFn*: AddLogEntryFn - beginSavepointFn*: BeginSavepointFn - clearStorageFn*: ClearStorageFn - clearTransientStorageFn*: ClearTransientStorageFn - collectWitnessDataFn*: CollectWitnessDataFn - commitFn*: CommitFn - deleteAccountFn*: DeleteAccountFn - disposeFn*: DisposeFn - getAndClearLogEntriesFn*: GetAndClearLogEntriesFn - getBalanceFn*: GetBalanceFn - getCodeFn*: GetCodeFn - getCodeHashFn*: GetCodeHashFn - getCodeSizeFn*: GetCodeSizeFn - getCommittedStorageFn*: GetCommittedStorageFn - getNonceFn*: GetNonceFn - getStorageFn*: GetStorageFn - getStorageRootFn*: GetStorageRootFn - getTransientStorageFn*: GetTransientStorageFn - contractCollisionFn*: ContractCollisionFn - inAccessListFn*: InAccessListFn - inAccessList2Fn*: InAccessList2Fn - incNonceFn*: IncNonceFn - isDeadAccountFn*: IsDeadAccountFn - isEmptyAccountFn*: IsEmptyAccountFn - isTopLevelCleanFn*: IsTopLevelCleanFn - logEntriesFn*: LogEntriesFn - makeMultiKeysFn*: MakeMultiKeysFn - persistFn*: PersistFn - ripemdSpecialFn*: RipemdSpecialFn - rollbackFn*: RollbackFn - safeDisposeFn*: SafeDisposeFn - selfDestruct6780Fn*: SelfDestruct6780Fn - selfDestructFn*: SelfDestructFn - selfDestructLenFn*: SelfDestructLenFn - setBalanceFn*: SetBalanceFn - setCodeFn*: SetCodeFn - setNonceFn*: SetNonceFn - setStorageFn*: SetStorageFn - setTransientStorageFn*: SetTransientStorageFn - stateFn*: StateFn - subBalanceFn*: SubBalanceFn - getAccessListFn*: GetAccessListFn + ac*: AccountsLedgerRef # End diff --git a/nimbus/db/ledger/base/validate.nim b/nimbus/db/ledger/base/validate.nim deleted file mode 100644 index 55a1443c1..000000000 --- a/nimbus/db/ledger/base/validate.nim +++ /dev/null @@ -1,68 +0,0 @@ -# Nimbus -# Copyright (c) 2023-2024 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or -# http://www.apache.org/licenses/LICENSE-2.0) -# * MIT license ([LICENSE-MIT](LICENSE-MIT) or -# http://opensource.org/licenses/MIT) -# at your option. This file may not be copied, modified, or distributed -# except according to those terms. - -{.push raises: [].} - -import - ./base_desc - -proc validate*(ldg: LedgerRef) = - doAssert ldg.ldgType != LedgerType(0) - - doAssert not ldg.extras.getMptFn.isNil - - doAssert not ldg.methods.accessListFn.isNil - doAssert not ldg.methods.accessList2Fn.isNil - doAssert not ldg.methods.accountExistsFn.isNil - doAssert not ldg.methods.addBalanceFn.isNil - doAssert not ldg.methods.addLogEntryFn.isNil - doAssert not ldg.methods.beginSavepointFn.isNil - doAssert not ldg.methods.clearStorageFn.isNil - doAssert not ldg.methods.clearTransientStorageFn.isNil - doAssert not ldg.methods.collectWitnessDataFn.isNil - doAssert not ldg.methods.commitFn.isNil - doAssert not ldg.methods.deleteAccountFn.isNil - doAssert not ldg.methods.disposeFn.isNil - doAssert not ldg.methods.getAccessListFn.isNil - doAssert not ldg.methods.getAndClearLogEntriesFn.isNil - doAssert not ldg.methods.getBalanceFn.isNil - doAssert not ldg.methods.getCodeFn.isNil - doAssert not ldg.methods.getCodeHashFn.isNil - doAssert not ldg.methods.getCodeSizeFn.isNil - doAssert not ldg.methods.getCommittedStorageFn.isNil - doAssert not ldg.methods.getNonceFn.isNil - doAssert not ldg.methods.getStorageFn.isNil - doAssert not ldg.methods.getStorageRootFn.isNil - doAssert not ldg.methods.getTransientStorageFn.isNil - doAssert not ldg.methods.contractCollisionFn.isNil - doAssert not ldg.methods.inAccessListFn.isNil - doAssert not ldg.methods.inAccessList2Fn.isNil - doAssert not ldg.methods.incNonceFn.isNil - doAssert not ldg.methods.isDeadAccountFn.isNil - doAssert not ldg.methods.isEmptyAccountFn.isNil - doAssert not ldg.methods.isTopLevelCleanFn.isNil - doAssert not ldg.methods.logEntriesFn.isNil - doAssert not ldg.methods.makeMultiKeysFn.isNil - doAssert not ldg.methods.persistFn.isNil - doAssert not ldg.methods.ripemdSpecialFn.isNil - doAssert not ldg.methods.rollbackFn.isNil - doAssert not ldg.methods.safeDisposeFn.isNil - doAssert not ldg.methods.selfDestruct6780Fn.isNil - doAssert not ldg.methods.selfDestructFn.isNil - doAssert not ldg.methods.selfDestructLenFn.isNil - doAssert not ldg.methods.setBalanceFn.isNil - doAssert not ldg.methods.setCodeFn.isNil - doAssert not ldg.methods.setNonceFn.isNil - doAssert not ldg.methods.setStorageFn.isNil - doAssert not ldg.methods.setTransientStorageFn.isNil - doAssert not ldg.methods.stateFn.isNil - doAssert not ldg.methods.subBalanceFn.isNil - -# End diff --git a/nimbus/db/ledger/base_iterators.nim b/nimbus/db/ledger/base_iterators.nim index 6269fbd74..dc4b1f6d0 100644 --- a/nimbus/db/ledger/base_iterators.nim +++ b/nimbus/db/ledger/base_iterators.nim @@ -13,7 +13,7 @@ import eth/common, ../core_db, - ./backend/[accounts_ledger, accounts_ledger_desc], + ./accounts_ledger, ./base/api_tracking, ./base @@ -32,45 +32,29 @@ when LedgerEnableApiTracking: iterator accounts*(ldg: LedgerRef): Account = ldg.beginTrackApi LdgAccountsIt - case ldg.ldgType: - of LedgerCache: - for w in ldg.AccountsLedgerRef.accountsIt(): - yield w - else: - raiseAssert: "Unsupported ledger type: " & $ldg.ldgType + for w in ldg.ac.accounts(): + yield w ldg.ifTrackApi: debug apiTxt, api, elapsed iterator addresses*(ldg: LedgerRef): EthAddress = ldg.beginTrackApi LdgAdressesIt - case ldg.ldgType: - of LedgerCache: - for w in ldg.AccountsLedgerRef.addressesIt(): - yield w - else: - raiseAssert: "Unsupported ledger type: " & $ldg.ldgType + for w in ldg.ac.addresses(): + yield w ldg.ifTrackApi: debug apiTxt, api, elapsed iterator cachedStorage*(ldg: LedgerRef, eAddr: EthAddress): (UInt256,UInt256) = ldg.beginTrackApi LdgCachedStorageIt - case ldg.ldgType: - of LedgerCache: - for w in ldg.AccountsLedgerRef.cachedStorageIt(eAddr): - yield w - else: - raiseAssert: "Unsupported ledger type: " & $ldg.ldgType + for w in ldg.ac.cachedStorage(eAddr): + yield w ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr iterator pairs*(ldg: LedgerRef): (EthAddress,Account) = ldg.beginTrackApi LdgPairsIt - case ldg.ldgType: - of LedgerCache: - for w in ldg.AccountsLedgerRef.pairsIt(): - yield w - else: - raiseAssert: "Unsupported ledger type: " & $ldg.ldgType + for w in ldg.ac.pairs(): + yield w ldg.ifTrackApi: debug apiTxt, api, elapsed @@ -79,12 +63,8 @@ iterator storage*( eAddr: EthAddress; ): (UInt256,UInt256) = ldg.beginTrackApi LdgStorageIt - case ldg.ldgType: - of LedgerCache: - for w in ldg.AccountsLedgerRef.storageIt(eAddr): - yield w - else: - raiseAssert: "Unsupported ledger type: " & $ldg.ldgType + for w in ldg.ac.storage(eAddr): + yield w ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr # ------------------------------------------------------------------------------ diff --git a/nimbus/evm/state.nim b/nimbus/evm/state.nim index 03dcc60c1..b07ae51af 100644 --- a/nimbus/evm/state.nim +++ b/nimbus/evm/state.nim @@ -75,7 +75,7 @@ proc new*( ## with the `parent` block header. new result result.init( - ac = com.ledgerType.init(com.db, parent.stateRoot), + ac = LedgerRef.init(com.db, parent.stateRoot), parent = parent, blockCtx = blockCtx, com = com, @@ -100,7 +100,7 @@ proc reinit*(self: BaseVMState; ## Object descriptor com = self.com db = com.db ac = if self.stateDB.rootHash == parent.stateRoot: self.stateDB - else: com.ledgerType.init(db, parent.stateRoot) + else: LedgerRef.init(db, parent.stateRoot) flags = self.flags self[].reset self.init( @@ -157,7 +157,7 @@ proc init*( ## It requires the `header` argument properly initalised so that for PoA ## networks, the miner address is retrievable via `ecRecover()`. self.init( - ac = com.ledgerType.init(com.db, parent.stateRoot), + ac = LedgerRef.init(com.db, parent.stateRoot), parent = parent, blockCtx = com.blockCtx(header), com = com, diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index 2a2188f2d..970cd5ea5 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -169,7 +169,7 @@ proc traceTransaction*(com: CommonRef, header: BlockHeader, # internal transactions: let saveCtxBefore = setCtx beforeCtx - stateBefore = AccountsLedgerRef.init(capture.recorder, beforeRoot) + stateBefore = LedgerRef.init(capture.recorder, beforeRoot) defer: saveCtxBefore.setCtx().ctx.forget() @@ -208,7 +208,7 @@ proc dumpBlockState*(com: CommonRef, header: BlockHeader, body: BlockBody, dumpS var before = newJArray() after = newJArray() - stateBefore = AccountsLedgerRef.init(capture.recorder, parent.stateRoot) + stateBefore = LedgerRef.init(capture.recorder, parent.stateRoot) for idx, tx in body.transactions: let sender = tx.getSender diff --git a/stateless/test_block_witness.nim b/stateless/test_block_witness.nim index f0b5e63ce..9b02a7cc8 100644 --- a/stateless/test_block_witness.nim +++ b/stateless/test_block_witness.nim @@ -88,7 +88,7 @@ proc setupStateDB(tester: var Tester, wantedState: JsonNode, stateDB: LedgerRef) proc testBlockWitness(node: JsonNode, rootHash: Hash256, testStatusIMPL: var TestStatus) = var tester = Tester(memDB: newCoreDbRef(DefaultDbMemory)) - ac = LedgerCache.init(tester.memDB, emptyRlpHash) + ac = LedgerRef.init(tester.memDB, emptyRlpHash) let root = tester.setupStateDB(node, ac) if rootHash != emptyRlpHash: diff --git a/stateless/test_witness_verification.nim b/stateless/test_witness_verification.nim index 376e450fa..0b89bbce6 100644 --- a/stateless/test_witness_verification.nim +++ b/stateless/test_witness_verification.nim @@ -52,7 +52,7 @@ proc buildWitness( let coreDb = newCoreDbRef(DefaultDbMemory) - accountsCache = LedgerCache.init(coreDb, emptyRlpHash) + accountsCache = LedgerRef.init(coreDb, emptyRlpHash) (rootHash, multiKeys) = setupStateDB(genAccounts, accountsCache) var wb = initWitnessBuilder(coreDb, rootHash, {wfNoFlag}) diff --git a/tests/test_blockchain_json.nim b/tests/test_blockchain_json.nim index 2591d2fc1..ad61f4d7c 100644 --- a/tests/test_blockchain_json.nim +++ b/tests/test_blockchain_json.nim @@ -373,7 +373,7 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal let memDB = newCoreDbRef DefaultDbMemory - stateDB = LedgerCache.init(memDB, emptyRlpHash) + stateDB = LedgerRef.init(memDB, emptyRlpHash) config = getChainConfig(ctx.network) com = CommonRef.new(memDB, config) @@ -403,7 +403,7 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal elif lastBlockHash == ctx.lastBlockHash: # multiple chain, we are using the last valid canonical # state root to test against 'postState' - let stateDB = LedgerCache.init(memDB, header.stateRoot) + let stateDB = LedgerRef.init(memDB, header.stateRoot) verifyStateDB(fixture["postState"], ledger.ReadOnlyStateDB(stateDB)) success = lastBlockHash == ctx.lastBlockHash diff --git a/tests/test_coredb.nim b/tests/test_coredb.nim index d713418a4..ccf23cde3 100644 --- a/tests/test_coredb.nim +++ b/tests/test_coredb.nim @@ -17,7 +17,6 @@ import results, unittest2, ../nimbus/db/core_db/persistent, - ../nimbus/db/ledger, ../nimbus/core/chain, ./replay/pp, ./test_coredb/[coredb_test_xx, test_chainsync, test_helpers] @@ -34,7 +33,6 @@ const sampleDirRefFile = "coredb_test_xx.nim" dbTypeDefault = AristoDbMemory - ldgTypeDefault = LedgerCache let # Standard test sample @@ -152,9 +150,7 @@ proc setErrorLevel {.used.} = proc initRunnerDB( path: string; specs: CaptureSpecs; - dbType: CoreDbType; - ldgType: LedgerType; - ): CommonRef = + dbType: CoreDbType): CommonRef = let coreDB = # Resolve for static `dbType` case dbType: @@ -181,8 +177,7 @@ proc initRunnerDB( result = CommonRef.new( db = coreDB, networkId = networkId, - params = params, - ldgType = ldgType) + params = params) result.initializeEmptyDb @@ -199,7 +194,6 @@ proc chainSyncRunner( noisy = true; capture = memorySampleDefault; dbType = CoreDbType(0); - ldgType = ldgTypeDefault; profilingOk = false; finalDiskCleanUpOk = true; enaLoggingOk = false; @@ -231,11 +225,11 @@ proc chainSyncRunner( defer: if persistent: baseDir.flushDbDir - suite &"CoreDB and LedgerRef API on {fileInfo}, {dbType}, {ldgType}": + suite &"CoreDB and LedgerRef API on {fileInfo}, {dbType}": - test &"Ledger API {ldgType}, {numBlocksInfo} blocks": + test &"Ledger API {numBlocksInfo} blocks": let - com = initRunnerDB(dbDir, capture, dbType, ldgType) + com = initRunnerDB(dbDir, capture, dbType) defer: com.db.finish(flush = finalDiskCleanUpOk) if profilingOk: noisy.test_chainSyncProfilingPrint numBlocks @@ -254,7 +248,6 @@ proc persistentSyncPreLoadAndResumeRunner( noisy = true; capture = persistentSampleDefault; dbType = CoreDbType(0); - ldgType = ldgTypeDefault; profilingOk = false; finalDiskCleanUpOk = true; enaLoggingOk = false; @@ -290,7 +283,7 @@ proc persistentSyncPreLoadAndResumeRunner( test "Populate db by initial sample parts": let - com = initRunnerDB(dbDir, capture, dbType, ldgType) + com = initRunnerDB(dbDir, capture, dbType) defer: com.db.finish(flush = finalDiskCleanUpOk) if profilingOk: noisy.test_chainSyncProfilingPrint firstPart @@ -305,7 +298,7 @@ proc persistentSyncPreLoadAndResumeRunner( test &"Continue with rest of sample": let - com = initRunnerDB(dbDir, capture, dbType, ldgType) + com = initRunnerDB(dbDir, capture, dbType) defer: com.db.finish(flush = finalDiskCleanUpOk) if profilingOk: noisy.test_chainSyncProfilingPrint secndPart diff --git a/tests/test_coredb/test_chainsync.nim b/tests/test_coredb/test_chainsync.nim index d84e48c15..2b4e18179 100644 --- a/tests/test_coredb/test_chainsync.nim +++ b/tests/test_coredb/test_chainsync.nim @@ -19,9 +19,6 @@ import ../replay/[pp, undump_blocks, undump_blocks_era1, xcheck], ./test_helpers -type - StopMoaningAboutLedger {.used.} = LedgerType - when CoreDbEnableApiProfiling: import std/sequtils, diff --git a/tests/test_getproof_json.nim b/tests/test_getproof_json.nim index f4b5dd786..e6c08deba 100644 --- a/tests/test_getproof_json.nim +++ b/tests/test_getproof_json.nim @@ -135,7 +135,7 @@ proc getProofJsonMain*() = let accounts = getGenesisAlloc("tests" / "customgenesis" / file) coreDb = newCoreDbRef(DefaultDbMemory) - accountsCache = LedgerCache.init(coreDb, emptyRlpHash) + accountsCache = LedgerRef.init(coreDb, emptyRlpHash) stateRootHash = setupStateDB(accounts, accountsCache) accountDb = newAccountStateDB(coreDb, stateRootHash) readOnlyDb = ReadOnlyStateDB(accountDb) @@ -148,7 +148,7 @@ proc getProofJsonMain*() = let accounts = getGenesisAlloc("tests" / "customgenesis" / file) coreDb = newCoreDbRef(DefaultDbMemory) - accountsCache = LedgerCache.init(coreDb, emptyRlpHash) + accountsCache = LedgerRef.init(coreDb, emptyRlpHash) stateRootHash = setupStateDB(accounts, accountsCache) accountDb = newAccountStateDB(coreDb, stateRootHash) readOnlyDb = ReadOnlyStateDB(accountDb) diff --git a/tests/test_rpc_experimental_json.nim b/tests/test_rpc_experimental_json.nim index 38692a99d..2fbe3204f 100644 --- a/tests/test_rpc_experimental_json.nim +++ b/tests/test_rpc_experimental_json.nim @@ -64,7 +64,7 @@ proc checkAndValidateWitnessAgainstProofs( proofs: seq[ProofResponse]) = let - stateDB = LedgerCache.init(db, parentStateRoot) + stateDB = LedgerRef.init(db, parentStateRoot) verifyWitnessResult = verifyWitness(expectedStateRoot, witness, {wfNoFlag}) check verifyWitnessResult.isOk()