Skip to content

Commit

Permalink
Remove usages of CoreDb in Fluffy. (#2152)
Browse files Browse the repository at this point in the history
* Remove references to CoreDb in Fluffy code.

* Add missing import.

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

* Fix formatting using nph.
  • Loading branch information
web3-developer committed Apr 25, 2024
1 parent 70be982 commit d12300e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions fluffy/network/history/history_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import
stew/results,
chronos,
chronicles,
eth/[common/eth_types_rlp, rlp],
eth/[common/eth_types_rlp, rlp, trie, trie/db],
eth/p2p/discoveryv5/[protocol, enr],
../../common/common_types,
../../database/content_db,
../../network_metadata,
../../../nimbus/[constants, db/core_db],
../../../nimbus/constants,
../wire/[portal_protocol, portal_stream, portal_protocol_config],
"."/[history_content, accumulator, beacon_chain_historical_roots]

Expand Down Expand Up @@ -190,7 +190,7 @@ func encode*(receipts: seq[Receipt]): seq[byte] =
# for if/when peer scoring/banning is added.

proc calcRootHash(items: Transactions | PortalReceipts | Withdrawals): Hash256 =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune
var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, item in items:
try:
tr.put(rlp.encode(i), item.asSeq())
Expand Down
6 changes: 4 additions & 2 deletions fluffy/tests/test_discovery_rpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TestCase = ref object
proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
let
localSrvAddress = "127.0.0.1"
localSrvPort = 8545
localSrvPort = 0 # let the OS choose a port
ta = initTAddress(localSrvAddress, localSrvPort)
localDiscoveryNode =
initDiscoveryNode(rng, PrivateKey.random(rng[]), localAddress(20302))
Expand All @@ -39,7 +39,9 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
rpcHttpServerWithProxy.installDiscoveryApiHandlers(localDiscoveryNode)

await rpcHttpServerWithProxy.start()
await client.connect(localSrvAddress, Port(localSrvPort), false)
await client.connect(
localSrvAddress, rpcHttpServerWithProxy.localAddress[0].port, false
)
return TestCase(
localDiscovery: localDiscoveryNode, server: rpcHttpServerWithProxy, client: client
)
Expand Down
7 changes: 3 additions & 4 deletions fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import
chronicles,
chronos,
confutils,
eth/[keys, rlp],
eth/[keys, rlp, trie, trie/db],
# Need to rename this because of web3 ethtypes and ambigious indentifier mess
# for `BlockHeader`.
eth/common/eth_types as etypes,
Expand All @@ -59,7 +59,6 @@ import
../../network/history/[history_content, history_network],
../../network/beacon/beacon_content,
../../common/common_types,
../../nimbus/db/core_db,
./beacon_lc_bridge_conf

from stew/objects import checkedEnumAssign
Expand All @@ -81,7 +80,7 @@ template unsafeQuantityToInt64(q: Quantity): int64 =
proc calculateTransactionData(
items: openArray[TypedTransaction]
): Hash256 {.raises: [].} =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune
var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, t in items:
try:
let tx = distinctBase(t)
Expand All @@ -95,7 +94,7 @@ proc calculateTransactionData(
# TODO: Since Capella we can also access ExecutionPayloadHeader and thus
# could get the Roots through there instead.
proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash256 {.raises: [].} =
var tr = newCoreDbRef(LegacyDbMemory).mptPrune
var tr = initHexaryTrie(newMemoryDB(), isPruning = false)
for i, w in items:
try:
let withdrawal = etypes.Withdrawal(
Expand Down

0 comments on commit d12300e

Please sign in to comment.