Skip to content

Commit

Permalink
Add more log messages for startup
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jan 30, 2024
1 parent b60c1a8 commit 82c89cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
18 changes: 16 additions & 2 deletions packages/cli/test/utils/simulation/SimulationEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {nodeUtils} from "@lodestar/beacon-node";
import {ChainForkConfig} from "@lodestar/config";
import {activePreset} from "@lodestar/params";
import {BeaconStateAllForks, interopSecretKey} from "@lodestar/state-transition";
import {formatTime} from "@lodestar/test-utils";
import {EpochClock, MS_IN_SEC} from "./EpochClock.js";
import {ExternalSignerServer} from "./ExternalSignerServer.js";
import {SimulationTracker} from "./SimulationTracker.js";
Expand Down Expand Up @@ -96,6 +97,11 @@ export class SimulationEnvironment {

async start(opts: StartOpts): Promise<void> {
const currentTime = Date.now();
console.log(
`Starting simulation environment "${this.options.id}". currentTime=${new Date(
currentTime
).toISOString()} simulationTimeout=${formatTime(opts.runTimeoutMs)}`
);
if (opts.runTimeoutMs > 0) {
setTimeout(() => {
const slots = this.clock.getSlotFor((currentTime + opts.runTimeoutMs) / MS_IN_SEC);
Expand All @@ -119,28 +125,35 @@ export class SimulationEnvironment {
`Start sequence not completed before genesis, in ${msToGenesis}ms (approx. ${epoch}/${slot}).`
).catch((e) => console.error("Error on stop", e));
}, msToGenesis);
console.log(`Waiting for genesis for ${formatTime(msToGenesis)} else simulation will stop.`);

try {
registerProcessHandler(this);
if (!fs.existsSync(this.options.rootDir)) {
await mkdir(this.options.rootDir);
}

console.log("Starting the simulation runner");
await this.runner.start();

console.log("Starting execution nodes");
await Promise.all(this.nodes.map((node) => node.execution.job.start()));

console.log("Initializing genesis state for beacon nodes");
await this.initGenesisState();
if (!this.genesisState) {
throw new Error("The genesis state for CL clients is not defined.");
}

console.log("Starting beacon nodes");
await Promise.all(this.nodes.map((node) => node.beacon.job.start()));

console.log("Starting validators");
await Promise.all(this.nodes.map((node) => node.validator?.job.start()));

if (this.nodes.some((node) => node.validator?.keys.type === "remote")) {
console.log("Starting external signer...");
console.log("Starting external signer");
await this.externalSigner.start();
console.log("Started external signer");

for (const node of this.nodes) {
if (node.validator?.keys.type === "remote") {
Expand All @@ -156,6 +169,7 @@ export class SimulationEnvironment {
}
}

console.log("Starting the simulation tracker");
await this.tracker.start();
await Promise.all(this.nodes.map((node) => this.tracker.track(node)));
} catch (error) {
Expand Down
6 changes: 1 addition & 5 deletions packages/test-utils/src/childProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from "node:fs";
import path from "node:path";
import {sleep} from "@lodestar/utils";
import {TestContext} from "./interfaces.js";
import {formatTime} from "./format.js";

/**
* If timeout is greater than 0, the parent will send the signal
Expand Down Expand Up @@ -202,11 +203,6 @@ const defaultStartOpts = {
resolveOn: ChildProcessResolve.Immediate,
};

function formatTime(timeMs: number): string {
const d = new Date(timeMs);
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
}

/**
* Spawn child process and return it
*
Expand Down
9 changes: 9 additions & 0 deletions packages/test-utils/src/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Format a time in milliseconds to a string.
* @param timeMs
* @returns
*/
export function formatTime(timeMs: number): string {
const d = new Date(timeMs);
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
}
1 change: 1 addition & 0 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./cli.js";
export * from "./childProcess.js";
export * from "./externalSigner.js";
export * from "./format.js";
export * from "./keystores.js";
export * from "./path.js";
export * from "./timeout.js";
Expand Down

0 comments on commit 82c89cf

Please sign in to comment.