restore a few tests, cleanup (#2234)

* remove `compensateLegacySetup`, `localDbOnly`
* enable trivially fixable tests
This commit is contained in:
Jacek Sieka 2024-05-28 14:49:35 +02:00 committed by GitHub
parent 741fcca9b6
commit 08e98eb385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 17 additions and 53 deletions

View File

@ -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

View File

@ -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()"),

View File

@ -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 |

View File

@ -49,7 +49,6 @@ type
BaseColStateFn = "state"
BaseDbTypeFn = "dbType"
BaseFinishFn = "finish"
BaseLegacySetupFn = "compensateLegacySetup"
BaseLevelFn = "level"
BaseNewCaptureFn = "newCapture"
BaseNewCtxFn = "ctx"

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -241,7 +241,6 @@ proc start(nimbus: NimbusNode, conf: NimbusConf) =
params = conf.networkParams)
com.initializeEmptyDb()
com.db.compensateLegacySetup()
let protocols = conf.getProtocolFlags()

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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) =

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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)
# ------------------------------------------------------------------------------