2021-07-07 09:04:18 +00:00
|
|
|
# Nimbus
|
Core db and aristo updates for destructor and tx logic (#1894)
* Disable `TransactionID` related functions from `state_db.nim`
why:
Functions `getCommittedStorage()` and `updateOriginalRoot()` from
the `state_db` module are nowhere used. The emulation of a legacy
`TransactionID` type functionality is administratively expensive to
provide by `Aristo` (the legacy DB version is only partially
implemented, anyway).
As there is no other place where `TransactionID`s are used, they will
not be provided by the `Aristo` variant of the `CoreDb`. For the
legacy DB API, nothing will change.
* Fix copyright headers in source code
* Get rid of compiler warning
* Update Aristo code, remove unused `merge()` variant, export `hashify()`
why:
Adapt to upcoming `CoreDb` wrapper
* Remove synced tx feature from `Aristo`
why:
+ This feature allowed to synchronise transaction methods like begin,
commit, and rollback for a group of descriptors.
+ The feature is over engineered and not needed for `CoreDb`, neither
is it complete (some convergence features missing.)
* Add debugging helpers to `Kvt`
also:
Update database iterator, add count variable yield argument similar
to `Aristo`.
* Provide optional destructors for `CoreDb` API
why;
For the upcoming Aristo wrapper, this allows to control when certain
smart destruction and update can take place. The auto destructor works
fine in general when the storage/cache strategy is known and acceptable
when creating descriptors.
* Add update option for `CoreDb` API function `hash()`
why;
The hash function is typically used to get the state root of the MPT.
Due to lazy hashing, this might be not available on the `Aristo` DB.
So the `update` function asks for re-hashing the gurrent state changes
if needed.
* Update API tracking log mode: `info` => `debug
* Use shared `Kvt` descriptor in new Ledger API
why:
No need to create a new descriptor all the time
2023-11-16 19:35:03 +00:00
|
|
|
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
2021-07-07 09:04:18 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-10-19 03:52:24 +00:00
|
|
|
import
|
|
|
|
std/[times, macros, strutils, os, osproc, threadpool],
|
|
|
|
unittest2,
|
|
|
|
../nimbus/vm_compile_info,
|
|
|
|
../nimbus/utils/utils
|
2021-07-07 09:04:18 +00:00
|
|
|
|
|
|
|
export strutils, os, unittest2, osproc, threadpool
|
|
|
|
|
|
|
|
# AppVeyor may go out of memory with the default of 4
|
|
|
|
setMinPoolSize(2)
|
|
|
|
|
|
|
|
proc executeMyself(numModules: int, names: openArray[string]): int =
|
|
|
|
let appName = getAppFilename()
|
2022-07-28 19:34:38 +00:00
|
|
|
var elpdList = newSeq[Duration](numModules)
|
2021-07-07 09:04:18 +00:00
|
|
|
for i in 0..<numModules:
|
2022-07-28 19:34:38 +00:00
|
|
|
let start = getTime()
|
2021-07-07 09:04:18 +00:00
|
|
|
let execResult = execCmd(appName & " " & $i)
|
2022-07-28 19:34:38 +00:00
|
|
|
let elpd = getTime() - start
|
|
|
|
elpdList[i] = elpd
|
2021-07-07 09:04:18 +00:00
|
|
|
if execResult != 0:
|
|
|
|
stderr.writeLine("subtest no: " & $i & " failed: " & names[i])
|
|
|
|
result = result or execResult
|
|
|
|
|
2022-07-28 19:34:38 +00:00
|
|
|
var f = open("all_test.md", fmWrite)
|
|
|
|
for i in 0..<numModules:
|
|
|
|
f.write("* " & names[i])
|
2023-10-19 03:52:24 +00:00
|
|
|
f.write(" - " & elpdList[i].short)
|
2022-07-28 19:34:38 +00:00
|
|
|
f.write("\n")
|
|
|
|
f.close()
|
|
|
|
|
2021-07-07 09:04:18 +00:00
|
|
|
proc getImportStmt(stmtList: NimNode): NimNode =
|
|
|
|
result = stmtList[0]
|
|
|
|
result.expectKind nnkImportStmt
|
|
|
|
|
|
|
|
proc ofStmt(idx: int, singleModule: NimNode): NimNode =
|
|
|
|
# remove the "test_" prefix
|
|
|
|
let moduleName = normalize(singleModule.toStrLit.strVal).substr(4)
|
|
|
|
let moduleMain = newIdentNode(moduleName & "Main")
|
|
|
|
|
|
|
|
# construct `of` branch
|
|
|
|
# of idx: moduleMain()
|
|
|
|
result = nnkOfBranch.newTree(
|
|
|
|
newLit(idx),
|
|
|
|
newCall(moduleMain)
|
|
|
|
)
|
|
|
|
|
|
|
|
proc toModuleNames(importStmt: NimNode): NimNode =
|
|
|
|
result = nnkBracket.newTree
|
|
|
|
for singleModule in importStmt:
|
|
|
|
let x = normalize(singleModule.toStrLit.strVal)
|
|
|
|
result.add newLit(x)
|
|
|
|
|
|
|
|
macro cliBuilder*(stmtList: typed): untyped =
|
|
|
|
let importStmt = stmtList.getImportStmt
|
|
|
|
let moduleCount = importStmt.len
|
|
|
|
let moduleNames = importStmt.toModuleNames
|
|
|
|
|
|
|
|
# case paramStr(1).parseInt
|
|
|
|
var caseStmt = nnkCaseStmt.newTree(
|
|
|
|
quote do: paramStr(1).parseInt
|
|
|
|
)
|
|
|
|
|
|
|
|
# of 0: codeStreamMain()
|
|
|
|
# of 1: gasMeterMain()
|
|
|
|
# of 2: memoryMain()
|
|
|
|
# ...
|
|
|
|
for idx, singleModule in importStmt:
|
|
|
|
caseStmt.add ofStmt(idx, singleModule)
|
|
|
|
|
|
|
|
# else:
|
|
|
|
# echo "invalid argument"
|
|
|
|
caseStmt.add nnkElse.newTree(
|
|
|
|
quote do: echo "invalid argument"
|
|
|
|
)
|
|
|
|
|
|
|
|
result = quote do:
|
|
|
|
if paramCount() == 0:
|
|
|
|
const names = `moduleNames`
|
|
|
|
quit(executeMyself(`moduleCount`, names))
|
|
|
|
else:
|
|
|
|
`caseStmt`
|
|
|
|
|
|
|
|
# if you want to add new test module(s)
|
|
|
|
# make sure you define an entry poin
|
|
|
|
# e.g.
|
|
|
|
# proc mytestMain*() =
|
|
|
|
# # put anything you want here
|
|
|
|
# and then give it a name `test_mytest.nim`
|
|
|
|
# the `mytest` part should match between
|
|
|
|
# the proc name and the module name
|
|
|
|
|
|
|
|
# if this executable called without any params
|
|
|
|
# it will execute each of the test by executing itself
|
|
|
|
# repeatedly until all sub-tests are executed.
|
|
|
|
# you can execute the sub-test by a number start from zero.
|