Skip to content

Commit

Permalink
no really tested yet ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mjfh committed Jun 20, 2024
1 parent bf0669f commit 1064b43
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 437 deletions.
4 changes: 2 additions & 2 deletions nimbus/core/tx_pool/tx_tasks/tx_packer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ proc vmExecInit(xp: TxPoolRef): Result[TxPackerStateRef, string]

let packer = TxPackerStateRef( # return value
xp: xp,
tr: AristoDbMemory.newCoreDbRef().ctx.getMpt CtGeneric,
tr: AristoDbMemory.newCoreDbRef().ctx.getColumn(CtGeneric, clearData=true),
balance: xp.chain.vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient),
numBlobPerBlock: 0,
)
Expand Down Expand Up @@ -255,7 +255,7 @@ proc vmExecCommit(pst: TxPackerStateRef)
vmState.receipts.setLen(nItems)

xp.chain.receipts = vmState.receipts
xp.chain.txRoot = pst.tr.getColumn.state.valueOr:
xp.chain.txRoot = pst.tr.state.valueOr:
raiseAssert "vmExecCommit(): state() failed " & $$error
xp.chain.stateRoot = vmState.stateDB.rootHash

Expand Down
17 changes: 17 additions & 0 deletions nimbus/db/aristo/aristo_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ type
## For a generic sub-tree starting at `root`, fetch the data record
## indexed by `path`.

AristoApiFetchGenericStateFn* =
proc(db: AristoDbRef;
root: VertexID;
): Result[Hash256,AristoError]
{.noRaise.}
## Fetch the Merkle hash of the argument `root`.

AristoApiFetchStorageDataFn* =
proc(db: AristoDbRef;
path: openArray[byte];
Expand Down Expand Up @@ -434,6 +441,7 @@ type
fetchAccountPayload*: AristoApiFetchAccountPayloadFn
fetchAccountState*: AristoApiFetchAccountStateFn
fetchGenericData*: AristoApiFetchGenericDataFn
fetchGenericState*: AristoApiFetchGenericStateFn
fetchStorageData*: AristoApiFetchStorageDataFn
fetchStorageState*: AristoApiFetchStorageStateFn

Expand Down Expand Up @@ -482,6 +490,7 @@ type
AristoApiProfFetchAccountPayloadFn = "fetchAccountPayload"
AristoApiProfFetchAccountStateFn = "fetchAccountState"
AristoApiProfFetchGenericDataFn = "fetchGenericData"
AristoApiProfFetchGenericStateFn = "fetchGenericState"
AristoApiProfFetchStorageDataFn = "fetchStorageData"
AristoApiProfFetchStorageStateFn = "fetchStorageState"

Expand Down Expand Up @@ -547,6 +556,7 @@ when AutoValidateApiHooks:
doAssert not api.fetchAccountPayload.isNil
doAssert not api.fetchAccountState.isNil
doAssert not api.fetchGenericData.isNil
doAssert not api.fetchGenericState.isNil
doAssert not api.fetchStorageData.isNil
doAssert not api.fetchStorageState.isNil

Expand Down Expand Up @@ -616,6 +626,7 @@ func init*(api: var AristoApiObj) =
api.fetchAccountPayload = fetchAccountPayload
api.fetchAccountState = fetchAccountState
api.fetchGenericData = fetchGenericData
api.fetchGenericState = fetchGenericState
api.fetchStorageData = fetchStorageData
api.fetchStorageState = fetchStorageState

Expand Down Expand Up @@ -667,6 +678,7 @@ func dup*(api: AristoApiRef): AristoApiRef =
fetchAccountPayload: api.fetchAccountPayload,
fetchAccountState: api.fetchAccountState,
fetchGenericData: api.fetchGenericData,
fetchGenericState: api.fetchGenericState,
fetchStorageData: api.fetchStorageData,
fetchStorageState: api.fetchStorageState,

Expand Down Expand Up @@ -777,6 +789,11 @@ func init*(
AristoApiProfFetchGenericDataFn.profileRunner:
result = api.fetchGenericData(a, b, c)

profApi.fetchGenericState =
proc(a: AristoDbRef; b: VertexID;): auto =
AristoApiProfFetchGenericStateFn.profileRunner:
result = api.fetchGenericState(a, b)

profApi.fetchStorageData =
proc(a: AristoDbRef; b: openArray[byte]; c: PathID;): auto =
AristoApiProfFetchStorageDataFn.profileRunner:
Expand Down
41 changes: 24 additions & 17 deletions nimbus/db/aristo/aristo_fetch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ proc retrieveStoID(
ok stoID


proc retrieveMerkleHash(
db: AristoDbRef;
root: VertexID;
): Result[Hash256,AristoError] =
let key = db.getKeyRc(root).valueOr:
if error == GetKeyNotFound:
return ok(EMPTY_ROOT_HASH) # empty sub-tree
return err(error)
ok key.to(Hash256)


proc hasPayload(
db: AristoDbRef;
root: VertexID;
Expand Down Expand Up @@ -107,11 +118,7 @@ proc fetchAccountState*(
db: AristoDbRef;
): Result[Hash256,AristoError] =
## Fetch the Merkle hash of the account root.
let key = db.getKeyRc(VertexID 1).valueOr:
if error == GetKeyNotFound:
return ok(EMPTY_ROOT_HASH) # empty sub-tree
return err(error)
ok key.to(Hash256)
db.retrieveMerkleHash VertexID(1)

proc hasPathAccount*(
db: AristoDbRef;
Expand All @@ -136,6 +143,13 @@ proc fetchGenericData*(
assert pyl.pType == RawData # debugging only
ok pyl.rawBlob

proc fetchGenericState*(
db: AristoDbRef;
root: VertexID;
): Result[Hash256,AristoError] =
## Fetch the Merkle hash of the argument `root`.
db.retrieveMerkleHash root

proc hasPathGeneric*(
db: AristoDbRef;
root: VertexID;
Expand Down Expand Up @@ -165,18 +179,11 @@ proc fetchStorageState*(
accPath: PathID;
): Result[Hash256,AristoError] =
## Fetch the Merkle hash of the storage root related to `accPath`.
let
stoID = db.retrieveStoID(accPath).valueOr:
if error == FetchPathNotFound:
return ok(EMPTY_ROOT_HASH) # no sub-tree
return err(error)

key = db.getKeyRc(stoID).valueOr:
if error == GetKeyNotFound:
return ok(EMPTY_ROOT_HASH) # empty or no sub-tree
return err(error)

ok key.to(Hash256)
let stoID = db.retrieveStoID(accPath).valueOr:
if error == FetchPathNotFound:
return ok(EMPTY_ROOT_HASH) # no sub-tree
return err(error)
db.retrieveMerkleHash stoID

proc hasPathStorage*(
db: AristoDbRef;
Expand Down
Loading

0 comments on commit 1064b43

Please sign in to comment.