From 036dd23e9b0bba425ad87dbbb0d938f379a26e8e Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 20 Dec 2024 12:57:15 +0100 Subject: [PATCH] cleanups, import fixes (#2964) * more generic-path removal * tighter imports --- .../nodocker/engine/cancun/blobs.nim | 5 +- nimbus/common/common.nim | 6 - nimbus/db/access_list.nim | 2 + nimbus/db/aristo/aristo_api.nim | 110 ++---------------- nimbus/db/aristo/aristo_check.nim | 18 +-- nimbus/db/aristo/aristo_check/check_twig.nim | 11 +- nimbus/db/aristo/aristo_compute.nim | 2 +- nimbus/db/aristo/aristo_delete.nim | 2 +- .../aristo/aristo_delete/delete_subtree.nim | 2 +- nimbus/db/aristo/aristo_delta.nim | 3 +- nimbus/db/aristo/aristo_desc.nim | 4 +- .../aristo/aristo_desc/desc_identifiers.nim | 9 +- .../db/aristo/aristo_desc/desc_structural.nim | 6 +- nimbus/db/aristo/aristo_fetch.nim | 2 +- nimbus/db/aristo/aristo_get.nim | 1 - nimbus/db/aristo/aristo_hike.nim | 3 +- nimbus/db/aristo/aristo_init/memory_db.nim | 1 - nimbus/db/aristo/aristo_init/rocks_db.nim | 1 - .../aristo/aristo_init/rocks_db/rdb_desc.nim | 1 - .../aristo/aristo_init/rocks_db/rdb_get.nim | 1 - .../aristo/aristo_init/rocks_db/rdb_put.nim | 1 - .../aristo/aristo_init/rocks_db/rdb_walk.nim | 1 - nimbus/db/aristo/aristo_layers.nim | 2 +- nimbus/db/aristo/aristo_merge.nim | 2 +- nimbus/db/aristo/aristo_part.nim | 60 ++-------- nimbus/db/aristo/aristo_path.nim | 2 +- nimbus/db/aristo/aristo_utils.nim | 1 - nimbus/db/core_db/base.nim | 83 +------------ nimbus/db/core_db/base/api_tracking.nim | 3 +- nimbus/db/kvt/kvt_api.nim | 38 ++---- nimbus/db/kvt/kvt_desc.nim | 2 +- nimbus/db/kvt/kvt_init/memory_db.nim | 1 - nimbus/db/ledger.nim | 2 +- nimbus/db/storage_types.nim | 6 +- nimbus/evm/code_stream.nim | 2 +- nimbus/evm/interpreter/gas_meter.nim | 2 +- .../interpreter/op_handlers/oph_blockdata.nim | 1 - .../evm/interpreter/op_handlers/oph_call.nim | 3 +- .../interpreter/op_handlers/oph_create.nim | 5 +- .../interpreter/op_handlers/oph_envinfo.nim | 4 +- .../interpreter/op_handlers/oph_helpers.nim | 4 +- .../evm/interpreter/op_handlers/oph_log.nim | 6 +- .../interpreter/op_handlers/oph_memory.nim | 4 +- .../interpreter/op_handlers/oph_sysops.nim | 4 +- 44 files changed, 77 insertions(+), 352 deletions(-) diff --git a/hive_integration/nodocker/engine/cancun/blobs.nim b/hive_integration/nodocker/engine/cancun/blobs.nim index 7f83069dd..09d459534 100644 --- a/hive_integration/nodocker/engine/cancun/blobs.nim +++ b/hive_integration/nodocker/engine/cancun/blobs.nim @@ -9,9 +9,7 @@ # according to those terms. import - eth/common, - eth/common/hashes, - stint, + eth/common/[base, hashes], kzg4844/kzg, kzg4844/kzg_abi, stew/endians2, @@ -19,6 +17,7 @@ import results, ../../../../nimbus/core/eip4844 +export base, hashes type BlobID* = uint64 BlobIDs* = seq[BlobID] diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index 0747b8bbf..965e83dfc 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -105,12 +105,6 @@ type taskpool*: Taskpool ## Shared task pool for offloading computation to other threads -# ------------------------------------------------------------------------------ -# Forward declarations -# ------------------------------------------------------------------------------ - -proc proofOfStake*(com: CommonRef, header: Header): bool {.gcsafe.} - # ------------------------------------------------------------------------------ # Private helper functions # ------------------------------------------------------------------------------ diff --git a/nimbus/db/access_list.nim b/nimbus/db/access_list.nim index 925282937..0f14e4287 100644 --- a/nimbus/db/access_list.nim +++ b/nimbus/db/access_list.nim @@ -14,6 +14,8 @@ import eth/common/[addresses, transactions], ../utils/mergeutils +export addresses + type SlotSet = HashSet[UInt256] diff --git a/nimbus/db/aristo/aristo_api.nim b/nimbus/db/aristo/aristo_api.nim index 2809d2e60..d81c83571 100644 --- a/nimbus/db/aristo/aristo_api.nim +++ b/nimbus/db/aristo/aristo_api.nim @@ -14,7 +14,7 @@ import std/times, - eth/common, + eth/common/hashes, results, ./aristo_desc/desc_backend, ./aristo_init/memory_db, @@ -230,32 +230,6 @@ type ## Variant of `partAccountTwig()`. Note that the function always returns ## an error unless the `accPath` is valid. - AristoApiPartUntwigGeneric* = - proc(chain: openArray[seq[byte]]; - root: Hash32; - path: openArray[byte]; - ): Result[Opt[seq[byte]],AristoError] - {.noRaise.} - ## Follow and verify the argument `chain` up unlil the last entry which - ## must be a leaf node. Extract the payload and pass it on as return - ## code. If a `Opt.none()` result is returned then the `path` argument - ## does provably not exist relative to `chain`. - - AristoApiPartUntwigGenericOk* = - proc(chain: openArray[seq[byte]]; - root: Hash32; - path: openArray[byte]; - payload: Opt[seq[byte]]; - ): Result[void,AristoError] - {.noRaise.} - ## Variant of `partUntwigGeneric()`. The function verifies the argument - ## `chain` of rlp-encoded nodes against the `path` and `payload` - ## arguments. If `payload` is passed `Opt.none()`, then the function is - ## subject to proving that the `path` does not exist relaive to `chain`. - ## - ## Note: This function provides a functionality comparable to the - ## `isValidBranch()` function from `hexary.nim`. - AristoApiPartUntwigPath* = proc(chain: openArray[seq[byte]]; root: Hash32; @@ -359,8 +333,6 @@ type partAccountTwig*: AristoApiPartAccountTwig partStorageTwig*: AristoApiPartStorageTwig - partUntwigGeneric*: AristoApiPartUntwigGeneric - partUntwigGenericOk*: AristoApiPartUntwigGenericOk partUntwigPath*: AristoApiPartUntwigPath partUntwigPathOk*: AristoApiPartUntwigPathOk @@ -429,45 +401,12 @@ type # ------------------------------------------------------------------------------ when AutoValidateApiHooks: - proc validate(api: AristoApiObj|AristoApiRef) = - doAssert not api.commit.isNil - - doAssert not api.deleteAccountRecord.isNil - doAssert not api.deleteStorageData.isNil - doAssert not api.deleteStorageTree.isNil - - doAssert not api.fetchLastSavedState.isNil - - doAssert not api.fetchAccountRecord.isNil - doAssert not api.fetchStateRoot.isNil - doAssert not api.fetchStorageData.isNil - doAssert not api.fetchStorageRoot.isNil - - doAssert not api.finish.isNil - - doAssert not api.hasPathAccount.isNil - doAssert not api.hasPathStorage.isNil - doAssert not api.hasStorageData.isNil - - doAssert not api.isTop.isNil - doAssert not api.txFrameLevel.isNil - - doAssert not api.mergeAccountRecord.isNil - doAssert not api.mergeStorageData.isNil - - doAssert not api.partAccountTwig.isNil - doAssert not api.partStorageTwig.isNil - doAssert not api.partUntwigPath.isNil - doAssert not api.partUntwigPathOk.isNil - - doAssert not api.pathAsBlob.isNil - doAssert not api.persist.isNil - doAssert not api.rollback.isNil - doAssert not api.txFrameBegin.isNil - doAssert not api.txFrameTop.isNil + proc validate(api: AristoApiObj) = + for _, field in api.fieldPairs(): + doAssert not field.isNil proc validate(prf: AristoApiProfRef) = - prf.AristoApiRef.validate + prf.AristoApiRef[].validate doAssert not prf.data.isNil proc dup(be: BackendRef): BackendRef = @@ -534,43 +473,10 @@ func init*(T: type AristoApiRef): T = result[].init() func dup*(api: AristoApiRef): AristoApiRef = - result = AristoApiRef( - commit: api.commit, - - deleteAccountRecord: api.deleteAccountRecord, - deleteStorageData: api.deleteStorageData, - deleteStorageTree: api.deleteStorageTree, - - fetchLastSavedState: api.fetchLastSavedState, - fetchAccountRecord: api.fetchAccountRecord, - fetchStateRoot: api.fetchStateRoot, - fetchStorageData: api.fetchStorageData, - fetchStorageRoot: api.fetchStorageRoot, - - finish: api.finish, - - hasPathAccount: api.hasPathAccount, - hasPathStorage: api.hasPathStorage, - hasStorageData: api.hasStorageData, - - isTop: api.isTop, - txFrameLevel: api.txFrameLevel, - - mergeAccountRecord: api.mergeAccountRecord, - mergeStorageData: api.mergeStorageData, - - partAccountTwig: api.partAccountTwig, - partStorageTwig: api.partStorageTwig, - partUntwigPath: api.partUntwigPath, - partUntwigPathOk: api.partUntwigPathOk, - - pathAsBlob: api.pathAsBlob, - persist: api.persist, - rollback: api.rollback, - txFrameBegin: api.txFrameBegin, - txFrameTop: api.txFrameTop) + result = AristoApiRef() + result[] = api[] when AutoValidateApiHooks: - result.validate + result[].validate # ------------------------------------------------------------------------------ # Public profile API constuctor diff --git a/nimbus/db/aristo/aristo_check.nim b/nimbus/db/aristo/aristo_check.nim index fec9158c9..31f69f967 100644 --- a/nimbus/db/aristo/aristo_check.nim +++ b/nimbus/db/aristo/aristo_check.nim @@ -14,9 +14,7 @@ {.push raises: [].} import - std/[algorithm, sequtils, tables], - eth/common, - stew/interval_set, + eth/common/hashes, results, ./aristo_walk/persistent, "."/[aristo_desc, aristo_get, aristo_init], @@ -88,18 +86,6 @@ proc check*( ? db.checkBE() ok() -proc check*( - db: AristoDbRef; # Database - root: VertexID; # Start node - path: openArray[byte]; # Data path - ): Result[void,AristoError] = - ## Check generic path `path` against portal proof generation and - ## verification. - ## - ## Note that this check might have side effects in that it might compile - ## the hash keys on the `root` sub-tree. - db.checkTwig(root, path) - proc check*( db: AristoDbRef; # Database accPath: Hash32; # Account key @@ -109,7 +95,7 @@ proc check*( ## ## Note that this check might have side effects in that it might compile ## the hash keys on the accounts sub-tree. - db.checkTwig(VertexID(1), accPath.data) + db.checkTwig(accPath) proc check*( db: AristoDbRef; # Database diff --git a/nimbus/db/aristo/aristo_check/check_twig.nim b/nimbus/db/aristo/aristo_check/check_twig.nim index 83fda9d90..664b9ec33 100644 --- a/nimbus/db/aristo/aristo_check/check_twig.nim +++ b/nimbus/db/aristo/aristo_check/check_twig.nim @@ -11,7 +11,7 @@ {.push raises: [].} import - eth/common, + eth/common/hashes, results, ".."/[aristo_compute, aristo_desc, aristo_fetch, aristo_part] @@ -21,13 +21,12 @@ import proc checkTwig*( db: AristoDbRef; # Database - root: VertexID; # Start node - path: openArray[byte]; # Data path + accPath: Hash32; # Data path ): Result[void,AristoError] = let - proof = ? db.partGenericTwig(root, path) - key = ? db.computeKey (root,root) - discard ? proof[0].partUntwigGeneric(key.to(Hash32), path) + proof = ? db.partAccountTwig(accPath) + key = ? db.computeKey (VertexID(1),VertexID(1)) + discard ? proof[0].partUntwigPath(key.to(Hash32), accPath) ok() diff --git a/nimbus/db/aristo/aristo_compute.nim b/nimbus/db/aristo/aristo_compute.nim index 52fc124f5..ecb4c12c9 100644 --- a/nimbus/db/aristo/aristo_compute.nim +++ b/nimbus/db/aristo/aristo_compute.nim @@ -13,7 +13,7 @@ import std/strformat, chronicles, - eth/common, + eth/common/[accounts_rlp, base_rlp, hashes_rlp], results, "."/[aristo_desc, aristo_get, aristo_walk/persistent], ./aristo_desc/desc_backend diff --git a/nimbus/db/aristo/aristo_delete.nim b/nimbus/db/aristo/aristo_delete.nim index 86a4cd6ab..3223e4ed6 100644 --- a/nimbus/db/aristo/aristo_delete.nim +++ b/nimbus/db/aristo/aristo_delete.nim @@ -16,7 +16,7 @@ import std/typetraits, - eth/common, + eth/common/hashes, results, ./aristo_delete/delete_subtree, "."/[aristo_desc, aristo_fetch, aristo_get, aristo_hike, aristo_layers] diff --git a/nimbus/db/aristo/aristo_delete/delete_subtree.nim b/nimbus/db/aristo/aristo_delete/delete_subtree.nim index 038c01f8c..659a6b9ed 100644 --- a/nimbus/db/aristo/aristo_delete/delete_subtree.nim +++ b/nimbus/db/aristo/aristo_delete/delete_subtree.nim @@ -11,7 +11,7 @@ {.push raises: [].} import - eth/common, + eth/common/hashes, ".."/[aristo_desc, aristo_get, aristo_layers] # ------------------------------------------------------------------------------ diff --git a/nimbus/db/aristo/aristo_delta.nim b/nimbus/db/aristo/aristo_delta.nim index 9b33aee1c..3e066c42b 100644 --- a/nimbus/db/aristo/aristo_delta.nim +++ b/nimbus/db/aristo/aristo_delta.nim @@ -14,10 +14,9 @@ import std/tables, - eth/common, results, ./aristo_desc/desc_backend, - "."/[aristo_desc] + ./aristo_desc # ------------------------------------------------------------------------------ # Public functions, save to backend diff --git a/nimbus/db/aristo/aristo_desc.nim b/nimbus/db/aristo/aristo_desc.nim index c8ed52797..fdb738986 100644 --- a/nimbus/db/aristo/aristo_desc.nim +++ b/nimbus/db/aristo/aristo_desc.nim @@ -23,7 +23,7 @@ import std/[hashes, sets, tables], - eth/common, + eth/common/hashes, results, ./aristo_constants, ./aristo_desc/[desc_error, desc_identifiers, desc_nibbles, desc_structural], @@ -36,7 +36,7 @@ from ./aristo_desc/desc_backend # Not auto-exporting backend export tables, aristo_constants, desc_error, desc_identifiers, desc_nibbles, - desc_structural, minilru, common + desc_structural, minilru, hashes type AristoTxRef* = ref object diff --git a/nimbus/db/aristo/aristo_desc/desc_identifiers.nim b/nimbus/db/aristo/aristo_desc/desc_identifiers.nim index 231526968..8458a7cdf 100644 --- a/nimbus/db/aristo/aristo_desc/desc_identifiers.nim +++ b/nimbus/db/aristo/aristo_desc/desc_identifiers.nim @@ -16,7 +16,8 @@ import std/[algorithm, sequtils, sets, strutils, hashes], - eth/common, + eth/common/[base, hashes], + eth/rlp, stew/byteutils, chronicles, results, @@ -24,7 +25,7 @@ import ./desc_nibbles export - desc_nibbles + desc_nibbles, base, hashes, rlp type VertexID* = distinct uint64 @@ -311,12 +312,12 @@ func to*(lid: HashKey; T: type Hash32): T = elif 0 < lid.len: lid.data.keccak256 else: - EMPTY_ROOT_HASH + emptyRoot func to*(key: Hash32; T: type HashKey): T = ## This is an efficient version of `HashKey.fromBytes(key.data).value`, not ## to be confused with `digestTo(HashKey)`. - if key == EMPTY_ROOT_HASH: + if key == emptyRoot: T() else: T(len: 32, buf: key.data) diff --git a/nimbus/db/aristo/aristo_desc/desc_structural.nim b/nimbus/db/aristo/aristo_desc/desc_structural.nim index f3e5f4ba9..309feaf64 100644 --- a/nimbus/db/aristo/aristo_desc/desc_structural.nim +++ b/nimbus/db/aristo/aristo_desc/desc_structural.nim @@ -15,12 +15,12 @@ {.push raises: [].} import - std/[hashes, tables], + std/[hashes as std_hashes, tables], stint, - eth/common, + eth/common/[accounts, base, hashes], ./desc_identifiers -export stint +export stint, tables, accounts, base, hashes type LeafTiePayload* = object diff --git a/nimbus/db/aristo/aristo_fetch.nim b/nimbus/db/aristo/aristo_fetch.nim index b364b5091..ecca2c34b 100644 --- a/nimbus/db/aristo/aristo_fetch.nim +++ b/nimbus/db/aristo/aristo_fetch.nim @@ -15,7 +15,7 @@ import std/typetraits, - eth/common, + eth/common/[base, hashes], results, "."/[aristo_compute, aristo_desc, aristo_get, aristo_layers, aristo_hike] diff --git a/nimbus/db/aristo/aristo_get.nim b/nimbus/db/aristo/aristo_get.nim index f50f63072..d3e83be37 100644 --- a/nimbus/db/aristo/aristo_get.nim +++ b/nimbus/db/aristo/aristo_get.nim @@ -14,7 +14,6 @@ {.push raises: [].} import - std/tables, results, "."/[aristo_desc, aristo_layers] diff --git a/nimbus/db/aristo/aristo_hike.nim b/nimbus/db/aristo/aristo_hike.nim index 3c51a4ad1..f627b158e 100644 --- a/nimbus/db/aristo/aristo_hike.nim +++ b/nimbus/db/aristo/aristo_hike.nim @@ -11,9 +11,8 @@ {.push raises: [].} import - eth/common, + eth/common/hashes, results, - stew/arraybuf, "."/[aristo_desc, aristo_get] const diff --git a/nimbus/db/aristo/aristo_init/memory_db.nim b/nimbus/db/aristo/aristo_init/memory_db.nim index e70484f60..ba2a7b0c4 100644 --- a/nimbus/db/aristo/aristo_init/memory_db.nim +++ b/nimbus/db/aristo/aristo_init/memory_db.nim @@ -28,7 +28,6 @@ import std/[algorithm, options, sequtils, tables], - eth/common, results, ../aristo_constants, ../aristo_desc, diff --git a/nimbus/db/aristo/aristo_init/rocks_db.nim b/nimbus/db/aristo/aristo_init/rocks_db.nim index 36baa6734..443b008ff 100644 --- a/nimbus/db/aristo/aristo_init/rocks_db.nim +++ b/nimbus/db/aristo/aristo_init/rocks_db.nim @@ -27,7 +27,6 @@ {.push raises: [].} import - eth/common, rocksdb, results, ../aristo_desc, diff --git a/nimbus/db/aristo/aristo_init/rocks_db/rdb_desc.nim b/nimbus/db/aristo/aristo_init/rocks_db/rdb_desc.nim index 3bf8a2eb7..9d302eaf8 100644 --- a/nimbus/db/aristo/aristo_init/rocks_db/rdb_desc.nim +++ b/nimbus/db/aristo/aristo_init/rocks_db/rdb_desc.nim @@ -16,7 +16,6 @@ import std/os, std/concurrency/atomics, - eth/common, rocksdb, stew/endians2, ../../aristo_desc, diff --git a/nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim b/nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim index ce957abc2..e2fe837e5 100644 --- a/nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim +++ b/nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim @@ -14,7 +14,6 @@ {.push raises: [].} import - eth/common, rocksdb, results, ../../[aristo_blobify, aristo_desc], diff --git a/nimbus/db/aristo/aristo_init/rocks_db/rdb_put.nim b/nimbus/db/aristo/aristo_init/rocks_db/rdb_put.nim index cb134db04..a222dc7cc 100644 --- a/nimbus/db/aristo/aristo_init/rocks_db/rdb_put.nim +++ b/nimbus/db/aristo/aristo_init/rocks_db/rdb_put.nim @@ -14,7 +14,6 @@ {.push raises: [].} import - eth/common, rocksdb, results, ../../[aristo_blobify, aristo_desc], diff --git a/nimbus/db/aristo/aristo_init/rocks_db/rdb_walk.nim b/nimbus/db/aristo/aristo_init/rocks_db/rdb_walk.nim index 24551a092..6a0e9f496 100644 --- a/nimbus/db/aristo/aristo_init/rocks_db/rdb_walk.nim +++ b/nimbus/db/aristo/aristo_init/rocks_db/rdb_walk.nim @@ -14,7 +14,6 @@ {.push raises: [].} import - eth/common, stew/endians2, rocksdb, ./rdb_desc, diff --git a/nimbus/db/aristo/aristo_layers.nim b/nimbus/db/aristo/aristo_layers.nim index 8859b6910..742caf3eb 100644 --- a/nimbus/db/aristo/aristo_layers.nim +++ b/nimbus/db/aristo/aristo_layers.nim @@ -12,7 +12,7 @@ import std/[enumerate, sequtils, sets, tables], - eth/common, + eth/common/hashes, results, ./aristo_desc diff --git a/nimbus/db/aristo/aristo_merge.nim b/nimbus/db/aristo/aristo_merge.nim index 00275066a..bafc22c6f 100644 --- a/nimbus/db/aristo/aristo_merge.nim +++ b/nimbus/db/aristo/aristo_merge.nim @@ -26,7 +26,7 @@ import std/typetraits, - eth/common, + eth/common/hashes, results, "."/[aristo_desc, aristo_fetch, aristo_get, aristo_layers, aristo_vid] diff --git a/nimbus/db/aristo/aristo_part.nim b/nimbus/db/aristo/aristo_part.nim index 21bea627d..17ecedea0 100644 --- a/nimbus/db/aristo/aristo_part.nim +++ b/nimbus/db/aristo/aristo_part.nim @@ -15,7 +15,7 @@ import std/[sets, sequtils], - eth/common, + eth/common/hashes, results, "."/[aristo_desc, aristo_fetch, aristo_get, aristo_merge, aristo_layers, aristo_utils], @@ -66,7 +66,7 @@ iterator vkPairs*(ps: PartStateRef): (RootedVertexID, HashKey) = # Public functions # ------------------------------------------------------------------------------ -proc partGenericTwig*( +proc partTwig( db: AristoDbRef; root: VertexID; path: NibblesBuf; @@ -87,51 +87,38 @@ proc partGenericTwig*( else: err(rc.error) -proc partGenericTwig*( - db: AristoDbRef; - root: VertexID; - path: openArray[byte]; - ): Result[(seq[seq[byte]],bool), AristoError] = - ## Variant of `partGenericTwig()`. - ## - ## Note: This function provides a functionality comparable to the - ## `getBranch()` function from `hexary.nim` - ## - db.partGenericTwig(root, NibblesBuf.fromBytes path) - proc partAccountTwig*( db: AristoDbRef; accPath: Hash32; ): Result[(seq[seq[byte]],bool), AristoError] = - ## Variant of `partGenericTwig()`. - db.partGenericTwig(VertexID(1), NibblesBuf.fromBytes accPath.data) + db.partTwig(VertexID(1), NibblesBuf.fromBytes accPath.data) proc partStorageTwig*( db: AristoDbRef; accPath: Hash32; stoPath: Hash32; ): Result[(seq[seq[byte]],bool), AristoError] = - ## Variant of `partGenericTwig()`. Note that the function returns an error unless + ## Note that the function returns an error unless ## the argument `accPath` is valid. let vid = db.fetchStorageID(accPath).valueOr: if error == FetchPathStoRootMissing: return ok((@[],false)) return err(error) - db.partGenericTwig(vid, NibblesBuf.fromBytes stoPath.data) + db.partTwig(vid, NibblesBuf.fromBytes stoPath.data) # ---------- -proc partUntwigGeneric*( +proc partUntwigPath*( chain: openArray[seq[byte]]; root: Hash32; - path: openArray[byte]; + path: Hash32; ): Result[Opt[seq[byte]],AristoError] = ## Verify the chain of rlp-encoded nodes and return the payload. If a ## `Opt.none()` result is returned then the `path` argument does provably ## not exist relative to `chain`. try: let - nibbles = NibblesBuf.fromBytes path + nibbles = NibblesBuf.fromBytes path.data rc = chain.trackRlpNodes(root.to(HashKey), nibbles, start=true) if rc.isOk: return ok(Opt.some rc.value) @@ -141,32 +128,6 @@ proc partUntwigGeneric*( except RlpError: return err(PartTrkRlpError) -proc partUntwigPath*( - chain: openArray[seq[byte]]; - root: Hash32; - path: Hash32; - ): Result[Opt[seq[byte]],AristoError] = - ## Variant of `partUntwigGeneric()`. - chain.partUntwigGeneric(root, path.data) - - -proc partUntwigGenericOk*( - chain: openArray[seq[byte]]; - root: Hash32; - path: openArray[byte]; - payload: Opt[seq[byte]]; - ): Result[void,AristoError] = - ## Verify the argument `chain` of rlp-encoded nodes against the `path` - ## and `payload` arguments. - ## - ## Note: This function provides a functionality comparable to the - ## `isValidBranch()` function from `hexary.nim`. - ## - if payload == ? chain.partUntwigGeneric(root, path): - ok() - else: - err(PartTrkPayloadMismatch) - proc partUntwigPathOk*( chain: openArray[seq[byte]]; root: Hash32; @@ -174,7 +135,10 @@ proc partUntwigPathOk*( payload: Opt[seq[byte]]; ): Result[void,AristoError] = ## Variant of `partUntwigGenericOk()`. - chain.partUntwigGenericOk(root, path.data, payload) + if payload == ? chain.partUntwigPath(root, path): + ok() + else: + err(PartTrkPayloadMismatch) # ---------------- diff --git a/nimbus/db/aristo/aristo_path.nim b/nimbus/db/aristo/aristo_path.nim index dbbc9bf59..808c1739e 100644 --- a/nimbus/db/aristo/aristo_path.nim +++ b/nimbus/db/aristo/aristo_path.nim @@ -12,7 +12,7 @@ import std/sequtils, - eth/common, + eth/common/hashes, results, ./aristo_desc diff --git a/nimbus/db/aristo/aristo_utils.nim b/nimbus/db/aristo/aristo_utils.nim index d6ffaf134..912175aa9 100644 --- a/nimbus/db/aristo/aristo_utils.nim +++ b/nimbus/db/aristo/aristo_utils.nim @@ -14,7 +14,6 @@ {.push raises: [].} import - eth/common, results, "."/[aristo_desc, aristo_compute] diff --git a/nimbus/db/core_db/base.nim b/nimbus/db/core_db/base.nim index bfc511cbb..8c91b9aed 100644 --- a/nimbus/db/core_db/base.nim +++ b/nimbus/db/core_db/base.nim @@ -12,9 +12,9 @@ import std/typetraits, - eth/common, - "../.."/[constants], - ".."/[kvt, aristo], + eth/common/[accounts, base, hashes], + ../../constants, + ../[kvt, aristo], ./base/[api_tracking, base_config, base_desc, base_helpers] export @@ -134,61 +134,6 @@ proc stateBlockNumber*(db: CoreDbRef): BlockNumber = 0u64 db.ifTrackNewApi: debug logTxt, api, elapsed, result -proc verify*( - db: CoreDbRef | CoreDbAccRef; - proof: openArray[seq[byte]]; - root: Hash32; - path: openArray[byte]; - ): CoreDbRc[Opt[seq[byte]]] = - ## This function os the counterpart of any of the `proof()` functions. Given - ## the argument chain of rlp-encoded nodes `proof`, this function verifies - ## that the chain represents a partial MPT starting with a root node state - ## `root` followig the path `key` leading to leaf node encapsulating a - ## payload which is passed back as return code. - ## - ## Note: The `mpt` argument is used for administative purposes (e.g. logging) - ## only. The functionality is provided by the `Aristo` database - ## function `aristo_part.partUntwigGeneric()` with the same prototype - ## arguments except the `db`. - ## - template mpt: untyped = - when db is CoreDbRef: - CoreDbAccRef(db.defCtx) - else: - db - mpt.setTrackNewApi BaseVerifyFn - result = block: - let rc = mpt.call(partUntwigGeneric, proof, root, path) - if rc.isOk: - ok(rc.value) - else: - err(rc.error.toError($api, ProofVerify)) - mpt.ifTrackNewApi: debug logTxt, api, elapsed, result - -proc verifyOk*( - db: CoreDbRef | CoreDbAccRef; - proof: openArray[seq[byte]]; - root: Hash32; - path: openArray[byte]; - payload: Opt[seq[byte]]; - ): CoreDbRc[void] = - ## Variant of `verify()` which directly checks the argument `payload` - ## against what would be the return code in `verify()`. - ## - template mpt: untyped = - when db is CoreDbRef: - CoreDbAccRef(db.defCtx) - else: - db - mpt.setTrackNewApi BaseVerifyOkFn - result = block: - let rc = mpt.call(partUntwigGenericOk, proof, root, path, payload) - if rc.isOk: - ok() - else: - err(rc.error.toError($api, ProofVerify)) - mpt.ifTrackNewApi: debug logTxt, api, elapsed, result - proc verify*( db: CoreDbRef | CoreDbAccRef; proof: openArray[seq[byte]]; @@ -210,28 +155,6 @@ proc verify*( err(rc.error.toError($api, ProofVerify)) mpt.ifTrackNewApi: debug logTxt, api, elapsed, result -proc verifyOk*( - db: CoreDbRef | CoreDbAccRef; - proof: openArray[seq[byte]]; - root: Hash32; - path: Hash32; - payload: Opt[seq[byte]]; - ): CoreDbRc[void] = - ## Variant of `verifyOk()`. - template mpt: untyped = - when db is CoreDbRef: - CoreDbAccRef(db.defCtx) - else: - db - mpt.setTrackNewApi BaseVerifyOkFn - result = block: - let rc = mpt.call(partUntwigPathOk, proof, root, path, payload) - if rc.isOk: - ok() - else: - err(rc.error.toError($api, ProofVerify)) - mpt.ifTrackNewApi: debug logTxt, api, elapsed, result - # ------------------------------------------------------------------------------ # Public key-value table methods # ------------------------------------------------------------------------------ diff --git a/nimbus/db/core_db/base/api_tracking.nim b/nimbus/db/core_db/base/api_tracking.nim index c0ddaa46d..5ebac1c88 100644 --- a/nimbus/db/core_db/base/api_tracking.nim +++ b/nimbus/db/core_db/base/api_tracking.nim @@ -12,7 +12,7 @@ import std/[sequtils, strutils, times, typetraits], - eth/common, + eth/common/[accounts, base, hashes], results, stew/byteutils, ../../aristo/aristo_profile, @@ -56,7 +56,6 @@ type BasePersistentFn = "persistent" BaseStateBlockNumberFn = "stateBlockNumber" BaseVerifyFn = "verify" - BaseVerifyOkFn = "verifyOk" CptKvtLogFn = "kvtLog" CptLevelFn = "level" diff --git a/nimbus/db/kvt/kvt_api.nim b/nimbus/db/kvt/kvt_api.nim index 4d6264f8a..93dbe79ff 100644 --- a/nimbus/db/kvt/kvt_api.nim +++ b/nimbus/db/kvt/kvt_api.nim @@ -116,23 +116,12 @@ type # ------------------------------------------------------------------------------ when AutoValidateApiHooks: - proc validate(api: KvtApiObj|KvtApiRef) = - doAssert not api.commit.isNil - doAssert not api.del.isNil - doAssert not api.finish.isNil - doAssert not api.get.isNil - doAssert not api.hasKeyRc.isNil - doAssert not api.isTop.isNil - doAssert not api.txFrameLevel.isNil - doAssert not api.put.isNil - doAssert not api.rollback.isNil - doAssert not api.persist.isNil - doAssert not api.toKvtDbRef.isNil - doAssert not api.txFrameBegin.isNil - doAssert not api.txFrameTop.isNil + proc validate(api: KvtApiObj) = + for _, field in api.fieldPairs: + doAssert not field.isNil proc validate(prf: KvtApiProfRef) = - prf.KvtApiRef.validate + prf.KvtApiRef[].validate doAssert not prf.data.isNil proc dup(be: BackendRef): BackendRef = @@ -176,23 +165,10 @@ func init*(T: type KvtApiRef): T = result[].init() func dup*(api: KvtApiRef): KvtApiRef = - result = KvtApiRef( - commit: api.commit, - del: api.del, - finish: api.finish, - get: api.get, - len: api.len, - hasKeyRc: api.hasKeyRc, - isTop: api.isTop, - txFrameLevel: api.txFrameLevel, - put: api.put, - rollback: api.rollback, - persist: api.persist, - toKvtDbRef: api.toKvtDbRef, - txFrameBegin: api.txFrameBegin, - txFrameTop: api.txFrameTop) + result = KvtApiRef() + result[] = api[] when AutoValidateApiHooks: - result.validate + result[].validate # ------------------------------------------------------------------------------ # Public profile API constuctor # ------------------------------------------------------------------------------ diff --git a/nimbus/db/kvt/kvt_desc.nim b/nimbus/db/kvt/kvt_desc.nim index 2170629b2..0f007e20e 100644 --- a/nimbus/db/kvt/kvt_desc.nim +++ b/nimbus/db/kvt/kvt_desc.nim @@ -23,7 +23,7 @@ from ./kvt_desc/desc_backend # Not auto-exporting backend export - tables, kvt_constants, desc_error, desc_structural + hashes, tables, kvt_constants, desc_error, desc_structural type KvtTxRef* = ref object diff --git a/nimbus/db/kvt/kvt_init/memory_db.nim b/nimbus/db/kvt/kvt_init/memory_db.nim index 5fc599969..c5ee4571a 100644 --- a/nimbus/db/kvt/kvt_init/memory_db.nim +++ b/nimbus/db/kvt/kvt_init/memory_db.nim @@ -29,7 +29,6 @@ import std/tables, chronicles, - eth/common, results, stew/byteutils, ../kvt_desc, diff --git a/nimbus/db/ledger.nim b/nimbus/db/ledger.nim index ed58cda55..e2c1ed661 100644 --- a/nimbus/db/ledger.nim +++ b/nimbus/db/ledger.nim @@ -884,7 +884,7 @@ proc clearTransientStorage*(ac: LedgerRef) = doAssert(ac.savePoint.parentSavepoint.isNil) ac.savePoint.transientStorage.clear() -func getAccessList*(ac: LedgerRef): common.AccessList = +func getAccessList*(ac: LedgerRef): transactions.AccessList = # make sure all savepoint already committed doAssert(ac.savePoint.parentSavepoint.isNil) ac.savePoint.accessList.getAccessList() diff --git a/nimbus/db/storage_types.nim b/nimbus/db/storage_types.nim index e6eb41145..d87336268 100644 --- a/nimbus/db/storage_types.nim +++ b/nimbus/db/storage_types.nim @@ -9,7 +9,9 @@ # according to those terms. import - eth/common + eth/common/[base, hashes] + +export base, hashes type DBKeyKind* = enum @@ -61,7 +63,7 @@ func canonicalHeadHashKey*(): DbKey {.inline.} = func dataDirIdKey*(): DbKey {.inline.} = result.data[0] = byte ord(dataDirId) result.dataEndPos = 1 - + func slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} = doAssert(h.len == 32) result.data[0] = byte ord(slotHashToSlot) diff --git a/nimbus/evm/code_stream.nim b/nimbus/evm/code_stream.nim index 10308cb8c..7231b9b84 100644 --- a/nimbus/evm/code_stream.nim +++ b/nimbus/evm/code_stream.nim @@ -5,7 +5,7 @@ # * 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 chronicles, eth/common, stew/byteutils, ./interpreter/op_codes, ./code_bytes +import chronicles, stint, stew/byteutils, ./interpreter/op_codes, ./code_bytes export code_bytes diff --git a/nimbus/evm/interpreter/gas_meter.nim b/nimbus/evm/interpreter/gas_meter.nim index 8ae5e649f..2a4707c0d 100644 --- a/nimbus/evm/interpreter/gas_meter.nim +++ b/nimbus/evm/interpreter/gas_meter.nim @@ -11,7 +11,7 @@ {.push raises: [].} import - eth/common, # GasInt + eth/common/base, ../evm_errors, ../types diff --git a/nimbus/evm/interpreter/op_handlers/oph_blockdata.nim b/nimbus/evm/interpreter/op_handlers/oph_blockdata.nim index 979f23235..fa063376a 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_blockdata.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_blockdata.nim @@ -15,7 +15,6 @@ {.push raises: [].} import - eth/common, ../../computation, ../../stack, ../../evm_errors, diff --git a/nimbus/evm/interpreter/op_handlers/oph_call.nim b/nimbus/evm/interpreter/op_handlers/oph_call.nim index 9558f2eb6..d88e5bcea 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_call.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_call.nim @@ -30,8 +30,7 @@ import ./oph_defs, ./oph_helpers, chronicles, - eth/common, - eth/common/eth_types, + eth/common/addresses, stew/assign2, stint diff --git a/nimbus/evm/interpreter/op_handlers/oph_create.nim b/nimbus/evm/interpreter/op_handlers/oph_create.nim index ead9dd277..ebac243c1 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_create.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_create.nim @@ -28,10 +28,7 @@ import ../op_codes, ./oph_defs, ./oph_helpers, - chronicles, - eth/common, - eth/common/eth_types, - stint + chronicles when not defined(evmc_enabled): import diff --git a/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim b/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim index 63566174c..bf68b5340 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim @@ -24,9 +24,7 @@ import ../op_codes, ./oph_defs, ./oph_helpers, - eth/common, - stew/assign2, - stint + stew/assign2 when not defined(evmc_enabled): import ../../state diff --git a/nimbus/evm/interpreter/op_handlers/oph_helpers.nim b/nimbus/evm/interpreter/op_handlers/oph_helpers.nim index 32382ef1d..2a98b9a5b 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_helpers.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_helpers.nim @@ -19,9 +19,7 @@ import ../../evm_errors, ../../types, ../gas_costs, - eth/common, - eth/common/eth_types, - stint + eth/common/[addresses, base, hashes] when defined(evmc_enabled): import diff --git a/nimbus/evm/interpreter/op_handlers/oph_log.nim b/nimbus/evm/interpreter/op_handlers/oph_log.nim index cb23ac390..58e9d0706 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_log.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_log.nim @@ -15,6 +15,7 @@ {.push raises: [].} import + std/sequtils, stew/assign2, ../../../constants, ../../evm_errors, @@ -26,10 +27,7 @@ import ../op_codes, ./oph_defs, ./oph_gen_handlers, - ./oph_helpers, - eth/common, - sequtils, - stint + ./oph_helpers # ------------------------------------------------------------------------------ # Private, names & settings diff --git a/nimbus/evm/interpreter/op_handlers/oph_memory.nim b/nimbus/evm/interpreter/op_handlers/oph_memory.nim index fbc80f2ba..23482b3f6 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_memory.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_memory.nim @@ -25,9 +25,7 @@ import ../gas_costs, ../op_codes, ./oph_defs, - ./oph_helpers, - eth/common, - stint + ./oph_helpers when not defined(evmc_enabled): import diff --git a/nimbus/evm/interpreter/op_handlers/oph_sysops.nim b/nimbus/evm/interpreter/op_handlers/oph_sysops.nim index b5b363e09..4f057d24b 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_sysops.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_sysops.nim @@ -24,9 +24,7 @@ import ../gas_costs, ../op_codes, ./oph_defs, - ./oph_helpers, - eth/common, - stint + ./oph_helpers when not defined(evmc_enabled): import