2023-10-18 19:27:22 +00:00
|
|
|
# Nimbus
|
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
|
|
|
# Copyright (c) 2023 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,
|
|
|
|
../../../stateless/multi_keys,
|
2023-10-25 14:03:09 +00:00
|
|
|
../core_db,
|
2023-10-18 19:27:22 +00:00
|
|
|
./base/[base_desc, validate]
|
|
|
|
|
|
|
|
type
|
|
|
|
ReadOnlyStateDB* = distinct LedgerRef
|
|
|
|
|
|
|
|
export
|
|
|
|
LedgerType,
|
|
|
|
LedgerRef,
|
|
|
|
LedgerSpRef
|
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
const
|
2023-11-24 22:16:21 +00:00
|
|
|
AutoValidateDescriptors = defined(release).not
|
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
EnableApiTracking = true and false
|
|
|
|
## When enabled, API functions are logged. Tracking is enabled by setting
|
|
|
|
## the `trackApi` flag to `true`.
|
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
apiTxt = "Ledger API"
|
|
|
|
|
2023-10-18 19:27:22 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-25 14:03:09 +00:00
|
|
|
# Private helpers
|
2023-10-18 19:27:22 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-10-25 14:03:09 +00:00
|
|
|
when EnableApiTracking:
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
{.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,
|
|
|
|
chronicles,
|
|
|
|
base/api_tracking
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
proc `$`(a: EthAddress): string {.used.} = a.toStr
|
|
|
|
proc `$`(e: Duration): string {.used.} = e.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-11-24 22:16:21 +00:00
|
|
|
template beginTrackApi(ldg: LedgerRef; s: static[string]) =
|
|
|
|
when EnableApiTracking:
|
|
|
|
ldg.beginApi
|
|
|
|
let ctx {.inject.} = s
|
2023-10-25 14:03:09 +00:00
|
|
|
|
2023-11-24 22:16:21 +00:00
|
|
|
template ifTrackApi(ldg: LedgerRef; code: untyped) =
|
|
|
|
when EnableApiTracking:
|
|
|
|
ldg.endApiIf: code
|
2023-10-25 14:03:09 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor helper
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc bless*(ldg: LedgerRef; db: CoreDbRef): LedgerRef =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "LedgerRef.init()"
|
2023-10-25 14:03:09 +00:00
|
|
|
when AutoValidateDescriptors:
|
|
|
|
ldg.validate()
|
|
|
|
when EnableApiTracking:
|
|
|
|
ldg.trackApi = db.trackLedgerApi
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, ldgType=ldg.ldgType
|
2023-10-25 14:03:09 +00:00
|
|
|
ldg
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc accessList*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "accessList()"
|
|
|
|
ldg.methods.accessListFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc accessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "accessList()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.accessList2Fn(eAddr, slot)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc accountExists*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "accountExists()"
|
|
|
|
result = ldg.methods.accountExistsFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc addBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "addBalance()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.addBalanceFn(eAddr, delta)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, delta
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc addLogEntry*(ldg: LedgerRef, log: Log) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "addLogEntry()"
|
|
|
|
ldg.methods.addLogEntryFn log
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc beginSavepoint*(ldg: LedgerRef): LedgerSpRef =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "beginSavepoint()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.beginSavepointFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc clearStorage*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "clearStorage()"
|
|
|
|
ldg.methods.clearStorageFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc clearTransientStorage*(ldg: LedgerRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "clearTransientStorage()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.clearTransientStorageFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc collectWitnessData*(ldg: LedgerRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "collectWitnessData()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.collectWitnessDataFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc commit*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "commit()"
|
|
|
|
ldg.methods.commitFn sp
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc deleteAccount*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "deleteAccount()"
|
|
|
|
ldg.methods.deleteAccountFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc dispose*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "dispose()"
|
|
|
|
ldg.methods.disposeFn sp
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getAndClearLogEntries*(ldg: LedgerRef): seq[Log] =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getAndClearLogEntries()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.getAndClearLogEntriesFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getBalance*(ldg: LedgerRef, eAddr: EthAddress): UInt256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getBalance()"
|
|
|
|
result = ldg.methods.getBalanceFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getCode*(ldg: LedgerRef, eAddr: EthAddress): Blob =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getCode()"
|
|
|
|
result = ldg.methods.getCodeFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getCodeHash*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getCodeHash()"
|
|
|
|
result = ldg.methods.getCodeHashFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getCodeSize*(ldg: LedgerRef, eAddr: EthAddress): int =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getCodeSize()"
|
|
|
|
result = ldg.methods.getCodeSizeFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
|
|
|
|
|
|
|
proc getCommittedStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
): UInt256 =
|
|
|
|
ldg.beginTrackApi "getCommittedStorage()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.getCommittedStorageFn(eAddr, slot)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getNonce*(ldg: LedgerRef, eAddr: EthAddress): AccountNonce =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getNonce()"
|
|
|
|
result = ldg.methods.getNonceFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getStorage*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): UInt256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getStorage()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.getStorageFn(eAddr, slot)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc getStorageRoot*(ldg: LedgerRef, eAddr: EthAddress): Hash256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getStorageRoot()"
|
|
|
|
result = ldg.methods.getStorageRootFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result=result.toStr
|
|
|
|
|
|
|
|
proc getTransientStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
): UInt256 =
|
|
|
|
ldg.beginTrackApi "getTransientStorage()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.getTransientStorageFn(eAddr, slot)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc hasCodeOrNonce*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "hasCodeOrNonce()"
|
|
|
|
result = ldg.methods.hasCodeOrNonceFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "inAccessList()"
|
|
|
|
result = ldg.methods.inAccessListFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc inAccessList*(ldg: LedgerRef, eAddr: EthAddress, slot: UInt256): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "inAccessList()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.inAccessList2Fn(eAddr, slot)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc incNonce*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "incNonce()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.incNonceFn(eAddr)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isDeadAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "isDeadAccount()"
|
|
|
|
result = ldg.methods.isDeadAccountFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isEmptyAccount*(ldg: LedgerRef, eAddr: EthAddress): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "isEmptyAccount()"
|
|
|
|
result = ldg.methods.isEmptyAccountFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc isTopLevelClean*(ldg: LedgerRef): bool =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "isTopLevelClean()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.isTopLevelCleanFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc logEntries*(ldg: LedgerRef): seq[Log] =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "logEntries()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.logEntriesFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc makeMultiKeys*(ldg: LedgerRef): MultikeysRef =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "makeMultiKeys()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.makeMultiKeysFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc persist*(ldg: LedgerRef, clearEmptyAccount = false, clearCache = true) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "persist()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.persistFn(clearEmptyAccount, clearCache)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, clearEmptyAccount, clearCache
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc ripemdSpecial*(ldg: LedgerRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "ripemdSpecial()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.ripemdSpecialFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc rollback*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "rollback()"
|
|
|
|
ldg.methods.rollbackFn sp
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc rootHash*(ldg: LedgerRef): Hash256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "rootHash()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.rootHashFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc safeDispose*(ldg: LedgerRef, sp: LedgerSpRef) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "safeDispose()"
|
|
|
|
ldg.methods.safeDisposeFn sp
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestruct*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "selfDestruct()"
|
|
|
|
ldg.methods.selfDestructFn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestruct6780*(ldg: LedgerRef, eAddr: EthAddress) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "selfDestruct6780()"
|
|
|
|
ldg.methods.selfDestruct6780Fn eAddr
|
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc selfDestructLen*(ldg: LedgerRef): int =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "selfDestructLen()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.methods.selfDestructLenFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setBalance*(ldg: LedgerRef, eAddr: EthAddress, balance: UInt256) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "setBalance()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.setBalanceFn(eAddr, balance)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, balance
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setCode*(ldg: LedgerRef, eAddr: EthAddress, code: Blob) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "setCode()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.setCodeFn(eAddr, code)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, code=code.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setNonce*(ldg: LedgerRef, eAddr: EthAddress, nonce: AccountNonce) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "setNonce()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.setNonceFn(eAddr, nonce)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, nonce
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc setStorage*(ldg: LedgerRef, eAddr: EthAddress, slot, val: UInt256) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "setStorage()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.setStorageFn(eAddr, slot, val)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, val
|
|
|
|
|
|
|
|
proc setTransientStorage*(
|
|
|
|
ldg: LedgerRef;
|
|
|
|
eAddr: EthAddress;
|
|
|
|
slot: UInt256;
|
|
|
|
val: UInt256;
|
|
|
|
) =
|
|
|
|
ldg.beginTrackApi "setTransientStorage()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.setTransientStorageFn(eAddr, slot, val)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, slot, val
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "setTransientStorage()"
|
2023-10-18 19:27:22 +00:00
|
|
|
ldg.methods.subBalanceFn(eAddr, delta)
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, delta
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public methods, extensions to go away
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
proc getMpt*(ldg: LedgerRef): CoreDbMptRef =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "getMpt()"
|
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
|
|
|
result = ldg.extras.getMptFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result=result.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-10-18 19:27:22 +00:00
|
|
|
proc rawRootHash*(ldg: LedgerRef): Hash256 =
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.beginTrackApi "rawRootHash()"
|
2023-10-25 14:03:09 +00:00
|
|
|
result = ldg.extras.rawRootHashFn()
|
2023-11-24 22:16:21 +00:00
|
|
|
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, result=result.toStr
|
2023-10-18 19:27:22 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public virtual read-only methods
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
|
|
|
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.}
|
|
|
|
proc getCode*(db: ReadOnlyStateDB, eAddr: EthAddress): seq[byte] {.borrow.}
|
|
|
|
proc getCodeSize*(db: ReadOnlyStateDB, eAddr: EthAddress): int {.borrow.}
|
|
|
|
proc hasCodeOrNonce*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
|
|
|
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
|
|
|
|
# ------------------------------------------------------------------------------
|