From 08e98eb38542b829f44ce89076f2e207dbb99b84 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 28 May 2024 14:49:35 +0200 Subject: [PATCH] restore a few tests, cleanup (#2234) * remove `compensateLegacySetup`, `localDbOnly` * enable trivially fixable tests --- nimbus/common/common.nim | 12 ++++-------- nimbus/db/core_db/backend/aristo_db.nim | 3 --- nimbus/db/core_db/base.nim | 9 --------- nimbus/db/core_db/base/api_tracking.nim | 1 - nimbus/db/core_db/base/base_desc.nim | 5 +---- nimbus/db/core_db/base/validate.nim | 1 - nimbus/db/core_db/core_apps_newapi.nim | 3 +-- nimbus/db/ledger/accounts_ledger.nim | 2 -- nimbus/nimbus.nim | 1 - premix/persist.nim | 1 - tests/all_tests.nim | 4 ++-- tests/macro_assembler.nim | 3 --- tests/test_coredb.nim | 5 ----- tests/test_coredb/test_chainsync.nim | 7 +++---- tests/test_overflow.nim | 4 ++-- tests/test_precompiles.nim | 7 ++++--- tests/test_rpc_getproofs_track_state_changes.nim | 1 - tests/test_sync_snap.nim | 1 - 18 files changed, 17 insertions(+), 53 deletions(-) diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index 9d7fa4793..f69526cb1 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -286,8 +286,7 @@ func toHardFork*( toHardFork(com.forkTransitionTable, forkDeterminer) proc hardForkTransition( - com: CommonRef, forkDeterminer: ForkDeterminationInfo) - {.gcsafe, raises: [].} = + com: CommonRef, forkDeterminer: ForkDeterminationInfo) = ## When consensus type already transitioned to POS, ## the storage can choose not to store TD anymore, ## at that time, TD is no longer needed to find a fork @@ -302,8 +301,7 @@ proc hardForkTransition*( com: CommonRef, number: BlockNumber, td: Option[DifficultyInt], - time: Option[EthTime]) - {.gcsafe, raises: [].} = + time: Option[EthTime]) = com.hardForkTransition(ForkDeterminationInfo( blockNumber: number, time: time, td: td)) @@ -311,8 +309,7 @@ proc hardForkTransition*( com: CommonRef, parentHash: Hash256, number: BlockNumber, - time: Option[EthTime]) - {.gcsafe, raises: [].} = + time: Option[EthTime]) = com.hardForkTransition(number, getTdIfNecessary(com, parentHash), time) proc hardForkTransition*( @@ -341,8 +338,7 @@ func forkGTE*(com: CommonRef, fork: HardFork): bool = com.currentFork >= fork # TODO: move this consensus code to where it belongs -func minerAddress*(com: CommonRef; header: BlockHeader): EthAddress - {.gcsafe, raises: [CatchableError].} = +func minerAddress*(com: CommonRef; header: BlockHeader): EthAddress = # POW and POS return header.coinbase return header.coinbase diff --git a/nimbus/db/core_db/backend/aristo_db.nim b/nimbus/db/core_db/backend/aristo_db.nim index f357115ac..69b99a01a 100644 --- a/nimbus/db/core_db/backend/aristo_db.nim +++ b/nimbus/db/core_db/backend/aristo_db.nim @@ -158,9 +158,6 @@ proc baseMethods(db: AristoCoreDbRef): CoreDbBaseFns = errorPrintFn: proc(e: CoreDbErrorRef): string = e.errorPrint(), - legacySetupFn: proc() = - discard, - newKvtFn: proc(offSite: bool): CoreDbRc[CoreDxKvtRef] = kBase.newKvtHandler(offSite, "newKvtFn()"), diff --git a/nimbus/db/core_db/base.nim b/nimbus/db/core_db/base.nim index 6afe2a144..9c35c9770 100644 --- a/nimbus/db/core_db/base.nim +++ b/nimbus/db/core_db/base.nim @@ -269,15 +269,6 @@ proc dbType*(db: CoreDbRef): CoreDbType = result = db.dbType db.ifTrackNewApi: debug newApiTxt, api, elapsed, result -proc compensateLegacySetup*(db: CoreDbRef) = - ## On the persistent legacy hexary trie, this function is needed for - ## bootstrapping and Genesis setup when the `purge` flag is activated. - ## Otherwise the database backend may defect on an internal inconsistency. - ## - db.setTrackNewApi BaseLegacySetupFn - db.methods.legacySetupFn() - db.ifTrackNewApi: debug newApiTxt, api, elapsed - proc parent*[T: CoreDxKvtRef | CoreDbColRef | CoreDbCtxRef | CoreDxMptRef | CoreDxPhkRef | CoreDxAccRef | diff --git a/nimbus/db/core_db/base/api_tracking.nim b/nimbus/db/core_db/base/api_tracking.nim index b3227e8ab..4a2fc4ca9 100644 --- a/nimbus/db/core_db/base/api_tracking.nim +++ b/nimbus/db/core_db/base/api_tracking.nim @@ -49,7 +49,6 @@ type BaseColStateFn = "state" BaseDbTypeFn = "dbType" BaseFinishFn = "finish" - BaseLegacySetupFn = "compensateLegacySetup" BaseLevelFn = "level" BaseNewCaptureFn = "newCapture" BaseNewCtxFn = "ctx" diff --git a/nimbus/db/core_db/base/base_desc.nim b/nimbus/db/core_db/base/base_desc.nim index 35a36ee2f..c98ae46a5 100644 --- a/nimbus/db/core_db/base/base_desc.nim +++ b/nimbus/db/core_db/base/base_desc.nim @@ -102,7 +102,6 @@ type col: CoreDbColRef): CoreDbRc[Hash256] {.noRaise.} CoreDbBaseColPrintFn* = proc(vid: CoreDbColRef): string {.noRaise.} CoreDbBaseErrorPrintFn* = proc(e: CoreDbErrorRef): string {.noRaise.} - CoreDbBaseInitLegaSetupFn* = proc() {.noRaise.} CoreDbBaseLevelFn* = proc(): int {.noRaise.} CoreDbBaseNewKvtFn* = proc(offSite: bool): CoreDbRc[CoreDxKvtRef] {.noRaise.} CoreDbBaseNewCtxFn* = proc(): CoreDbCtxRef {.noRaise.} @@ -121,7 +120,6 @@ type colStateFn*: CoreDbBaseColStateFn colPrintFn*: CoreDbBaseColPrintFn errorPrintFn*: CoreDbBaseErrorPrintFn - legacySetupFn*: CoreDbBaseInitLegaSetupFn levelFn*: CoreDbBaseLevelFn # Kvt constructor @@ -146,7 +144,7 @@ type # Sub-descriptor: KVT methods # -------------------------------------------------- CoreDbKvtBackendFn* = proc(): CoreDbKvtBackendRef {.noRaise.} - CoreDbKvtGetFn* = proc(k: openArray[byte]): CoreDbRc[Blob] {.noRaise.} + CoreDbKvtGetFn* = proc(k: openArray[byte]): CoreDbRc[Blob] {.noRaise.} CoreDbKvtDelFn* = proc(k: openArray[byte]): CoreDbRc[void] {.noRaise.} CoreDbKvtPutFn* = proc(k: openArray[byte]; v: openArray[byte]): CoreDbRc[void] {.noRaise.} @@ -281,7 +279,6 @@ type trackLegaApi*: bool ## Debugging, support trackNewApi*: bool ## Debugging, support trackLedgerApi*: bool ## Debugging, suggestion for subsequent ledger - localDbOnly*: bool ## Debugging, suggestion to ignore async fetch profTab*: CoreDbProfListRef ## Profiling data (if any) ledgerHook*: RootRef ## Debugging/profiling, to be used by ledger methods*: CoreDbBaseFns diff --git a/nimbus/db/core_db/base/validate.nim b/nimbus/db/core_db/base/validate.nim index 77543abc6..840e42299 100644 --- a/nimbus/db/core_db/base/validate.nim +++ b/nimbus/db/core_db/base/validate.nim @@ -32,7 +32,6 @@ proc validateMethodsDesc(base: CoreDbBaseFns) = doAssert not base.colStateFn.isNil doAssert not base.colPrintFn.isNil doAssert not base.errorPrintFn.isNil - doAssert not base.legacySetupFn.isNil doAssert not base.levelFn.isNil doAssert not base.newKvtFn.isNil doAssert not base.newCtxFn.isNil diff --git a/nimbus/db/core_db/core_apps_newapi.nim b/nimbus/db/core_db/core_apps_newapi.nim index 65d665804..396194dc3 100644 --- a/nimbus/db/core_db/core_apps_newapi.nim +++ b/nimbus/db/core_db/core_apps_newapi.nim @@ -577,8 +577,7 @@ proc persistTransactions*( let mpt = db.ctx.getMpt(CtTxs) kvt = db.newKvt() - # Prevent DB from coughing. - db.compensateLegacySetup() + for idx, tx in transactions: let encodedKey = rlp.encode(idx) diff --git a/nimbus/db/ledger/accounts_ledger.nim b/nimbus/db/ledger/accounts_ledger.nim index 80078ebfd..9507feaf5 100644 --- a/nimbus/db/ledger/accounts_ledger.nim +++ b/nimbus/db/ledger/accounts_ledger.nim @@ -333,8 +333,6 @@ proc persistStorage(acc: AccountRef, ac: AccountsLedgerRef, clearCache: bool) = if not clearCache and acc.originalStorage.isNil: acc.originalStorage = newTable[UInt256, UInt256]() - ac.ledger.db.compensateLegacySetup() - # Make sure that there is an account column on the database. This is needed # for saving the account-linked storage column on the Aristo database. if acc.statement.storage.isNil: diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index 33c1d50c2..89e07500f 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -241,7 +241,6 @@ proc start(nimbus: NimbusNode, conf: NimbusConf) = params = conf.networkParams) com.initializeEmptyDb() - com.db.compensateLegacySetup() let protocols = conf.getProtocolFlags() diff --git a/premix/persist.nim b/premix/persist.nim index 2f663b4b0..8d9566385 100644 --- a/premix/persist.nim +++ b/premix/persist.nim @@ -65,7 +65,6 @@ proc main() {.used.} = if canonicalHeadHashKey().toOpenArray notin com.db.kvt: persistToDb(com.db): com.initializeEmptyDb() - com.db.compensateLegacySetup() doAssert(canonicalHeadHashKey().toOpenArray in com.db.kvt) var head = com.db.getCanonicalHead() diff --git a/tests/all_tests.nim b/tests/all_tests.nim index 9d05e2ae9..b4ad9bc14 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -19,7 +19,7 @@ cliBuilder: ./test_memory, ./test_stack, ./test_genesis, - #./test_precompiles, -- fails + /test_precompiles, #./test_generalstate_json, -- fails ./test_tracer_json, #./test_persistblock_json, -- fails @@ -49,7 +49,7 @@ cliBuilder: #./test_merge, -- fails ./test_eip4844, ./test_beacon/test_skeleton, - #./test_overflow, -- fails + /test_overflow, #./test_getproof_json, -- fails #./test_rpc_experimental_json, -- fails #./test_persistblock_witness_json -- fails diff --git a/tests/macro_assembler.nim b/tests/macro_assembler.nim index b44ad2603..0c1646d63 100644 --- a/tests/macro_assembler.nim +++ b/tests/macro_assembler.nim @@ -299,8 +299,6 @@ proc initVMEnv*(network: string): BaseVMState = gasLimit: 100_000 ) - # Disable opportunistic DB layer features - com.db.localDbOnly = true com.initializeEmptyDb() BaseVMState.new(parent, header, com) @@ -347,7 +345,6 @@ proc verifyAsmResult(vmState: BaseVMState, boa: Assembler, asmResult: CallResult var stateDB = vmState.stateDB stateDB.persist() - var storageRoot = stateDB.getStorageRoot(codeAddress) trie = initStorageTrie(com.db, storageRoot) diff --git a/tests/test_coredb.nim b/tests/test_coredb.nim index e64700938..d713418a4 100644 --- a/tests/test_coredb.nim +++ b/tests/test_coredb.nim @@ -167,7 +167,6 @@ proc initRunnerDB( setDebugLevel() coreDB.trackLegaApi = true coreDB.trackNewApi = true - coreDB.localDbOnly = true var params: NetworkParams @@ -191,7 +190,6 @@ proc initRunnerDB( coreDB.trackLegaApi = false coreDB.trackNewApi = false coreDB.trackLedgerApi =false - coreDB.localDbOnly = false # ------------------------------------------------------------------------------ # Test Runners: accounts and accounts storages @@ -247,7 +245,6 @@ proc chainSyncRunner( com.db.trackNewApi = true com.db.trackNewApi = true com.db.trackLedgerApi = true - com.db.localDbOnly = true check noisy.test_chainSync(filePaths, com, numBlocks, lastOneExtra=lastOneExtraOk, enaLogging=enaLoggingOk) @@ -302,7 +299,6 @@ proc persistentSyncPreLoadAndResumeRunner( com.db.trackNewApi = true com.db.trackNewApi = true com.db.trackLedgerApi = true - com.db.localDbOnly = true check noisy.test_chainSync(filePaths, com, firstPart, lastOneExtra=lastOneExtraOk, enaLogging=enaLoggingOk) @@ -319,7 +315,6 @@ proc persistentSyncPreLoadAndResumeRunner( com.db.trackNewApi = true com.db.trackNewApi = true com.db.trackLedgerApi = true - com.db.localDbOnly = true check noisy.test_chainSync(filePaths, com, secndPart, lastOneExtra=lastOneExtraOk, enaLogging=enaLoggingOk) diff --git a/tests/test_coredb/test_chainsync.nim b/tests/test_coredb/test_chainsync.nim index 4bebb74c9..d84e48c15 100644 --- a/tests/test_coredb/test_chainsync.nim +++ b/tests/test_coredb/test_chainsync.nim @@ -43,7 +43,7 @@ const EnableExtraLoggingControl = true var logStartTime {.used.} = Time() - logSavedEnv {.used.}: (bool,bool,bool,bool) + logSavedEnv {.used.}: (bool,bool,bool) # ------------------------------------------------------------------------------ # Private helpers @@ -70,18 +70,17 @@ template initLogging(noisy: bool, com: CommonRef) = debug "start undumping into persistent blocks" logStartTime = Time() logSavedEnv = (com.db.trackLegaApi, com.db.trackNewApi, - com.db.trackLedgerApi, com.db.localDbOnly) + com.db.trackLedgerApi) setErrorLevel() com.db.trackLegaApi = true com.db.trackNewApi = true com.db.trackLedgerApi = true - com.db.localDbOnly = true proc finishLogging(com: CommonRef) = when EnableExtraLoggingControl: setErrorLevel() (com.db.trackLegaApi, com.db.trackNewApi, - com.db.trackLedgerApi, com.db.localDbOnly) = logSavedEnv + com.db.trackLedgerApi) = logSavedEnv template startLogging(noisy: bool; num: BlockNumber) = diff --git a/tests/test_overflow.nim b/tests/test_overflow.nim index ad7d48e8c..a4c8e0dac 100644 --- a/tests/test_overflow.nim +++ b/tests/test_overflow.nim @@ -8,7 +8,7 @@ # at your option. This file may not be copied, modified, or distributed except # according to those terms. -import eth/keys +import eth/[keys, trie] import stew/byteutils import unittest2 import ../nimbus/common @@ -38,6 +38,7 @@ const proc overflowMain*() = test "GasCall unhandled overflow": let header = BlockHeader( + stateRoot: emptyRlpHash, blockNumber: u256(1150000), coinBase: coinbase, gasLimit: 30000000, @@ -45,7 +46,6 @@ proc overflowMain*() = ) let com = CommonRef.new(newCoreDbRef(DefaultDbMemory), config = chainConfigForNetwork(MainNet)) - let s = BaseVMState.new( header, header, diff --git a/tests/test_precompiles.nim b/tests/test_precompiles.nim index 1f1baea34..60b68c453 100644 --- a/tests/test_precompiles.nim +++ b/tests/test_precompiles.nim @@ -8,7 +8,7 @@ import std/[strformat, strutils, json, os, tables, macros], unittest2, stew/byteutils, - eth/keys, + eth/[keys, trie], ../nimbus/common/common, ../nimbus/[vm_computation, vm_state, @@ -69,10 +69,11 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) = fork = parseFork(fixtures["fork"].getStr) data = fixtures["data"] privateKey = PrivateKey.fromHex("7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d")[] + com = CommonRef.new(newCoreDbRef DefaultDbMemory, config = ChainConfig()) vmState = BaseVMState.new( - BlockHeader(blockNumber: 1.u256), + BlockHeader(blockNumber: 1.u256, stateRoot: emptyRlpHash), BlockHeader(), - CommonRef.new(newCoreDbRef DefaultDbMemory, config = ChainConfig()) + com ) case toLowerAscii(label) diff --git a/tests/test_rpc_getproofs_track_state_changes.nim b/tests/test_rpc_getproofs_track_state_changes.nim index bececabd6..2988467fc 100644 --- a/tests/test_rpc_getproofs_track_state_changes.nim +++ b/tests/test_rpc_getproofs_track_state_changes.nim @@ -147,7 +147,6 @@ proc rpcGetProofsTrackStateChangesMain*() = let com = CommonRef.new(newCoreDbRef(DefaultDbPersistent, DATABASE_PATH)) com.initializeEmptyDb() - com.db.compensateLegacySetup() let blockHeader = waitFor client.eth_getBlockByNumber(blockId(START_BLOCK), false) diff --git a/tests/test_sync_snap.nim b/tests/test_sync_snap.nim index 3d1f69e69..8e1d1b9aa 100644 --- a/tests/test_sync_snap.nim +++ b/tests/test_sync_snap.nim @@ -436,7 +436,6 @@ proc snapRunner(noisy = true; specs: SnapSyncSpecs) {.used.} = if dsc.chn.db.newKvt.backend.toRocksStoreRef.isNil: skip() else: - dsc.chn.db.compensateLegacySetup dsc.chn.test_syncdbAppendBlocks(tailPath,pivot,updateSize,noisy) # ------------------------------------------------------------------------------