Remove hashify calls when forking (#2377)

This appears to no longer be needed and we want to delay hashing as much
as possible.
This commit is contained in:
Jacek Sieka 2024-06-17 14:18:50 +02:00 committed by GitHub
parent 61a809cf4d
commit 1fb658ff03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 36 deletions

View File

@ -151,7 +151,6 @@ type
AristoApiForkTxFn* = AristoApiForkTxFn* =
proc(db: AristoDbRef; proc(db: AristoDbRef;
backLevel: int; backLevel: int;
dontHashify = false;
): Result[AristoDbRef,AristoError] ): Result[AristoDbRef,AristoError]
{.noRaise.} {.noRaise.}
## Fork a new descriptor obtained from parts of the argument database ## Fork a new descriptor obtained from parts of the argument database
@ -173,9 +172,6 @@ type
## If there were no transactions that could be squashed, an empty ## If there were no transactions that could be squashed, an empty
## transaction is added. ## transaction is added.
## ##
## If the arguent flag `dontHashify` is passed `true`, the forked descriptor
## will *NOT* be hashified right after construction.
##
## Use `aristo_desc.forget()` to clean up this descriptor. ## Use `aristo_desc.forget()` to clean up this descriptor.
AristoApiGetKeyRcFn* = AristoApiGetKeyRcFn* =

View File

@ -51,7 +51,6 @@ func to*(tx: AristoTxRef; T: type[AristoDbRef]): T =
proc forkTx*( proc forkTx*(
db: AristoDbRef; db: AristoDbRef;
backLevel: int; # Backward location of transaction backLevel: int; # Backward location of transaction
dontHashify = false; # Process/fix MPT hashes
): Result[AristoDbRef,AristoError] = ): Result[AristoDbRef,AristoError] =
## Fork a new descriptor obtained from parts of the argument database ## Fork a new descriptor obtained from parts of the argument database
## as described by arguments `db` and `backLevel`. ## as described by arguments `db` and `backLevel`.
@ -71,18 +70,15 @@ proc forkTx*(
## If there were no transactions that could be squashed, an empty ## If there were no transactions that could be squashed, an empty
## transaction is added. ## transaction is added.
## ##
## If the arguent flag `dontHashify` is passed `true`, the forked descriptor
## will *NOT* be hashified right after construction.
##
## Use `aristo_desc.forget()` to clean up this descriptor. ## Use `aristo_desc.forget()` to clean up this descriptor.
## ##
# Fork top layer (with or without pending transaction)? # Fork top layer (with or without pending transaction)?
if backLevel == 0: if backLevel == 0:
return db.txForkTop dontHashify return db.txForkTop()
# Fork bottom layer (=> 0 < db.stack.len) # Fork bottom layer (=> 0 < db.stack.len)
if backLevel == db.stack.len: if backLevel == db.stack.len:
return db.txForkBase dontHashify return db.txForkBase()
# Inspect transaction stack # Inspect transaction stack
if 0 < backLevel: if 0 < backLevel:
@ -95,7 +91,7 @@ proc forkTx*(
tx = tx.parent tx = tx.parent
if tx.isNil: if tx.isNil:
return err(TxStackGarbled) return err(TxStackGarbled)
return tx.txFork dontHashify return tx.txFork()
# Plain fork, include `balancer` # Plain fork, include `balancer`
if backLevel == -1: if backLevel == -1:

View File

@ -16,7 +16,7 @@
import import
results, results,
./tx_frame, ./tx_frame,
".."/[aristo_desc, aristo_get, aristo_layers, aristo_hashify] ".."/[aristo_desc, aristo_get, aristo_layers]
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Public functions # Public functions
@ -24,7 +24,6 @@ import
proc txFork*( proc txFork*(
tx: AristoTxRef; # Transaction descriptor tx: AristoTxRef; # Transaction descriptor
dontHashify = false; # Process/fix MPT hashes
): Result[AristoDbRef,AristoError] = ): Result[AristoDbRef,AristoError] =
## Clone a transaction into a new DB descriptor accessing the same backend ## Clone a transaction into a new DB descriptor accessing the same backend
## database (if any) as the argument `db`. The new descriptor is linked to ## database (if any) as the argument `db`. The new descriptor is linked to
@ -48,9 +47,6 @@ proc txFork*(
## `tx` as top layer of level 1 (i.e. this is he only transaction.) Rolling ## `tx` as top layer of level 1 (i.e. this is he only transaction.) Rolling
## back will end up at the backend layer (incl. backend filter.) ## back will end up at the backend layer (incl. backend filter.)
## ##
## If the arguent flag `dontHashify` is passed `true`, the clone descriptor
## will *NOT* be hashified right after construction.
##
## Use `aristo_desc.forget()` to clean up this descriptor. ## Use `aristo_desc.forget()` to clean up this descriptor.
## ##
let db = tx.db let db = tx.db
@ -89,17 +85,11 @@ proc txFork*(
txUid: 1, txUid: 1,
level: 1) level: 1)
if not dontHashify:
txClone.hashify().isOkOr:
discard txClone.forget()
return err(error[1])
ok(txClone) ok(txClone)
proc txForkTop*( proc txForkTop*(
db: AristoDbRef; db: AristoDbRef;
dontHashify = false; # Process/fix MPT hashes
): Result[AristoDbRef,AristoError] = ): Result[AristoDbRef,AristoError] =
## Variant of `forkTx()` for the top transaction if there is any. Otherwise ## Variant of `forkTx()` for the top transaction if there is any. Otherwise
## the top layer is cloned, and an empty transaction is set up. After ## the top layer is cloned, and an empty transaction is set up. After
@ -111,21 +101,15 @@ proc txForkTop*(
let txClone = ? db.fork(noToplayer=true, noFilter=false) let txClone = ? db.fork(noToplayer=true, noFilter=false)
txClone.top = db.layersCc # Is a deep copy txClone.top = db.layersCc # Is a deep copy
if not dontHashify:
txClone.hashify().isOkOr:
discard txClone.forget()
return err(error[1])
discard txClone.txFrameBegin() discard txClone.txFrameBegin()
return ok(txClone) return ok(txClone)
# End if() # End if()
db.txRef.txFork dontHashify db.txRef.txFork()
proc txForkBase*( proc txForkBase*(
db: AristoDbRef; db: AristoDbRef;
dontHashify = false; # Process/fix MPT hashes
): Result[AristoDbRef,AristoError] = ): Result[AristoDbRef,AristoError] =
## Variant of `forkTx()`, sort of the opposite of `forkTop()`. This is the ## Variant of `forkTx()`, sort of the opposite of `forkTop()`. This is the
## equivalent of top layer forking after all tranactions have been rolled ## equivalent of top layer forking after all tranactions have been rolled
@ -134,16 +118,11 @@ proc txForkBase*(
## Use `aristo_desc.forget()` to clean up this descriptor. ## Use `aristo_desc.forget()` to clean up this descriptor.
## ##
if db.txRef.isNil: if db.txRef.isNil:
return db.txForkTop dontHashify return db.txForkTop()
let txClone = ? db.fork(noToplayer=true, noFilter=false) let txClone = ? db.fork(noToplayer=true, noFilter=false)
txClone.top = db.layersCc 0 txClone.top = db.layersCc 0
if not dontHashify:
txClone.hashify().isOkOr:
discard txClone.forget()
return err(error[1])
discard txClone.txFrameBegin() discard txClone.txFrameBegin()
ok(txClone) ok(txClone)