Provide public default db symbol (#2050)

* CoreDb: Provide default db backend symbols

why:
  Handy for running `Aristo` against standard tests

note:
  These defaults are currently set to legacy DB types. The must be
  enabled manually in `db/core_db.nim`.

* Provide `Aristo` for macro assembler related tests

caveat:
  Some tests use `initStorageTrie()` which lets `Aristo` bail out. The
  test need to run on `distinct_ledgers` (or something like) rather than
  `distinct_tries`.

* Tests: Misc modules that can run on `Aristo` as well

* NoHive: Module that can run on `Aristo` as well

* Fix copyright year

* ditto
This commit is contained in:
Jordan Hrycaj 2024-02-23 09:17:24 +00:00 committed by GitHub
parent 8e18e85288
commit a02a915039
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 68 additions and 23 deletions

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@ -19,7 +19,7 @@ import
proc processChainData(cd: ChainData): TestStatus =
let
networkId = NetworkId(cd.params.config.chainId)
com = CommonRef.new(newCoreDbRef LegacyDbMemory,
com = CommonRef.new(newCoreDbRef DefaultDbMemory,
pruneTrie = false,
networkId,
cd.params

View File

@ -97,8 +97,9 @@ type
## Optional suggestion for the ledger cache to be used as state DB
const
CommonLedgerTypeDefault* = LegacyAccountsCache
## Default ledger type to use, see `ldgType` above
CommonLegacyDbLedgerTypeDefault = LegacyAccountsCache
## Default ledger type to use, see `ldgType` above. This default will be
## superseded by `LedgerCache` as default for `Aristo` type deb backend.
# ------------------------------------------------------------------------------
# Forward declarations
@ -156,7 +157,14 @@ proc init(com : CommonRef,
com.forkTransitionTable = config.toForkTransitionTable()
com.networkId = networkId
com.syncProgress= SyncProgress()
com.ldgType = ldgType
com.ldgType = block:
if ldgType != LedgerType(0):
ldgType
elif db.dbType in {AristoDbMemory,AristoDbRocks,AristoDbVoid}:
# The `Aristo` backend does not work well with the `LegacyAccountsCache`
LedgerCache
else:
CommonLegacyDbLedgerTypeDefault
# Initalise the PoA state regardless of whether it is needed on the current
# network. For non-PoA networks this descriptor is ignored.
@ -223,7 +231,7 @@ proc new*(
pruneTrie: bool = true;
networkId: NetworkId = MainNet;
params = networkParams(MainNet);
ldgType = CommonLedgerTypeDefault;
ldgType = LedgerType(0);
): CommonRef
{.gcsafe, raises: [CatchableError].} =
@ -244,7 +252,7 @@ proc new*(
config: ChainConfig;
pruneTrie: bool = true;
networkId: NetworkId = MainNet;
ldgType = CommonLedgerTypeDefault;
ldgType = LedgerType(0);
): CommonRef
{.gcsafe, raises: [CatchableError].} =

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 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)
@ -25,4 +25,20 @@ import
export
memory_only
# Default database backend selection. Note that an `Aristo` type backend
# should run on a `LedgerCache` type ledger (will not work with
# `LegacyAccountsCache`.) The `common` module automatically sets that up
# (unless overridden.) Practically, these constants are mainly used for
# setting up DB agnostic unit/integration tests.
#
# Uncomment the below symbols in order to activate the `Aristo` database.
#const DefaultDbMemory* = AristoDbMemory
#const DefaultDbPersistent* = AristoDbRocks
# Catch undefined symbols and set them to the legacy database.
when not declared(DefaultDbMemory):
const DefaultDbMemory* = LegacyDbMemory
when not declared(DefaultDbPersistent):
const DefaultDbPersistent* = LegacyDbPersistent
# End

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2024 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)
@ -63,6 +63,15 @@ type
const
idToOpcode = CacheTable"NimbusMacroAssembler"
var
coreDbType* = DefaultDbMemory
## This variable needs to be accessible for unit tests like
## `test_op_memory` which implicitely uses the `initStorageTrie()` call
## from the `distinct_tries` module. The `Aristo` API cannot handle that
## because it needs the account addressfor accessing the storage trie.
##
## This problem can be fixed here in the `verifyAsmResult()` function once
## there is the time to do it ...
static:
for n in Op:
@ -269,8 +278,14 @@ const
proc initVMEnv*(network: string): BaseVMState =
let
conf = getChainConfig(network)
cdb = block:
# Need static binding
case coreDbType:
of AristoDbMemory: newCoreDbRef AristoDbMemory
of LegacyDbMemory: newCoreDbRef LegacyDbMemory
else: raiseAssert "unsupported: " & $coreDbType
com = CommonRef.new(
newCoreDbRef LegacyDbMemory,
cdb,
conf,
false,
conf.chainId.NetworkId)
@ -286,6 +301,9 @@ proc initVMEnv*(network: string): BaseVMState =
gasLimit: 100_000
)
when DefaultDbMemory in {AristoDbMemory, AristoDbRocks}:
# Disable opportunistic DB layer features for `Aristo`
com.db.localDbOnly = true
com.initializeEmptyDb()
BaseVMState.new(parent, header, com)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2024 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)
@ -58,7 +58,7 @@ proc main() {.used.} =
# nimbus --rpcapi: eth, debug --prune: archive
var conf = makeConfig()
let db = newCoreDbRef(LegacyDbPersistent, string conf.dataDir)
let db = newCoreDbRef(DefaultDbPersistent, string conf.dataDir)
let com = CommonRef.new(db, false)
com.dumpTest(97)

View File

@ -82,7 +82,7 @@ template runTest(network: untyped, name: string) =
test name:
var
params = networkParams(network)
com = CommonRef.new(newCoreDbRef LegacyDbMemory, true, network, params)
com = CommonRef.new(newCoreDbRef DefaultDbMemory, true, network, params)
for i, x in `network IDs`:
let id = com.forkId(x.number, x.time)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2024 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)
@ -27,7 +27,7 @@ proc findFilePath(file: string): string =
return path
proc makeGenesis(networkId: NetworkId): BlockHeader =
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = networkParams(networkId))
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = networkParams(networkId))
com.genesisHeader
proc genesisTest() =
@ -63,7 +63,7 @@ proc customGenesisTest() =
test "calaveras.json":
var cg: NetworkParams
check loadNetworkParams("calaveras.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "664c93de37eb4a72953ea42b8c046cdb64c9f0b0bca5505ade8d970d49ebdb8c".toDigest
let genesisHash = "eb9233d066c275efcdfed8037f4fc082770176aefdbcb7691c71da412a5670f2".toDigest
check com.genesisHeader.stateRoot == stateRoot
@ -75,7 +75,7 @@ proc customGenesisTest() =
test "Devnet4.json (aka Kintsugi in all but chainId)":
var cg: NetworkParams
check loadNetworkParams("devnet4.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "3b84f313bfd49c03cc94729ade2e0de220688f813c0c895a99bd46ecc9f45e1e".toDigest
let genesisHash = "a28d8d73e087a01d09d8cb806f60863652f30b6b6dfa4e0157501ff07d422399".toDigest
check com.genesisHeader.stateRoot == stateRoot
@ -85,7 +85,7 @@ proc customGenesisTest() =
test "Devnet5.json (aka Kiln in all but chainId and TTD)":
var cg: NetworkParams
check loadNetworkParams("devnet5.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "52e628c7f35996ba5a0402d02b34535993c89ff7fc4c430b2763ada8554bee62".toDigest
let genesisHash = "51c7fe41be669f69c45c33a56982cbde405313342d9e2b00d7c91a7b284dd4f8".toDigest
check com.genesisHeader.stateRoot == stateRoot
@ -95,7 +95,7 @@ proc customGenesisTest() =
test "Mainnet shadow fork 1":
var cg: NetworkParams
check loadNetworkParams("mainshadow1.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".toDigest
let genesisHash = "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".toDigest
let ttd = "46_089_003_871_917_200_000_000".parse(Uint256)
@ -108,7 +108,7 @@ proc customGenesisTest() =
# parse using geth format should produce the same result with nimbus format
var cg: NetworkParams
check loadNetworkParams("geth_mainshadow1.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".toDigest
let genesisHash = "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".toDigest
let ttd = "46_089_003_871_917_200_000_000".parse(Uint256)
@ -123,7 +123,7 @@ proc customGenesisTest() =
test "Holesky":
var cg: NetworkParams
check loadNetworkParams("holesky.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "69D8C9D72F6FA4AD42D4702B433707212F90DB395EB54DC20BC85DE253788783".toDigest
let genesisHash = "b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4".toDigest
check com.genesisHeader.stateRoot == stateRoot
@ -134,7 +134,7 @@ proc customGenesisTest() =
# parse using geth format should produce the same result with nimbus format
var cg: NetworkParams
check loadNetworkParams("geth_holesky.json".findFilePath, cg)
let com = CommonRef.new(newCoreDbRef LegacyDbMemory, params = cg)
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
let stateRoot = "69D8C9D72F6FA4AD42D4702B433707212F90DB395EB54DC20BC85DE253788783".toDigest
let genesisHash = "b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4".toDigest
check com.genesisHeader.stateRoot == stateRoot

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2024 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)
@ -12,6 +12,9 @@ import
std/[macros, strutils],
macro_assembler, unittest2
# Currently fails on `AristoDb*`
macro_assembler.coreDbType = LegacyDbMemory
proc opMemoryMain*() =
suite "Memory Opcodes":
assembler: # PUSH1 OP