@chainsafe/lodestar 1.46.0-dev.4c86702f24 → 1.46.0-dev.74a3175f1e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.git-data.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "branch": "unstable",
3
- "commit": "4c86702f24311a714c196bddaa9f0599dc76a927"
3
+ "commit": "74a3175f1e42cc0f4a753a653a8ba217bd3f6827"
4
4
  }
@@ -0,0 +1,4 @@
1
+ import { GlobalArgs } from "../../options/index.js";
2
+ import { IBuilderCliArgs } from "./options.js";
3
+ export declare function builderHandler(args: IBuilderCliArgs & GlobalArgs): Promise<void>;
4
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/cmds/builder/handler.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAIlD,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7C,wBAAsB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCtF"}
@@ -0,0 +1,38 @@
1
+ import path from "node:path";
2
+ import { getClient } from "@lodestar/api";
3
+ import { Builder } from "@lodestar/builder";
4
+ import { getNodeLogger } from "@lodestar/logger/node";
5
+ import { getBeaconConfigFromArgs } from "../../config/beaconParams.js";
6
+ import { getGlobalPaths } from "../../paths/global.js";
7
+ import { cleanOldLogFiles, onGracefulShutdown, parseLoggerArgs } from "../../util/index.js";
8
+ import { loadBuilderKeypair } from "./loadKeypair.js";
9
+ export async function builderHandler(args) {
10
+ const { config, network } = getBeaconConfigFromArgs(args);
11
+ const globalPaths = getGlobalPaths(args, network);
12
+ const defaultLogFilepath = path.join(globalPaths.dataDir, "builder.log");
13
+ const logger = getNodeLogger(parseLoggerArgs(args, { defaultLogFilepath }, config));
14
+ try {
15
+ cleanOldLogFiles(args, { defaultLogFilepath });
16
+ }
17
+ catch (e) {
18
+ logger.debug("Not able to delete log files", {}, e);
19
+ }
20
+ const keypair = await loadBuilderKeypair(args.keystore, args.keystorePassword, args.builderPubkey);
21
+ const onGracefulShutdownCbs = [];
22
+ onGracefulShutdown(async () => {
23
+ for (const cb of onGracefulShutdownCbs)
24
+ await cb();
25
+ }, logger.info.bind(logger));
26
+ const abortController = new AbortController();
27
+ onGracefulShutdownCbs.push(async () => abortController.abort());
28
+ const api = getClient({ urls: [args.beaconNodeUrl], globalInit: { signal: abortController.signal } }, { config, logger });
29
+ const builder = await Builder.init({
30
+ keypair,
31
+ logger,
32
+ config,
33
+ abortController,
34
+ api,
35
+ });
36
+ onGracefulShutdownCbs.push(() => builder.close());
37
+ }
38
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/cmds/builder/handler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AAGpD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAkC,EAAiB;IACtF,MAAM,EAAC,MAAM,EAAE,OAAO,EAAC,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE,EAAC,kBAAkB,EAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAElF,IAAI,CAAC;QACH,gBAAgB,CAAC,IAAI,EAAE,EAAC,kBAAkB,EAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,EAAE,EAAE,CAAU,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAEnG,MAAM,qBAAqB,GAAmC,EAAE,CAAC;IACjE,kBAAkB,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7B,KAAK,MAAM,EAAE,IAAI,qBAAqB;YAAE,MAAM,EAAE,EAAE,CAAC;IAAA,CACpD,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7B,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,qBAAqB,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC;IAEhE,MAAM,GAAG,GAAG,SAAS,CAAC,EAAC,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,EAAC,MAAM,EAAE,eAAe,CAAC,MAAM,EAAC,EAAC,EAAE,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;IAEpH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;QACjC,OAAO;QACP,MAAM;QACN,MAAM;QACN,eAAe;QACf,GAAG;KACJ,CAAC,CAAC;IAEH,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AAAA,CACnD"}
@@ -0,0 +1,5 @@
1
+ import { CliCommand } from "@lodestar/utils";
2
+ import { GlobalArgs } from "../../options/index.js";
3
+ import { IBuilderCliArgs } from "./options.js";
4
+ export declare const builder: CliCommand<IBuilderCliArgs, GlobalArgs>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cmds/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAC,eAAe,EAAiB,MAAM,cAAc,CAAC;AAE7D,eAAO,MAAM,OAAO,EAAE,UAAU,CAAC,eAAe,EAAE,UAAU,CAc3D,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { builderHandler } from "./handler.js";
2
+ import { builderOptions } from "./options.js";
3
+ export const builder = {
4
+ command: "builder",
5
+ describe: "Run a builder client",
6
+ docsFolder: "run/builder-management",
7
+ examples: [
8
+ {
9
+ command: "builder",
10
+ title: "Base `builder` command",
11
+ description: "Run builder client",
12
+ },
13
+ ],
14
+ options: builderOptions,
15
+ handler: builderHandler,
16
+ subcommands: [],
17
+ };
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/builder/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAkB,cAAc,EAAC,MAAM,cAAc,CAAC;AAE7D,MAAM,CAAC,MAAM,OAAO,GAA4C;IAC9D,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,sBAAsB;IAChC,UAAU,EAAE,wBAAwB;IACpC,QAAQ,EAAE;QACR;YACE,OAAO,EAAE,SAAS;YAClB,KAAK,EAAE,wBAAwB;YAC/B,WAAW,EAAE,oBAAoB;SAClC;KACF;IACD,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,cAAc;IACvB,WAAW,EAAE,EAAE;CAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Keypair } from "@lodestar/builder";
2
+ export declare function loadBuilderKeypair(keystorePath: string, passwordPath: string, expectedPubkey?: string): Promise<Keypair>;
3
+ //# sourceMappingURL=loadKeypair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadKeypair.d.ts","sourceRoot":"","sources":["../../../src/cmds/builder/loadKeypair.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAI1C,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
@@ -0,0 +1,22 @@
1
+ import fs from "node:fs";
2
+ import { Keystore } from "@chainsafe/bls-keystore";
3
+ import { SecretKey } from "@chainsafe/blst";
4
+ import { ensure0xPrefix } from "../../util/format.js";
5
+ import { readPassphraseFile } from "../../util/passphrase.js";
6
+ export async function loadBuilderKeypair(keystorePath, passwordPath, expectedPubkey) {
7
+ const password = readPassphraseFile(passwordPath);
8
+ const keystoreStr = fs.readFileSync(keystorePath, "utf8");
9
+ const keystore = Keystore.parse(keystoreStr);
10
+ if (!(await keystore.verifyPassword(password))) {
11
+ throw Error(`Invalid password for keystore ${keystorePath}`);
12
+ }
13
+ const secretKeyBytes = await keystore.decrypt(password);
14
+ const secretKey = SecretKey.fromBytes(secretKeyBytes);
15
+ const publicKey = secretKey.toPublicKey();
16
+ const publicKeyHex = publicKey.toHex();
17
+ if (expectedPubkey && publicKeyHex !== ensure0xPrefix(expectedPubkey.toLowerCase())) {
18
+ throw Error(`Pubkey mismatch: keystore ${publicKeyHex}, expected ${expectedPubkey}`);
19
+ }
20
+ return { secretKey, publicKey };
21
+ }
22
+ //# sourceMappingURL=loadKeypair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadKeypair.js","sourceRoot":"","sources":["../../../src/cmds/builder/loadKeypair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAE5D,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAoB,EACpB,YAAoB,EACpB,cAAuB,EACL;IAClB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC/C,MAAM,KAAK,CAAC,iCAAiC,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAEtD,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC;IAEvC,IAAI,cAAc,IAAI,YAAY,KAAK,cAAc,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACpF,MAAM,KAAK,CAAC,6BAA6B,YAAY,cAAc,cAAc,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,CAAC;AAAA,CAC/B"}
@@ -0,0 +1,10 @@
1
+ import { CliCommandOptions } from "@lodestar/utils";
2
+ import { LogArgs } from "../../options/logOptions.js";
3
+ export type IBuilderCliArgs = LogArgs & {
4
+ beaconNodeUrl: string;
5
+ keystore: string;
6
+ keystorePassword: string;
7
+ builderPubkey?: string;
8
+ };
9
+ export declare const builderOptions: CliCommandOptions<IBuilderCliArgs>;
10
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/cmds/builder/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,OAAO,EAAa,MAAM,6BAA6B,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,eAAe,CAyB7D,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { defaultOptions } from "@lodestar/builder";
2
+ import { logOptions } from "../../options/logOptions.js";
3
+ export const builderOptions = {
4
+ ...logOptions,
5
+ beaconNodeUrl: {
6
+ description: "Url to a trusted beacon node",
7
+ type: "string",
8
+ default: defaultOptions.beaconNodeUrl,
9
+ },
10
+ keystore: {
11
+ description: "Path to a keystore file",
12
+ type: "string",
13
+ demandOption: true,
14
+ },
15
+ keystorePassword: {
16
+ description: "Path to a file with password to decrypt the keystore from 'keystore' option",
17
+ type: "string",
18
+ demandOption: true,
19
+ },
20
+ builderPubkey: {
21
+ description: "Builder's expected public key based on the keystore from 'keystore' option",
22
+ type: "string",
23
+ },
24
+ };
25
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/cmds/builder/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAU,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAShE,MAAM,CAAC,MAAM,cAAc,GAAuC;IAChE,GAAG,UAAU;IAEb,aAAa,EAAE;QACb,WAAW,EAAE,8BAA8B;QAC3C,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,cAAc,CAAC,aAAa;KACtC;IAED,QAAQ,EAAE;QACR,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;IAED,gBAAgB,EAAE;QAChB,WAAW,EAAE,6EAA6E;QAC1F,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;IAED,aAAa,EAAE;QACb,WAAW,EAAE,4EAA4E;QACzF,IAAI,EAAE,QAAQ;KACf;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAM/C,eAAO,MAAM,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAKtF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAO/C,eAAO,MAAM,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAMtF,CAAC"}
package/lib/cmds/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { beacon } from "./beacon/index.js";
2
2
  import { bootnode } from "./bootnode/index.js";
3
+ import { builder } from "./builder/index.js";
3
4
  import { dev } from "./dev/index.js";
4
5
  import { validator } from "./validator/index.js";
5
6
  export const cmds = [
6
7
  beacon,
7
8
  validator,
9
+ builder,
8
10
  dev,
9
11
  bootnode,
10
12
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,IAAI,GAA0E;IACzF,MAAM;IACN,SAAS;IACT,GAAG;IACH,QAAQ;CACT,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,IAAI,GAA0E;IACzF,MAAM;IACN,SAAS;IACT,OAAO;IACP,GAAG;IACH,QAAQ;CACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainsafe/lodestar",
3
- "version": "1.46.0-dev.4c86702f24",
3
+ "version": "1.46.0-dev.74a3175f1e",
4
4
  "description": "Command line interface for lodestar",
5
5
  "author": "ChainSafe Systems",
6
6
  "license": "Apache-2.0",
@@ -68,16 +68,17 @@
68
68
  "@libp2p/crypto": "^5.1.13",
69
69
  "@libp2p/interface": "^3.1.0",
70
70
  "@libp2p/peer-id": "^6.0.4",
71
- "@lodestar/api": "^1.46.0-dev.4c86702f24",
72
- "@lodestar/beacon-node": "^1.46.0-dev.4c86702f24",
73
- "@lodestar/config": "^1.46.0-dev.4c86702f24",
74
- "@lodestar/db": "^1.46.0-dev.4c86702f24",
75
- "@lodestar/logger": "^1.46.0-dev.4c86702f24",
76
- "@lodestar/params": "^1.46.0-dev.4c86702f24",
77
- "@lodestar/state-transition": "^1.46.0-dev.4c86702f24",
78
- "@lodestar/types": "^1.46.0-dev.4c86702f24",
79
- "@lodestar/utils": "^1.46.0-dev.4c86702f24",
80
- "@lodestar/validator": "^1.46.0-dev.4c86702f24",
71
+ "@lodestar/api": "^1.46.0-dev.74a3175f1e",
72
+ "@lodestar/beacon-node": "^1.46.0-dev.74a3175f1e",
73
+ "@lodestar/builder": "^1.46.0-dev.74a3175f1e",
74
+ "@lodestar/config": "^1.46.0-dev.74a3175f1e",
75
+ "@lodestar/db": "^1.46.0-dev.74a3175f1e",
76
+ "@lodestar/logger": "^1.46.0-dev.74a3175f1e",
77
+ "@lodestar/params": "^1.46.0-dev.74a3175f1e",
78
+ "@lodestar/state-transition": "^1.46.0-dev.74a3175f1e",
79
+ "@lodestar/types": "^1.46.0-dev.74a3175f1e",
80
+ "@lodestar/utils": "^1.46.0-dev.74a3175f1e",
81
+ "@lodestar/validator": "^1.46.0-dev.74a3175f1e",
81
82
  "@multiformats/multiaddr": "^13.0.1",
82
83
  "deepmerge": "^4.3.1",
83
84
  "ethers": "^6.7.0",
@@ -93,7 +94,7 @@
93
94
  "devDependencies": {
94
95
  "@chainsafe/as-sha256": "^1.2.4",
95
96
  "@ethereumjs/rlp": "^4.0.1",
96
- "@lodestar/test-utils": "^1.46.0-dev.4c86702f24",
97
+ "@lodestar/test-utils": "^1.46.0-dev.74a3175f1e",
97
98
  "@types/debug": "^4.1.7",
98
99
  "@types/inquirer": "^9.0.3",
99
100
  "@types/js-yaml": "^4.0.5",
@@ -107,5 +108,5 @@
107
108
  "web3": "^4.0.3",
108
109
  "web3-eth-accounts": "^4.0.3"
109
110
  },
110
- "gitHead": "f3ea5e32becacc19c1b203b6a355a196e9d70635"
111
+ "gitHead": "bb58606a6a75525e2b09366cd00c8c9feb3b0eee"
111
112
  }
@@ -0,0 +1,46 @@
1
+ import path from "node:path";
2
+ import {getClient} from "@lodestar/api";
3
+ import {Builder} from "@lodestar/builder";
4
+ import {getNodeLogger} from "@lodestar/logger/node";
5
+ import {getBeaconConfigFromArgs} from "../../config/beaconParams.js";
6
+ import {GlobalArgs} from "../../options/index.js";
7
+ import {getGlobalPaths} from "../../paths/global.js";
8
+ import {cleanOldLogFiles, onGracefulShutdown, parseLoggerArgs} from "../../util/index.js";
9
+ import {loadBuilderKeypair} from "./loadKeypair.js";
10
+ import {IBuilderCliArgs} from "./options.js";
11
+
12
+ export async function builderHandler(args: IBuilderCliArgs & GlobalArgs): Promise<void> {
13
+ const {config, network} = getBeaconConfigFromArgs(args);
14
+
15
+ const globalPaths = getGlobalPaths(args, network);
16
+ const defaultLogFilepath = path.join(globalPaths.dataDir, "builder.log");
17
+ const logger = getNodeLogger(parseLoggerArgs(args, {defaultLogFilepath}, config));
18
+
19
+ try {
20
+ cleanOldLogFiles(args, {defaultLogFilepath});
21
+ } catch (e) {
22
+ logger.debug("Not able to delete log files", {}, e as Error);
23
+ }
24
+
25
+ const keypair = await loadBuilderKeypair(args.keystore, args.keystorePassword, args.builderPubkey);
26
+
27
+ const onGracefulShutdownCbs: (() => Promise<void> | void)[] = [];
28
+ onGracefulShutdown(async () => {
29
+ for (const cb of onGracefulShutdownCbs) await cb();
30
+ }, logger.info.bind(logger));
31
+
32
+ const abortController = new AbortController();
33
+ onGracefulShutdownCbs.push(async () => abortController.abort());
34
+
35
+ const api = getClient({urls: [args.beaconNodeUrl], globalInit: {signal: abortController.signal}}, {config, logger});
36
+
37
+ const builder = await Builder.init({
38
+ keypair,
39
+ logger,
40
+ config,
41
+ abortController,
42
+ api,
43
+ });
44
+
45
+ onGracefulShutdownCbs.push(() => builder.close());
46
+ }
@@ -0,0 +1,20 @@
1
+ import {CliCommand} from "@lodestar/utils";
2
+ import {GlobalArgs} from "../../options/index.js";
3
+ import {builderHandler} from "./handler.js";
4
+ import {IBuilderCliArgs, builderOptions} from "./options.js";
5
+
6
+ export const builder: CliCommand<IBuilderCliArgs, GlobalArgs> = {
7
+ command: "builder",
8
+ describe: "Run a builder client",
9
+ docsFolder: "run/builder-management",
10
+ examples: [
11
+ {
12
+ command: "builder",
13
+ title: "Base `builder` command",
14
+ description: "Run builder client",
15
+ },
16
+ ],
17
+ options: builderOptions,
18
+ handler: builderHandler,
19
+ subcommands: [],
20
+ };
@@ -0,0 +1,32 @@
1
+ import fs from "node:fs";
2
+ import {Keystore} from "@chainsafe/bls-keystore";
3
+ import {SecretKey} from "@chainsafe/blst";
4
+ import {Keypair} from "@lodestar/builder";
5
+ import {ensure0xPrefix} from "../../util/format.js";
6
+ import {readPassphraseFile} from "../../util/passphrase.js";
7
+
8
+ export async function loadBuilderKeypair(
9
+ keystorePath: string,
10
+ passwordPath: string,
11
+ expectedPubkey?: string
12
+ ): Promise<Keypair> {
13
+ const password = readPassphraseFile(passwordPath);
14
+ const keystoreStr = fs.readFileSync(keystorePath, "utf8");
15
+ const keystore = Keystore.parse(keystoreStr);
16
+
17
+ if (!(await keystore.verifyPassword(password))) {
18
+ throw Error(`Invalid password for keystore ${keystorePath}`);
19
+ }
20
+
21
+ const secretKeyBytes = await keystore.decrypt(password);
22
+ const secretKey = SecretKey.fromBytes(secretKeyBytes);
23
+
24
+ const publicKey = secretKey.toPublicKey();
25
+ const publicKeyHex = publicKey.toHex();
26
+
27
+ if (expectedPubkey && publicKeyHex !== ensure0xPrefix(expectedPubkey.toLowerCase())) {
28
+ throw Error(`Pubkey mismatch: keystore ${publicKeyHex}, expected ${expectedPubkey}`);
29
+ }
30
+
31
+ return {secretKey, publicKey};
32
+ }
@@ -0,0 +1,37 @@
1
+ import {defaultOptions} from "@lodestar/builder";
2
+ import {CliCommandOptions} from "@lodestar/utils";
3
+ import {LogArgs, logOptions} from "../../options/logOptions.js";
4
+
5
+ export type IBuilderCliArgs = LogArgs & {
6
+ beaconNodeUrl: string;
7
+ keystore: string;
8
+ keystorePassword: string;
9
+ builderPubkey?: string;
10
+ };
11
+
12
+ export const builderOptions: CliCommandOptions<IBuilderCliArgs> = {
13
+ ...logOptions,
14
+
15
+ beaconNodeUrl: {
16
+ description: "Url to a trusted beacon node",
17
+ type: "string",
18
+ default: defaultOptions.beaconNodeUrl,
19
+ },
20
+
21
+ keystore: {
22
+ description: "Path to a keystore file",
23
+ type: "string",
24
+ demandOption: true,
25
+ },
26
+
27
+ keystorePassword: {
28
+ description: "Path to a file with password to decrypt the keystore from 'keystore' option",
29
+ type: "string",
30
+ demandOption: true,
31
+ },
32
+
33
+ builderPubkey: {
34
+ description: "Builder's expected public key based on the keystore from 'keystore' option",
35
+ type: "string",
36
+ },
37
+ };
package/src/cmds/index.ts CHANGED
@@ -2,12 +2,14 @@ import {CliCommand} from "@lodestar/utils";
2
2
  import {GlobalArgs} from "../options/index.js";
3
3
  import {beacon} from "./beacon/index.js";
4
4
  import {bootnode} from "./bootnode/index.js";
5
+ import {builder} from "./builder/index.js";
5
6
  import {dev} from "./dev/index.js";
6
7
  import {validator} from "./validator/index.js";
7
8
 
8
9
  export const cmds: Required<CliCommand<GlobalArgs, Record<never, never>>>["subcommands"] = [
9
10
  beacon,
10
11
  validator,
12
+ builder,
11
13
  dev,
12
14
  bootnode,
13
15
  ];