Skip to content

Commit

Permalink
Transform JSON trusted setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcoffman committed Nov 17, 2022
1 parent 1bd9bb8 commit 2942065
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4,173 deletions.
7 changes: 5 additions & 2 deletions packages/beacon-node/src/node/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {setMaxListeners} from "node:events";
import {Libp2p} from "libp2p";
import {Registry} from "prom-client";

import {loadTrustedSetup} from "c-kzg";
import {loadTrustedSetup, transformTrustedSetupJSON} from "c-kzg";
import {IBeaconConfig} from "@lodestar/config";
import {phase0} from "@lodestar/types";
import {ILogger} from "@lodestar/utils";
Expand Down Expand Up @@ -71,6 +71,8 @@ enum LoggerModule {
sync = "sync",
}

const SETUP_FILE_PATH = "testing_trusted_setups.json";

/**
* The main Beacon Node class. Contains various components for getting and processing data from the
* Ethereum Consensus ecosystem as well as systems for getting beacon node metadata.
Expand Down Expand Up @@ -147,7 +149,8 @@ export class BeaconNode {

// Load our KZG trusted setup into C-KZG for later use
try {
loadTrustedSetup("trusted_setup.txt");
const file = await transformTrustedSetupJSON(SETUP_FILE_PATH);
loadTrustedSetup(file);
} catch (e) {
logger.warn("Beacon node did not load trusted setup: ", undefined, e as Error);
}
Expand Down
19 changes: 11 additions & 8 deletions packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {loadTrustedSetup} from "c-kzg";
import {loadTrustedSetup, transformTrustedSetupJSON} from "c-kzg";
import {IDatabaseApiOptions} from "@lodestar/db";
import {BLSPubkey, ssz} from "@lodestar/types";
import {createIBeaconConfig, IBeaconConfig} from "@lodestar/config";
Expand Down Expand Up @@ -48,6 +48,8 @@ enum Status {
closed,
}

const SETUP_FILE_PATH = "testing_trusted_setups.json";

/**
* Main class for the Validator client.
*/
Expand All @@ -72,13 +74,6 @@ export class Validator {
const clock = new Clock(config, logger, {genesisTime: Number(genesis.genesisTime)});
const loggerVc = getLoggerVc(logger, clock);

// Load our KZG trusted setup into C-KZG for later use
try {
loadTrustedSetup("trusted_setup.txt");
} catch (e) {
logger.warn("Validator node did not load trusted setup: ", undefined, e as Error);
}

let api: Api;
if (typeof opts.api === "string" || Array.isArray(opts.api)) {
// This new api instance can make do with default timeout as a faster timeout is
Expand Down Expand Up @@ -198,6 +193,14 @@ export class Validator {
await assertEqualGenesis(opts, genesis);
logger.info("Verified connected beacon node and validator have the same genesisValidatorRoot");

// Load our KZG trusted setup into C-KZG for later use
try {
const file = await transformTrustedSetupJSON(SETUP_FILE_PATH);
loadTrustedSetup(file);
} catch (e) {
logger.error("Validator node did not load trusted setup: ", undefined, e as Error);
}

return new Validator(opts, genesis, metrics);
}

Expand Down
1 change: 1 addition & 0 deletions testing_trusted_setups.json

Large diffs are not rendered by default.

Loading

0 comments on commit 2942065

Please sign in to comment.