UNPKG

@lodestar/prover

Version:

A Typescript implementation of the Ethereum Consensus light client

84 lines 3.26 kB
// MUST import this file first before anything and not import any Lodestar code. import { setHasher } from "@chainsafe/persistent-merkle-tree"; import { hasher as asSha256Hasher } from "@chainsafe/persistent-merkle-tree/hasher/as-sha256"; import { hasher as hashtreeHasher } from "@chainsafe/persistent-merkle-tree/hasher/hashtree"; import CpuFeatures from "cpu-features"; // without setting this first, persistent-merkle-tree will use noble instead const cpuFeatures = CpuFeatures(); if (cpuFeatures.arch === "x86" && !((cpuFeatures.flags.avx512f && cpuFeatures.flags.avx512vl) || (cpuFeatures.flags.avx2 && cpuFeatures.flags.bmi2) || (cpuFeatures.flags.avx && cpuFeatures.flags.sha))) { setHasher(asSha256Hasher); } else { setHasher(hashtreeHasher); } // // ## Rationale // // Lodestar implemented PRESET / CONFIG separation to allow importing types and preset constants directly // see https://github.com/ChainSafe/lodestar/pull/2585 // // However this prevents dynamic configuration changes which is exactly what the CLI required before. // - The dev command can't apply the minimal preset dynamically // - `--network gnosis` can't apply a different preset dynamically // - `--network chiado` can't apply a different preset dynamically // // Running this file allows us to keep a static export strategy while NOT requiring users to // set LODESTAR_PRESET manually every time. // IMPORTANT: only import Lodestar code here which does not import any other Lodestar libraries import { PresetName, presetFromJson, setActivePreset } from "@lodestar/params/setPreset"; import { readFile } from "../utils/file.js"; const network = valueOfArg("network"); const preset = valueOfArg("preset"); const presetFile = valueOfArg("presetFile"); // Apply preset flag if present if (preset) { process.env.LODESTAR_PRESET = preset; } // If ENV is set overrides, network (otherwise can not override network --dev in mainnet mode) else if (process.env.LODESTAR_PRESET) { // break } // Translate network to preset else if (network) { if (network === "dev") { process.env.LODESTAR_PRESET = "minimal"; // the kzg library has hardcoded the mainnet value, do not use presets setActivePreset(PresetName.minimal, { FIELD_ELEMENTS_PER_BLOB: 4096 }); } else if (network === "gnosis" || network === "chiado") { process.env.LODESTAR_PRESET = "gnosis"; } } if (presetFile) { // Override the active preset with custom values from file // Do not modify the preset to use as a base by passing null setActivePreset(null, presetFromJson(readFile(presetFile) ?? {})); } /** * Valid syntax * - `--preset minimal` * - `--preset=minimal` */ function valueOfArg(argName) { // Syntax `--preset minimal` // process.argv = ["--preset", "minimal"]; { const index = process.argv.indexOf(`--${argName}`); if (index > -1) { return process.argv[index + 1] ?? ""; } } // Syntax `--preset=minimal` { const prefix = `--${argName}=`; const item = process.argv.find((arg) => arg.startsWith(prefix)); if (item) { return item.slice(prefix.length); } } return null; } //# sourceMappingURL=applyPreset.js.map