Simplify AccountsLedgerRef complexity (#2239)

This commit is contained in:
andri lim 2024-05-29 18:06:49 +07:00 committed by GitHub
parent 9d9aa738db
commit eaf3d9897e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 98 additions and 609 deletions

View File

@ -53,7 +53,7 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
) )
t.chainRef = newChain(t.com, extraValidation = true) t.chainRef = newChain(t.com, extraValidation = true)
let let
stateDB = LedgerCache.init(memDB, emptyRlpHash) stateDB = LedgerRef.init(memDB, emptyRlpHash)
genesisHeader = node.genesisHeader genesisHeader = node.genesisHeader
setupStateDB(node["pre"], stateDB) setupStateDB(node["pre"], stateDB)

View File

@ -94,9 +94,6 @@ type
pos: CasperRef pos: CasperRef
## Proof Of Stake descriptor ## Proof Of Stake descriptor
ldgType: LedgerType
## Optional suggestion for the ledger cache to be used as state DB
pruneHistory: bool pruneHistory: bool
## Must not not set for a full node, might go away some time ## Must not not set for a full node, might go away some time
@ -140,7 +137,6 @@ proc init(com : CommonRef,
networkId : NetworkId, networkId : NetworkId,
config : ChainConfig, config : ChainConfig,
genesis : Genesis, genesis : Genesis,
ldgType : LedgerType,
pruneHistory: bool, pruneHistory: bool,
) {.gcsafe, raises: [CatchableError].} = ) {.gcsafe, raises: [CatchableError].} =
@ -151,7 +147,6 @@ proc init(com : CommonRef,
com.forkTransitionTable = config.toForkTransitionTable() com.forkTransitionTable = config.toForkTransitionTable()
com.networkId = networkId com.networkId = networkId
com.syncProgress= SyncProgress() com.syncProgress= SyncProgress()
com.ldgType = (if ldgType == LedgerType(0): LedgerCache else: ldgType)
com.pruneHistory= pruneHistory com.pruneHistory= pruneHistory
# Always initialise the PoW epoch cache even though it migh no be used # 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 # Must not overwrite the global state on the single state DB
if not db.getBlockHeader(0.toBlockNumber, com.genesisHeader): if not db.getBlockHeader(0.toBlockNumber, com.genesisHeader):
com.genesisHeader = toGenesisHeader(genesis, com.genesisHeader = toGenesisHeader(genesis,
com.currentFork, com.db, com.ldgType) com.currentFork, com.db)
com.setForkId(com.genesisHeader) com.setForkId(com.genesisHeader)
com.pos.timestamp = genesis.timestamp com.pos.timestamp = genesis.timestamp
@ -218,7 +213,6 @@ proc new*(
db: CoreDbRef; db: CoreDbRef;
networkId: NetworkId = MainNet; networkId: NetworkId = MainNet;
params = networkParams(MainNet); params = networkParams(MainNet);
ldgType = LedgerType(0);
pruneHistory = false; pruneHistory = false;
): CommonRef ): CommonRef
{.gcsafe, raises: [CatchableError].} = {.gcsafe, raises: [CatchableError].} =
@ -231,7 +225,6 @@ proc new*(
networkId, networkId,
params.config, params.config,
params.genesis, params.genesis,
ldgType,
pruneHistory) pruneHistory)
proc new*( proc new*(
@ -239,7 +232,6 @@ proc new*(
db: CoreDbRef; db: CoreDbRef;
config: ChainConfig; config: ChainConfig;
networkId: NetworkId = MainNet; networkId: NetworkId = MainNet;
ldgType = LedgerType(0);
pruneHistory = false; pruneHistory = false;
): CommonRef ): CommonRef
{.gcsafe, raises: [CatchableError].} = {.gcsafe, raises: [CatchableError].} =
@ -252,7 +244,6 @@ proc new*(
networkId, networkId,
config, config,
nil, nil,
ldgType,
pruneHistory) pruneHistory)
proc clone*(com: CommonRef, db: CoreDbRef): CommonRef = proc clone*(com: CommonRef, db: CoreDbRef): CommonRef =
@ -271,7 +262,6 @@ proc clone*(com: CommonRef, db: CoreDbRef): CommonRef =
consensusType: com.consensusType, consensusType: com.consensusType,
pow : com.pow, pow : com.pow,
pos : com.pos, pos : com.pos,
ldgType : com.ldgType,
pruneHistory : com.pruneHistory) pruneHistory : com.pruneHistory)
proc clone*(com: CommonRef): CommonRef = proc clone*(com: CommonRef): CommonRef =
@ -482,9 +472,6 @@ func syncHighest*(com: CommonRef): BlockNumber =
func syncReqRelaxV2*(com: CommonRef): bool = func syncReqRelaxV2*(com: CommonRef): bool =
com.syncReqRelaxV2 com.syncReqRelaxV2
func ledgerType*(com: CommonRef): LedgerType =
com.ldgType
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Setters # Setters
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -53,7 +53,7 @@ proc initAccountsLedgerRef(
db: CoreDbRef; db: CoreDbRef;
): GenesisLedgerRef = ): GenesisLedgerRef =
## Methods jump table ## Methods jump table
let ac = LedgerCache.init(db, EMPTY_ROOT_HASH) let ac = LedgerRef.init(db, EMPTY_ROOT_HASH)
GenesisLedgerRef( GenesisLedgerRef(
addAccount: proc( addAccount: proc(
@ -77,7 +77,7 @@ proc initAccountsLedgerRef(
ac.persist(), ac.persist(),
rootHash: proc(): Hash256 = rootHash: proc(): Hash256 =
ac.rootHash(), ac.state(),
getTrie: proc(): CoreDbMptRef = getTrie: proc(): CoreDbMptRef =
ac.getMpt()) ac.getMpt())
@ -88,10 +88,7 @@ proc initAccountsLedgerRef(
proc newStateDB*( proc newStateDB*(
db: CoreDbRef; db: CoreDbRef;
ledgerType: LedgerType;
): GenesisLedgerRef = ): GenesisLedgerRef =
## Currently only `LedgerCache` supported for `ledgerType`.
doAssert ledgerType == LedgerCache
db.initAccountsLedgerRef() db.initAccountsLedgerRef()
proc getTrie*(sdb: GenesisLedgerRef): CoreDbMptRef = proc getTrie*(sdb: GenesisLedgerRef): CoreDbMptRef =
@ -155,28 +152,25 @@ proc toGenesisHeader*(
proc toGenesisHeader*( proc toGenesisHeader*(
genesis: Genesis; genesis: Genesis;
fork: HardFork; fork: HardFork;
db = CoreDbRef(nil); db = CoreDbRef(nil)): BlockHeader
ledgerType = LedgerCache;
): BlockHeader
{.gcsafe, raises: [CatchableError].} = {.gcsafe, raises: [CatchableError].} =
## Generate the genesis block header from the `genesis` and `config` ## Generate the genesis block header from the `genesis` and `config`
## argument value. ## argument value.
let let
db = if db.isNil: AristoDbMemory.newCoreDbRef() else: db db = if db.isNil: AristoDbMemory.newCoreDbRef() else: db
sdb = db.newStateDB(ledgerType) sdb = db.newStateDB()
toGenesisHeader(genesis, sdb, fork) toGenesisHeader(genesis, sdb, fork)
proc toGenesisHeader*( proc toGenesisHeader*(
params: NetworkParams; params: NetworkParams;
db = CoreDbRef(nil); db = CoreDbRef(nil)
ledgerType = LedgerCache;
): BlockHeader ): BlockHeader
{.raises: [CatchableError].} = {.raises: [CatchableError].} =
## Generate the genesis block header from the `genesis` and `config` ## Generate the genesis block header from the `genesis` and `config`
## argument value. ## argument value.
let map = toForkTransitionTable(params.config) let map = toForkTransitionTable(params.config)
let fork = map.toHardFork(forkDeterminationInfo(0.toBlockNumber, params.genesis.timestamp)) let fork = map.toHardFork(forkDeterminationInfo(0.toBlockNumber, params.genesis.timestamp))
toGenesisHeader(params.genesis, fork, db, ledgerType) toGenesisHeader(params.genesis, fork, db)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# End # End

View File

@ -123,7 +123,7 @@ proc update(dh: TxChainRef; parent: BlockHeader)
let let
timestamp = dh.getTimestamp(parent) timestamp = dh.getTimestamp(parent)
db = dh.com.db 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): fee = if dh.com.isLondon(parent.blockNumber + 1, timestamp):
some(dh.com.baseFeeGet(parent).uint64.u256) some(dh.com.baseFeeGet(parent).uint64.u256)
else: else:

View File

@ -18,15 +18,13 @@
import import
eth/common, eth/common,
./core_db, ./core_db,
./ledger/backend/[accounts_ledger, accounts_ledger_desc], ./ledger/[base_iterators, distinct_ledgers, accounts_ledger]
./ledger/[base_iterators, distinct_ledgers]
import import
./ledger/base except LedgerApiTxt, beginTrackApi, bless, ifTrackApi ./ledger/base except LedgerApiTxt, beginTrackApi, bless, ifTrackApi
export export
AccountsLedgerRef, AccountsLedgerRef,
LedgerType,
base, base,
base_iterators, base_iterators,
distinct_ledgers, distinct_ledgers,
@ -36,17 +34,8 @@ export
# Public constructor # Public constructor
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc init*( proc init*(_: type LedgerRef, db: CoreDbRef; root: Hash256): LedgerRef =
ldgType: LedgerType; LedgerRef(ac: AccountsLedgerRef.init(db, root)).bless(db)
db: CoreDbRef;
root: Hash256;
): LedgerRef =
case ldgType:
of LedgerCache:
AccountsLedgerRef.init(db, root)
else:
raiseAssert: "Missing ledger type label"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# End # End

View File

@ -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
# ------------------------------------------------------------------------------

View File

@ -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

View File

@ -19,9 +19,6 @@ import
./base/[api_tracking, base_desc] ./base/[api_tracking, base_desc]
const const
AutoValidateDescriptors = defined(release).not
## No validatinon needed for production suite.
EnableApiTracking = false EnableApiTracking = false
## When enabled, API functions are logged. Tracking is enabled by setting ## When enabled, API functions are logged. Tracking is enabled by setting
## the `trackApi` flag to `true`. ## the `trackApi` flag to `true`.
@ -38,7 +35,6 @@ type
export export
LedgerFnInx, LedgerFnInx,
LedgerProfListRef, LedgerProfListRef,
LedgerType,
LedgerRef, LedgerRef,
LedgerSpRef LedgerSpRef
@ -47,9 +43,6 @@ const
LedgerEnableApiProfiling* = EnableApiTracking and EnableApiProfiling LedgerEnableApiProfiling* = EnableApiTracking and EnableApiProfiling
LedgerApiTxt* = apiTxt LedgerApiTxt* = apiTxt
when AutoValidateDescriptors:
import ./base/validate
proc ldgProfData*(db: CoreDbRef): LedgerProfListRef {.gcsafe.} proc ldgProfData*(db: CoreDbRef): LedgerProfListRef {.gcsafe.}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -88,8 +81,6 @@ template ifTrackApi*(ldg: LedgerRef; code: untyped) =
proc bless*(ldg: LedgerRef; db: CoreDbRef): LedgerRef = proc bless*(ldg: LedgerRef; db: CoreDbRef): LedgerRef =
ldg.beginTrackApi LdgBlessFn ldg.beginTrackApi LdgBlessFn
when AutoValidateDescriptors:
ldg.validate()
when EnableApiTracking: when EnableApiTracking:
ldg.trackApi = db.trackLedgerApi ldg.trackApi = db.trackLedgerApi
when LedgerEnableApiProfiling: when LedgerEnableApiProfiling:
@ -116,87 +107,87 @@ proc ldgProfData*(db: CoreDbRef): LedgerProfListRef =
proc accessList*(ldg: LedgerRef, eAddr: EthAddress) = proc accessList*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgAccessListFn ldg.beginTrackApi LdgAccessListFn
ldg.methods.accessListFn eAddr ldg.ac.accessList(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
proc accessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256) = proc accessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256) =
ldg.beginTrackApi LdgAccessListFn ldg.beginTrackApi LdgAccessListFn
ldg.methods.accessList2Fn(eAddr, slot) ldg.ac.accessList(eAddr, slot)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot
proc accountExists*(ldg: LedgerRef, eAddr: EthAddress): bool = proc accountExists*(ldg: LedgerRef, eAddr: EthAddress): bool =
ldg.beginTrackApi LdgAccountExistsFn ldg.beginTrackApi LdgAccountExistsFn
result = ldg.methods.accountExistsFn eAddr result = ldg.ac.accountExists(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc addBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) = proc addBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
ldg.beginTrackApi LdgAddBalanceFn ldg.beginTrackApi LdgAddBalanceFn
ldg.methods.addBalanceFn(eAddr, delta) ldg.ac.addBalance(eAddr, delta)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta
proc addLogEntry*(ldg: LedgerRef, log: Log) = proc addLogEntry*(ldg: LedgerRef, log: Log) =
ldg.beginTrackApi LdgAddLogEntryFn ldg.beginTrackApi LdgAddLogEntryFn
ldg.methods.addLogEntryFn log ldg.ac.addLogEntry(log)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc beginSavepoint*(ldg: LedgerRef): LedgerSpRef = proc beginSavepoint*(ldg: LedgerRef): LedgerSpRef =
ldg.beginTrackApi LdgBeginSavepointFn ldg.beginTrackApi LdgBeginSavepointFn
result = ldg.methods.beginSavepointFn() result = ldg.ac.beginSavepoint()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc clearStorage*(ldg: LedgerRef, eAddr: EthAddress) = proc clearStorage*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgClearStorageFn ldg.beginTrackApi LdgClearStorageFn
ldg.methods.clearStorageFn eAddr ldg.ac.clearStorage(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
proc clearTransientStorage*(ldg: LedgerRef) = proc clearTransientStorage*(ldg: LedgerRef) =
ldg.beginTrackApi LdgClearTransientStorageFn ldg.beginTrackApi LdgClearTransientStorageFn
ldg.methods.clearTransientStorageFn() ldg.ac.clearTransientStorage()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc collectWitnessData*(ldg: LedgerRef) = proc collectWitnessData*(ldg: LedgerRef) =
ldg.beginTrackApi LdgCollectWitnessDataFn ldg.beginTrackApi LdgCollectWitnessDataFn
ldg.methods.collectWitnessDataFn() ldg.ac.collectWitnessData()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc commit*(ldg: LedgerRef, sp: LedgerSpRef) = proc commit*(ldg: LedgerRef, sp: LedgerSpRef) =
ldg.beginTrackApi LdgCommitFn ldg.beginTrackApi LdgCommitFn
ldg.methods.commitFn sp ldg.ac.commit(sp)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc deleteAccount*(ldg: LedgerRef, eAddr: EthAddress) = proc deleteAccount*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgDeleteAccountFn ldg.beginTrackApi LdgDeleteAccountFn
ldg.methods.deleteAccountFn eAddr ldg.ac.deleteAccount(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
proc dispose*(ldg: LedgerRef, sp: LedgerSpRef) = proc dispose*(ldg: LedgerRef, sp: LedgerSpRef) =
ldg.beginTrackApi LdgDisposeFn ldg.beginTrackApi LdgDisposeFn
ldg.methods.disposeFn sp ldg.ac.dispose(sp)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc getAndClearLogEntries*(ldg: LedgerRef): seq[Log] = proc getAndClearLogEntries*(ldg: LedgerRef): seq[Log] =
ldg.beginTrackApi LdgGetAndClearLogEntriesFn ldg.beginTrackApi LdgGetAndClearLogEntriesFn
result = ldg.methods.getAndClearLogEntriesFn() result = ldg.ac.getAndClearLogEntries()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc getBalance*(ldg: LedgerRef, eAddr: EthAddress): UInt256 = proc getBalance*(ldg: LedgerRef, eAddr: EthAddress): UInt256 =
ldg.beginTrackApi LdgGetBalanceFn ldg.beginTrackApi LdgGetBalanceFn
result = ldg.methods.getBalanceFn eAddr result = ldg.ac.getBalance(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc getCode*(ldg: LedgerRef, eAddr: EthAddress): Blob = proc getCode*(ldg: LedgerRef, eAddr: EthAddress): Blob =
ldg.beginTrackApi LdgGetCodeFn ldg.beginTrackApi LdgGetCodeFn
result = ldg.methods.getCodeFn eAddr result = ldg.ac.getCode(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result=result.toStr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result=result.toStr
proc getCodeHash*(ldg: LedgerRef, eAddr: EthAddress): Hash256 = proc getCodeHash*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
ldg.beginTrackApi LdgGetCodeHashFn ldg.beginTrackApi LdgGetCodeHashFn
result = ldg.methods.getCodeHashFn eAddr result = ldg.ac.getCodeHash(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc getCodeSize*(ldg: LedgerRef, eAddr: EthAddress): int = proc getCodeSize*(ldg: LedgerRef, eAddr: EthAddress): int =
ldg.beginTrackApi LdgGetCodeSizeFn ldg.beginTrackApi LdgGetCodeSizeFn
result = ldg.methods.getCodeSizeFn eAddr result = ldg.ac.getCodeSize(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc getCommittedStorage*( proc getCommittedStorage*(
@ -205,22 +196,22 @@ proc getCommittedStorage*(
slot: UInt256; slot: UInt256;
): UInt256 = ): UInt256 =
ldg.beginTrackApi LdgGetCommittedStorageFn ldg.beginTrackApi LdgGetCommittedStorageFn
result = ldg.methods.getCommittedStorageFn(eAddr, slot) result = ldg.ac.getCommittedStorage(eAddr, slot)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
proc getNonce*(ldg: LedgerRef, eAddr: EthAddress): AccountNonce = proc getNonce*(ldg: LedgerRef, eAddr: EthAddress): AccountNonce =
ldg.beginTrackApi LdgGetNonceFn ldg.beginTrackApi LdgGetNonceFn
result = ldg.methods.getNonceFn eAddr result = ldg.ac.getNonce(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc getStorage*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): UInt256 = proc getStorage*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): UInt256 =
ldg.beginTrackApi LdgGetStorageFn ldg.beginTrackApi LdgGetStorageFn
result = ldg.methods.getStorageFn(eAddr, slot) result = ldg.ac.getStorage(eAddr, slot)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
proc getStorageRoot*(ldg: LedgerRef, eAddr: EthAddress): Hash256 = proc getStorageRoot*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
ldg.beginTrackApi LdgGetStorageRootFn ldg.beginTrackApi LdgGetStorageRootFn
result = ldg.methods.getStorageRootFn eAddr result = ldg.ac.getStorageRoot(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc getTransientStorage*( proc getTransientStorage*(
@ -229,107 +220,107 @@ proc getTransientStorage*(
slot: UInt256; slot: UInt256;
): UInt256 = ): UInt256 =
ldg.beginTrackApi LdgGetTransientStorageFn ldg.beginTrackApi LdgGetTransientStorageFn
result = ldg.methods.getTransientStorageFn(eAddr, slot) result = ldg.ac.getTransientStorage(eAddr, slot)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
proc contractCollision*(ldg: LedgerRef, eAddr: EthAddress): bool = proc contractCollision*(ldg: LedgerRef, eAddr: EthAddress): bool =
ldg.beginTrackApi LdgContractCollisionFn ldg.beginTrackApi LdgContractCollisionFn
result = ldg.methods.contractCollisionFn eAddr result = ldg.ac.contractCollision(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress): bool = proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress): bool =
ldg.beginTrackApi LdgInAccessListFn ldg.beginTrackApi LdgInAccessListFn
result = ldg.methods.inAccessListFn eAddr result = ldg.ac.inAccessList(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): bool = proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): bool =
ldg.beginTrackApi LdgInAccessListFn ldg.beginTrackApi LdgInAccessListFn
result = ldg.methods.inAccessList2Fn(eAddr, slot) result = ldg.ac.inAccessList(eAddr, slot)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
proc incNonce*(ldg: LedgerRef, eAddr: EthAddress) = proc incNonce*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgIncNonceFn ldg.beginTrackApi LdgIncNonceFn
ldg.methods.incNonceFn eAddr ldg.ac.incNonce(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
proc isDeadAccount*(ldg: LedgerRef, eAddr: EthAddress): bool = proc isDeadAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
ldg.beginTrackApi LdgIsDeadAccountFn ldg.beginTrackApi LdgIsDeadAccountFn
result = ldg.methods.isDeadAccountFn eAddr result = ldg.ac.isDeadAccount(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc isEmptyAccount*(ldg: LedgerRef, eAddr: EthAddress): bool = proc isEmptyAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
ldg.beginTrackApi LdgIsEmptyAccountFn ldg.beginTrackApi LdgIsEmptyAccountFn
result = ldg.methods.isEmptyAccountFn eAddr result = ldg.ac.isEmptyAccount(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
proc isTopLevelClean*(ldg: LedgerRef): bool = proc isTopLevelClean*(ldg: LedgerRef): bool =
ldg.beginTrackApi LdgIsTopLevelCleanFn ldg.beginTrackApi LdgIsTopLevelCleanFn
result = ldg.methods.isTopLevelCleanFn() result = ldg.ac.isTopLevelClean()
ldg.ifTrackApi: debug apiTxt, api, elapsed, result ldg.ifTrackApi: debug apiTxt, api, elapsed, result
proc logEntries*(ldg: LedgerRef): seq[Log] = proc logEntries*(ldg: LedgerRef): seq[Log] =
ldg.beginTrackApi LdgLogEntriesFn ldg.beginTrackApi LdgLogEntriesFn
result = ldg.methods.logEntriesFn() result = ldg.ac.logEntries()
ldg.ifTrackApi: debug apiTxt, api, elapsed, result ldg.ifTrackApi: debug apiTxt, api, elapsed, result
proc makeMultiKeys*(ldg: LedgerRef): MultiKeysRef = proc makeMultiKeys*(ldg: LedgerRef): MultiKeysRef =
ldg.beginTrackApi LdgMakeMultiKeysFn ldg.beginTrackApi LdgMakeMultiKeysFn
result = ldg.methods.makeMultiKeysFn() result = ldg.ac.makeMultiKeys()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc persist*(ldg: LedgerRef, clearEmptyAccount = false, clearCache = true) = proc persist*(ldg: LedgerRef, clearEmptyAccount = false, clearCache = true) =
ldg.beginTrackApi LdgPersistFn ldg.beginTrackApi LdgPersistFn
ldg.methods.persistFn(clearEmptyAccount, clearCache) ldg.ac.persist(clearEmptyAccount, clearCache)
ldg.ifTrackApi: debug apiTxt, api, elapsed, clearEmptyAccount, clearCache ldg.ifTrackApi: debug apiTxt, api, elapsed, clearEmptyAccount, clearCache
proc ripemdSpecial*(ldg: LedgerRef) = proc ripemdSpecial*(ldg: LedgerRef) =
ldg.beginTrackApi LdgRipemdSpecialFn ldg.beginTrackApi LdgRipemdSpecialFn
ldg.methods.ripemdSpecialFn() ldg.ac.ripemdSpecial()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc rollback*(ldg: LedgerRef, sp: LedgerSpRef) = proc rollback*(ldg: LedgerRef, sp: LedgerSpRef) =
ldg.beginTrackApi LdgRollbackFn ldg.beginTrackApi LdgRollbackFn
ldg.methods.rollbackFn sp ldg.ac.rollback(sp)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc safeDispose*(ldg: LedgerRef, sp: LedgerSpRef) = proc safeDispose*(ldg: LedgerRef, sp: LedgerSpRef) =
ldg.beginTrackApi LdgSafeDisposeFn ldg.beginTrackApi LdgSafeDisposeFn
ldg.methods.safeDisposeFn sp ldg.ac.safeDispose(sp)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc selfDestruct*(ldg: LedgerRef, eAddr: EthAddress) = proc selfDestruct*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgSelfDestructFn ldg.beginTrackApi LdgSelfDestructFn
ldg.methods.selfDestructFn eAddr ldg.ac.selfDestruct(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc selfDestruct6780*(ldg: LedgerRef, eAddr: EthAddress) = proc selfDestruct6780*(ldg: LedgerRef, eAddr: EthAddress) =
ldg.beginTrackApi LdgSelfDestruct6780Fn ldg.beginTrackApi LdgSelfDestruct6780Fn
ldg.methods.selfDestruct6780Fn eAddr ldg.ac.selfDestruct6780(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
proc selfDestructLen*(ldg: LedgerRef): int = proc selfDestructLen*(ldg: LedgerRef): int =
ldg.beginTrackApi LdgSelfDestructLenFn ldg.beginTrackApi LdgSelfDestructLenFn
result = ldg.methods.selfDestructLenFn() result = ldg.ac.selfDestructLen()
ldg.ifTrackApi: debug apiTxt, api, elapsed, result ldg.ifTrackApi: debug apiTxt, api, elapsed, result
proc setBalance*(ldg: LedgerRef, eAddr: EthAddress, balance: UInt256) = proc setBalance*(ldg: LedgerRef, eAddr: EthAddress, balance: UInt256) =
ldg.beginTrackApi LdgSetBalanceFn ldg.beginTrackApi LdgSetBalanceFn
ldg.methods.setBalanceFn(eAddr, balance) ldg.ac.setBalance(eAddr, balance)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, balance ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, balance
proc setCode*(ldg: LedgerRef, eAddr: EthAddress, code: Blob) = proc setCode*(ldg: LedgerRef, eAddr: EthAddress, code: Blob) =
ldg.beginTrackApi LdgSetCodeFn ldg.beginTrackApi LdgSetCodeFn
ldg.methods.setCodeFn(eAddr, code) ldg.ac.setCode(eAddr, code)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, code=code.toStr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, code=code.toStr
proc setNonce*(ldg: LedgerRef, eAddr: EthAddress, nonce: AccountNonce) = proc setNonce*(ldg: LedgerRef, eAddr: EthAddress, nonce: AccountNonce) =
ldg.beginTrackApi LdgSetNonceFn ldg.beginTrackApi LdgSetNonceFn
ldg.methods.setNonceFn(eAddr, nonce) ldg.ac.setNonce(eAddr, nonce)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, nonce ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, nonce
proc setStorage*(ldg: LedgerRef, eAddr: EthAddress, slot, val: UInt256) = proc setStorage*(ldg: LedgerRef, eAddr: EthAddress, slot, val: UInt256) =
ldg.beginTrackApi LdgSetStorageFn ldg.beginTrackApi LdgSetStorageFn
ldg.methods.setStorageFn(eAddr, slot, val) ldg.ac.setStorage(eAddr, slot, val)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val
proc setTransientStorage*( proc setTransientStorage*(
@ -339,44 +330,37 @@ proc setTransientStorage*(
val: UInt256; val: UInt256;
) = ) =
ldg.beginTrackApi LdgSetTransientStorageFn ldg.beginTrackApi LdgSetTransientStorageFn
ldg.methods.setTransientStorageFn(eAddr, slot, val) ldg.ac.setTransientStorage(eAddr, slot, val)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val
proc state*(ldg: LedgerRef): Hash256 = proc state*(ldg: LedgerRef): Hash256 =
ldg.beginTrackApi LdgStateFn ldg.beginTrackApi LdgStateFn
result = ldg.methods.stateFn() result = ldg.ac.state()
ldg.ifTrackApi: debug apiTxt, api, elapsed, result ldg.ifTrackApi: debug apiTxt, api, elapsed, result
proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) = proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
ldg.beginTrackApi LdgSubBalanceFn ldg.beginTrackApi LdgSubBalanceFn
ldg.methods.subBalanceFn(eAddr, delta) ldg.ac.subBalance(eAddr, delta)
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta
proc getAccessList*(ldg: LedgerRef): AccessList = proc getAccessList*(ldg: LedgerRef): AccessList =
ldg.beginTrackApi LdgGetAccessListFn ldg.beginTrackApi LdgGetAccessListFn
result = ldg.methods.getAccessListFn() result = ldg.ac.getAccessList()
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
# ------------------------------------------------------------------------------ proc rootHash*(ldg: LedgerRef): KeccakHash =
# Public methods, extensions to go away ldg.state()
# ------------------------------------------------------------------------------
proc rootHash*(ldg: LedgerRef): Hash256 =
## Replaced by `state()`
ldg.beginTrackApi LdgRootHashFn
result = ldg.methods.stateFn()
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
proc getMpt*(ldg: LedgerRef): CoreDbMptRef = proc getMpt*(ldg: LedgerRef): CoreDbMptRef =
ldg.beginTrackApi LdgGetMptFn ldg.beginTrackApi LdgGetMptFn
result = ldg.extras.getMptFn() result = ldg.ac.rawTrie.CoreDxAccRef.getMpt.CoreDbMptRef
ldg.ifTrackApi: debug apiTxt, api, elapsed, result ldg.ifTrackApi: debug apiTxt, api, elapsed, result
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Public virtual read-only methods # 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 getCodeHash*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.}
proc getStorageRoot*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.} proc getStorageRoot*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.}
proc getBalance*(db: ReadOnlyStateDB, eAddr: EthAddress): UInt256 {.borrow.} proc getBalance*(db: ReadOnlyStateDB, eAddr: EthAddress): UInt256 {.borrow.}

View File

@ -11,13 +11,11 @@
{.push raises: [].} {.push raises: [].}
import import
eth/common, ../../aristo/aristo_profile,
../../core_db, ../accounts_ledger
../../../../stateless/multi_keys,
../../aristo/aristo_profile
# Annotation helpers export
{.pragma: noRaise, gcsafe, raises: [].} accounts_ledger
type type
LedgerProfListRef* = AristoDbProfListRef LedgerProfListRef* = AristoDbProfListRef
@ -26,122 +24,13 @@ type
LedgerProfData* = AristoDbProfData LedgerProfData* = AristoDbProfData
## Borrowed from `aristo_profile`, only used in profiling mode ## Borrowed from `aristo_profile`, only used in profiling mode
LedgerType* = enum LedgerSpRef* = LedgerSavePoint
Ooops = 0
LedgerCache
LedgerSpRef* = ref object of RootRef
## Object for check point or save point ## Object for check point or save point
LedgerRef* = ref object of RootRef LedgerRef* = ref object of RootRef
## Root object with closures ## Root object with closures
ldgType*: LedgerType ## For debugging
trackApi*: bool ## For debugging trackApi*: bool ## For debugging
profTab*: LedgerProfListRef ## Profiling data (if any) profTab*: LedgerProfListRef ## Profiling data (if any)
extras*: LedgerExtras ## Support might go away ac*: AccountsLedgerRef
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
# End # End

View File

@ -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

View File

@ -13,7 +13,7 @@
import import
eth/common, eth/common,
../core_db, ../core_db,
./backend/[accounts_ledger, accounts_ledger_desc], ./accounts_ledger,
./base/api_tracking, ./base/api_tracking,
./base ./base
@ -32,45 +32,29 @@ when LedgerEnableApiTracking:
iterator accounts*(ldg: LedgerRef): Account = iterator accounts*(ldg: LedgerRef): Account =
ldg.beginTrackApi LdgAccountsIt ldg.beginTrackApi LdgAccountsIt
case ldg.ldgType: for w in ldg.ac.accounts():
of LedgerCache: yield w
for w in ldg.AccountsLedgerRef.accountsIt():
yield w
else:
raiseAssert: "Unsupported ledger type: " & $ldg.ldgType
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
iterator addresses*(ldg: LedgerRef): EthAddress = iterator addresses*(ldg: LedgerRef): EthAddress =
ldg.beginTrackApi LdgAdressesIt ldg.beginTrackApi LdgAdressesIt
case ldg.ldgType: for w in ldg.ac.addresses():
of LedgerCache: yield w
for w in ldg.AccountsLedgerRef.addressesIt():
yield w
else:
raiseAssert: "Unsupported ledger type: " & $ldg.ldgType
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
iterator cachedStorage*(ldg: LedgerRef, eAddr: EthAddress): (UInt256,UInt256) = iterator cachedStorage*(ldg: LedgerRef, eAddr: EthAddress): (UInt256,UInt256) =
ldg.beginTrackApi LdgCachedStorageIt ldg.beginTrackApi LdgCachedStorageIt
case ldg.ldgType: for w in ldg.ac.cachedStorage(eAddr):
of LedgerCache: yield w
for w in ldg.AccountsLedgerRef.cachedStorageIt(eAddr):
yield w
else:
raiseAssert: "Unsupported ledger type: " & $ldg.ldgType
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
iterator pairs*(ldg: LedgerRef): (EthAddress,Account) = iterator pairs*(ldg: LedgerRef): (EthAddress,Account) =
ldg.beginTrackApi LdgPairsIt ldg.beginTrackApi LdgPairsIt
case ldg.ldgType: for w in ldg.ac.pairs():
of LedgerCache: yield w
for w in ldg.AccountsLedgerRef.pairsIt():
yield w
else:
raiseAssert: "Unsupported ledger type: " & $ldg.ldgType
ldg.ifTrackApi: debug apiTxt, api, elapsed ldg.ifTrackApi: debug apiTxt, api, elapsed
@ -79,12 +63,8 @@ iterator storage*(
eAddr: EthAddress; eAddr: EthAddress;
): (UInt256,UInt256) = ): (UInt256,UInt256) =
ldg.beginTrackApi LdgStorageIt ldg.beginTrackApi LdgStorageIt
case ldg.ldgType: for w in ldg.ac.storage(eAddr):
of LedgerCache: yield w
for w in ldg.AccountsLedgerRef.storageIt(eAddr):
yield w
else:
raiseAssert: "Unsupported ledger type: " & $ldg.ldgType
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ proc new*(
## with the `parent` block header. ## with the `parent` block header.
new result new result
result.init( result.init(
ac = com.ledgerType.init(com.db, parent.stateRoot), ac = LedgerRef.init(com.db, parent.stateRoot),
parent = parent, parent = parent,
blockCtx = blockCtx, blockCtx = blockCtx,
com = com, com = com,
@ -100,7 +100,7 @@ proc reinit*(self: BaseVMState; ## Object descriptor
com = self.com com = self.com
db = com.db db = com.db
ac = if self.stateDB.rootHash == parent.stateRoot: self.stateDB 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 flags = self.flags
self[].reset self[].reset
self.init( self.init(
@ -157,7 +157,7 @@ proc init*(
## It requires the `header` argument properly initalised so that for PoA ## It requires the `header` argument properly initalised so that for PoA
## networks, the miner address is retrievable via `ecRecover()`. ## networks, the miner address is retrievable via `ecRecover()`.
self.init( self.init(
ac = com.ledgerType.init(com.db, parent.stateRoot), ac = LedgerRef.init(com.db, parent.stateRoot),
parent = parent, parent = parent,
blockCtx = com.blockCtx(header), blockCtx = com.blockCtx(header),
com = com, com = com,

View File

@ -169,7 +169,7 @@ proc traceTransaction*(com: CommonRef, header: BlockHeader,
# internal transactions: # internal transactions:
let let
saveCtxBefore = setCtx beforeCtx saveCtxBefore = setCtx beforeCtx
stateBefore = AccountsLedgerRef.init(capture.recorder, beforeRoot) stateBefore = LedgerRef.init(capture.recorder, beforeRoot)
defer: defer:
saveCtxBefore.setCtx().ctx.forget() saveCtxBefore.setCtx().ctx.forget()
@ -208,7 +208,7 @@ proc dumpBlockState*(com: CommonRef, header: BlockHeader, body: BlockBody, dumpS
var var
before = newJArray() before = newJArray()
after = newJArray() after = newJArray()
stateBefore = AccountsLedgerRef.init(capture.recorder, parent.stateRoot) stateBefore = LedgerRef.init(capture.recorder, parent.stateRoot)
for idx, tx in body.transactions: for idx, tx in body.transactions:
let sender = tx.getSender let sender = tx.getSender

View File

@ -88,7 +88,7 @@ proc setupStateDB(tester: var Tester, wantedState: JsonNode, stateDB: LedgerRef)
proc testBlockWitness(node: JsonNode, rootHash: Hash256, testStatusIMPL: var TestStatus) = proc testBlockWitness(node: JsonNode, rootHash: Hash256, testStatusIMPL: var TestStatus) =
var var
tester = Tester(memDB: newCoreDbRef(DefaultDbMemory)) tester = Tester(memDB: newCoreDbRef(DefaultDbMemory))
ac = LedgerCache.init(tester.memDB, emptyRlpHash) ac = LedgerRef.init(tester.memDB, emptyRlpHash)
let root = tester.setupStateDB(node, ac) let root = tester.setupStateDB(node, ac)
if rootHash != emptyRlpHash: if rootHash != emptyRlpHash:

View File

@ -52,7 +52,7 @@ proc buildWitness(
let let
coreDb = newCoreDbRef(DefaultDbMemory) coreDb = newCoreDbRef(DefaultDbMemory)
accountsCache = LedgerCache.init(coreDb, emptyRlpHash) accountsCache = LedgerRef.init(coreDb, emptyRlpHash)
(rootHash, multiKeys) = setupStateDB(genAccounts, accountsCache) (rootHash, multiKeys) = setupStateDB(genAccounts, accountsCache)
var wb = initWitnessBuilder(coreDb, rootHash, {wfNoFlag}) var wb = initWitnessBuilder(coreDb, rootHash, {wfNoFlag})

View File

@ -373,7 +373,7 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal
let let
memDB = newCoreDbRef DefaultDbMemory memDB = newCoreDbRef DefaultDbMemory
stateDB = LedgerCache.init(memDB, emptyRlpHash) stateDB = LedgerRef.init(memDB, emptyRlpHash)
config = getChainConfig(ctx.network) config = getChainConfig(ctx.network)
com = CommonRef.new(memDB, config) com = CommonRef.new(memDB, config)
@ -403,7 +403,7 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal
elif lastBlockHash == ctx.lastBlockHash: elif lastBlockHash == ctx.lastBlockHash:
# multiple chain, we are using the last valid canonical # multiple chain, we are using the last valid canonical
# state root to test against 'postState' # 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)) verifyStateDB(fixture["postState"], ledger.ReadOnlyStateDB(stateDB))
success = lastBlockHash == ctx.lastBlockHash success = lastBlockHash == ctx.lastBlockHash

View File

@ -17,7 +17,6 @@ import
results, results,
unittest2, unittest2,
../nimbus/db/core_db/persistent, ../nimbus/db/core_db/persistent,
../nimbus/db/ledger,
../nimbus/core/chain, ../nimbus/core/chain,
./replay/pp, ./replay/pp,
./test_coredb/[coredb_test_xx, test_chainsync, test_helpers] ./test_coredb/[coredb_test_xx, test_chainsync, test_helpers]
@ -34,7 +33,6 @@ const
sampleDirRefFile = "coredb_test_xx.nim" sampleDirRefFile = "coredb_test_xx.nim"
dbTypeDefault = AristoDbMemory dbTypeDefault = AristoDbMemory
ldgTypeDefault = LedgerCache
let let
# Standard test sample # Standard test sample
@ -152,9 +150,7 @@ proc setErrorLevel {.used.} =
proc initRunnerDB( proc initRunnerDB(
path: string; path: string;
specs: CaptureSpecs; specs: CaptureSpecs;
dbType: CoreDbType; dbType: CoreDbType): CommonRef =
ldgType: LedgerType;
): CommonRef =
let coreDB = let coreDB =
# Resolve for static `dbType` # Resolve for static `dbType`
case dbType: case dbType:
@ -181,8 +177,7 @@ proc initRunnerDB(
result = CommonRef.new( result = CommonRef.new(
db = coreDB, db = coreDB,
networkId = networkId, networkId = networkId,
params = params, params = params)
ldgType = ldgType)
result.initializeEmptyDb result.initializeEmptyDb
@ -199,7 +194,6 @@ proc chainSyncRunner(
noisy = true; noisy = true;
capture = memorySampleDefault; capture = memorySampleDefault;
dbType = CoreDbType(0); dbType = CoreDbType(0);
ldgType = ldgTypeDefault;
profilingOk = false; profilingOk = false;
finalDiskCleanUpOk = true; finalDiskCleanUpOk = true;
enaLoggingOk = false; enaLoggingOk = false;
@ -231,11 +225,11 @@ proc chainSyncRunner(
defer: defer:
if persistent: baseDir.flushDbDir 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 let
com = initRunnerDB(dbDir, capture, dbType, ldgType) com = initRunnerDB(dbDir, capture, dbType)
defer: defer:
com.db.finish(flush = finalDiskCleanUpOk) com.db.finish(flush = finalDiskCleanUpOk)
if profilingOk: noisy.test_chainSyncProfilingPrint numBlocks if profilingOk: noisy.test_chainSyncProfilingPrint numBlocks
@ -254,7 +248,6 @@ proc persistentSyncPreLoadAndResumeRunner(
noisy = true; noisy = true;
capture = persistentSampleDefault; capture = persistentSampleDefault;
dbType = CoreDbType(0); dbType = CoreDbType(0);
ldgType = ldgTypeDefault;
profilingOk = false; profilingOk = false;
finalDiskCleanUpOk = true; finalDiskCleanUpOk = true;
enaLoggingOk = false; enaLoggingOk = false;
@ -290,7 +283,7 @@ proc persistentSyncPreLoadAndResumeRunner(
test "Populate db by initial sample parts": test "Populate db by initial sample parts":
let let
com = initRunnerDB(dbDir, capture, dbType, ldgType) com = initRunnerDB(dbDir, capture, dbType)
defer: defer:
com.db.finish(flush = finalDiskCleanUpOk) com.db.finish(flush = finalDiskCleanUpOk)
if profilingOk: noisy.test_chainSyncProfilingPrint firstPart if profilingOk: noisy.test_chainSyncProfilingPrint firstPart
@ -305,7 +298,7 @@ proc persistentSyncPreLoadAndResumeRunner(
test &"Continue with rest of sample": test &"Continue with rest of sample":
let let
com = initRunnerDB(dbDir, capture, dbType, ldgType) com = initRunnerDB(dbDir, capture, dbType)
defer: defer:
com.db.finish(flush = finalDiskCleanUpOk) com.db.finish(flush = finalDiskCleanUpOk)
if profilingOk: noisy.test_chainSyncProfilingPrint secndPart if profilingOk: noisy.test_chainSyncProfilingPrint secndPart

View File

@ -19,9 +19,6 @@ import
../replay/[pp, undump_blocks, undump_blocks_era1, xcheck], ../replay/[pp, undump_blocks, undump_blocks_era1, xcheck],
./test_helpers ./test_helpers
type
StopMoaningAboutLedger {.used.} = LedgerType
when CoreDbEnableApiProfiling: when CoreDbEnableApiProfiling:
import import
std/sequtils, std/sequtils,

View File

@ -135,7 +135,7 @@ proc getProofJsonMain*() =
let let
accounts = getGenesisAlloc("tests" / "customgenesis" / file) accounts = getGenesisAlloc("tests" / "customgenesis" / file)
coreDb = newCoreDbRef(DefaultDbMemory) coreDb = newCoreDbRef(DefaultDbMemory)
accountsCache = LedgerCache.init(coreDb, emptyRlpHash) accountsCache = LedgerRef.init(coreDb, emptyRlpHash)
stateRootHash = setupStateDB(accounts, accountsCache) stateRootHash = setupStateDB(accounts, accountsCache)
accountDb = newAccountStateDB(coreDb, stateRootHash) accountDb = newAccountStateDB(coreDb, stateRootHash)
readOnlyDb = ReadOnlyStateDB(accountDb) readOnlyDb = ReadOnlyStateDB(accountDb)
@ -148,7 +148,7 @@ proc getProofJsonMain*() =
let let
accounts = getGenesisAlloc("tests" / "customgenesis" / file) accounts = getGenesisAlloc("tests" / "customgenesis" / file)
coreDb = newCoreDbRef(DefaultDbMemory) coreDb = newCoreDbRef(DefaultDbMemory)
accountsCache = LedgerCache.init(coreDb, emptyRlpHash) accountsCache = LedgerRef.init(coreDb, emptyRlpHash)
stateRootHash = setupStateDB(accounts, accountsCache) stateRootHash = setupStateDB(accounts, accountsCache)
accountDb = newAccountStateDB(coreDb, stateRootHash) accountDb = newAccountStateDB(coreDb, stateRootHash)
readOnlyDb = ReadOnlyStateDB(accountDb) readOnlyDb = ReadOnlyStateDB(accountDb)

View File

@ -64,7 +64,7 @@ proc checkAndValidateWitnessAgainstProofs(
proofs: seq[ProofResponse]) = proofs: seq[ProofResponse]) =
let let
stateDB = LedgerCache.init(db, parentStateRoot) stateDB = LedgerRef.init(db, parentStateRoot)
verifyWitnessResult = verifyWitness(expectedStateRoot, witness, {wfNoFlag}) verifyWitnessResult = verifyWitness(expectedStateRoot, witness, {wfNoFlag})
check verifyWitnessResult.isOk() check verifyWitnessResult.isOk()