WIP; created test that persists mainnet blocks and

dumps the world state every X blocks.
This commit is contained in:
Daniel Lamberger 2024-02-09 16:11:27 +02:00
parent 5642662850
commit 2ea16613fa
14 changed files with 219 additions and 145 deletions

3
.gitignore vendored
View File

@ -35,6 +35,9 @@ nimcache
# local testnet files
/local_testnet_data
# test results / temporary data
testResults/*
# Nimble user files
nimble.develop
nimble.paths

View File

@ -55,7 +55,7 @@ proc getVmState(c: ChainRef, header: BlockHeader):
proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
bodies: openArray[BlockBody],
flags: PersistBlockFlags = {}): ValidationResult
flags: PersistBlockFlags = {}): tuple[status: ValidationResult, vmState: BaseVMState]
# wildcard exception, wrapped below in public section
{.inline, raises: [CatchableError].} =
@ -69,7 +69,7 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
# Note that `0 < headers.len`, assured when called from `persistBlocks()`
let vmState = c.getVmState(headers[0]).valueOr:
return ValidationResult.Error
return (ValidationResult.Error, nil)
trace "Persisting blocks",
fromBlock = headers[0].blockNumber,
@ -81,11 +81,15 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
c.com.hardForkTransition(header)
trace "Processing block",
number = header.blockNumber,
time = header.timestamp.int64.fromUnix.utc
if not vmState.reinit(header):
debug "Cannot update VmState",
blockNumber = header.blockNumber,
item = i
return ValidationResult.Error
return (ValidationResult.Error, nil)
if c.validateBlock and c.extraValidation and
c.verifyFrom <= header.blockNumber:
@ -98,7 +102,7 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
if res.isErr:
debug "block validation error",
msg = res.error
return ValidationResult.Error
return (ValidationResult.Error, nil)
if c.generateWitness:
vmState.generateWitness = true
@ -118,7 +122,7 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
warn "Validation error", blockNumber=header.blockNumber
if validationResult != ValidationResult.OK:
return validationResult
return (validationResult, nil)
if c.validateBlock and c.extraValidation and
c.verifyFrom <= header.blockNumber:
@ -133,7 +137,7 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
debug "PoA header verification failed",
blockNumber = header.blockNumber,
msg = $rc.error
return ValidationResult.Error
return (ValidationResult.Error, nil)
if c.generateWitness:
let dbTx = c.db.beginTransaction()
@ -169,6 +173,7 @@ proc persistBlocksImpl(c: ChainRef; headers: openArray[BlockHeader];
c.com.syncCurrent = header.blockNumber
dbTx.commit()
(ValidationResult.OK, vmState)
# ------------------------------------------------------------------------------
# Public `ChainDB` methods
@ -178,7 +183,7 @@ proc insertBlockWithoutSetHead*(c: ChainRef, header: BlockHeader,
body: BlockBody): ValidationResult
{.gcsafe, raises: [CatchableError].} =
result = c.persistBlocksImpl(
[header], [body], {NoPersistHeader, NoSaveReceipts})
[header], [body], {NoPersistHeader, NoSaveReceipts}).status
if result == ValidationResult.OK:
c.db.persistHeaderToDbWithoutSetHead(header, c.com.startOfHistory)
@ -195,7 +200,7 @@ proc setCanonical*(c: ChainRef, header: BlockHeader): ValidationResult
hash = header.blockHash
return ValidationResult.Error
result = c.persistBlocksImpl([header], [body], {NoPersistHeader, NoSaveTxs})
result = c.persistBlocksImpl([header], [body], {NoPersistHeader, NoSaveTxs}).status
if result == ValidationResult.OK:
discard c.db.setHead(header.blockHash)
@ -209,20 +214,26 @@ proc setCanonical*(c: ChainRef, blockHash: Hash256): ValidationResult
setCanonical(c, header)
proc persistBlocks*(c: ChainRef; headers: openArray[BlockHeader];
bodies: openArray[BlockBody]): ValidationResult
proc persistBlocksAndReturnVmState*(c: ChainRef; headers: openArray[BlockHeader];
bodies: openArray[BlockBody]): tuple[status: ValidationResult, vmState: BaseVMState]
{.gcsafe, raises: [CatchableError].} =
# Run the VM here
if headers.len != bodies.len:
debug "Number of headers not matching number of bodies"
return ValidationResult.Error
return (ValidationResult.Error, nil)
if headers.len == 0:
debug "Nothing to do"
return ValidationResult.OK
return (ValidationResult.OK, nil)
c.persistBlocksImpl(headers,bodies)
proc persistBlocks*(c: ChainRef; headers: openArray[BlockHeader];
bodies: openArray[BlockBody]): ValidationResult
{.gcsafe, raises: [CatchableError].} =
persistBlocksAndReturnVmState(c, headers, bodies).status
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------

View File

@ -19,8 +19,8 @@ import
../../kvstore_rocksdb
type
LegaPersDbRef = ref object of LegacyDbRef
rdb: RocksStoreRef # for backend access with legacy mode
LegaPersDbRef* = ref object of LegacyDbRef
rdb*: RocksStoreRef # for backend access with legacy mode
ChainDB = ref object of RootObj
kv: KvStoreRef

View File

@ -273,7 +273,7 @@ proc dbType*(db: CoreDbRef): CoreDbType =
##
db.setTrackNewApi BaseDbTypeFn
result = db.dbType
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc compensateLegacySetup*(db: CoreDbRef) =
## On the persistent legacy hexary trie, this function is needed for
@ -282,7 +282,7 @@ proc compensateLegacySetup*(db: CoreDbRef) =
##
db.setTrackNewApi BaseLegacySetupFn
db.methods.legacySetupFn()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stack=getStackTrace()
proc level*(db: CoreDbRef): int =
## Getter, retrieve transaction level (zero if there is no pending
@ -290,7 +290,7 @@ proc level*(db: CoreDbRef): int =
##
db.setTrackNewApi BaseLevelFn
result = db.methods.levelFn()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc parent*(cld: CoreDxChldRefs): CoreDbRef =
## Getter, common method for all sub-modules
@ -302,7 +302,7 @@ proc backend*(dsc: CoreDxKvtRef | CoreDxTrieRelated | CoreDbRef): auto =
##
dsc.setTrackNewApi AnyBackendFn
result = dsc.methods.backendFn()
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stack=getStackTrace()
proc finish*(db: CoreDbRef; flush = false) =
## Database destructor. If the argument `flush` is set `false`, the database
@ -314,7 +314,7 @@ proc finish*(db: CoreDbRef; flush = false) =
##
db.setTrackNewApi BaseFinishFn
db.methods.destroyFn flush
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stack=getStackTrace()
proc `$$`*(e: CoreDbErrorRef): string =
## Pretty print error symbol, note that this directive may have side effects
@ -322,7 +322,7 @@ proc `$$`*(e: CoreDbErrorRef): string =
##
e.setTrackNewApi ErrorPrintFn
result = e.prettyText()
e.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
e.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc `$$`*(trie: CoreDbTrieRef): string =
## Pretty print vertex ID symbol, note that this directive may have side
@ -349,7 +349,7 @@ proc rootHash*(trie: CoreDbTrieRef): CoreDbRc[Hash256] =
else:
ok EMPTY_ROOT_HASH
# Note: tracker will be silent if `vid` is NIL
trie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, result
trie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, result, stack=getStackTrace()
proc rootHashOrEmpty*(trie: CoreDbTrieRef): Hash256 =
## Convenience wrapper, returns `EMPTY_ROOT_HASH` where `hash()` would fail.
@ -376,7 +376,7 @@ proc recast*(account: CoreDbAccount): CoreDbRc[Account] =
storageRoot: rc.value)
else:
err(rc.error)
stoTrie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stoTrie, result
stoTrie.ifTrackNewApi: debug newApiTxt, ctx, elapsed, stoTrie, result, stack=getStackTrace()
proc getTrie*(
@ -421,7 +421,7 @@ proc getTrie*(
##
db.setTrackNewApi BaseGetTrieFn
result = db.methods.getTrieFn(StorageTrie, root, some(address))
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, address, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, root, address, result, stack=getStackTrace()
proc getTrie*(
db: CoreDbRef;
@ -435,7 +435,7 @@ proc getTrie*(
result = db.methods.getTrieFn(
StorageTrie, EMPTY_ROOT_HASH, some(address)).valueOr:
raiseAssert error.prettyText()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public key-value table methods
@ -482,13 +482,13 @@ proc newKvt*(db: CoreDbRef; saveMode = AutoSave): CoreDxKvtRef =
db.setTrackNewApi BaseNewKvtFn
result = db.methods.newKvtFn(saveMode).valueOr:
raiseAssert error.prettyText()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, saveMode
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, saveMode, stack=getStackTrace()
proc get*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
## This function always returns a non-empty `Blob` or an error code.
kvt.setTrackNewApi KvtGetFn
result = kvt.methods.getFn key
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc getOrEmpty*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
## This function sort of mimics the behaviour of the legacy database
@ -504,7 +504,7 @@ proc getOrEmpty*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[Blob] =
proc del*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[void] =
kvt.setTrackNewApi KvtDelFn
result = kvt.methods.delFn key
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc put*(
kvt: CoreDxKvtRef;
@ -514,14 +514,14 @@ proc put*(
kvt.setTrackNewApi KvtPutFn
result = kvt.methods.putFn(key, val)
kvt.ifTrackNewApi:
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, result
debug newApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, result, stack=getStackTrace()
proc hasKey*(kvt: CoreDxKvtRef; key: openArray[byte]): CoreDbRc[bool] =
## Would be named `contains` if it returned `bool` rather than `Result[]`.
##
kvt.setTrackNewApi KvtHasKeyFn
result = kvt.methods.hasKeyFn key
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result
kvt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc persistent*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
## For the legacy database, this function has no effect and succeeds always.
@ -539,7 +539,7 @@ proc persistent*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
##
dsc.setTrackNewApi KvtPersistentFn
result = dsc.methods.persistentFn()
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc forget*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
## For the legacy database, this function has no effect and succeeds always.
@ -557,7 +557,7 @@ proc forget*(dsc: CoreDxKvtRef): CoreDbRc[void] {.discardable.} =
##
dsc.setTrackNewApi KvtForgetFn
result = dsc.methods.forgetFn()
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public Merkle Patricia Tree, hexary trie constructors
@ -583,7 +583,7 @@ proc newMpt*(
##
db.setTrackNewApi BaseNewMptFn
result = db.methods.newMptFn(trie, prune, saveMode)
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, prune, saveMode, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, trie, prune, saveMode, result, stack=getStackTrace()
proc newMpt*(
db: CoreDbRef;
@ -600,7 +600,7 @@ proc newMpt*(
let trie = db.methods.getTrieFn(kind, EMPTY_ROOT_HASH, address).value
result = db.methods.newMptFn(trie, prune, saveMode).valueOr:
raiseAssert error.prettyText()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode, stack=getStackTrace()
proc newMpt*(acc: CoreDxAccRef): CoreDxMptRef =
@ -615,7 +615,7 @@ proc newMpt*(acc: CoreDxAccRef): CoreDxMptRef =
acc.ifTrackNewApi:
let root = result.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, root
, stack=getStackTrace()
proc newAccMpt*(
db: CoreDbRef;
@ -670,7 +670,7 @@ proc newAccMpt*(
raiseAssert error.prettyText()
result = db.methods.newAccFn(trie, prune, saveMode).valueOr:
raiseAssert error.prettyText()
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prune, saveMode, stack=getStackTrace()
proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
@ -682,7 +682,7 @@ proc toMpt*(phk: CoreDxPhkRef): CoreDxMptRef =
result = phk.fromMpt
phk.ifTrackNewApi:
let trie = result.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie
debug newApiTxt, ctx, elapsed, trie, stack=getStackTrace()
proc toPhk*(mpt: CoreDxMptRef): CoreDxPhkRef =
## Replaces argument `mpt` by a pre-hashed *MPT*.
@ -693,7 +693,7 @@ proc toPhk*(mpt: CoreDxMptRef): CoreDxPhkRef =
result = mpt.toCoreDxPhkRef
mpt.ifTrackNewApi:
let trie = result.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie
debug newApiTxt, ctx, elapsed, trie, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public common methods for all hexary trie databases (`mpt`, `phk`, or `acc`)
@ -704,7 +704,7 @@ proc isPruning*(dsc: CoreDxTrieRefs): bool =
##
dsc.setTrackNewApi AnyIsPruningFn
result = dsc.methods.isPruningFn()
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
dsc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc getTrie*(acc: CoreDxAccRef): CoreDbTrieRef =
@ -712,19 +712,19 @@ proc getTrie*(acc: CoreDxAccRef): CoreDbTrieRef =
##
acc.setTrackNewApi AccGetTrieFn
result = acc.methods.getTrieFn()
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc getTrie*(mpt: CoreDxMptRef): CoreDbTrieRef =
## Variant of `getTrie()`
mpt.setTrackNewApi MptGetTrieFn
result = mpt.methods.getTrieFn()
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
mpt.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc getTrie*(phk: CoreDxPhkRef): CoreDbTrieRef =
## Variant of `getTrie()`
phk.setTrackNewApi PhkGetTrieFn
result = phk.methods.getTrieFn()
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
phk.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc persistent*(acc: CoreDxAccRef): CoreDbRc[void] =
@ -743,7 +743,7 @@ proc persistent*(acc: CoreDxAccRef): CoreDbRc[void] =
##
acc.setTrackNewApi AccPersistentFn
result = acc.methods.persistentFn()
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc persistent*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
## Variant of `persistent()`
@ -751,7 +751,7 @@ proc persistent*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
result = mpt.methods.persistentFn()
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, result
debug newApiTxt, ctx, elapsed, trie, result, stack=getStackTrace()
proc persistent*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
## Variant of `persistent()`
@ -759,7 +759,7 @@ proc persistent*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
result = phk.methods.persistentFn()
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, result
debug newApiTxt, ctx, elapsed, trie, result, stack=getStackTrace()
proc forget*(acc: CoreDxAccRef): CoreDbRc[void] {.discardable.} =
@ -773,7 +773,7 @@ proc forget*(acc: CoreDxAccRef): CoreDbRc[void] {.discardable.} =
##
acc.setTrackNewApi AccForgetFn
result = acc.methods.forgetFn()
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc forget*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
## Variant of `forget()`
@ -781,7 +781,7 @@ proc forget*(mpt: CoreDxMptRef): CoreDbRc[void] {.discardable.} =
result = mpt.methods.forgetFn()
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, result
debug newApiTxt, ctx, elapsed, trie, result, stack=getStackTrace()
proc forget*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
## Variant of `forget()`
@ -789,7 +789,7 @@ proc forget*(phk: CoreDxPhkRef): CoreDbRc[void] {.discardable.} =
result = phk.methods.forgetFn()
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, result
debug newApiTxt, ctx, elapsed, trie, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public generic hexary trie database methods (`mpt` or `phk`)
@ -803,7 +803,7 @@ proc fetch*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
result = mpt.methods.fetchFn key
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc fetch*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
## Variant of `fetch()"
@ -811,7 +811,7 @@ proc fetch*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
result = phk.methods.fetchFn key
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc fetchOrEmpty*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
@ -824,7 +824,7 @@ proc fetchOrEmpty*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[Blob] =
result = CoreDbRc[Blob].ok(EmptyBlob)
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc fetchOrEmpty*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
## Variant of `fetchOrEmpty()`
@ -834,7 +834,7 @@ proc fetchOrEmpty*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[Blob] =
result = CoreDbRc[Blob].ok(EmptyBlob)
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc delete*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[void] =
@ -842,14 +842,14 @@ proc delete*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[void] =
result = mpt.methods.deleteFn key
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc delete*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[void] =
phk.setTrackNewApi PhkDeleteFn
result = phk.methods.deleteFn key
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc merge*(
@ -861,7 +861,7 @@ proc merge*(
result = mpt.methods.mergeFn(key, val)
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result, stack=getStackTrace()
proc merge*(
phk: CoreDxPhkRef;
@ -872,7 +872,7 @@ proc merge*(
result = phk.methods.mergeFn(key, val)
phk.ifTrackNewApi:
let trie = phk.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, val=val.toLenStr, result, stack=getStackTrace()
proc hasPath*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[bool] =
@ -883,7 +883,7 @@ proc hasPath*(mpt: CoreDxMptRef; key: openArray[byte]): CoreDbRc[bool] =
result = mpt.methods.hasPathFn key
mpt.ifTrackNewApi:
let trie = mpt.methods.getTrieFn()
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result
debug newApiTxt, ctx, elapsed, trie, key=key.toStr, result, stack=getStackTrace()
proc hasPath*(phk: CoreDxPhkRef; key: openArray[byte]): CoreDbRc[bool] =
## Variant of `hasPath()`
@ -904,12 +904,12 @@ proc fetch*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[CoreDbAccount] =
result = acc.methods.fetchFn address
acc.ifTrackNewApi:
let stoTrie = if result.isErr: "n/a" else: result.value.stoTrie.prettyText()
debug newApiTxt, ctx, elapsed, address, stoTrie, result
debug newApiTxt, ctx, elapsed, address, stoTrie, result, stack=getStackTrace()
proc delete*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
acc.setTrackNewApi AccDeleteFn
result = acc.methods.deleteFn address
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result, stack=getStackTrace()
proc stoFlush*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[void] =
## Recursively delete all data elements from the storage trie associated to
@ -941,7 +941,7 @@ proc hasPath*(acc: CoreDxAccRef; address: EthAddress): CoreDbRc[bool] =
##
acc.setTrackNewApi AccHasPathFn
result = acc.methods.hasPathFn address
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result
acc.ifTrackNewApi: debug newApiTxt, ctx, elapsed, address, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public transaction related methods
@ -953,38 +953,38 @@ proc newTransaction*(db: CoreDbRef): CoreDbRc[CoreDxTxRef] =
db.setTrackNewApi BaseNewTxFn
result = db.methods.beginFn()
db.ifTrackNewApi:
debug newApiTxt, ctx, elapsed, newLevel=db.methods.levelFn(), result
debug newApiTxt, ctx, elapsed, newLevel=db.methods.levelFn(), result, stack=getStackTrace()
proc level*(tx: CoreDxTxRef): int =
## Print positive argument `tx` transaction level
##
tx.setTrackNewApi TxLevelFn
result = tx.methods.levelFn()
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc commit*(tx: CoreDxTxRef, applyDeletes = true): CoreDbRc[void] =
tx.setTrackNewApi TxCommitFn:
let prvLevel {.used.} = tx.methods.levelFn()
result = tx.methods.commitFn applyDeletes
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result, stack=getStackTrace()
proc rollback*(tx: CoreDxTxRef): CoreDbRc[void] =
tx.setTrackNewApi TxRollbackFn:
let prvLevel {.used.} = tx.methods.levelFn()
result = tx.methods.rollbackFn()
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result, stack=getStackTrace()
proc dispose*(tx: CoreDxTxRef): CoreDbRc[void] =
tx.setTrackNewApi TxDisposeFn:
let prvLevel {.used.} = tx.methods.levelFn()
result = tx.methods.disposeFn()
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result, stack=getStackTrace()
proc safeDispose*(tx: CoreDxTxRef): CoreDbRc[void] =
tx.setTrackNewApi TxSaveDisposeFn:
let prvLevel {.used.} = tx.methods.levelFn()
result = tx.methods.safeDisposeFn()
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result
tx.ifTrackNewApi: debug newApiTxt, ctx, elapsed, prvLevel, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public tracer methods
@ -997,24 +997,24 @@ proc newCapture*(
## Constructor
db.setTrackNewApi BaseCaptureFn
result = db.methods.captureFn flags
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
db.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc recorder*(cp: CoreDxCaptRef): CoreDbRc[CoreDbRef] =
## Getter
cp.setTrackNewApi CptRecorderFn
result = cp.methods.recorderFn()
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc logDb*(cp: CoreDxCaptRef): CoreDbRc[CoreDbRef] =
cp.setTrackNewApi CptLogDbFn
result = cp.methods.logDbFn()
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc flags*(cp: CoreDxCaptRef): set[CoreDbCaptFlags] =
## Getter
cp.setTrackNewApi CptFlagsFn
result = cp.methods.getFlagsFn()
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result
cp.ifTrackNewApi: debug newApiTxt, ctx, elapsed, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# Public methods, legacy API
@ -1029,7 +1029,7 @@ when ProvideLegacyAPI:
proc backend*(dsc: CoreDbChldRefs): auto =
dsc.setTrackLegaApi LegaBackendFn
result = dsc.distinctBase.backend
dsc.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
dsc.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
# ----------------
@ -1037,35 +1037,35 @@ when ProvideLegacyAPI:
## Legacy pseudo constructor, see `toKvt()` for production constructor
db.setTrackLegaApi LegaNewKvtFn
result = db.newKvt().CoreDbKvtRef
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc get*(kvt: CoreDbKvtRef; key: openArray[byte]): Blob =
kvt.setTrackLegaApi LegaKvtGetFn
result = kvt.distinctBase.getOrEmpty(key).expect $ctx
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc del*(kvt: CoreDbKvtRef; key: openArray[byte]): void =
kvt.setTrackLegaApi LegaKvtDelFn
kvt.distinctBase.del(key).expect $ctx
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, stack=getStackTrace()
proc put*(kvt: CoreDbKvtRef; key: openArray[byte]; val: openArray[byte]) =
kvt.setTrackLegaApi LegaKvtPutFn
kvt.distinctBase.parent.newKvt().put(key, val).expect $ctx
kvt.ifTrackLegaApi:
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, stack=getStackTrace()
proc contains*(kvt: CoreDbKvtRef; key: openArray[byte]): bool =
kvt.setTrackLegaApi LegaKvtContainsFn
result = kvt.distinctBase.hasKey(key).expect $ctx
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
kvt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
# ----------------
proc toMpt*(phk: CoreDbPhkRef): CoreDbMptRef =
phk.setTrackLegaApi LegaToMptFn
result = phk.distinctBase.toMpt.CoreDbMptRef
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc mptPrune*(db: CoreDbRef; root: Hash256; prune = true): CoreDbMptRef =
db.setTrackLegaApi LegaNewMptFn
@ -1075,7 +1075,7 @@ when ProvideLegacyAPI:
mpt = db.newMpt(trie, prune).valueOr:
raiseAssert error.prettyText() & ": " & $ctx
result = mpt.CoreDbMptRef
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune, stack=getStackTrace()
proc mptPrune*(db: CoreDbRef; prune = true): CoreDbMptRef =
db.setTrackLegaApi LegaNewMptFn
@ -1087,7 +1087,7 @@ when ProvideLegacyAPI:
proc toPhk*(mpt: CoreDbMptRef): CoreDbPhkRef =
mpt.setTrackLegaApi LegaToPhkFn
result = mpt.distinctBase.toPhk.CoreDbPhkRef
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc phkPrune*(db: CoreDbRef; root: Hash256; prune = true): CoreDbPhkRef =
db.setTrackLegaApi LegaNewPhkFn
@ -1097,7 +1097,7 @@ when ProvideLegacyAPI:
phk = db.newMpt(trie, prune).valueOr:
raiseAssert error.prettyText() & ": " & $ctx
result = phk.toCoreDxPhkRef.CoreDbPhkRef
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, root, prune, stack=getStackTrace()
proc phkPrune*(db: CoreDbRef; prune = true): CoreDbPhkRef =
db.setTrackLegaApi LegaNewPhkFn
@ -1110,61 +1110,61 @@ when ProvideLegacyAPI:
proc isPruning*(trie: CoreDbTrieRefs): bool =
trie.setTrackLegaApi LegaIsPruningFn
result = trie.distinctBase.isPruning()
trie.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
trie.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc get*(mpt: CoreDbMptRef; key: openArray[byte]): Blob =
mpt.setTrackLegaApi LegaMptGetFn
result = mpt.distinctBase.fetchOrEmpty(key).expect $ctx
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc get*(phk: CoreDbPhkRef; key: openArray[byte]): Blob =
phk.setTrackLegaApi LegaPhkGetFn
result = phk.distinctBase.fetchOrEmpty(key).expect $ctx
phk.ifTrackLegaApi:
debug legaApiTxt, ctx, elapsed, key=key.toStr, result
debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc del*(mpt: CoreDbMptRef; key: openArray[byte]) =
mpt.setTrackLegaApi LegaMptDelFn
mpt.distinctBase.delete(key).expect $ctx
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, stack=getStackTrace()
proc del*(phk: CoreDbPhkRef; key: openArray[byte]) =
phk.setTrackLegaApi LegaPhkDelFn
phk.distinctBase.delete(key).expect $ctx
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, stack=getStackTrace()
proc put*(mpt: CoreDbMptRef; key: openArray[byte]; val: openArray[byte]) =
mpt.setTrackLegaApi LegaMptPutFn
mpt.distinctBase.merge(key, val).expect $ctx
mpt.ifTrackLegaApi:
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, stack=getStackTrace()
proc put*(phk: CoreDbPhkRef; key: openArray[byte]; val: openArray[byte]) =
phk.setTrackLegaApi LegaPhkPutFn
phk.distinctBase.merge(key, val).expect $ctx
phk.ifTrackLegaApi:
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr
debug legaApiTxt, ctx, elapsed, key=key.toStr, val=val.toLenStr, stack=getStackTrace()
proc contains*(mpt: CoreDbMptRef; key: openArray[byte]): bool =
mpt.setTrackLegaApi LegaMptContainsFn
result = mpt.distinctBase.hasPath(key).expect $ctx
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc contains*(phk: CoreDbPhkRef; key: openArray[byte]): bool =
phk.setTrackLegaApi LegaPhkContainsFn
result = phk.distinctBase.hasPath(key).expect $ctx
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result
phk.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, key=key.toStr, result, stack=getStackTrace()
proc rootHash*(mpt: CoreDbMptRef): Hash256 =
mpt.setTrackLegaApi LegaMptRootHashFn
result = mpt.distinctBase.methods.getTrieFn().rootHash.valueOr:
raiseAssert error.prettyText() & ": " & $ctx
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
mpt.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result, stack=getStackTrace()
proc rootHash*(phk: CoreDbPhkRef): Hash256 =
phk.setTrackLegaApi LegaPhkRootHashFn
@ -1177,7 +1177,7 @@ when ProvideLegacyAPI:
proc getTransactionID*(db: CoreDbRef): CoreDbTxID =
db.setTrackLegaApi LegaGetTxIdFn
result = db.methods.getIdFn().expect($ctx).CoreDbTxID
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc shortTimeReadOnly*(
id: CoreDbTxID;
@ -1201,37 +1201,37 @@ when ProvideLegacyAPI:
msg = "delayed and reraised" &
", name=" & $e.name & ", msg=\"" & e.msg & "\""
raise (ref TxWrapperApiError)(msg: msg)
id.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
id.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc beginTransaction*(db: CoreDbRef): CoreDbTxRef =
db.setTrackLegaApi LegaBeginTxFn
result = (db.distinctBase.methods.beginFn().expect $ctx).CoreDbTxRef
db.ifTrackLegaApi:
debug legaApiTxt, ctx, elapsed, newLevel=db.methods.levelFn()
debug legaApiTxt, ctx, elapsed, newLevel=db.methods.levelFn(), stack=getStackTrace()
proc commit*(tx: CoreDbTxRef, applyDeletes = true) =
tx.setTrackLegaApi LegaTxCommitFn:
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
tx.distinctBase.commit(applyDeletes).expect $ctx
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel, stack=getStackTrace()
proc rollback*(tx: CoreDbTxRef) =
tx.setTrackLegaApi LegaTxCommitFn:
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
tx.distinctBase.rollback().expect $ctx
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel, stack=getStackTrace()
proc dispose*(tx: CoreDbTxRef) =
tx.setTrackLegaApi LegaTxDisposeFn:
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
tx.distinctBase.dispose().expect $ctx
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel, stack=getStackTrace()
proc safeDispose*(tx: CoreDbTxRef) =
tx.setTrackLegaApi LegaTxSaveDisposeFn:
let prvLevel {.used.} = tx.distinctBase.methods.levelFn()
tx.distinctBase.safeDispose().expect $ctx
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel
tx.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, prvLevel, stack=getStackTrace()
# ----------------
@ -1241,22 +1241,22 @@ when ProvideLegacyAPI:
): CoreDbCaptRef =
db.setTrackLegaApi LegaCaptureFn
result = db.newCapture(flags).expect($ctx).CoreDbCaptRef
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
db.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc recorder*(cp: CoreDbCaptRef): CoreDbRef =
cp.setTrackLegaApi LegaCptRecorderFn
result = cp.distinctBase.recorder().expect $ctx
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc logDb*(cp: CoreDbCaptRef): CoreDbRef =
cp.setTrackLegaApi LegaCptLogDbFn
result = cp.distinctBase.logDb().expect $ctx
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, stack=getStackTrace()
proc flags*(cp: CoreDbCaptRef): set[CoreDbCaptFlags] =
cp.setTrackLegaApi LegaCptFlagsFn
result = cp.distinctBase.flags()
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result
cp.ifTrackLegaApi: debug legaApiTxt, ctx, elapsed, result, stack=getStackTrace()
# ------------------------------------------------------------------------------
# End

View File

@ -179,7 +179,13 @@ proc safeDispose*(ac: AccountsCache, sp: SavePoint) {.inline.} =
if (not isNil(sp)) and (sp.state == Pending):
ac.rollback(sp)
var ALL_ACCOUNTS_QUERIED* {.threadvar.}: HashSet[EthAddress]
proc getAccount(ac: AccountsCache, address: EthAddress, shouldCreate = true): RefAccount =
ALL_ACCOUNTS_QUERIED.incl address
# search account from layers of cache
var sp = ac.savePoint
while sp != nil:

View File

@ -70,7 +70,7 @@ type
# 30s: Environmental Information
Address = 0x30, ## Get address of currently executing account.
Balance = 0x31, ## Get balance of the given account.
Balance = 0x31, ## Get balance of the given account. DANIEL - to handle
Origin = 0x32, ## Get execution origination address.
Caller = 0x33, ## Get caller address.
CallValue = 0x34, ## Get deposited value by the
@ -84,16 +84,16 @@ type
CodeCopy = 0x39, ## Copy code running in current environment to
## memory.
GasPrice = 0x3a, ## Get price of gas in current environment.
ExtCodeSize = 0x3b, ## Get size of an account's code
ExtCodeCopy = 0x3c, ## Copy an account's code to memory.
ExtCodeSize = 0x3b, ## Get size of an account's code DANIEL - to handle
ExtCodeCopy = 0x3c, ## Copy an account's code to memory. DANIEL - to handle
ReturnDataSize = 0x3d, ## Get size of output data from the previous call
## from the current environment.
ReturnDataCopy = 0x3e, ## Copy output data from the previous call to
## memory.
ExtCodeHash = 0x3f, ## Returns the keccak256 hash of a contracts code
ExtCodeHash = 0x3f, ## Returns the keccak256 hash of a contracts code DANIEL - to handle
# 40s: Block Information
Blockhash = 0x40, ## Get the hash of one of the 256 most recent
Blockhash = 0x40, ## Get the hash of one of the 256 most recent DANIEL - to handle -- pending decision!
## complete blocks.
Coinbase = 0x41, ## Get the block's beneficiary address.
Timestamp = 0x42, ## Get the block's timestamp.
@ -102,7 +102,7 @@ type
GasLimit = 0x45, ## Get the block's gas limit.
ChainIdOp = 0x46, ## Get current chains EIP-155 unique identifier.
SelfBalance = 0x47, ## Get current contract's balance.
SelfBalance = 0x47, ## Get current contract's balance. ?? to handle? Note: db is not accessed if vmState.com.db.localDbOnly == true
BaseFee = 0x48, ## Get blocks base fee. EIP-3198
BlobHash = 0x49, ## Get transaction's versionedHash. EIP-4844
BlobBaseFee = 0x4A, ## Returns the current data-blob base-fee
@ -115,8 +115,8 @@ type
Mload = 0x51, ## Load word from memory.
Mstore = 0x52, ## Save word to memory.
Mstore8 = 0x53, ## Save byte to memory.
Sload = 0x54, ## Load word from storage.
Sstore = 0x55, ## Save word to storage.
Sload = 0x54, ## Load word from storage. DANIEL - to handle
Sstore = 0x55, ## Save word to storage. DANIEL - to handle
Jump = 0x56, ## Alter the program counter.
JumpI = 0x57, ## Conditionally alter the program counter.
Pc = 0x58, ## Get the value of the program counter prior to
@ -128,10 +128,10 @@ type
JumpDest = 0x5b, ## Mark a valid destination for jumps. This
## operation has no effect on machine state during
## execution.
Tload = 0x5c, ## Load word from transient storage.
Tstore = 0x5d, ## Save word to transient storage.
Tload = 0x5c, ## Load word from transient storage. DANIEL - no need (?)
Tstore = 0x5d, ## Save word to transient storage. DANIEL - no need (?)
Mcopy = 0x5e, ## Memory copy
Mcopy = 0x5e, ## Memory copy DANIEL - no need!
# 5f, 60s & 70s: Push Operations.
Push0 = 0x5f, ## Place 0 on stack. EIP-3855
@ -189,27 +189,27 @@ type
Nop0xED, Nop0xEE, Nop0xEF, ## ..
# f0s: System operations
Create = 0xf0, ## Create a new account with associated code.
Call = 0xf1, ## Message-call into an account.
CallCode = 0xf2, ## Message-call into this account with an
Create = 0xf0, ## Create a new account with associated code. DANIEL - to handle
Call = 0xf1, ## Message-call into an account. DANIEL - to handle (call reads target account code)
CallCode = 0xf2, ## Message-call into this account with an DANIEL - to handle
## alternative account's code.
Return = 0xf3, ## Halt execution returning output data.
DelegateCall = 0xf4, ## Message-call into this account with an
DelegateCall = 0xf4, ## Message-call into this account with an DANIEL - to handle
## alternative account's code, but persisting the
## current values for sender and value.
Create2 = 0xf5, ## Behaves identically to CREATE, except using
Create2 = 0xf5, ## Behaves identically to CREATE, except using DANIEL - to handle
## keccak256
Nop0xF6, Nop0xF7, Nop0xF8, Nop0xF9, ## ..
StaticCall = 0xfa, ## Static message-call into an account.
StaticCall = 0xfa, ## Static message-call into an account. DANIEL - to handle
Nop0xFB, Nop0xFC, ## ..
Revert = 0xfd, ## Halt execution reverting state changes but
## returning data and remaining gas.
Invalid = 0xfe, ## Designated invalid instruction.
SelfDestruct = 0xff ## Halt execution and register account for later
SelfDestruct = 0xff ## Halt execution and register account for later DANIEL - no need, assuming this opcode is being deprecated?
## deletion.
const

View File

@ -11,7 +11,7 @@
## Testing `CoreDB` wrapper implementation
import
std/[algorithm, os, strformat, strutils, times],
std/[algorithm, os, strformat, strutils, times, json],
chronicles,
eth/common,
results,
@ -19,6 +19,7 @@ import
../nimbus/db/core_db/persistent,
../nimbus/db/ledger,
../nimbus/core/chain,
../../nimbus/tracer,
./replay/pp,
./test_coredb/[coredb_test_xx, test_chainsync, test_helpers]
@ -201,7 +202,7 @@ proc chainSyncRunner(
dbType = CoreDbType(0);
ldgType = ldgTypeDefault;
profilingOk = false;
finalDiskCleanUpOk = true;
finalDiskCleanUpOk = false;
enaLoggingOk = false;
lastOneExtraOk = true;
) =
@ -210,8 +211,8 @@ proc chainSyncRunner(
let
fileInfo = capture.files[0].splitFile.name.split(".")[0]
filePaths = capture.files.mapIt(it.findFilePath(baseDir,repoDir).value)
baseDir = getTmpDir() / capture.name & "-chain-sync"
dbDir = baseDir / "tmp"
baseDir = "../testResults"
dbDir = baseDir / now().format("yyyy-MM-dd-HH-mm-ss")
numBlocks = capture.numBlocks
numBlocksInfo = if numBlocks == high(int): "all" else: $numBlocks
@ -226,8 +227,8 @@ proc chainSyncRunner(
persistent = dbType in CoreDbPersistentTypes
defer:
if persistent: baseDir.flushDbDir
#defer:
# if persistent: baseDir.flushDbDir
suite &"CoreDB and LedgerRef API on {fileInfo}, {dbType}, {ldgType}":
@ -266,23 +267,17 @@ when isMainModule:
# This one uses the readily available dump: `bulkTest0` and some huge replay
# dumps `bulkTest2`, `bulkTest3`, .. from the `nimbus-eth1-blobs` package.
# For specs see `tests/test_coredb/bulk_test_xx.nim`.
sampleList = cmdLineConfig().samples
if sampleList.len == 0:
sampleList = @[bulkTest0]
when true:
sampleList = @[bulkTest2, bulkTest3]
sampleList = @[ariTest1] # debugging
var testList = @[bulkTest3] # This test is superseded by `bulkTest1` and `2`
var state: (Duration, int)
for n,capture in sampleList:
for n,capture in testList:
noisy.profileSection("@testList #" & $n, state):
noisy.chainSyncRunner(
capture = capture,
#dbType = ..,
ldgType=LedgerCache,
#profilingOk = ..,
capture=capture,
dbType=LegacyDbPersistent,
ldgType=LegacyAccountsCache,
finalDiskCleanUpOk = false,
#profilingOk = ..,
#enaLoggingOk = ..,
#lastOneExtraOk = ..,
)

View File

@ -9,15 +9,23 @@
# distributed except according to those terms.
import
std/[strformat, times],
std/[strformat, times, streams, sets],
chronicles,
eth/common,
results,
unittest2,
../../nimbus/core/chain,
../../nimbus/db/ledger,
../../nimbus/db/[ledger],
../../nimbus/db/ledger/accounts_cache,
../../nimbus/db/ledger/base/base_desc,
../../nimbus/db/core_db/base/base_desc,
../../nimbus/db/core_db/backend/legacy_rocksdb,
../../nimbus/db/core_db/base_iterators,
../../nimbus/evm/types,
../replay/[pp, undump_blocks, xcheck],
./test_helpers
./test_helpers,
../../vendor/nim-rocksdb/rocksdb,
../../vendor/nim-stew/stew/byteutils
type StopMoaningAboutLedger {.used.} = LedgerType
@ -128,6 +136,46 @@ proc ledgerProfResults(info: string; indent = 4): string =
result &= pfx2 & $count & ": " &
w.mapIt($it & ledgerProfTab.stats(it).pp).sorted.join(", ")
proc createFileAndLogBlockHeaders(lastBlock: BlockHeader, vmState: BaseVMState, name: string): Stream =
let blockNumber = lastBlock.blockNumber.truncate(uint)
let baseDir = cast[LegaPersDbRef](vmState.com.db).rdb.store.dbPath
let path = &"{baseDir}/{name}_at_block_{blockNumber}.dump"
let stream = newFileStream(path, fmWrite)
stream.writeLine(&"# Block number: {blockNumber}")
stream.writeLine(&"# Block time: {lastBlock.timestamp.int64.fromUnix.utc}")
stream.writeLine(&"# Block root hash: {$lastBlock.stateRoot}")
stream.writeLine("#")
echo &"Block {blockNumber} reached; dumping world state key-values into {path}"
return stream
proc dumpWorldStateKvs(lastBlock: BlockHeader, vmState: BaseVMState) =
let stream = createFileAndLogBlockHeaders(lastBlock, vmState, "all_kvs")
defer:
try: stream.close() except: discard
let mpt = cast[CoreDxMptRef](vmState.stateDB.extras.getMptFn())
for kvp in mpt.pairs():
let key: Blob = kvp[0]
let value: Blob = kvp[1]
stream.writeLine(&"key={key.toHex} value={value.toHex}")
proc dumpWorldStateMptAccounts(lastBlock: BlockHeader, vmState: BaseVMState) =
let stream = createFileAndLogBlockHeaders(lastBlock, vmState, "mpt_accounts")
defer:
try: stream.close() except: discard
let accMethods = vmState.stateDB.methods
for address in ALL_ACCOUNTS_QUERIED.items:
let addressHash = address.keccakHash.data
let balance: UInt256 = accMethods.getBalanceFn(address)
let nonce: AccountNonce = accMethods.getNonceFn(address)
let codeHash: Hash256 = accMethods.getCodeHashFn(address)
let codeSize: int = accMethods.getCodeSizeFn(address)
let storageRoot: Hash256 = accMethods.getStorageRootFn(address)
stream.writeLine(&"address={address.toHex} addrHash={addressHash.toHex} balance={balance.toHex:>22} nonce={nonce:>6} codeHash={$codeHash} codeSize={codeSize:>6} storageRoot={$storageRoot}")
# ------------------------------------------------------------------------------
# Public test function
# ------------------------------------------------------------------------------
@ -165,6 +213,9 @@ proc test_chainSync*(
noisy.initLogging com
defer: com.finishLogging()
var dataDumpsPerformed = 0
const blocksBetweenDataDumps = 20_000
for w in filePaths.undumpBlocks:
let (fromBlock, toBlock) = (w[0][0].blockNumber, w[0][^1].blockNumber)
if fromBlock == 0.u256:
@ -179,7 +230,7 @@ proc test_chainSync*(
if enaLogging:
noisy.startLogging(w[0][0].blockNumber)
noisy.stopLoggingAfter():
let runPersistBlocksRc = chain.persistBlocks(w[0], w[1])
let (runPersistBlocksRc, vmState) = chain.persistBlocksAndReturnVmState(w[0], w[1])
xCheck runPersistBlocksRc == ValidationResult.OK:
if noisy:
# Re-run with logging enabled
@ -188,6 +239,13 @@ proc test_chainSync*(
com.db.trackNewApi = false
com.db.trackLedgerApi = false
discard chain.persistBlocks(w[0], w[1])
# Optionally dump the world state
if w[0][^1].blockNumber.truncate(int) >= (dataDumpsPerformed+1) * blocksBetweenDataDumps:
inc dataDumpsPerformed
dumpWorldStateKvs(w[0][^1], vmState)
dumpWorldStateMptAccounts(w[0][^1], vmState)
continue
# Last group or single block

View File

@ -112,6 +112,7 @@ proc flushDbDir(s: string; subDir = "") =
proc flushDbs(db: TestDbs) =
echo "tests/test_rocksdb_timing.nim: flushDbs" & getStackTrace()
if db.persistent:
for n in 0 ..< nTestDbInstances:
if db.cdb[n].isNil or db.cdb[n].dbType != LegacyDbPersistent:

2
vendor/ethash vendored

@ -1 +1 @@
Subproject commit 0306443c52db0bffb59650ad10bcb119477ce9b1
Subproject commit c1d640184bffa38714974e883f9a9f856779fefa

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit b9c40e1380e328d25210bad9bd15da3801df32fe
Subproject commit 2ad07a60109a4609d672f9f147eeee987e43a15d

2
vendor/nim-metrics vendored

@ -1 +1 @@
Subproject commit 0e768ca7fb7df4798649145a403e7db65cae1f8b
Subproject commit a2293e8a34f2a6cf264aec47e4becf2f53a0e467

2
vendor/nim-rocksdb vendored

@ -1 +1 @@
Subproject commit 5e2b026f841fa57b10e669a2ab1d88a0e40f6bbe
Subproject commit 9fab9369331934f355b6abb0a0e58c1e533228a2

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit 10538c667a0a29c7692cce3679ff3bb002624086
Subproject commit ce47cde31c9b08e4b702766d4d788cc83fa55cf0