Skip to content

Commit

Permalink
test: add debug messages to waitForSlot helper (#6639)
Browse files Browse the repository at this point in the history
* Move syncing logic to helper functions

* Add debug messages to waitForSlot helper
  • Loading branch information
nazarhussain authored Apr 5, 2024
1 parent 91801fa commit ee1169a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 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
4 changes: 2 additions & 2 deletions packages/cli/test/sim/deneb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ await connectAllNodes(env.nodes);

// The `TTD` will be reach around `start of bellatrixForkEpoch + additionalSlotsForMerge` slot
// We wait for the end of that epoch with half more epoch to make sure merge transition is complete
await waitForSlot(env.clock.getLastSlotOfEpoch(bellatrixForkEpoch) + activePreset.SLOTS_PER_EPOCH / 2, env.nodes, {
silent: true,
await waitForSlot("Waiting for the 2nd epoch to pass", {
slot: env.clock.getLastSlotOfEpoch(bellatrixForkEpoch) + activePreset.SLOTS_PER_EPOCH / 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 @@ -120,16 +120,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
4 changes: 3 additions & 1 deletion packages/cli/test/utils/simulation/utils/syncing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export async function assertRangeSync(env: SimulationEnvironment): Promise<void>
export async function assertCheckpointSync(env: SimulationEnvironment): Promise<void> {
if (env.clock.currentEpoch <= 4) {
// First checkpoint finalized is at least 4 epochs
await waitForSlot(env.clock.getFirstSlotOfEpoch(4), [env.nodes[0]], {
await waitForSlot("Waiting for 4th epoch to pass, to get first finalized checkpoint", {
env,
slot: env.clock.getFirstSlotOfEpoch(4),
nodes: [env.nodes[0]],
});
}

Expand Down

0 comments on commit ee1169a

Please sign in to comment.