Skip to content

Commit

Permalink
cleanups, import fixes
Browse files Browse the repository at this point in the history
* more generic-path removal
* tighter imports
  • Loading branch information
arnetheduck committed Dec 20, 2024
1 parent 80f8b3c commit 59b9303
Show file tree
Hide file tree
Showing 44 changed files with 76 additions and 351 deletions.
5 changes: 2 additions & 3 deletions hive_integration/nodocker/engine/cancun/blobs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
# according to those terms.

import
eth/common,
eth/common/hashes,
stint,
eth/common/[base, hashes],
kzg4844/kzg,
kzg4844/kzg_abi,
stew/endians2,
nimcrypto/sha2,
results,
../../../../nimbus/core/eip4844

export base, hashes
type
BlobID* = uint64
BlobIDs* = seq[BlobID]
Expand Down
6 changes: 0 additions & 6 deletions nimbus/common/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions nimbus/db/access_list.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import
eth/common/[addresses, transactions],
../utils/mergeutils

export addresses

type
SlotSet = HashSet[UInt256]

Expand Down
110 changes: 8 additions & 102 deletions nimbus/db/aristo/aristo_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import
std/times,
eth/common,
eth/common/hashes,
results,
./aristo_desc/desc_backend,
./aristo_init/memory_db,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -359,8 +333,6 @@ type

partAccountTwig*: AristoApiPartAccountTwig
partStorageTwig*: AristoApiPartStorageTwig
partUntwigGeneric*: AristoApiPartUntwigGeneric
partUntwigGenericOk*: AristoApiPartUntwigGenericOk
partUntwigPath*: AristoApiPartUntwigPath
partUntwigPathOk*: AristoApiPartUntwigPathOk

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions nimbus/db/aristo/aristo_check.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions nimbus/db/aristo/aristo_check/check_twig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{.push raises: [].}

import
eth/common,
eth/common/hashes,
results,
".."/[aristo_compute, aristo_desc, aristo_fetch, aristo_part]

Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_compute.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_delete.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_delete/delete_subtree.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{.push raises: [].}

import
eth/common,
eth/common/hashes,
".."/[aristo_desc, aristo_get, aristo_layers]

# ------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions nimbus/db/aristo/aristo_delta.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

import
std/tables,
eth/common,
results,
./aristo_desc/desc_backend,
"."/[aristo_desc]
./aristo_desc

# ------------------------------------------------------------------------------
# Public functions, save to backend
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions nimbus/db/aristo/aristo_desc/desc_identifiers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

import
std/[algorithm, sequtils, sets, strutils, hashes],
eth/common,
eth/common/[base, hashes],
eth/rlp,
stew/byteutils,
chronicles,
results,
stint,
./desc_nibbles

export
desc_nibbles
desc_nibbles, base, hashes, rlp

type
VertexID* = distinct uint64
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions nimbus/db/aristo/aristo_desc/desc_structural.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_fetch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import
std/typetraits,
eth/common,
eth/common/[base, hashes],
results,
"."/[aristo_compute, aristo_desc, aristo_get, aristo_layers, aristo_hike]

Expand Down
1 change: 0 additions & 1 deletion nimbus/db/aristo/aristo_get.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{.push raises: [].}

import
std/tables,
results,
"."/[aristo_desc, aristo_layers]

Expand Down
3 changes: 1 addition & 2 deletions nimbus/db/aristo/aristo_hike.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
{.push raises: [].}

import
eth/common,
eth/common/hashes,
results,
stew/arraybuf,
"."/[aristo_desc, aristo_get]

const
Expand Down
1 change: 0 additions & 1 deletion nimbus/db/aristo/aristo_init/memory_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import
std/[algorithm, options, sequtils, tables],
eth/common,
results,
../aristo_constants,
../aristo_desc,
Expand Down
Loading

0 comments on commit 59b9303

Please sign in to comment.