mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
[skip ci] simplify rootHash usage
This commit is contained in:
parent
d37e37e5f3
commit
2472662057
@ -79,11 +79,9 @@ proc isSuicided*(c: BaseComputation, address: EthAddress): bool =
|
||||
proc snapshot*(comp: BaseComputation) =
|
||||
comp.dbsnapshot.transaction = comp.vmState.chaindb.db.beginTransaction()
|
||||
comp.dbsnapshot.intermediateRoot = comp.vmState.accountDb.rootHash
|
||||
comp.vmState.blockHeader.stateRoot = comp.vmState.accountDb.rootHash
|
||||
|
||||
proc commit*(comp: BaseComputation) =
|
||||
comp.dbsnapshot.transaction.commit()
|
||||
comp.vmState.accountDb.rootHash = comp.vmState.blockHeader.stateRoot
|
||||
|
||||
proc dispose*(comp: BaseComputation) {.inline.} =
|
||||
comp.dbsnapshot.transaction.dispose()
|
||||
@ -91,7 +89,6 @@ proc dispose*(comp: BaseComputation) {.inline.} =
|
||||
proc rollback*(comp: BaseComputation) =
|
||||
comp.dbsnapshot.transaction.rollback()
|
||||
comp.vmState.accountDb.rootHash = comp.dbsnapshot.intermediateRoot
|
||||
comp.vmState.blockHeader.stateRoot = comp.dbsnapshot.intermediateRoot
|
||||
|
||||
proc setError*(comp: BaseComputation, msg: string, burnsGas = false) {.inline.} =
|
||||
comp.error = Error(info: msg, burnsGas: burnsGas)
|
||||
|
@ -34,7 +34,6 @@ proc init*(self: BaseVMState, prevStateRoot: Hash256, header: BlockHeader,
|
||||
self.tracer.initTracer(tracerFlags)
|
||||
self.tracingEnabled = TracerFlags.EnableTracing in tracerFlags
|
||||
self.logEntries = @[]
|
||||
self.blockHeader.stateRoot = prevStateRoot
|
||||
self.accountDb = newAccountStateDB(chainDB.db, prevStateRoot, chainDB.pruneTrie)
|
||||
self.touchedAccounts = initHashSet[EthAddress]()
|
||||
|
||||
@ -43,9 +42,6 @@ proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
|
||||
new result
|
||||
result.init(prevStateRoot, header, chainDB, tracerFlags)
|
||||
|
||||
proc stateRoot*(vmState: BaseVMState): Hash256 =
|
||||
vmState.blockHeader.stateRoot
|
||||
|
||||
method blockhash*(vmState: BaseVMState): Hash256 {.base, gcsafe.} =
|
||||
vmState.blockHeader.hash
|
||||
|
||||
@ -85,56 +81,14 @@ method getAncestorHash*(vmState: BaseVMState, blockNumber: BlockNumber): Hash256
|
||||
var header = vmState.prevHeaders[idx]
|
||||
result = header.hash
|
||||
|
||||
when false:
|
||||
# this was an older version of `mutateStateDB`, kept here for reference
|
||||
# until `mutateStateDB` is fully implemented.
|
||||
macro db*(vmState: untyped, readOnly: bool, handler: untyped): untyped =
|
||||
# vm.state.db:
|
||||
# setupStateDB(fixture{"pre"}, stateDb)
|
||||
# code = db.getCode(fixture{"exec"}{"address"}.getStr)
|
||||
let db = ident("db")
|
||||
result = quote:
|
||||
block:
|
||||
var `db` = `vmState`.chaindb.getStateDB(`vmState`.blockHeader.stateRoot, `readOnly`)
|
||||
`handler`
|
||||
if `readOnly`:
|
||||
# This acts as a secondary check that no mutation took place for
|
||||
# read_only databases.
|
||||
doAssert `db`.rootHash == `vmState`.blockHeader.stateRoot
|
||||
elif `vmState`.blockHeader.stateRoot != `db`.rootHash:
|
||||
`vmState`.blockHeader.stateRoot = `db`.rootHash
|
||||
|
||||
# TODO
|
||||
# `vmState`.accessLogs.reads.update(`db`.db.accessLogs.reads)
|
||||
# `vmState`.accessLogs.writes.update(`db`.db.accessLogs.writes)
|
||||
|
||||
# remove the reference to the underlying `db` object to ensure that no
|
||||
# further modifications can occur using the `State` object after
|
||||
# leaving the context.
|
||||
# TODO `db`.db = nil
|
||||
# state._trie = None
|
||||
|
||||
proc getStateDb*(vmState: BaseVMState; stateRoot: Hash256): AccountStateDB =
|
||||
# TODO: use AccountStateDB revert/commit after JournalDB implemented
|
||||
vmState.accountDb.rootHash = stateRoot
|
||||
vmState.accountDb
|
||||
|
||||
proc readOnlyStateDB*(vmState: BaseVMState): ReadOnlyStateDB {.inline.} =
|
||||
ReadOnlyStateDB(vmState.accountDb)
|
||||
|
||||
template mutateStateDB*(vmState: BaseVMState, body: untyped) =
|
||||
# This should provide more clever change handling in the future
|
||||
# TODO: use AccountStateDB revert/commit after JournalDB implemented
|
||||
block:
|
||||
let initialStateRoot = vmState.blockHeader.stateRoot
|
||||
var db {.inject.} = vmState.getStateDB(initialStateRoot)
|
||||
|
||||
var db {.inject.} = vmState.accountDb
|
||||
body
|
||||
|
||||
let finalStateRoot = db.rootHash
|
||||
if finalStateRoot != initialStateRoot:
|
||||
vmState.blockHeader.stateRoot = finalStateRoot
|
||||
|
||||
proc getTracingResult*(vmState: BaseVMState): JsonNode =
|
||||
doAssert(vmState.tracingEnabled)
|
||||
vmState.tracer.trace
|
||||
|
Loading…
x
Reference in New Issue
Block a user