From bd2ca07da64f8f8954dd3ed7ecf30b6fde9e73b4 Mon Sep 17 00:00:00 2001 From: web3-developer <51288821+web3-developer@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:48:45 +0800 Subject: [PATCH] Update Fluffy data directory location based on selected network. (#2400) --- fluffy/fluffy.nim | 13 +++++++++---- fluffy/network/beacon/beacon_network.nim | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index f808c2691..83a1bfa44 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.nim @@ -8,7 +8,7 @@ {.push raises: [].} import - std/os, + std/[os, enumutils], confutils, confutils/std/net, chronicles, @@ -60,6 +60,12 @@ proc onOptimisticHeader( when lcDataFork > LightClientDataFork.None: info "New LC optimistic header", optimistic_header = shortLog(forkyHeader) +proc getDbDirectory(network: PortalNetwork): string = + if network == PortalNetwork.mainnet: + "db" + else: + "db_" & network.symbolName() + proc run(config: PortalConf) {.raises: [CatchableError].} = setupLogging(config.logLevel, config.logStdout) @@ -163,7 +169,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = # Force pruning if config.forcePrune: let db = ContentDB.new( - config.dataDir / "db" / "contentdb_" & + config.dataDir / portalNetwork.getDbDirectory() / "contentdb_" & d.localNode.id.toBytesBE().toOpenArray(0, 8).toHex(), storageCapacity = config.storageCapacityMB * 1_000_000, manualCheckpoint = true, @@ -195,7 +201,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = # the selected `Radius`. let db = ContentDB.new( - config.dataDir / "db" / "contentdb_" & + config.dataDir / portalNetwork.getDbDirectory() / "contentdb_" & d.localNode.id.toBytesBE().toOpenArray(0, 8).toHex(), storageCapacity = config.storageCapacityMB * 1_000_000, ) @@ -260,7 +266,6 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = config.trustedBlockRoot.isSome(): let # Portal works only over mainnet data currently - # TODO: investigate this load network data function networkData = loadNetworkData("mainnet") beaconDb = BeaconDb.new(networkData, config.dataDir / "db" / "beacon_db") beaconNetwork = BeaconNetwork.new( diff --git a/fluffy/network/beacon/beacon_network.nim b/fluffy/network/beacon/beacon_network.nim index 8959513bf..6e3b675d9 100644 --- a/fluffy/network/beacon/beacon_network.nim +++ b/fluffy/network/beacon/beacon_network.nim @@ -324,7 +324,7 @@ proc processContentLoop(n: BeaconNetwork) {.async: (raises: []).} = trace "processContentLoop canceled" proc start*(n: BeaconNetwork) = - info "Starting portal beacon chain network" + info "Starting Portal beacon chain network" n.portalProtocol.start() n.processContentLoop = processContentLoop(n)