import path from "node:path"; import {GlobalArgs} from "../../options/index.js"; import {GlobalPaths, getGlobalPaths} from "../../paths/global.js"; export type BeaconPathsPartial = Partial<{ beaconDir: string; peerStoreDir: string; dbDir: string; persistInvalidSszObjectsDir: string; persistOrphanedBlocksDir?: string; }>; export type BeaconPaths = { beaconDir: string; peerStoreDir: string; dbDir: string; persistInvalidSszObjectsDir: string; persistOrphanedBlocksDir: string; }; /** * Defines the path structure of the files relevant to the beacon node * * ```bash * $dataDir * └── $beaconDir * ├── beacon.config.json * ├── peer-id.json * ├── enr * ├── chain-db * └── beacon.log * ``` */ export function getBeaconPaths( // Using Pick make changes in GlobalArgs throw a type error here args: BeaconPathsPartial & Pick, network: string ): GlobalPaths & Required { // Compute global paths first const globalPaths = getGlobalPaths(args, network); const dataDir = globalPaths.dataDir; const beaconDir = dataDir; const dbDir = args.dbDir ?? path.join(beaconDir, "chain-db"); const persistInvalidSszObjectsDir = args.persistInvalidSszObjectsDir ?? path.join(beaconDir, "invalidSszObjects"); const peerStoreDir = args.peerStoreDir ?? path.join(beaconDir, "peerstore"); const persistOrphanedBlocksDir = args.persistOrphanedBlocksDir ?? path.join(beaconDir, "orphaned_blocks"); return { ...globalPaths, beaconDir, dbDir, persistInvalidSszObjectsDir, peerStoreDir, persistOrphanedBlocksDir, }; } /** * Constructs representations of the path structure to show in command's description */ export const defaultBeaconPaths = getBeaconPaths({dataDir: "$dataDir"}, "$network");