Remove usages of CoreDb in Fluffy. (#2152)

* Remove references to CoreDb in Fluffy code.

* Add missing import.

* Remove coredb imports and use dynamic server port in tests.

* Fix formatting using nph.
This commit is contained in:
web3-developer 2024-04-25 18:22:21 +08:00 committed by GitHub
parent 70be982259
commit d12300ecc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View File

@ -11,12 +11,12 @@ import
stew/results, stew/results,
chronos, chronos,
chronicles, chronicles,
eth/[common/eth_types_rlp, rlp], eth/[common/eth_types_rlp, rlp, trie, trie/db],
eth/p2p/discoveryv5/[protocol, enr], eth/p2p/discoveryv5/[protocol, enr],
../../common/common_types, ../../common/common_types,
../../database/content_db, ../../database/content_db,
../../network_metadata, ../../network_metadata,
../../../nimbus/[constants, db/core_db], ../../../nimbus/constants,
../wire/[portal_protocol, portal_stream, portal_protocol_config], ../wire/[portal_protocol, portal_stream, portal_protocol_config],
"."/[history_content, accumulator, beacon_chain_historical_roots] "."/[history_content, accumulator, beacon_chain_historical_roots]
@ -190,7 +190,7 @@ func encode*(receipts: seq[Receipt]): seq[byte] =
# for if/when peer scoring/banning is added. # for if/when peer scoring/banning is added.
proc calcRootHash(items: Transactions | PortalReceipts | Withdrawals): Hash256 = proc calcRootHash(items: Transactions | PortalReceipts | Withdrawals): Hash256 =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, item in items: for i, item in items:
try: try:
tr.put(rlp.encode(i), item.asSeq()) tr.put(rlp.encode(i), item.asSeq())

View File

@ -27,7 +27,7 @@ type TestCase = ref object
proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} = proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
let let
localSrvAddress = "127.0.0.1" localSrvAddress = "127.0.0.1"
localSrvPort = 8545 localSrvPort = 0 # let the OS choose a port
ta = initTAddress(localSrvAddress, localSrvPort) ta = initTAddress(localSrvAddress, localSrvPort)
localDiscoveryNode = localDiscoveryNode =
initDiscoveryNode(rng, PrivateKey.random(rng[]), localAddress(20302)) initDiscoveryNode(rng, PrivateKey.random(rng[]), localAddress(20302))
@ -39,7 +39,9 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
rpcHttpServerWithProxy.installDiscoveryApiHandlers(localDiscoveryNode) rpcHttpServerWithProxy.installDiscoveryApiHandlers(localDiscoveryNode)
await rpcHttpServerWithProxy.start() await rpcHttpServerWithProxy.start()
await client.connect(localSrvAddress, Port(localSrvPort), false) await client.connect(
localSrvAddress, rpcHttpServerWithProxy.localAddress[0].port, false
)
return TestCase( return TestCase(
localDiscovery: localDiscoveryNode, server: rpcHttpServerWithProxy, client: client localDiscovery: localDiscoveryNode, server: rpcHttpServerWithProxy, client: client
) )

View File

@ -41,7 +41,7 @@ import
chronicles, chronicles,
chronos, chronos,
confutils, confutils,
eth/[keys, rlp], eth/[keys, rlp, trie, trie/db],
# Need to rename this because of web3 ethtypes and ambigious indentifier mess # Need to rename this because of web3 ethtypes and ambigious indentifier mess
# for `BlockHeader`. # for `BlockHeader`.
eth/common/eth_types as etypes, eth/common/eth_types as etypes,
@ -59,7 +59,6 @@ import
../../network/history/[history_content, history_network], ../../network/history/[history_content, history_network],
../../network/beacon/beacon_content, ../../network/beacon/beacon_content,
../../common/common_types, ../../common/common_types,
../../nimbus/db/core_db,
./beacon_lc_bridge_conf ./beacon_lc_bridge_conf
from stew/objects import checkedEnumAssign from stew/objects import checkedEnumAssign
@ -81,7 +80,7 @@ template unsafeQuantityToInt64(q: Quantity): int64 =
proc calculateTransactionData( proc calculateTransactionData(
items: openArray[TypedTransaction] items: openArray[TypedTransaction]
): Hash256 {.raises: [].} = ): Hash256 {.raises: [].} =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, t in items: for i, t in items:
try: try:
let tx = distinctBase(t) let tx = distinctBase(t)
@ -95,7 +94,7 @@ proc calculateTransactionData(
# TODO: Since Capella we can also access ExecutionPayloadHeader and thus # TODO: Since Capella we can also access ExecutionPayloadHeader and thus
# could get the Roots through there instead. # could get the Roots through there instead.
proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash256 {.raises: [].} = proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash256 {.raises: [].} =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, w in items: for i, w in items:
try: try:
let withdrawal = etypes.Withdrawal( let withdrawal = etypes.Withdrawal(