Skip to content

Commit

Permalink
Compute effective genesis delay
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Feb 5, 2024
1 parent 06c697b commit 038e3e2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/test/sim/backup_eth_provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({
ALTAIR_FORK_EPOCH: altairForkEpoch,
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
runTillEpoch: runTillEpoch + syncWaitEpoch,
initialNodes: 3,
});

const env = await SimulationEnvironment.initWithDefaults(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/sim/deneb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({
ALTAIR_FORK_EPOCH: altairForkEpoch,
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
runTillEpoch: runTillEpoch + syncWaitEpoch,
initialNodes: 2,
});

const env = await SimulationEnvironment.initWithDefaults(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/sim/endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({
ALTAIR_FORK_EPOCH: altairForkEpoch,
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
runTillEpoch: 2,
initialNodes: 1,
});

const env = await SimulationEnvironment.initWithDefaults(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/sim/mixed_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
CAPELLA_FORK_EPOCH: capellaForkEpoch,
runTillEpoch: runTillEpoch + syncWaitEpoch,
initialNodes: 2,
});

const env = await SimulationEnvironment.initWithDefaults(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/sim/multi_fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
CAPELLA_FORK_EPOCH: capellaForkEpoch,
runTillEpoch: runTillEpoch + syncWaitEpoch,
initialNodes: 5,
});

const env = await SimulationEnvironment.initWithDefaults(
Expand Down
22 changes: 20 additions & 2 deletions packages/cli/test/utils/simulation/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,36 @@ export const avg = (arr: number[]): number => {
return arr.length === 0 ? 0 : arr.reduce((p, c) => p + c, 0) / arr.length;
};

function getGenesisDelaySlots(initialNodes?: number): number {
if (process.env.GENESIS_DELAY_SLOTS) {
const genesisDelaySlots = parseInt(process.env.GENESIS_DELAY_SLOTS);
// If custom job is invoked and want to use default genesis delay then provider -1 as value
if (genesisDelaySlots >= 0) return genesisDelaySlots;
}

if (initialNodes == null) return 40;
// Considering each node consists of EN, BN, VC and KM
// EN - Execution Node - 5s
// BN - Beacon Node - 10s
// VC - Validator Client - 5s
// KM - Key Manager - 3s
// Initial script launch time - 10s
return Math.ceil(((5 + 10 + 5 + 3) * initialNodes + 10) / SIM_TESTS_SECONDS_PER_SLOT);
}

export function defineSimTestConfig(
opts: Partial<ChainConfig> & {
cliqueSealingPeriod?: number;
additionalSlotsForTTD?: number;
runTillEpoch: number;
// Used to calculate genesis delay
initialNodes?: number;
}
): {
estimatedTimeoutMs: number;
forkConfig: ChainForkConfig;
} {
const genesisDelaySeconds =
(process.env.GENESIS_DELAY_SLOTS ? parseInt(process.env.GENESIS_DELAY_SLOTS) : 40) * SIM_TESTS_SECONDS_PER_SLOT;
const genesisDelaySeconds = getGenesisDelaySlots(opts.initialNodes) * SIM_TESTS_SECONDS_PER_SLOT;

const estimatedTimeoutMs =
getEstimatedTimeInSecForRun({
Expand Down

0 comments on commit 038e3e2

Please sign in to comment.