datahaven/test/launcher/parameters.ts
Ahmad Kaouk 9344e243cf
perf: Batch runtime parameter updates to speed up E2E setup (#368)
## Summary
Optimizes the DataHaven parameter configuration during E2E test
infrastructure setup by batching multiple extrinsics into a single
transaction, reducing setup time.
## Problem
Setting runtime parameters required 5 separate
`Parameters.set_parameter` calls, each waiting for block finality. This
created unnecessary delays during infrastructure setup since each call
blocked sequentially.
## Solution
- **Batch parameter updates:** Combine all `Parameters.set_parameter
`calls into a single `Utility.batch_all` transaction wrapped in
`Sudo.sudo`.
- **~5× faster parameter setup:** Only wait for finality once instead of
5 separate times
- **Code simplification:** Refactored parameter handling code, removing
~190 lines of unnecessary abstractions and complexity
2025-12-22 15:57:32 +01:00

55 lines
2 KiB
TypeScript

import { setDataHavenParameters as setDataHavenParametersScript } from "scripts/set-datahaven-parameters";
import { logger } from "utils";
import type { ParameterCollection } from "utils/parameters";
import type { LaunchedNetwork } from "./types/launchedNetwork";
/**
* Configuration options for setting DataHaven runtime parameters.
*/
export interface ParametersOptions {
launchedNetwork: LaunchedNetwork;
collection: ParameterCollection;
}
/**
* Sets DataHaven runtime parameters from a parameter collection.
*
* This function updates various runtime parameters on the DataHaven chain:
* - Bridge configuration parameters
* - Network timing parameters
* - Validator configuration
* - Fee structures
* - Other protocol-specific settings
*
* The parameters are collected throughout the deployment process and
* applied in a single transaction to minimize gas costs and ensure
* consistency.
*
* @param options - Configuration options for setting parameters
* @param options.launchedNetwork - The launched network instance containing connection details
* @param options.collection - The parameter collection containing all parameters to set
*
* @throws {Error} If the parameter file generation fails
* @throws {Error} If the RPC connection cannot be established
* @throws {Error} If the parameter update transaction fails
*/
export const setDataHavenParameters = async (options: ParametersOptions): Promise<void> => {
logger.info("⚙️ Setting DataHaven runtime parameters...");
const { launchedNetwork, collection } = options;
// Generate the parameters file from the collection
const parametersFilePath = await collection.generateParametersFile();
// Get the WebSocket RPC URL from the launched network
const rpcUrl = `ws://127.0.0.1:${launchedNetwork.getPublicWsPort()}`;
// Execute the parameter update
const success = await setDataHavenParametersScript(rpcUrl, parametersFilePath);
if (!success) {
throw new Error("Failed to set DataHaven parameters");
}
logger.success("DataHaven parameters set successfully");
};