Skip to content

Commit

Permalink
Add wait messages for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Apr 2, 2024
1 parent 9620a7c commit 09b081e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/cli/test/sim/backup_eth_provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ env.nodes.push(node3);
await env.start({runTimeoutMs: estimatedTimeoutMs});
await connectAllNodes(env.nodes);

await waitForSlot(env.clock.getLastSlotOfEpoch(1), env.nodes, {silent: true, env});
await waitForSlot("Waiting for two epochs to pass", {env, slot: env.clock.getLastSlotOfEpoch(1)});

// Stop node2, node3 EL, so the only way they produce blocks is via node1 EL
await node2.execution.job.stop();
await node3.execution.job.stop();

// node2 and node3 will successfully reach TTD if they can communicate to an EL on node1
await waitForSlot(env.clock.getLastSlotOfEpoch(bellatrixForkEpoch) + activePreset.SLOTS_PER_EPOCH / 2, env.nodes, {
silent: true,
await waitForSlot("Wait half additional epoch to bellatrix fork epoch", {
slot: env.clock.getLastSlotOfEpoch(bellatrixForkEpoch) + activePreset.SLOTS_PER_EPOCH / 2,
env,
});

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/sim/deneb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ env.tracker.register(
})
);

await waitForSlot(env.clock.getLastSlotOfEpoch(2), env.nodes, {
await waitForSlot("Waiting for the 2nd epoch to pass", {
slot: env.clock.getLastSlotOfEpoch(2),
env,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/sim/endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const env = await SimulationEnvironment.initWithDefaults(
await env.start({runTimeoutMs: estimatedTimeoutMs});

const node = env.nodes[0].beacon;
await waitForSlot(2, env.nodes, {env, silent: true});
await waitForSlot("Wait for 2 slots before checking endpoints", {env, slot: 2});

const res = await node.api.beacon.getStateValidators("head");
ApiError.assert(res);
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/test/sim/mixed_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ await env.start({runTimeoutMs: estimatedTimeoutMs});
await connectAllNodes(env.nodes);

// Stopping at last slot usually cause assertion to fail because of missing data as node are shutting down
await waitForSlot(env.clock.getLastSlotOfEpoch(capellaForkEpoch + 1) + 2, env.nodes, {env, silent: true});
await waitForSlot("Waiting for the one additional epoch for capellaFork", {
slot: env.clock.getLastSlotOfEpoch(capellaForkEpoch + 1) + 2,
env,
});

await env.stop();
3 changes: 2 additions & 1 deletion packages/cli/test/sim/multi_fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ for (const fork of env.forkConfig.forksAscendingEpochOrder) {
env.tracker.register(createForkAssertion(fork.name, fork.epoch));
}

await waitForSlot(env.clock.getLastSlotOfEpoch(lastForkEpoch + 1), env.nodes, {
await waitForSlot("Waiting for last forks to pass", {
slot: env.clock.getLastSlotOfEpoch(lastForkEpoch + 1),
env,
});

Expand Down
18 changes: 9 additions & 9 deletions packages/cli/test/utils/simulation/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ export async function waitForHead(
}

export async function waitForSlot(
slot: Slot,
nodes: NodePair[],
{silent, env}: {silent?: boolean; env: SimulationEnvironment}
message: string,
{env, slot, nodes}: {env: SimulationEnvironment; slot: Slot; nodes?: NodePair[]}
): Promise<void> {
if (!silent) {
console.log(`\nWaiting for slot on "${nodes.map((n) => n.beacon.id).join(",")}"`, {
target: slot,
current: env.clock.currentSlot,
});
}
nodes = nodes ?? env.nodes;

console.log(`\n${message}`, {
target: slot,
current: env.clock.currentSlot,
nodes: nodes.map((n) => n.beacon.id).join(","),
});

await Promise.all(
nodes.map(
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/test/utils/simulation/utils/syncing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export async function assertRangeSync(env: SimulationEnvironment): Promise<void>

export async function assertCheckpointSync(env: SimulationEnvironment): Promise<void> {
// First checkpoint finalized is at least 4 epochs
await waitForSlot(env.clock.getFirstSlotOfEpoch(4), [env.nodes[0]], {env, silent: false});
await waitForSlot("Waiting for 4th epoch to pass, to get first finalized checkpoint", {
env,
slot: env.clock.getFirstSlotOfEpoch(4),
nodes: [env.nodes[0]],
});

const finalizedCheckpoint = await env.nodes[0].beacon.api.beacon.getStateFinalityCheckpoints("head");
ApiError.assert(finalizedCheckpoint);
Expand Down

0 comments on commit 09b081e

Please sign in to comment.