2023-10-18 19:27:22 +00:00
|
|
|
# Nimbus
|
2024-02-21 16:04:59 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-10-18 19:27:22 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
## Unify different ledger management APIs.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
eth/common,
|
2024-06-21 07:44:10 +00:00
|
|
|
../../evm/code_bytes,
|
2024-06-08 08:05:00 +00:00
|
|
|
../../stateless/multi_keys,
|
2023-10-25 14:03:09 +00:00
|
|
|
../core_db,
|
2023-12-12 17:47:41 +00:00
|
|
|
./base/[api_tracking, base_desc]
|
|
|
|
|
|
|
|
const
|
|
|
|
EnableApiTracking = false
|
|
|
|
## When enabled, API functions are logged. Tracking is enabled by setting
|
|
|
|
## the `trackApi` flag to `true`.
|
|
|
|
|
|
|
|
EnableApiProfiling = true
|
|
|
|
## Enable functions profiling (only if `EnableApiTracking` is set `true`.)
|
|
|
|
|
|
|
|
apiTxt = "Ledger API"
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
ReadOnlyStateDB* = distinct LedgerRef
|
|
|
|
|
|
|
|
export
|
2024-06-21 07:44:10 +00:00
|
|
|
code_bytes,
|
2024-02-29 21:10:24 +00:00
|
|
|
LedgerFnInx,
|
|
|
|
LedgerProfListRef,
|
2023-10-18 19:27:22 +00:00
|
|
|
LedgerRef,
|
2024-02-29 21:10:24 +00:00
|
|
|
LedgerSpRef
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
const
|
2023-12-12 17:47:41 +00:00
|
|
|
LedgerEnableApiTracking* = EnableApiTracking
|
|
|
|
LedgerEnableApiProfiling* = EnableApiTracking and EnableApiProfiling
|
|
|
|
LedgerApiTxt* = apiTxt
|
2023-11-24 22:16:21 +00:00
|
|
|
|
2024-02-29 21:10:24 +00:00
|
|
|
proc ldgProfData*(db: CoreDbRef): LedgerProfListRef {.gcsafe.}
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-12-12 17:47:41 +00:00
|
|
|
# Logging/tracking helpers (some public)
|
2023-10-18 19:27:22 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
when EnableApiTracking:
|
2023-12-12 17:47:41 +00:00
|
|
|
when EnableApiProfiling:
|
|
|
|
{.warning: "*** Provided API profiling for Ledger (disabled by default)".}
|
|
|
|
else:
|
|
|
|
{.warning: "*** Provided API logging for Ledger (disabled by default)".}
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
import
|
|
|
|
std/times,
|
2023-12-12 17:47:41 +00:00
|
|
|
chronicles
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
func `$`(e: Duration): string {.used.} = e.toStr
|
|
|
|
func `$`(c: CoreDbMptRef): string {.used.} = c.toStr
|
|
|
|
func `$`(l: seq[Log]): string {.used.} = l.toStr
|
|
|
|
func `$`(h: Hash256): string {.used.} = h.toStr
|
|
|
|
func `$`(a: EthAddress): string {.used.} = a.toStr
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
# Publicly available for API logging
|
|
|
|
template beginTrackApi*(ldg: LedgerRef; s: LedgerFnInx) =
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
2024-02-29 21:10:24 +00:00
|
|
|
ldg.beginApi(s)
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2023-12-12 17:47:41 +00:00
|
|
|
template ifTrackApi*(ldg: LedgerRef; code: untyped) =
|
2023-11-24 22:16:21 +00:00
|
|
|
when EnableApiTracking:
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.endApiIf:
|
|
|
|
code
|
2023-10-25 14:03:09 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor helper
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc bless*(ldg: LedgerRef; db: CoreDbRef): LedgerRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgBlessFn
|
2023-10-25 14:03:09 +00:00
|
|
|
when EnableApiTracking:
|
|
|
|
ldg.trackApi = db.trackLedgerApi
|
2024-02-29 21:10:24 +00:00
|
|
|
when LedgerEnableApiProfiling:
|
|
|
|
ldg.profTab = db.ldgProfData()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, ldgType=ldg.ldgType
|
2023-10-25 14:03:09 +00:00
|
|
|
ldg
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-02-29 21:10:24 +00:00
|
|
|
proc ldgProfData*(db: CoreDbRef): LedgerProfListRef =
|
|
|
|
## Return profiling data table (only available in profiling mode). If
|
|
|
|
## available (i.e. non-nil), result data can be organised by the functions
|
|
|
|
## available with `aristo_profile`.
|
|
|
|
##
|
|
|
|
## Note that profiling these data have accumulated over several ledger
|
|
|
|
## sessions running on the same `CoreDb` instance.
|
|
|
|
##
|
|
|
|
when LedgerEnableApiProfiling:
|
|
|
|
if db.ledgerHook.isNil:
|
|
|
|
db.ledgerHook = LedgerProfListRef.init()
|
|
|
|
cast[LedgerProfListRef](db.ledgerHook)
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
proc accessList*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgAccessListFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.accessList(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc accessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgAccessListFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.accessList(eAddr, slot)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc accountExists*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgAccountExistsFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.accountExists(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc addBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgAddBalanceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.addBalance(eAddr, delta)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc addLogEntry*(ldg: LedgerRef, log: Log) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgAddLogEntryFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.addLogEntry(log)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc beginSavepoint*(ldg: LedgerRef): LedgerSpRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgBeginSavepointFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.beginSavepoint()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc clearStorage*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgClearStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.clearStorage(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc clearTransientStorage*(ldg: LedgerRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgClearTransientStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.clearTransientStorage()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc collectWitnessData*(ldg: LedgerRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgCollectWitnessDataFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.collectWitnessData()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc commit*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgCommitFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.commit(sp)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc deleteAccount*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgDeleteAccountFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.deleteAccount(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc dispose*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgDisposeFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.dispose(sp)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getAndClearLogEntries*(ldg: LedgerRef): seq[Log] =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetAndClearLogEntriesFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getAndClearLogEntries()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getBalance*(ldg: LedgerRef, eAddr: EthAddress): UInt256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetBalanceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getBalance(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-06-21 07:44:10 +00:00
|
|
|
proc getCode*(ldg: LedgerRef, eAddr: EthAddress): CodeBytesRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetCodeFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getCode(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getCodeHash*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetCodeHashFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getCodeHash(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getCodeSize*(ldg: LedgerRef, eAddr: EthAddress): int =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetCodeSizeFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getCodeSize(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
proc getCommittedStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
): UInt256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetCommittedStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getCommittedStorage(eAddr, slot)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getNonce*(ldg: LedgerRef, eAddr: EthAddress): AccountNonce =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetNonceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getNonce(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getStorage*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): UInt256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getStorage(eAddr, slot)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getStorageRoot*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetStorageRootFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getStorageRoot(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
proc getTransientStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
): UInt256 =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetTransientStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getTransientStorage(eAddr, slot)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-04-16 02:31:10 +00:00
|
|
|
proc contractCollision*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
|
|
|
ldg.beginTrackApi LdgContractCollisionFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.contractCollision(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgInAccessListFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.inAccessList(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgInAccessListFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.inAccessList(eAddr, slot)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc incNonce*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgIncNonceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.incNonce(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isDeadAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgIsDeadAccountFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.isDeadAccount(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isEmptyAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgIsEmptyAccountFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.isEmptyAccount(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isTopLevelClean*(ldg: LedgerRef): bool =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgIsTopLevelCleanFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.isTopLevelClean()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc logEntries*(ldg: LedgerRef): seq[Log] =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgLogEntriesFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.logEntries()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-02-21 16:04:59 +00:00
|
|
|
proc makeMultiKeys*(ldg: LedgerRef): MultiKeysRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgMakeMultiKeysFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.makeMultiKeys()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-06-25 05:30:32 +00:00
|
|
|
proc persist*(ldg: LedgerRef, clearEmptyAccount = false, clearCache = false) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgPersistFn
|
2024-06-25 05:30:32 +00:00
|
|
|
ldg.ac.persist(clearEmptyAccount, clearCache)
|
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, clearEmptyAccount, clearCache
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc ripemdSpecial*(ldg: LedgerRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgRipemdSpecialFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.ripemdSpecial()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc rollback*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgRollbackFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.rollback(sp)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc safeDispose*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSafeDisposeFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.safeDispose(sp)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestruct*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSelfDestructFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.selfDestruct(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestruct6780*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSelfDestruct6780Fn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.selfDestruct6780(eAddr)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestructLen*(ldg: LedgerRef): int =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSelfDestructLenFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.selfDestructLen()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setBalance*(ldg: LedgerRef, eAddr: EthAddress, balance: UInt256) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSetBalanceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.setBalance(eAddr, balance)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, balance
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setCode*(ldg: LedgerRef, eAddr: EthAddress, code: Blob) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSetCodeFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.setCode(eAddr, code)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, code=code.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setNonce*(ldg: LedgerRef, eAddr: EthAddress, nonce: AccountNonce) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSetNonceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.setNonce(eAddr, nonce)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, nonce
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setStorage*(ldg: LedgerRef, eAddr: EthAddress, slot, val: UInt256) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSetStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.setStorage(eAddr, slot, val)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val
|
2023-11-24 22:16:21 +00:00
|
|
|
|
|
|
|
proc setTransientStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
val: UInt256;
|
|
|
|
) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSetTransientStorageFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.setTransientStorage(eAddr, slot, val)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, slot, val
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-04-19 18:37:27 +00:00
|
|
|
proc state*(ldg: LedgerRef): Hash256 =
|
|
|
|
ldg.beginTrackApi LdgStateFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.state()
|
2024-04-19 18:37:27 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgSubBalanceFn
|
2024-05-29 11:06:49 +00:00
|
|
|
ldg.ac.subBalance(eAddr, delta)
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, eAddr, delta
|
2023-10-18 19:27:22 +00:00
|
|
|
|
2024-02-29 11:16:47 +00:00
|
|
|
proc getAccessList*(ldg: LedgerRef): AccessList =
|
|
|
|
ldg.beginTrackApi LdgGetAccessListFn
|
2024-05-29 11:06:49 +00:00
|
|
|
result = ldg.ac.getAccessList()
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed
|
2024-02-29 11:16:47 +00:00
|
|
|
|
2024-05-29 11:06:49 +00:00
|
|
|
proc rootHash*(ldg: LedgerRef): KeccakHash =
|
|
|
|
ldg.state()
|
2024-04-19 18:37:27 +00:00
|
|
|
|
2024-06-19 14:13:12 +00:00
|
|
|
proc getMpt*(ldg: LedgerRef): CoreDbMptRef =
|
2023-12-12 17:47:41 +00:00
|
|
|
ldg.beginTrackApi LdgGetMptFn
|
2024-06-19 14:13:12 +00:00
|
|
|
result = ldg.ac.rawTrie.CoreDbAccRef.getMpt
|
2024-03-18 19:40:23 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
Optional accounts cache module for creating genesis (#1897)
* Split off `ReadOnlyStateDB` from `AccountStateDB` from `state_db.nim`
why:
Apart from testing, applications use `ReadOnlyStateDB` as an easy
way to access the accounts ledger. This is well supported by the
`Aristo` db, but writable mode is only parially supported.
The writable AccountStateDB` object for modifying accounts is not
used by production code.
So, for lecgacy and testing apps, the full support of the previous
`AccountStateDB` is now enabled by `import db/state_db/read_write`
and the `import db/state_db` provides read-only mode.
* Encapsulate `AccountStateDB` as `GenesisLedgerRef` or genesis creation
why:
`AccountStateDB` has poor support for `Aristo` and is not widely used
in favour of `AccountsLedger` (which will be abstracted as `ledger`.)
Currently, using other than the `AccountStateDB` ledgers within the
`GenesisLedgerRef` wrapper is experimental and test only. Eventually,
the wrapper should disappear so that the `Ledger` object (which
encapsulates `AccountsCache` and `AccountsLedger`) will prevail.
* For the `Ledger`, provide access to raw accounts `MPT`
why:
This gives to the `CoreDbMptRef` descriptor from the `CoreDb` (which is
the legacy version of CoreDxMptRef`.) For the new `ledger` API, the
accounts are based on the `CoreDxMAccRef` descriptor which uses a
particular sub-system for accounts while legacy applications use the
`CoreDbPhkRef` equivalent of the `SecureHexaryTrie`.
The only place where this feature will currently be used is the
`genesis.nim` source file.
* Fix `Aristo` bugs, missing boundary checks, typos, etc.
* Verify root vertex in `MPT` and account constructors
why:
Was missing so far, in particular the accounts constructor must
verify `VertexID(1)
* Fix include file
2023-11-20 11:51:43 +00:00
|
|
|
|
2024-06-16 03:21:02 +00:00
|
|
|
proc getEthAccount*(ldg: LedgerRef, eAddr: EthAddress): Account =
|
|
|
|
ldg.beginTrackApi LdgGetAthAccountFn
|
|
|
|
result = ldg.ac.getEthAccount(eAddr)
|
|
|
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public virtual read-only methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-05-29 11:06:49 +00:00
|
|
|
proc rootHash*(db: ReadOnlyStateDB): KeccakHash = db.LedgerRef.state()
|
2023-10-18 19:27:22 +00:00
|
|
|
proc getCodeHash*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.}
|
|
|
|
proc getStorageRoot*(db: ReadOnlyStateDB, eAddr: EthAddress): Hash256 {.borrow.}
|
|
|
|
proc getBalance*(db: ReadOnlyStateDB, eAddr: EthAddress): UInt256 {.borrow.}
|
|
|
|
proc getStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
|
|
|
proc getNonce*(db: ReadOnlyStateDB, eAddr: EthAddress): AccountNonce {.borrow.}
|
2024-06-21 07:44:10 +00:00
|
|
|
proc getCode*(db: ReadOnlyStateDB, eAddr: EthAddress): CodeBytesRef {.borrow.}
|
2023-10-18 19:27:22 +00:00
|
|
|
proc getCodeSize*(db: ReadOnlyStateDB, eAddr: EthAddress): int {.borrow.}
|
2024-04-16 02:31:10 +00:00
|
|
|
proc contractCollision*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
2023-10-18 19:27:22 +00:00
|
|
|
proc accountExists*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
|
|
|
proc isDeadAccount*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
|
|
|
proc isEmptyAccount*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
|
|
|
proc getCommittedStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
|
|
|
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
|
|
|
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): bool {.borrow.}
|
|
|
|
func getTransientStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|