Skip to content

Commit

Permalink
Remove forkTx and friends (#2951)
Browse files Browse the repository at this point in the history
The forking facility has been replaced by ForkedChain - frames and
layers are two other mechanisms that mostly do the same thing at the
aristo level, without quite providing the functionality FC needs - this
cleanup will make that integration easier.
  • Loading branch information
arnetheduck authored Dec 18, 2024
1 parent 45bc642 commit 06a544a
Show file tree
Hide file tree
Showing 47 changed files with 67 additions and 1,447 deletions.
2 changes: 1 addition & 1 deletion nimbus/common/genesis.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import
std/tables,
eth/eip1559,
eth/common/[hashes, accounts, headers, addresses],
eth/common/[blocks, hashes, accounts, headers, addresses],
../db/[ledger, core_db],
../constants,
./chain_config
Expand Down
6 changes: 3 additions & 3 deletions nimbus/db/access_list.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import
std/[tables, sets],
stint,
eth/common,
eth/common/[addresses, transactions],
../utils/mergeutils

type
Expand Down Expand Up @@ -67,9 +67,9 @@ proc add*(ac: var AccessList, address: Address, slot: UInt256) =
proc clear*(ac: var AccessList) {.inline.} =
ac.slots.clear()

func getAccessList*(ac: AccessList): common.AccessList =
func getAccessList*(ac: AccessList): transactions.AccessList =
for address, slots in ac.slots:
result.add common.AccessPair(
result.add transactions.AccessPair(
address : address,
storageKeys: slots.toStorageKeys,
)
Expand Down
123 changes: 0 additions & 123 deletions nimbus/db/aristo/aristo_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,6 @@ type
{.noRaise.}
## Fetch the Merkle hash of the storage root related to `accPath`.

AristoApiFindTxFn* =
proc(db: AristoDbRef;
rvid: RootedVertexID;
key: HashKey;
): Result[int,AristoError]
{.noRaise.}
## Find the transaction where the vertex with ID `vid` exists and has
## the Merkle hash key `key`. If there is no transaction available,
## search in the filter and then in the backend.
##
## If the above procedure succeeds, an integer indicating the transaction
## level is returned:
##
## * `0` -- top level, current layer
## * `1`,`2`,`..` -- some transaction level further down the stack
## * `-1` -- the filter between transaction stack and database backend
## * `-2` -- the databse backend
##
## A successful return code might be used for the `forkTx()` call for
## creating a forked descriptor that provides the pair `(vid,key)`.
##

AristoApiFinishFn* =
proc(db: AristoDbRef;
eradicate = false;
Expand All @@ -161,32 +139,6 @@ type
## A non centre descriptor should always be destructed after use (see
## also# comments on `fork()`.)

AristoApiForkTxFn* =
proc(db: AristoDbRef;
backLevel: int;
): Result[AristoDbRef,AristoError]
{.noRaise.}
## Fork a new descriptor obtained from parts of the argument database
## as described by arguments `db` and `backLevel`.
##
## If the argument `backLevel` is non-negative, the forked descriptor
## will provide the database view where the first `backLevel` transaction
## layers are stripped and the remaing layers are squashed into a single
## transaction.
##
## If `backLevel` is `-1`, a database descriptor with empty transaction
## layers will be provided where the `balancer` between database and
## transaction layers are kept in place.
##
## If `backLevel` is `-2`, a database descriptor with empty transaction
## layers will be provided without a `balancer`.
##
## The returned database descriptor will always have transaction level one.
## If there were no transactions that could be squashed, an empty
## transaction is added.
##
## Use `aristo_desc.forget()` to clean up this descriptor.

AristoApiHashifyFn* =
proc(db: AristoDbRef;
): Result[void,(VertexID,AristoError)]
Expand Down Expand Up @@ -233,14 +185,6 @@ type
## Getter, non-negative nesting level (i.e. number of pending
## transactions)

AristoApiNForkedFn* =
proc(db: AristoDbRef;
): int
{.noRaise.}
## Returns the number of non centre descriptors (see comments on
## `reCentre()` for details.) This function is a fast version of
## `db.forked.toSeq.len`.

AristoApiMergeAccountRecordFn* =
proc(db: AristoDbRef;
accPath: Hash32;
Expand Down Expand Up @@ -358,23 +302,6 @@ type
##
## The argument `nxtSid` will be the ID for the next saved state record.

AristoApiReCentreFn* =
proc(db: AristoDbRef;
): Result[void,AristoError]
{.noRaise.}
## Re-focus the `db` argument descriptor so that it becomes the centre.
## Nothing is done if the `db` descriptor is the centre, already.
##
## With several descriptors accessing the same backend database there is
## a single one that has write permission for the backend (regardless
## whether there is a backend, at all.) The descriptor entity with write
## permission is called *the centre*.
##
## After invoking `reCentre()`, the argument database `db` can only be
## destructed by `finish()` which also destructs all other descriptors
## accessing the same backend database. Descriptors where `isCentre()`
## returns `false` must be single destructed with `forget()`.

AristoApiRollbackFn* =
proc(tx: AristoTxRef;
): Result[void,AristoError]
Expand Down Expand Up @@ -425,17 +352,13 @@ type
fetchStorageData*: AristoApiFetchStorageDataFn
fetchStorageRoot*: AristoApiFetchStorageRootFn

findTx*: AristoApiFindTxFn
finish*: AristoApiFinishFn
forget*: AristoApiForgetFn
forkTx*: AristoApiForkTxFn
hasPathAccount*: AristoApiHasPathAccountFn
hasPathStorage*: AristoApiHasPathStorageFn
hasStorageData*: AristoApiHasStorageDataFn

isTop*: AristoApiIsTopFn
level*: AristoApiLevelFn
nForked*: AristoApiNForkedFn

mergeAccountRecord*: AristoApiMergeAccountRecordFn
mergeStorageData*: AristoApiMergeStorageDataFn
Expand All @@ -449,7 +372,6 @@ type

pathAsBlob*: AristoApiPathAsBlobFn
persist*: AristoApiPersistFn
reCentre*: AristoApiReCentreFn
rollback*: AristoApiRollbackFn
txBegin*: AristoApiTxBeginFn
txLevel*: AristoApiTxLevelFn
Expand All @@ -472,18 +394,14 @@ type
AristoApiProfFetchStorageDataFn = "fetchStorageData"
AristoApiProfFetchStorageRootFn = "fetchStorageRoot"

AristoApiProfFindTxFn = "findTx"
AristoApiProfFinishFn = "finish"
AristoApiProfForgetFn = "forget"
AristoApiProfForkTxFn = "forkTx"

AristoApiProfHasPathAccountFn = "hasPathAccount"
AristoApiProfHasPathStorageFn = "hasPathStorage"
AristoApiProfHasStorageDataFn = "hasStorageData"

AristoApiProfIsTopFn = "isTop"
AristoApiProfLevelFn = "level"
AristoApiProfNForkedFn = "nForked"

AristoApiProfMergeAccountRecordFn = "mergeAccountRecord"
AristoApiProfMergeStorageDataFn = "mergeStorageData"
Expand All @@ -495,7 +413,6 @@ type

AristoApiProfPathAsBlobFn = "pathAsBlob"
AristoApiProfPersistFn = "persist"
AristoApiProfReCentreFn = "reCentre"
AristoApiProfRollbackFn = "rollback"
AristoApiProfTxBeginFn = "txBegin"
AristoApiProfTxLevelFn = "txLevel"
Expand Down Expand Up @@ -534,18 +451,14 @@ when AutoValidateApiHooks:
doAssert not api.fetchStorageData.isNil
doAssert not api.fetchStorageRoot.isNil

doAssert not api.findTx.isNil
doAssert not api.finish.isNil
doAssert not api.forget.isNil
doAssert not api.forkTx.isNil

doAssert not api.hasPathAccount.isNil
doAssert not api.hasPathStorage.isNil
doAssert not api.hasStorageData.isNil

doAssert not api.isTop.isNil
doAssert not api.level.isNil
doAssert not api.nForked.isNil

doAssert not api.mergeAccountRecord.isNil
doAssert not api.mergeStorageData.isNil
Expand All @@ -557,7 +470,6 @@ when AutoValidateApiHooks:

doAssert not api.pathAsBlob.isNil
doAssert not api.persist.isNil
doAssert not api.reCentre.isNil
doAssert not api.rollback.isNil
doAssert not api.txBegin.isNil
doAssert not api.txLevel.isNil
Expand Down Expand Up @@ -601,18 +513,14 @@ func init*(api: var AristoApiObj) =
api.fetchStorageData = fetchStorageData
api.fetchStorageRoot = fetchStorageRoot

api.findTx = findTx
api.finish = finish
api.forget = forget
api.forkTx = forkTx

api.hasPathAccount = hasPathAccount
api.hasPathStorage = hasPathStorage
api.hasStorageData = hasStorageData

api.isTop = isTop
api.level = level
api.nForked = nForked

api.mergeAccountRecord = mergeAccountRecord
api.mergeStorageData = mergeStorageData
Expand All @@ -624,7 +532,6 @@ func init*(api: var AristoApiObj) =

api.pathAsBlob = pathAsBlob
api.persist = persist
api.reCentre = reCentre
api.rollback = rollback
api.txBegin = txBegin
api.txLevel = txLevel
Expand All @@ -650,18 +557,14 @@ func dup*(api: AristoApiRef): AristoApiRef =
fetchStorageData: api.fetchStorageData,
fetchStorageRoot: api.fetchStorageRoot,

findTx: api.findTx,
finish: api.finish,
forget: api.forget,
forkTx: api.forkTx,

hasPathAccount: api.hasPathAccount,
hasPathStorage: api.hasPathStorage,
hasStorageData: api.hasStorageData,

isTop: api.isTop,
level: api.level,
nForked: api.nForked,

mergeAccountRecord: api.mergeAccountRecord,
mergeStorageData: api.mergeStorageData,
Expand All @@ -673,7 +576,6 @@ func dup*(api: AristoApiRef): AristoApiRef =

pathAsBlob: api.pathAsBlob,
persist: api.persist,
reCentre: api.reCentre,
rollback: api.rollback,
txBegin: api.txBegin,
txLevel: api.txLevel,
Expand Down Expand Up @@ -753,26 +655,11 @@ func init*(
AristoApiProfFetchStorageRootFn.profileRunner:
result = api.fetchStorageRoot(a, b)

profApi.findTx =
proc(a: AristoDbRef; b: RootedVertexID; c: HashKey): auto =
AristoApiProfFindTxFn.profileRunner:
result = api.findTx(a, b, c)

profApi.finish =
proc(a: AristoDbRef; b = false) =
AristoApiProfFinishFn.profileRunner:
api.finish(a, b)

profApi.forget =
proc(a: AristoDbRef): auto =
AristoApiProfForgetFn.profileRunner:
result = api.forget(a)

profApi.forkTx =
proc(a: AristoDbRef; b: int): auto =
AristoApiProfForkTxFn.profileRunner:
result = api.forkTx(a, b)

profApi.hasPathAccount =
proc(a: AristoDbRef; b: Hash32): auto =
AristoApiProfHasPathAccountFn.profileRunner:
Expand All @@ -798,11 +685,6 @@ func init*(
AristoApiProfLevelFn.profileRunner:
result = api.level(a)

profApi.nForked =
proc(a: AristoDbRef): auto =
AristoApiProfNForkedFn.profileRunner:
result = api.nForked(a)

profApi.mergeAccountRecord =
proc(a: AristoDbRef; b: Hash32; c: AristoAccount): auto =
AristoApiProfMergeAccountRecordFn.profileRunner:
Expand Down Expand Up @@ -843,11 +725,6 @@ func init*(
AristoApiProfPersistFn.profileRunner:
result = api.persist(a, b)

profApi.reCentre =
proc(a: AristoDbRef): auto =
AristoApiProfReCentreFn.profileRunner:
result = api.reCentre(a)

profApi.rollback =
proc(a: AristoTxRef): auto =
AristoApiProfRollbackFn.profileRunner:
Expand Down
32 changes: 2 additions & 30 deletions nimbus/db/aristo/aristo_delta.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ import
std/tables,
eth/common,
results,
./aristo_delta/[delta_merge, delta_reverse],
./aristo_desc/desc_backend,
"."/[aristo_desc, aristo_layers]
"."/[aristo_desc]

# ------------------------------------------------------------------------------
# Public functions, save to backend
# ------------------------------------------------------------------------------

proc deltaPersistentOk*(db: AristoDbRef): bool =
## Check whether the read-only filter can be merged into the backend
not db.backend.isNil and db.isCentre
not db.backend.isNil


proc deltaPersistent*(
db: AristoDbRef; # Database
nxtFid = 0u64; # Next filter ID (if any)
reCentreOk = false;
): Result[void,AristoError] =
## Resolve (i.e. move) the balancer into the physical backend database.
##
Expand Down Expand Up @@ -62,32 +60,6 @@ proc deltaPersistent*(
? be.putEndFn(? be.putBegFn())
return ok()

# Make sure that the argument `db` is at the centre so the backend is in
# read-write mode for this peer.
let parent = db.getCentre
if db != parent:
if not reCentreOk:
return err(FilBackendRoMode)
? db.reCentre()
# Always re-centre to `parent` (in case `reCentreOk` was set)
defer: discard parent.reCentre()

# Update forked balancers here do that errors are detected early (if any.)
if 0 < db.nForked:
let rev = db.revFilter(db.balancer).valueOr:
return err(error[1])
if not rev.isEmpty: # Can an empty `rev` happen at all?
var unsharedRevOk = true
for w in db.forked:
if not w.db.balancer.isValid:
unsharedRevOk = false
# The `rev` filter can be modified if one can make sure that it is
# not shared (i.e. only previously merged into the w.db.balancer.)
# Note that it is trivially true for a single fork.
let modLowerOk = w.isLast and unsharedRevOk
w.db.balancer = deltaMerge(
w.db.balancer, modUpperOk=false, rev, modLowerOk=modLowerOk)

let lSst = SavedState(
key: EMPTY_ROOT_HASH, # placeholder for more
serial: nxtFid)
Expand Down
Loading

0 comments on commit 06a544a

Please sign in to comment.