Skip to content

Commit

Permalink
Merge 7ec526a into 2c41af0
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Sep 13, 2022
2 parents 2c41af0 + 7ec526a commit 491aea0
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {fromHexString} from "@chainsafe/ssz";
import {ssz} from "@lodestar/types";
import {BeaconDb} from "../../../../../../src/db/index.js";
import {generateSignedBlock} from "../../../../../utils/block.js";
import {testLogger} from "../../../../../utils/logger.js";
import {startTmpBeaconDb} from "../../../../../utils/db.js";

describe("BlockArchiveRepository", function () {
let db: BeaconDb;
const logger = testLogger();
const sampleBlock = generateSignedBlock({
message: {
slot: 0,
Expand All @@ -34,7 +32,7 @@ describe("BlockArchiveRepository", function () {
});

before(async () => {
db = await startTmpBeaconDb(config, logger);
db = await startTmpBeaconDb(config);
});

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("eth1 / Eth1Provider", function () {
// Nuke DB to make sure it's empty
await promisify<string>(leveldown.destroy)(dbLocation);

dbController = new LevelDbController({name: dbLocation}, {logger});
dbController = new LevelDbController({name: dbLocation}, {});
db = new BeaconDb({
config,
controller: dbController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe.skip("verify+import blocks - range sync perf test", () => {

let db: BeaconDb;
before(async () => {
db = new BeaconDb({config, controller: new LevelDbController({name: ".tmpdb"}, {logger})});
db = new BeaconDb({config, controller: new LevelDbController({name: ".tmpdb"}, {})});
await db.start();
});
after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import {LevelDbController, Bucket, encodeKey} from "@lodestar/db";

import {generateEmptySignedBlock} from "../../../../utils/block.js";
import {BlockArchiveRepository} from "../../../../../src/db/repositories/index.js";
import {testLogger} from "../../../../utils/logger.js";

describe("block archive repository", function () {
const testDir = "./.tmp";
const logger = testLogger();
let blockArchive: BlockArchiveRepository;
let controller: LevelDbController;

beforeEach(async function () {
controller = new LevelDbController({name: testDir}, {logger});
controller = new LevelDbController({name: testDir}, {});
blockArchive = new BlockArchiveRepository(config, controller);
await controller.start();
});
Expand Down
5 changes: 2 additions & 3 deletions packages/beacon-node/test/utils/db.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import child_process from "node:child_process";
import {IFilterOptions, LevelDbController} from "@lodestar/db";
import {IChainForkConfig} from "@lodestar/config";
import {ILogger} from "@lodestar/utils";
import {BeaconDb} from "../../src/index.js";

export const TEMP_DB_LOCATION = ".tmpdb";

export async function startTmpBeaconDb(config: IChainForkConfig, logger: ILogger): Promise<BeaconDb> {
export async function startTmpBeaconDb(config: IChainForkConfig): Promise<BeaconDb> {
// Clean-up db first
child_process.execSync(`rm -rf ${TEMP_DB_LOCATION}`);

const db = new BeaconDb({
config,
controller: new LevelDbController({name: TEMP_DB_LOCATION}, {logger}),
controller: new LevelDbController({name: TEMP_DB_LOCATION}, {}),
});
await db.start();

Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/node/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getDevBeaconNode(
const config = createIChainForkConfig({...minimalConfig, ...params});
logger = logger ?? testLogger();

const db = new BeaconDb({config, controller: new LevelDbController({name: tmpDir.name}, {logger})});
const db = new BeaconDb({config, controller: new LevelDbController({name: tmpDir.name}, {})});
await db.start();

const libp2p = await createNodeJsLibp2p(
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/node/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function getAndInitDevValidators({
const tmpDir = tmp.dirSync({unsafeCleanup: true});
const dbOps = {
config: node.config,
controller: new LevelDbController({name: tmpDir.name}, {logger}),
controller: new LevelDbController({name: tmpDir.name}, {}),
};
const slashingProtection = new SlashingProtection(dbOps);

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/cmds/beacon/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function beaconHandler(args: IBeaconArgs & IGlobalArgs): Promise<vo
mkdir(beaconPaths.dbDir);

const abortController = new AbortController();
const logger = getCliLogger(args, beaconPaths, config);
const logger = getCliLogger(args, {defaultLogFile: "beacon.log"}, config);

onGracefulShutdown(async () => {
abortController.abort();
Expand All @@ -49,10 +49,11 @@ export async function beaconHandler(args: IBeaconArgs & IGlobalArgs): Promise<vo
const metricsRegistries: Registry[] = [];
const db = new BeaconDb({
config,
controller: new LevelDbController(options.db, {logger: logger.child({module: "db"})}),
controller: new LevelDbController(options.db, {metrics: null}),
});

await db.start();
logger.info("Connected to LevelDB database", {path: options.db.name});

// BeaconNode setup
try {
Expand Down
69 changes: 6 additions & 63 deletions packages/cli/src/cmds/beacon/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Options} from "yargs";
import {logFormats, LogLevel, LogLevels} from "@lodestar/utils";
import {beaconNodeOptions, paramsOptions, IBeaconNodeArgs} from "../../options/index.js";
import {defaultLogMaxFiles, ICliCommandOptions, ILogArgs} from "../../util/index.js";
import {logOptions} from "../../options/logOptions.js";
import {ICliCommandOptions, ILogArgs} from "../../util/index.js";
import {defaultBeaconPaths, IBeaconPaths} from "./paths.js";

interface IBeaconExtraArgs {
Expand All @@ -12,6 +12,10 @@ interface IBeaconExtraArgs {
checkpointSyncUrl?: string;
checkpointState?: string;
wssCheckpoint?: string;
beaconDir?: string;
dbDir?: string;
persistInvalidSszObjectsDir?: string;
peerStoreDir?: string;
}

export const beaconExtraOptions: ICliCommandOptions<IBeaconExtraArgs> = {
Expand Down Expand Up @@ -58,61 +62,7 @@ export const beaconExtraOptions: ICliCommandOptions<IBeaconExtraArgs> = {
type: "string",
group: "weak subjectivity",
},
};

export const logOptions: ICliCommandOptions<ILogArgs> = {
logLevel: {
choices: LogLevels,
description: "Logging verbosity level for emittings logs to terminal",
defaultDescription: LogLevel.info,
type: "string",
},

logFileLevel: {
choices: LogLevels,
description: "Logging verbosity level for emittings logs to file",
defaultDescription: LogLevel.debug,
type: "string",
},

logFileDailyRotate: {
description:
"Daily rotate log files, set to an integer to limit the file count, set to 0(zero) to disable rotation",
defaultDescription: defaultLogMaxFiles.toString(),
default: defaultLogMaxFiles,
type: "number",
},

logFormatGenesisTime: {
hidden: true,
description:
"Use epoch slot timestamp format, instead or regular timestamp. Must provide genesisTime to compute relative time",
type: "number",
},

logPrefix: {
hidden: true,
description: "Logger prefix module field with a string ID",
type: "string",
},

logFormat: {
hidden: true,
description: "Log format used when emitting logs to the terminal and / or file",
choices: logFormats,
type: "string",
},

logLevelModule: {
hidden: true,
description: "Set log level for a specific module by name: 'chain=debug' or 'network=debug,chain=debug'",
type: "array",
string: true,
coerce: (args: string[]) => args.map((item) => item.split(",")).flat(1),
},
};

export const beaconPathsOptions: ICliCommandOptions<IBeaconPaths> = {
beaconDir: {
description: "Beacon root directory",
defaultDescription: defaultBeaconPaths.beaconDir,
Expand Down Expand Up @@ -140,12 +90,6 @@ export const beaconPathsOptions: ICliCommandOptions<IBeaconPaths> = {
defaultDescription: defaultBeaconPaths.peerStoreDir,
type: "string",
},

logFile: {
description: "Path to output all logs to a persistent log file, use 'none' to disable",
defaultDescription: defaultBeaconPaths.logFile,
type: "string",
},
};

interface IENRArgs {
Expand Down Expand Up @@ -204,7 +148,6 @@ export type IBeaconArgs = IBeaconExtraArgs & ILogArgs & IBeaconPaths & IBeaconNo
export const beaconOptions: {[k: string]: Options} = {
...beaconExtraOptions,
...logOptions,
...beaconPathsOptions,
...beaconNodeOptions,
...paramsOptions,
...enrOptions,
Expand Down
16 changes: 10 additions & 6 deletions packages/cli/src/cmds/beacon/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import path from "node:path";
import {IGlobalArgs} from "../../options/index.js";
import {getGlobalPaths, IGlobalPaths} from "../../paths/global.js";

export type BeaconPaths = Partial<{
beaconDir: string;
peerStoreDir: string;
dbDir: string;
persistInvalidSszObjectsDir: string;
}>;

export interface IBeaconPaths {
beaconDir: string;
peerStoreDir: string;
dbDir: string;
persistInvalidSszObjectsDir: string;
logFile?: string;
}

/**
Expand All @@ -23,11 +29,11 @@ export interface IBeaconPaths {
* └── beacon.log
* ```
*/
// Using Pick<IGlobalArgs, "dataDir"> make changes in IGlobalArgs throw a type error here
export function getBeaconPaths(
args: Partial<IBeaconPaths> & Pick<IGlobalArgs, "dataDir">,
// Using Pick<IGlobalArgs, "dataDir"> make changes in IGlobalArgs throw a type error here
args: BeaconPaths & Pick<IGlobalArgs, "dataDir">,
network: string
): IBeaconPaths & IGlobalPaths {
): IGlobalPaths & Required<BeaconPaths> {
// Compute global paths first
const globalPaths = getGlobalPaths(args, network);

Expand All @@ -36,15 +42,13 @@ export function getBeaconPaths(
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 logFile = args.logFile?.trim() !== "none" ? args.logFile ?? path.join(dataDir, "beacon.log") : undefined;

return {
...globalPaths,
beaconDir,
dbDir,
persistInvalidSszObjectsDir,
peerStoreDir,
logFile,
};
}

Expand Down
9 changes: 2 additions & 7 deletions packages/cli/src/cmds/lightclient/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ import {fromHexString} from "@chainsafe/ssz";
import {getBeaconConfigFromArgs} from "../../config/beaconParams.js";
import {IGlobalArgs} from "../../options/index.js";
import {getCliLogger} from "../../util/index.js";
import {getBeaconPaths} from "../beacon/paths.js";
import {ILightClientArgs} from "./options.js";
import {getLightclientPaths} from "./paths.js";

export async function lightclientHandler(args: ILightClientArgs & IGlobalArgs): Promise<void> {
const {config, network} = getBeaconConfigFromArgs(args);
const {config} = getBeaconConfigFromArgs(args);

const beaconPaths = getBeaconPaths(args, network);
const lightclientPaths = getLightclientPaths(args, network);

const logger = getCliLogger(args, {...beaconPaths, logFile: lightclientPaths.logFile}, config);
const logger = getCliLogger(args, {defaultLogFile: "lightclient.log"}, config);
const {beaconApiUrl, checkpointRoot} = args;
const api = getClient({baseUrl: beaconApiUrl}, {config});
const {data: genesisData} = await api.beacon.getGenesis();
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/cmds/lightclient/options.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {logOptions} from "../../options/logOptions.js";
import {ICliCommandOptions, ILogArgs} from "../../util/index.js";
import {beaconPathsOptions, logOptions} from "../beacon/options.js";
import {IBeaconPaths} from "../beacon/paths.js";

export type ILightClientArgs = ILogArgs & {
logFile: IBeaconPaths["logFile"];
beaconApiUrl: string;
checkpointRoot: string;
};

export const lightclientOptions: ICliCommandOptions<ILightClientArgs> = {
...logOptions,
logFile: beaconPathsOptions.logFile,
beaconApiUrl: {
description: "Url to a beacon node that support lightclient API",
type: "string",
Expand Down
27 changes: 0 additions & 27 deletions packages/cli/src/cmds/lightclient/paths.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {IGlobalArgs} from "../../options/index.js";
import {YargsError, getDefaultGraffiti, mkdir, getCliLogger} from "../../util/index.js";
import {onGracefulShutdown, parseFeeRecipient, parseProposerConfig} from "../../util/index.js";
import {getVersionData} from "../../util/version.js";
import {getBeaconPaths} from "../beacon/paths.js";
import {getAccountPaths, getValidatorPaths} from "./paths.js";
import {IValidatorCliArgs, validatorMetricsDefaultOptions} from "./options.js";
import {getSignersFromArgs} from "./signers/index.js";
Expand All @@ -26,17 +25,17 @@ export async function validatorHandler(args: IValidatorCliArgs & IGlobalArgs): P

const doppelgangerProtectionEnabled = args.doppelgangerProtectionEnabled;

const beaconPaths = getBeaconPaths(args, network);
const validatorPaths = getValidatorPaths(args, network);
const accountPaths = getAccountPaths(args, network);

const logger = getCliLogger(args, {...beaconPaths, logFile: validatorPaths.logFile}, config);
const logger = getCliLogger(args, {defaultLogFile: "validator.log"}, config);

const persistedKeysBackend = new PersistedKeysBackend(accountPaths);
const valProposerConfig = getProposerConfigFromArgs(args, {persistedKeysBackend, accountPaths});

const {version, commit} = getVersionData();
logger.info("Lodestar", {network, version, commit});
logger.info("Connecting to LevelDB database", {path: validatorPaths.validatorsDbDir});

const dbPath = validatorPaths.validatorsDbDir;
mkdir(dbPath);
Expand Down Expand Up @@ -83,7 +82,7 @@ export async function validatorHandler(args: IValidatorCliArgs & IGlobalArgs): P

const dbOps = {
config,
controller: new LevelDbController({name: dbPath}, {logger}),
controller: new LevelDbController({name: dbPath}, {metrics: null}),
};
const slashingProtection = new SlashingProtection(dbOps);

Expand Down

0 comments on commit 491aea0

Please sign in to comment.