2022-07-01 11:42:17 +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.
|
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
## Snap sync components tester and TDD environment
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
import
|
2023-08-04 11:10:09 +00:00
|
|
|
std/[os, sets, sequtils, strformat, strutils, tables],
|
2022-07-01 11:42:17 +00:00
|
|
|
chronicles,
|
2023-01-23 16:09:12 +00:00
|
|
|
eth/[common, p2p],
|
2022-08-12 15:42:07 +00:00
|
|
|
rocksdb,
|
2022-07-01 11:42:17 +00:00
|
|
|
unittest2,
|
2023-08-04 11:10:09 +00:00
|
|
|
../nimbus/db/[core_db, kvstore_rocksdb],
|
2023-09-18 20:20:28 +00:00
|
|
|
../nimbus/db/core_db/[legacy_rocksdb, persistent],
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/core/chain,
|
2022-08-24 13:44:18 +00:00
|
|
|
../nimbus/sync/types,
|
2022-08-04 08:04:30 +00:00
|
|
|
../nimbus/sync/snap/range_desc,
|
2022-10-14 16:40:32 +00:00
|
|
|
../nimbus/sync/snap/worker/db/[
|
2022-12-06 17:35:56 +00:00
|
|
|
hexary_desc, hexary_envelope, hexary_error, hexary_inspect, hexary_nearby,
|
2023-03-17 14:46:50 +00:00
|
|
|
hexary_paths, rocky_bulk_load, snapdb_accounts, snapdb_debug, snapdb_desc],
|
2023-01-23 16:09:12 +00:00
|
|
|
./replay/[pp, undump_accounts, undump_storages],
|
|
|
|
./test_sync_snap/[
|
2023-04-21 21:11:04 +00:00
|
|
|
snap_test_xx,
|
2023-02-02 13:27:09 +00:00
|
|
|
test_accounts, test_calc, test_helpers, test_node_range, test_inspect,
|
2023-04-21 21:11:04 +00:00
|
|
|
test_pivot, test_storage, test_syncdb, test_types]
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
baseDir = [".", "..", ".."/"..", $DirSep]
|
2023-04-21 21:11:04 +00:00
|
|
|
repoDir = [".", "tests", "nimbus-eth1-blobs"]
|
|
|
|
subDir = ["replay", "test_sync_snap", "replay"/"snap"]
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
# Reference file for finding the database directory
|
|
|
|
sampleDirRefFile = "sample0.txt.gz"
|
|
|
|
|
|
|
|
# Standard test samples
|
|
|
|
accSample = snapTest0
|
|
|
|
storSample = snapTest4
|
|
|
|
|
2023-05-16 13:52:44 +00:00
|
|
|
# Number of database slots available
|
2022-08-12 15:42:07 +00:00
|
|
|
nTestDbInstances = 9
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TestDbs = object
|
2022-08-12 15:42:07 +00:00
|
|
|
## Provide enough spare empty databases
|
2022-07-01 11:42:17 +00:00
|
|
|
persistent: bool
|
|
|
|
dbDir: string
|
2023-02-14 20:27:17 +00:00
|
|
|
baseDir: string # for cleanup
|
|
|
|
subDir: string # for cleanup
|
2023-08-04 11:10:09 +00:00
|
|
|
cdb: array[nTestDbInstances,CoreDbRef]
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
SnapRunDesc = object
|
|
|
|
id: int
|
|
|
|
info: string
|
|
|
|
file: string
|
|
|
|
chn: ChainRef
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2022-08-12 15:42:07 +00:00
|
|
|
var
|
|
|
|
xTmpDir: string
|
|
|
|
xDbs: TestDbs # for repeated storage/overwrite tests
|
|
|
|
|
2022-07-01 11:42:17 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
proc findFilePath(
|
|
|
|
file: string;
|
|
|
|
baseDir: openArray[string] = baseDir;
|
|
|
|
repoDir: openArray[string] = repoDir;
|
|
|
|
subDir: openArray[string] = subDir;
|
|
|
|
): Result[string,void] =
|
2022-07-01 11:42:17 +00:00
|
|
|
for dir in baseDir:
|
2023-04-21 21:11:04 +00:00
|
|
|
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)
|
2022-09-02 18:16:09 +00:00
|
|
|
echo "*** File not found \"", file, "\"."
|
2022-07-01 11:42:17 +00:00
|
|
|
err()
|
|
|
|
|
2022-08-24 13:44:18 +00:00
|
|
|
proc getTmpDir(sampleDir = sampleDirRefFile): string =
|
2023-04-21 21:11:04 +00:00
|
|
|
sampleDir.findFilePath.value.splitFile.dir
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc setTraceLevel {.used.} =
|
2022-07-01 11:42:17 +00:00
|
|
|
discard
|
|
|
|
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
|
|
|
setLogLevel(LogLevel.TRACE)
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc setErrorLevel {.used.} =
|
2022-07-01 11:42:17 +00:00
|
|
|
discard
|
|
|
|
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
|
|
|
setLogLevel(LogLevel.ERROR)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
proc to(sample: AccountsSample; T: type seq[UndumpAccounts]): T =
|
|
|
|
## Convert test data into usable in-memory format
|
2023-04-21 21:11:04 +00:00
|
|
|
let file = sample.file.findFilePath.value
|
2022-09-02 18:16:09 +00:00
|
|
|
var root: Hash256
|
|
|
|
for w in file.undumpNextAccount:
|
|
|
|
let n = w.seenAccounts - 1
|
|
|
|
if n < sample.firstItem:
|
|
|
|
continue
|
|
|
|
if sample.lastItem < n:
|
|
|
|
break
|
|
|
|
if sample.firstItem == n:
|
|
|
|
root = w.root
|
|
|
|
elif w.root != root:
|
|
|
|
break
|
|
|
|
result.add w
|
|
|
|
|
|
|
|
proc to(sample: AccountsSample; T: type seq[UndumpStorages]): T =
|
|
|
|
## Convert test data into usable in-memory format
|
2023-04-21 21:11:04 +00:00
|
|
|
let file = sample.file.findFilePath.value
|
2022-09-02 18:16:09 +00:00
|
|
|
var root: Hash256
|
|
|
|
for w in file.undumpNextStorages:
|
|
|
|
let n = w.seenAccounts - 1 # storages selector based on accounts
|
2022-08-24 13:44:18 +00:00
|
|
|
if n < sample.firstItem:
|
|
|
|
continue
|
|
|
|
if sample.lastItem < n:
|
|
|
|
break
|
|
|
|
if sample.firstItem == n:
|
|
|
|
root = w.root
|
|
|
|
elif w.root != root:
|
|
|
|
break
|
|
|
|
result.add w
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2022-08-12 15:42:07 +00:00
|
|
|
proc flushDbDir(s: string; subDir = "") =
|
2022-07-01 11:42:17 +00:00
|
|
|
if s != "":
|
|
|
|
let baseDir = s / "tmp"
|
2022-08-12 15:42:07 +00:00
|
|
|
for n in 0 ..< nTestDbInstances:
|
|
|
|
let instDir = if subDir == "": baseDir / $n else: baseDir / subDir / $n
|
2022-07-01 11:42:17 +00:00
|
|
|
if (instDir / "nimbus" / "data").dirExists:
|
|
|
|
# Typically under Windows: there might be stale file locks.
|
2023-03-17 14:46:50 +00:00
|
|
|
try: instDir.removeDir except CatchableError: discard
|
|
|
|
try: (baseDir / subDir).removeDir except CatchableError: discard
|
2022-07-01 11:42:17 +00:00
|
|
|
block dontClearUnlessEmpty:
|
|
|
|
for w in baseDir.walkDir:
|
|
|
|
break dontClearUnlessEmpty
|
2023-03-17 14:46:50 +00:00
|
|
|
try: baseDir.removeDir except CatchableError: discard
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2023-02-14 20:27:17 +00:00
|
|
|
|
|
|
|
proc flushDbs(db: TestDbs) =
|
|
|
|
if db.persistent:
|
|
|
|
for n in 0 ..< nTestDbInstances:
|
2023-08-04 11:10:09 +00:00
|
|
|
if db.cdb[n].isNil or db.cdb[n].dbType != LegacyDbPersistent:
|
2023-02-14 20:27:17 +00:00
|
|
|
break
|
2023-09-26 09:21:13 +00:00
|
|
|
db.cdb[n].backend.toRocksStoreRef.store.db.rocksdb_close
|
2023-02-14 20:27:17 +00:00
|
|
|
db.baseDir.flushDbDir(db.subDir)
|
|
|
|
|
|
|
|
proc testDbs(
|
|
|
|
workDir: string;
|
|
|
|
subDir: string;
|
|
|
|
instances: int;
|
|
|
|
persistent: bool;
|
|
|
|
): TestDbs =
|
2023-08-04 11:10:09 +00:00
|
|
|
if workDir == "" or not persistent:
|
2022-07-01 11:42:17 +00:00
|
|
|
result.persistent = false
|
|
|
|
result.dbDir = "*notused*"
|
|
|
|
else:
|
|
|
|
result.persistent = true
|
2023-02-14 20:27:17 +00:00
|
|
|
result.baseDir = workDir
|
|
|
|
result.subDir = subDir
|
2022-08-12 15:42:07 +00:00
|
|
|
if subDir != "":
|
|
|
|
result.dbDir = workDir / "tmp" / subDir
|
|
|
|
else:
|
|
|
|
result.dbDir = workDir / "tmp"
|
2022-07-01 11:42:17 +00:00
|
|
|
if result.persistent:
|
2023-02-23 13:13:02 +00:00
|
|
|
workDir.flushDbDir(subDir)
|
2022-09-02 18:16:09 +00:00
|
|
|
for n in 0 ..< min(result.cdb.len, instances):
|
2023-08-04 11:10:09 +00:00
|
|
|
result.cdb[n] = newCoreDbRef(LegacyDbPersistent, result.dbDir / $n)
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc snapDbRef(cdb: CoreDbRef; pers: bool): SnapDbRef =
|
|
|
|
if pers: SnapDbRef.init(cdb)
|
|
|
|
else: SnapDbRef.init(newCoreDbRef LegacyDbMemory)
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc snapDbAccountsRef(
|
|
|
|
cdb: CoreDbRef;
|
|
|
|
root: Hash256;
|
|
|
|
pers: bool;
|
|
|
|
):SnapDbAccountsRef =
|
2023-01-23 16:09:12 +00:00
|
|
|
SnapDbAccountsRef.init(cdb.snapDbRef(pers), root, Peer())
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2022-07-01 11:42:17 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2022-09-02 18:16:09 +00:00
|
|
|
# Test Runners: accounts and accounts storages
|
2022-07-01 11:42:17 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
proc accountsRunner(noisy = true; persistent = true; sample = accSample) =
|
2022-07-01 11:42:17 +00:00
|
|
|
let
|
2023-01-23 16:09:12 +00:00
|
|
|
accLst = sample.to(seq[UndumpAccounts])
|
|
|
|
root = accLst[0].root
|
2022-08-12 15:42:07 +00:00
|
|
|
tmpDir = getTmpDir()
|
2023-02-14 20:27:17 +00:00
|
|
|
db = tmpDir.testDbs(sample.name & "-accounts", instances=3, persistent)
|
|
|
|
info = if db.persistent: &"persistent db on \"{db.baseDir}\""
|
2022-08-15 15:51:50 +00:00
|
|
|
else: "in-memory db"
|
2022-09-02 18:16:09 +00:00
|
|
|
fileInfo = sample.file.splitPath.tail.replace(".txt.gz","")
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
defer:
|
2023-02-14 20:27:17 +00:00
|
|
|
db.flushDbs
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
suite &"SyncSnap: {fileInfo} accounts and proofs for {info}":
|
2022-08-04 08:04:30 +00:00
|
|
|
|
2023-01-23 16:09:12 +00:00
|
|
|
block:
|
2023-01-30 17:50:58 +00:00
|
|
|
# New common descriptor for this sub-group of tests
|
2022-09-16 07:24:12 +00:00
|
|
|
let
|
2023-01-30 17:50:58 +00:00
|
|
|
desc = db.cdb[0].snapDbAccountsRef(root, db.persistent)
|
|
|
|
hexaDb = desc.hexaDb
|
|
|
|
getFn = desc.getAccountFn
|
|
|
|
dbg = if noisy: hexaDb else: nil
|
|
|
|
|
|
|
|
test &"Proofing {accLst.len} list items for state root ..{root.pp}":
|
|
|
|
accLst.test_accountsImport(desc, db.persistent)
|
|
|
|
|
2023-02-01 18:56:06 +00:00
|
|
|
# debugging, make sure that state root ~ "$0"
|
2023-03-07 14:23:22 +00:00
|
|
|
hexaDb.assignPrettyKeys(root.to(NodeKey))
|
2023-02-01 18:56:06 +00:00
|
|
|
|
|
|
|
# Beware: dumping a large database is not recommended
|
2023-03-17 14:46:50 +00:00
|
|
|
# true.say "***", "database dump\n ", hexaDb.pp(root.to(NodeKey))
|
2023-02-01 18:56:06 +00:00
|
|
|
|
2023-01-30 17:50:58 +00:00
|
|
|
test &"Retrieve accounts & proofs for previous account ranges":
|
|
|
|
if db.persistent:
|
2023-02-01 18:56:06 +00:00
|
|
|
accLst.test_NodeRangeProof(getFn, dbg)
|
2023-01-30 17:50:58 +00:00
|
|
|
else:
|
2023-03-07 14:23:22 +00:00
|
|
|
accLst.test_NodeRangeProof(hexaDb, dbg)
|
2023-01-30 17:50:58 +00:00
|
|
|
|
|
|
|
test &"Verify left boundary checks":
|
|
|
|
if db.persistent:
|
|
|
|
accLst.test_NodeRangeLeftBoundary(getFn, dbg)
|
|
|
|
else:
|
2023-03-07 14:23:22 +00:00
|
|
|
accLst.test_NodeRangeLeftBoundary(hexaDb, dbg)
|
2023-01-23 16:09:12 +00:00
|
|
|
|
2023-01-30 17:50:58 +00:00
|
|
|
block:
|
|
|
|
# List of keys to be shared by sub-group
|
|
|
|
var accKeys: seq[NodeKey]
|
|
|
|
|
|
|
|
# New common descriptor for this sub-group of tests
|
2023-02-14 20:27:17 +00:00
|
|
|
let desc = db.cdb[1].snapDbAccountsRef(root, db.persistent)
|
2023-01-30 17:50:58 +00:00
|
|
|
|
|
|
|
test &"Merging {accLst.len} accounts/proofs lists into single list":
|
2023-01-23 16:09:12 +00:00
|
|
|
accLst.test_accountsMergeProofs(desc, accKeys) # set up `accKeys`
|
|
|
|
|
|
|
|
test &"Revisiting {accKeys.len} stored items on ChainDBRef":
|
|
|
|
accKeys.test_accountsRevisitStoredItems(desc, noisy)
|
|
|
|
|
|
|
|
test &"Decompose path prefix envelopes on {info}":
|
2023-01-30 17:50:58 +00:00
|
|
|
let hexaDb = desc.hexaDb
|
2023-01-23 16:09:12 +00:00
|
|
|
if db.persistent:
|
2023-01-30 17:50:58 +00:00
|
|
|
accKeys.test_NodeRangeDecompose(root, desc.getAccountFn, hexaDb)
|
2023-01-23 16:09:12 +00:00
|
|
|
else:
|
2023-01-30 17:50:58 +00:00
|
|
|
accKeys.test_NodeRangeDecompose(root, hexaDb, hexaDb)
|
|
|
|
|
2023-02-14 20:27:17 +00:00
|
|
|
# This one works with a new clean database in order to avoid some
|
|
|
|
# problems on observed qemu/Win7.
|
2023-01-30 17:50:58 +00:00
|
|
|
test &"Storing/retrieving {accKeys.len} stored items " &
|
|
|
|
"on persistent pivot/checkpoint registry":
|
|
|
|
if db.persistent:
|
2023-02-14 20:27:17 +00:00
|
|
|
accKeys.test_pivotStoreRead(db.cdb[2])
|
2023-01-30 17:50:58 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
proc storagesRunner(
|
|
|
|
noisy = true;
|
|
|
|
persistent = true;
|
|
|
|
sample = storSample;
|
2022-11-28 09:03:23 +00:00
|
|
|
knownFailures: seq[(string,seq[(int,HexaryError)])] = @[]) =
|
2022-09-02 18:16:09 +00:00
|
|
|
let
|
2023-01-23 16:09:12 +00:00
|
|
|
accLst = sample.to(seq[UndumpAccounts])
|
|
|
|
stoLst = sample.to(seq[UndumpStorages])
|
2022-09-02 18:16:09 +00:00
|
|
|
tmpDir = getTmpDir()
|
2023-02-14 20:27:17 +00:00
|
|
|
db = tmpDir.testDbs(sample.name & "-storages", instances=1, persistent)
|
|
|
|
info = if db.persistent: &"persistent db" else: "in-memory db"
|
2023-01-23 16:09:12 +00:00
|
|
|
idPfx = sample.file.splitPath.tail.replace(".txt.gz","")
|
2022-09-02 18:16:09 +00:00
|
|
|
|
|
|
|
defer:
|
2023-02-14 20:27:17 +00:00
|
|
|
db.flushDbs
|
2022-09-02 18:16:09 +00:00
|
|
|
|
2023-01-23 16:09:12 +00:00
|
|
|
suite &"SyncSnap: {idPfx} accounts storage for {info}":
|
|
|
|
let xdb = db.cdb[0].snapDbRef(db.persistent)
|
2022-09-02 18:16:09 +00:00
|
|
|
|
2023-01-23 16:09:12 +00:00
|
|
|
test &"Merging {accLst.len} accounts for state root ..{accLst[0].root.pp}":
|
|
|
|
accLst.test_storageAccountsImport(xdb, db.persistent)
|
2022-09-02 18:16:09 +00:00
|
|
|
|
2023-01-23 16:09:12 +00:00
|
|
|
test &"Merging {stoLst.len} storages lists":
|
|
|
|
stoLst.test_storageSlotsImport(xdb, db.persistent, knownFailures,idPfx)
|
2022-10-20 16:59:54 +00:00
|
|
|
|
2023-01-23 16:09:12 +00:00
|
|
|
test &"Inspecting {stoLst.len} imported storages lists sub-tries":
|
|
|
|
stoLst.test_storageSlotsTries(xdb, db.persistent, knownFailures,idPfx)
|
2022-10-20 16:59:54 +00:00
|
|
|
|
2023-02-01 18:56:06 +00:00
|
|
|
|
2022-09-16 07:24:12 +00:00
|
|
|
proc inspectionRunner(
|
|
|
|
noisy = true;
|
|
|
|
persistent = true;
|
|
|
|
cascaded = true;
|
|
|
|
sample: openArray[AccountsSample] = snapTestList) =
|
|
|
|
let
|
|
|
|
inspectList = sample.mapIt(it.to(seq[UndumpAccounts]))
|
|
|
|
tmpDir = getTmpDir()
|
2023-02-14 20:27:17 +00:00
|
|
|
db = tmpDir.testDbs(
|
|
|
|
sample[0].name & "-inspection", instances=nTestDbInstances, persistent)
|
|
|
|
info = if db.persistent: &"persistent db" else: "in-memory db"
|
2022-09-16 07:24:12 +00:00
|
|
|
fileInfo = "[" & sample[0].file.splitPath.tail.replace(".txt.gz","") & "..]"
|
|
|
|
|
|
|
|
defer:
|
2023-02-14 20:27:17 +00:00
|
|
|
db.flushDbs
|
2022-09-16 07:24:12 +00:00
|
|
|
|
|
|
|
suite &"SyncSnap: inspect {fileInfo} lists for {info} for healing":
|
|
|
|
var
|
|
|
|
singleStats: seq[(int,TrieNodeStat)]
|
|
|
|
accuStats: seq[(int,TrieNodeStat)]
|
2023-01-23 16:09:12 +00:00
|
|
|
let
|
|
|
|
ingerprinting = &"ingerprinting {inspectList.len}"
|
|
|
|
singleAcc = &"F{ingerprinting} single accounts lists"
|
|
|
|
accumAcc = &"F{ingerprinting} accumulated accounts"
|
|
|
|
cascAcc = &"Cascaded f{ingerprinting} accumulated accounts lists"
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
memBase = SnapDbRef.init(newCoreDbRef LegacyDbMemory)
|
2023-01-23 16:09:12 +00:00
|
|
|
dbSlot = proc(n: int): SnapDbRef =
|
2023-08-04 11:10:09 +00:00
|
|
|
if 2+n < nTestDbInstances and
|
2023-09-26 09:21:13 +00:00
|
|
|
not db.cdb[2+n].backend.toRocksStoreRef.isNil:
|
2023-01-23 16:09:12 +00:00
|
|
|
return SnapDbRef.init(db.cdb[2+n])
|
|
|
|
|
|
|
|
test &"{singleAcc} for in-memory-db":
|
|
|
|
inspectList.test_inspectSingleAccountsMemDb(memBase, singleStats)
|
|
|
|
|
|
|
|
test &"{singleAcc} for persistent db":
|
|
|
|
if persistent:
|
|
|
|
inspectList.test_inspectSingleAccountsPersistent(dbSlot, singleStats)
|
2022-09-16 07:24:12 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2023-01-23 16:09:12 +00:00
|
|
|
|
|
|
|
test &"{accumAcc} for in-memory-db":
|
|
|
|
inspectList.test_inspectAccountsInMemDb(memBase, accuStats)
|
|
|
|
|
|
|
|
test &"{accumAcc} for persistent db":
|
|
|
|
if persistent:
|
|
|
|
inspectList.test_inspectAccountsPersistent(db.cdb[0], accuStats)
|
2022-09-16 07:24:12 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2023-01-23 16:09:12 +00:00
|
|
|
|
|
|
|
test &"{cascAcc} for in-memory-db":
|
|
|
|
if cascaded:
|
|
|
|
inspectList.test_inspectCascadedMemDb()
|
2022-09-16 07:24:12 +00:00
|
|
|
else:
|
|
|
|
skip()
|
2023-01-23 16:09:12 +00:00
|
|
|
|
|
|
|
test &"{cascAcc} for persistent db":
|
|
|
|
if cascaded and persistent:
|
|
|
|
inspectList.test_inspectCascadedPersistent(db.cdb[1])
|
2022-09-16 07:24:12 +00:00
|
|
|
else:
|
2023-01-23 16:09:12 +00:00
|
|
|
skip()
|
2022-09-02 18:16:09 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-04-21 21:11:04 +00:00
|
|
|
# Other test Runners
|
2022-09-02 18:16:09 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
proc miscRunner(noisy = true) =
|
|
|
|
suite "SyncSnap: Verify setup, constants, limits":
|
2022-08-04 08:04:30 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
test "RLP accounts list sizes":
|
|
|
|
test_calcAccountsListSizes()
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
test "RLP proofs list sizes":
|
|
|
|
test_calcProofsListSizes()
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
test "RLP en/decode GetTrieNodes arguments list":
|
|
|
|
test_calcTrieNodeTranscode()
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
test "RLP en/decode BockBody arguments list":
|
|
|
|
test_calcBlockBodyTranscode()
|
2023-01-23 16:09:12 +00:00
|
|
|
|
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
proc snapRunner(noisy = true; specs: SnapSyncSpecs) =
|
2022-08-12 15:42:07 +00:00
|
|
|
let
|
2023-04-21 21:11:04 +00:00
|
|
|
tailInfo = specs.tailBlocks.splitPath.tail.replace(".txt.gz","")
|
|
|
|
tailPath = specs.tailBlocks.findFilePath.value
|
|
|
|
allFile = "mainnet332160.txt.gz".findFilePath.value
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
pivot = specs.pivotBlock
|
|
|
|
updateSize = specs.nItems
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
tmpDir = getTmpDir()
|
|
|
|
db = tmpDir.testDbs(specs.name, instances=1, true)
|
2022-08-12 15:42:07 +00:00
|
|
|
|
2023-04-21 21:11:04 +00:00
|
|
|
defer:
|
|
|
|
db.flushDbs()
|
|
|
|
|
|
|
|
var dsc = SnapRunDesc(
|
|
|
|
info: specs.snapDump.splitPath.tail.replace(".txt.gz",""),
|
|
|
|
file: specs.snapDump.findFilePath.value,
|
|
|
|
chn: CommonRef.new(
|
2023-08-04 11:10:09 +00:00
|
|
|
db.cdb[0],
|
2023-04-21 21:11:04 +00:00
|
|
|
networkId = specs.network,
|
|
|
|
pruneTrie = true,
|
|
|
|
params = specs.network.networkParams).newChain)
|
|
|
|
|
|
|
|
dsc.chn.com.initializeEmptyDB()
|
|
|
|
|
|
|
|
suite &"SyncSnap: verify \"{dsc.info}\" snapshot against full sync":
|
|
|
|
|
|
|
|
#test "Import block chain":
|
2023-08-04 11:10:09 +00:00
|
|
|
# if dsc.chn.db.toLegacyBackend.rocksStoreRef.isNil:
|
2023-04-21 21:11:04 +00:00
|
|
|
# skip()
|
|
|
|
# else:
|
|
|
|
# noisy.showElapsed("import block chain"):
|
|
|
|
# check dsc.chn.test_syncdbImportChainBlocks(allFile, pivot) == pivot
|
|
|
|
# noisy.showElapsed("dump db"):
|
2023-08-04 11:10:09 +00:00
|
|
|
# dsc[1].chn.db.toLegacyBackend.rocksStoreRef.dumpAllDb()
|
2023-04-21 21:11:04 +00:00
|
|
|
|
|
|
|
test "Import snapshot dump":
|
2023-09-26 09:21:13 +00:00
|
|
|
if dsc.chn.db.backend.toRocksStoreRef.isNil:
|
2022-08-12 15:42:07 +00:00
|
|
|
skip()
|
|
|
|
else:
|
2023-04-21 21:11:04 +00:00
|
|
|
noisy.showElapsed(&"undump \"{dsc.info}\""):
|
|
|
|
let
|
|
|
|
(a,b,c) = dsc.chn.test_syncdbImportSnapshot(dsc.file, noisy=noisy)
|
|
|
|
aSum = a[0] + a[1]
|
|
|
|
bSum = b.foldl(a + b)
|
|
|
|
cSum = c.foldl(a + b)
|
|
|
|
noisy.say "***", "[", dsc.info, "]",
|
|
|
|
" undumped ", aSum + bSum + cSum, " snapshot records",
|
|
|
|
" (key32=", aSum, ",",
|
|
|
|
" key33=", bSum, ",",
|
|
|
|
" other=", cSum, ")" #, " b=",b.pp, " c=", c.pp
|
|
|
|
when false: # or true:
|
|
|
|
noisy.showElapsed(&"dump db \"{dsc.info}\""):
|
2023-08-04 11:10:09 +00:00
|
|
|
dsc.chn.db.toLegacyBackend.rocksStoreRef.dumpAllDb()
|
2023-04-21 21:11:04 +00:00
|
|
|
|
|
|
|
test &"Append block chain from \"{tailInfo}\"":
|
2023-09-26 09:21:13 +00:00
|
|
|
if dsc.chn.db.backend.toRocksStoreRef.isNil:
|
2023-04-21 21:11:04 +00:00
|
|
|
skip()
|
|
|
|
else:
|
2023-08-04 11:10:09 +00:00
|
|
|
dsc.chn.db.compensateLegacySetup
|
2023-04-21 21:11:04 +00:00
|
|
|
dsc.chn.test_syncdbAppendBlocks(tailPath,pivot,updateSize,noisy)
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Main function(s)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc syncSnapMain*(noisy = defined(debug)) =
|
2023-02-02 13:27:09 +00:00
|
|
|
noisy.miscRunner()
|
2022-08-15 15:51:50 +00:00
|
|
|
noisy.accountsRunner(persistent=true)
|
2022-12-06 17:35:56 +00:00
|
|
|
noisy.accountsRunner(persistent=false)
|
2022-09-16 07:24:12 +00:00
|
|
|
noisy.inspectionRunner()
|
2022-07-01 11:42:17 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
2022-08-04 08:04:30 +00:00
|
|
|
const
|
|
|
|
noisy = defined(debug) or true
|
2022-08-17 07:30:11 +00:00
|
|
|
|
2022-08-12 15:42:07 +00:00
|
|
|
#setTraceLevel()
|
2022-08-04 08:04:30 +00:00
|
|
|
setErrorLevel()
|
2022-07-01 11:42:17 +00:00
|
|
|
|
2023-02-23 13:13:02 +00:00
|
|
|
# Test constants, calculations etc.
|
2023-02-15 10:14:40 +00:00
|
|
|
when true: # and false:
|
|
|
|
noisy.miscRunner()
|
2022-08-17 07:30:11 +00:00
|
|
|
|
2023-05-16 13:52:44 +00:00
|
|
|
# Test database snapshot handling. The test samples ate too big for
|
2023-04-21 21:11:04 +00:00
|
|
|
# `nimbus-eth1` so they are available on `nimbus-eth1-blobs.`
|
|
|
|
when true: # or false
|
|
|
|
import ./test_sync_snap/snap_syncdb_xx
|
|
|
|
for n,sam in snapSyncdbList:
|
|
|
|
false.snapRunner(sam)
|
|
|
|
|
2022-09-02 18:16:09 +00:00
|
|
|
# This one uses dumps from the external `nimbus-eth1-blob` repo
|
2023-02-01 18:56:06 +00:00
|
|
|
when true and false:
|
2022-09-02 18:16:09 +00:00
|
|
|
import ./test_sync_snap/snap_other_xx
|
|
|
|
noisy.showElapsed("accountsRunner()"):
|
|
|
|
for n,sam in snapOtherList:
|
2022-12-06 20:13:31 +00:00
|
|
|
false.accountsRunner(persistent=true, sam)
|
2023-02-01 18:56:06 +00:00
|
|
|
noisy.showElapsed("inspectRunner()"):
|
|
|
|
for n,sam in snapOtherHealingList:
|
|
|
|
false.inspectionRunner(persistent=true, cascaded=false, sam)
|
2022-09-02 18:16:09 +00:00
|
|
|
|
|
|
|
# This one usues dumps from the external `nimbus-eth1-blob` repo
|
Prep for full sync after snap make 4 (#1282)
* Re-arrange fetching storage slots in batch module
why;
Previously, fetching partial slot ranges first has a chance of
terminating the worker peer 9due to network error) while there were
many inheritable storage slots on the queue.
Now, inheritance is checked first, then full slot ranges and finally
partial ranges.
* Update logging
* Bundled node information for healing into single object `NodeSpecs`
why:
Previously, partial paths and node keys were kept in separate variables.
This approach was error prone due to copying/reassembling function
argument objects.
As all partial paths, keys, and node data types are more or less handled
as `Blob`s over the network (using Eth/6x, or Snap/1) it makes sense to
hold these `Blob`s as named field in a single object (even if not all
fields are active for the current purpose.)
* For good housekeeping, using `NodeKey` type only for account keys
why:
previously, a mixture of `NodeKey` and `Hash256` was used. Now, only
state or storage root keys use the `Hash256` type.
* Always accept latest pivot (and not a slightly older one)
why;
For testing it was tried to use a slightly older pivot state root than
available. Some anecdotal tests seemed to suggest an advantage so that
more peers are willing to serve on that older pivot. But this could not
be confirmed in subsequent tests (still anecdotal, though.)
As a side note, the distance of the latest pivot to its predecessor is
at least 128 (or whatever the constant `minPivotBlockDistance` is
assigned to.)
* Reshuffle name components for some file and function names
why:
Clarifies purpose:
"storages" becomes: "storage slots"
"store" becomes: "range fetch"
* Stash away currently unused modules in sub-folder named "notused"
2022-10-27 13:49:28 +00:00
|
|
|
when true and false:
|
2022-09-02 18:16:09 +00:00
|
|
|
import ./test_sync_snap/snap_storage_xx
|
2023-02-01 18:56:06 +00:00
|
|
|
let knownFailures: KnownStorageFailure = @[
|
2022-09-02 18:16:09 +00:00
|
|
|
("storages5__34__41_dump#10", @[( 508, RootNodeMismatch)]),
|
|
|
|
]
|
|
|
|
noisy.showElapsed("storageRunner()"):
|
|
|
|
for n,sam in snapStorageList:
|
2022-09-16 07:24:12 +00:00
|
|
|
false.storagesRunner(persistent=true, sam, knownFailures)
|
2022-09-02 18:16:09 +00:00
|
|
|
|
|
|
|
# This one uses readily available dumps
|
2022-08-24 13:44:18 +00:00
|
|
|
when true: # and false:
|
2023-02-01 18:56:06 +00:00
|
|
|
false.inspectionRunner()
|
2022-12-06 17:35:56 +00:00
|
|
|
for n,sam in snapTestList:
|
|
|
|
false.accountsRunner(persistent=false, sam)
|
2022-09-02 18:16:09 +00:00
|
|
|
false.accountsRunner(persistent=true, sam)
|
2022-12-06 17:35:56 +00:00
|
|
|
for n,sam in snapTestStorageList:
|
|
|
|
false.accountsRunner(persistent=false, sam)
|
2022-09-02 18:16:09 +00:00
|
|
|
false.accountsRunner(persistent=true, sam)
|
2023-02-01 18:56:06 +00:00
|
|
|
false.storagesRunner(persistent=true, sam)
|
2022-09-02 18:16:09 +00:00
|
|
|
|
2022-07-01 11:42:17 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|