2023-05-11 14:25:29 +00:00
|
|
|
# Nimbus - Types, data structures and shared utilities used in network sync
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
## Re-invented implementation for Merkle Patricia Tree named as Aristo Trie
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[os, strformat, strutils],
|
|
|
|
chronicles,
|
2023-08-21 14:58:30 +00:00
|
|
|
eth/common,
|
|
|
|
results,
|
2023-05-11 14:25:29 +00:00
|
|
|
unittest2,
|
2023-06-09 11:17:37 +00:00
|
|
|
../nimbus/db/aristo/[aristo_desc, aristo_merge],
|
2023-06-02 10:04:29 +00:00
|
|
|
./replay/[pp, undump_accounts, undump_storages],
|
2023-08-21 14:58:30 +00:00
|
|
|
./test_sync_snap/[snap_test_xx, test_types],
|
|
|
|
./test_aristo/[test_backend, test_filter, test_helpers, test_misc, test_tx]
|
2023-05-11 14:25:29 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
baseDir = [".", "..", ".."/"..", $DirSep]
|
|
|
|
repoDir = [".", "tests", "nimbus-eth1-blobs"]
|
|
|
|
subDir = ["replay", "test_sync_snap", "replay"/"snap"]
|
|
|
|
|
|
|
|
# Reference file for finding the database directory
|
|
|
|
sampleDirRefFile = "sample0.txt.gz"
|
|
|
|
|
|
|
|
# Standard test samples
|
|
|
|
accSample = snapTest0
|
2023-06-02 10:04:29 +00:00
|
|
|
storSample = snapTest4
|
2023-05-11 14:25:29 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc findFilePath(
|
|
|
|
file: string;
|
|
|
|
baseDir: openArray[string] = baseDir;
|
|
|
|
repoDir: openArray[string] = repoDir;
|
|
|
|
subDir: openArray[string] = subDir;
|
|
|
|
): Result[string,void] =
|
|
|
|
for dir in baseDir:
|
|
|
|
if dir.dirExists:
|
|
|
|
for repo in repoDir:
|
|
|
|
if (dir / repo).dirExists:
|
|
|
|
for sub in subDir:
|
|
|
|
if (dir / repo / sub).dirExists:
|
|
|
|
let path = dir / repo / sub / file
|
|
|
|
if path.fileExists:
|
|
|
|
return ok(path)
|
|
|
|
echo "*** File not found \"", file, "\"."
|
|
|
|
err()
|
|
|
|
|
|
|
|
proc getTmpDir(sampleDir = sampleDirRefFile): string =
|
|
|
|
sampleDir.findFilePath.value.splitFile.dir
|
|
|
|
|
|
|
|
proc setTraceLevel {.used.} =
|
|
|
|
discard
|
|
|
|
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
|
|
|
setLogLevel(LogLevel.TRACE)
|
|
|
|
|
|
|
|
proc setErrorLevel {.used.} =
|
|
|
|
discard
|
|
|
|
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
|
|
|
setLogLevel(LogLevel.ERROR)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Test Runners: accounts and accounts storages
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-08-25 22:53:59 +00:00
|
|
|
proc miscRunner(
|
|
|
|
noisy = true;
|
|
|
|
qidSampleSize = QidSample;
|
|
|
|
) =
|
|
|
|
|
|
|
|
suite "Aristo: Miscellaneous tests":
|
|
|
|
|
|
|
|
test "VertexID recyling lists":
|
|
|
|
check noisy.testVidRecycleLists()
|
|
|
|
|
2023-08-30 17:08:39 +00:00
|
|
|
test &"QueueID cascaded fifos API (sample size: {qidSampleSize})":
|
2023-08-25 22:53:59 +00:00
|
|
|
check noisy.testQidScheduler(sampleSize = qidSampleSize)
|
2023-05-11 14:25:29 +00:00
|
|
|
|
2023-05-30 21:21:15 +00:00
|
|
|
|
2023-06-22 11:13:24 +00:00
|
|
|
proc accountsRunner(
|
|
|
|
noisy = true;
|
|
|
|
sample = accSample;
|
|
|
|
resetDb = false;
|
|
|
|
cmpBackends = true;
|
|
|
|
) =
|
2023-05-30 21:21:15 +00:00
|
|
|
let
|
2023-06-02 10:04:29 +00:00
|
|
|
accLst = sample.to(seq[UndumpAccounts]).to(seq[ProofTrieData])
|
2023-05-30 21:21:15 +00:00
|
|
|
fileInfo = sample.file.splitPath.tail.replace(".txt.gz","")
|
2023-06-02 10:04:29 +00:00
|
|
|
listMode = if resetDb: "" else: ", merged data lists"
|
2023-06-20 13:26:25 +00:00
|
|
|
baseDir = getTmpDir() / sample.name & "-accounts"
|
2023-06-22 19:21:33 +00:00
|
|
|
dbDir = baseDir / "tmp"
|
2023-06-20 13:26:25 +00:00
|
|
|
|
|
|
|
defer:
|
|
|
|
try: baseDir.removeDir except CatchableError: discard
|
2023-05-30 21:21:15 +00:00
|
|
|
|
2023-06-02 10:04:29 +00:00
|
|
|
suite &"Aristo: accounts data dump from {fileInfo}{listMode}":
|
2023-05-30 21:21:15 +00:00
|
|
|
|
|
|
|
test &"Merge {accLst.len} proof & account lists to database":
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testTxMergeProofAndKvpList(accLst, dbDir, resetDb)
|
2023-06-02 10:04:29 +00:00
|
|
|
|
2023-06-22 11:13:24 +00:00
|
|
|
test &"Compare {accLst.len} account lists on database backends":
|
|
|
|
if cmpBackends:
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testBackendConsistency(accLst, dbDir, resetDb)
|
2023-06-22 11:13:24 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2023-06-02 19:21:46 +00:00
|
|
|
test &"Delete accounts database, successively {accLst.len} entries":
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testTxMergeAndDelete(accLst, dbDir)
|
2023-06-02 19:21:46 +00:00
|
|
|
|
2023-08-17 13:42:01 +00:00
|
|
|
test &"Distributed backend access {accLst.len} entries":
|
|
|
|
check noisy.testDistributedAccess(accLst, dbDir)
|
|
|
|
|
2023-06-02 10:04:29 +00:00
|
|
|
|
|
|
|
proc storagesRunner(
|
|
|
|
noisy = true;
|
|
|
|
sample = storSample;
|
|
|
|
resetDb = false;
|
|
|
|
oops: KnownHasherFailure = @[];
|
2023-06-22 11:13:24 +00:00
|
|
|
cmpBackends = true;
|
2023-06-02 10:04:29 +00:00
|
|
|
) =
|
|
|
|
let
|
|
|
|
stoLst = sample.to(seq[UndumpStorages]).to(seq[ProofTrieData])
|
|
|
|
fileInfo = sample.file.splitPath.tail.replace(".txt.gz","")
|
|
|
|
listMode = if resetDb: "" else: ", merged data lists"
|
2023-06-20 13:26:25 +00:00
|
|
|
baseDir = getTmpDir() / sample.name & "-storage"
|
2023-06-22 19:21:33 +00:00
|
|
|
dbDir = baseDir / "tmp"
|
2023-06-20 13:26:25 +00:00
|
|
|
|
|
|
|
defer:
|
|
|
|
try: baseDir.removeDir except CatchableError: discard
|
2023-05-30 21:21:15 +00:00
|
|
|
|
2023-06-02 10:04:29 +00:00
|
|
|
suite &"Aristo: storages data dump from {fileInfo}{listMode}":
|
|
|
|
|
|
|
|
test &"Merge {stoLst.len} proof & slots lists to database":
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testTxMergeProofAndKvpList(
|
2023-06-22 19:21:33 +00:00
|
|
|
stoLst, dbDir, resetDb, fileInfo, oops)
|
2023-06-22 11:13:24 +00:00
|
|
|
|
|
|
|
test &"Compare {stoLst.len} slot lists on database backends":
|
|
|
|
if cmpBackends:
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testBackendConsistency(stoLst, dbDir, resetDb)
|
2023-06-22 11:13:24 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2023-06-02 19:21:46 +00:00
|
|
|
test &"Delete storage database, successively {stoLst.len} entries":
|
2023-07-05 13:50:11 +00:00
|
|
|
check noisy.testTxMergeAndDelete(stoLst, dbDir)
|
2023-06-02 19:21:46 +00:00
|
|
|
|
2023-08-17 13:42:01 +00:00
|
|
|
test &"Distributed backend access {stoLst.len} entries":
|
|
|
|
check noisy.testDistributedAccess(stoLst, dbDir)
|
|
|
|
|
2023-05-11 14:25:29 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Main function(s)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc aristoMain*(noisy = defined(debug)) =
|
2023-06-09 11:17:37 +00:00
|
|
|
noisy.miscRunner()
|
2023-06-02 10:04:29 +00:00
|
|
|
noisy.accountsRunner()
|
|
|
|
noisy.storagesRunner()
|
2023-05-11 14:25:29 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
const
|
|
|
|
noisy = defined(debug) or true
|
|
|
|
|
2023-06-09 11:17:37 +00:00
|
|
|
setErrorLevel()
|
|
|
|
|
2023-07-05 20:27:48 +00:00
|
|
|
when true: # and false:
|
2023-08-25 22:53:59 +00:00
|
|
|
noisy.miscRunner(qidSampleSize = 10_000)
|
2023-06-09 11:17:37 +00:00
|
|
|
|
2023-05-30 21:21:15 +00:00
|
|
|
# This one uses dumps from the external `nimbus-eth1-blob` repo
|
|
|
|
when true and false:
|
|
|
|
import ./test_sync_snap/snap_other_xx
|
2023-06-02 10:04:29 +00:00
|
|
|
noisy.showElapsed("@snap_other_xx"):
|
2023-05-30 21:21:15 +00:00
|
|
|
for n,sam in snapOtherList:
|
2023-06-02 19:21:46 +00:00
|
|
|
noisy.accountsRunner(sam, resetDb=true)
|
2023-05-30 21:21:15 +00:00
|
|
|
|
|
|
|
# This one usues dumps from the external `nimbus-eth1-blob` repo
|
2023-06-02 19:21:46 +00:00
|
|
|
when true and false:
|
2023-06-12 13:48:47 +00:00
|
|
|
import ./test_sync_snap/snap_storage_xx
|
2023-06-02 10:04:29 +00:00
|
|
|
let knownFailures: KnownHasherFailure = @[
|
2023-06-12 13:48:47 +00:00
|
|
|
("storages3__18__25_dump#12.27367",(3,HashifyExistingHashMismatch)),
|
|
|
|
("storages4__26__33_dump#12.23924",(6,HashifyExistingHashMismatch)),
|
2023-06-09 11:17:37 +00:00
|
|
|
("storages5__34__41_dump#10.20512",(1,HashifyRootHashMismatch)),
|
2023-06-12 13:48:47 +00:00
|
|
|
("storagesB__84__92_dump#7.9709", (7,HashifyExistingHashMismatch)),
|
|
|
|
("storagesD_102_109_dump#18.28287",(9,HashifyExistingHashMismatch)),
|
2023-06-02 10:04:29 +00:00
|
|
|
]
|
|
|
|
noisy.showElapsed("@snap_storage_xx"):
|
2023-05-30 21:21:15 +00:00
|
|
|
for n,sam in snapStorageList:
|
2023-06-02 19:21:46 +00:00
|
|
|
noisy.accountsRunner(sam, resetDb=true)
|
|
|
|
noisy.storagesRunner(sam, resetDb=true, oops=knownFailures)
|
2023-05-30 21:21:15 +00:00
|
|
|
|
|
|
|
when true: # and false:
|
|
|
|
for n,sam in snapTestList:
|
2023-06-02 10:04:29 +00:00
|
|
|
noisy.accountsRunner(sam)
|
2023-05-11 14:25:29 +00:00
|
|
|
for n,sam in snapTestStorageList:
|
2023-06-02 10:04:29 +00:00
|
|
|
noisy.accountsRunner(sam)
|
|
|
|
noisy.storagesRunner(sam)
|
2023-05-11 14:25:29 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|