@aztec/end-to-end 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bench/client_flows/benchmark.d.ts +3 -2
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/benchmark.js +21 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +14 -15
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +123 -136
- package/dest/bench/client_flows/data_extractor.js +3 -1
- package/dest/bench/utils.d.ts +9 -8
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +27 -18
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +96 -112
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +19 -13
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +91 -71
- package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +18 -13
- package/dest/e2e_epochs/epochs_test.d.ts +11 -9
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +18 -13
- package/dest/e2e_fees/bridging_race.notest.js +4 -6
- package/dest/e2e_fees/fees_test.d.ts +20 -16
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +126 -141
- package/dest/e2e_l1_publisher/write_json.d.ts +2 -2
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
- package/dest/e2e_l1_publisher/write_json.js +19 -15
- package/dest/e2e_multi_validator/utils.js +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +31 -39
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +4 -4
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +6 -9
- package/dest/e2e_p2p/p2p_network.d.ts +13 -11
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +120 -111
- package/dest/e2e_p2p/shared.d.ts +7 -7
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +11 -18
- package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +89 -91
- package/dest/fixtures/e2e_prover_test.d.ts +10 -18
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +90 -102
- package/dest/fixtures/fixtures.d.ts +2 -3
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +2 -3
- package/dest/fixtures/get_acvm_config.js +1 -1
- package/dest/fixtures/l1_to_l2_messaging.d.ts +4 -3
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +2 -2
- package/dest/fixtures/setup.d.ts +218 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +690 -0
- package/dest/fixtures/setup_p2p_test.js +3 -3
- package/dest/fixtures/token_utils.d.ts +1 -1
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +7 -4
- package/dest/fixtures/utils.d.ts +5 -637
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -647
- package/dest/fixtures/web3signer.js +1 -1
- package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +18 -6
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +14 -14
- package/dest/shared/gas_portal_test_harness.d.ts +12 -2
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +1 -1
- package/dest/shared/index.d.ts +2 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/submit-transactions.d.ts +3 -3
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +9 -11
- package/dest/shared/uniswap_l1_l2.d.ts +3 -27
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +55 -35
- package/dest/simulators/lending_simulator.d.ts +6 -2
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +2 -2
- package/dest/spartan/setup_test_wallets.d.ts +4 -3
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +63 -35
- package/dest/spartan/tx_metrics.d.ts +54 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +272 -0
- package/dest/spartan/utils/bot.d.ts +27 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +141 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +36 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +20 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +9 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +18 -0
- package/dest/spartan/utils/k8s.d.ts +98 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +257 -0
- package/dest/spartan/utils/nodes.d.ts +31 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +290 -0
- package/dest/spartan/utils/scripts.d.ts +16 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +66 -0
- package/dest/spartan/utils.d.ts +2 -218
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -749
- package/package.json +42 -41
- package/src/bench/client_flows/benchmark.ts +24 -2
- package/src/bench/client_flows/client_flows_benchmark.ts +145 -208
- package/src/bench/client_flows/data_extractor.ts +1 -1
- package/src/bench/utils.ts +30 -20
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +104 -142
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +140 -125
- package/src/e2e_deploy_contract/deploy_test.ts +21 -14
- package/src/e2e_epochs/epochs_test.ts +63 -45
- package/src/e2e_fees/bridging_race.notest.ts +4 -10
- package/src/e2e_fees/fees_test.ts +179 -221
- package/src/e2e_l1_publisher/write_json.ts +21 -16
- package/src/e2e_multi_validator/utils.ts +1 -1
- package/src/e2e_nested_contract/nested_contract_test.ts +33 -56
- package/src/e2e_p2p/inactivity_slash_test.ts +9 -12
- package/src/e2e_p2p/p2p_network.ts +180 -183
- package/src/e2e_p2p/shared.ts +21 -26
- package/src/e2e_token_contract/token_contract_test.ts +103 -118
- package/src/fixtures/e2e_prover_test.ts +103 -140
- package/src/fixtures/fixtures.ts +2 -5
- package/src/fixtures/get_acvm_config.ts +1 -1
- package/src/fixtures/l1_to_l2_messaging.ts +4 -2
- package/src/fixtures/setup.ts +1017 -0
- package/src/fixtures/setup_p2p_test.ts +3 -3
- package/src/fixtures/token_utils.ts +6 -5
- package/src/fixtures/utils.ts +27 -966
- package/src/fixtures/web3signer.ts +1 -1
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +19 -36
- package/src/shared/gas_portal_test_harness.ts +2 -2
- package/src/shared/index.ts +1 -1
- package/src/shared/submit-transactions.ts +9 -15
- package/src/shared/uniswap_l1_l2.ts +65 -86
- package/src/simulators/lending_simulator.ts +3 -3
- package/src/spartan/DEVELOP.md +7 -0
- package/src/spartan/setup_test_wallets.ts +81 -26
- package/src/spartan/tx_metrics.ts +250 -0
- package/src/spartan/utils/bot.ts +185 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +100 -0
- package/src/spartan/utils/config.ts +26 -0
- package/src/spartan/utils/health.ts +255 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +62 -0
- package/src/spartan/utils/k8s.ts +375 -0
- package/src/spartan/utils/nodes.ts +323 -0
- package/src/spartan/utils/scripts.ts +63 -0
- package/src/spartan/utils.ts +1 -942
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -477
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- package/dest/fixtures/snapshot_manager.d.ts +0 -95
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -505
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/src/fixtures/setup_l1_contracts.ts +0 -26
- package/src/fixtures/snapshot_manager.ts +0 -665
package/src/spartan/utils.ts
CHANGED
|
@@ -1,942 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { RollupCheatCodes } from '@aztec/aztec/testing';
|
|
3
|
-
import type { L1ContractAddresses, ViemPublicClient } from '@aztec/ethereum';
|
|
4
|
-
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
-
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
6
|
-
import { schemas } from '@aztec/foundation/schemas';
|
|
7
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
8
|
-
import {
|
|
9
|
-
type AztecNodeAdmin,
|
|
10
|
-
type AztecNodeAdminConfig,
|
|
11
|
-
createAztecNodeAdminClient,
|
|
12
|
-
createAztecNodeClient,
|
|
13
|
-
} from '@aztec/stdlib/interfaces/client';
|
|
14
|
-
|
|
15
|
-
import { ChildProcess, exec, execSync, spawn } from 'child_process';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
import { promisify } from 'util';
|
|
18
|
-
import { createPublicClient, fallback, http } from 'viem';
|
|
19
|
-
import { z } from 'zod';
|
|
20
|
-
|
|
21
|
-
const execAsync = promisify(exec);
|
|
22
|
-
|
|
23
|
-
const logger = createLogger('e2e:k8s-utils');
|
|
24
|
-
|
|
25
|
-
const testConfigSchema = z.object({
|
|
26
|
-
NAMESPACE: z.string().default('scenario'),
|
|
27
|
-
REAL_VERIFIER: schemas.Boolean.optional().default(true),
|
|
28
|
-
CREATE_ETH_DEVNET: schemas.Boolean.optional().default(false),
|
|
29
|
-
L1_RPC_URLS_JSON: z.string().optional(),
|
|
30
|
-
L1_ACCOUNT_MNEMONIC: z.string().optional(),
|
|
31
|
-
AZTEC_SLOT_DURATION: z.coerce.number().optional().default(24),
|
|
32
|
-
AZTEC_PROOF_SUBMISSION_WINDOW: z.coerce.number().optional().default(5),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export type TestConfig = z.infer<typeof testConfigSchema>;
|
|
36
|
-
|
|
37
|
-
export function setupEnvironment(env: unknown): TestConfig {
|
|
38
|
-
const config = testConfigSchema.parse(env);
|
|
39
|
-
logger.warn(`Loaded env config`, config);
|
|
40
|
-
return config;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param path - The path to the script, relative to the project root
|
|
45
|
-
* @param args - The arguments to pass to the script
|
|
46
|
-
* @param logger - The logger to use
|
|
47
|
-
* @returns The exit code of the script
|
|
48
|
-
*/
|
|
49
|
-
function runScript(path: string, args: string[], logger: Logger, env?: Record<string, string>) {
|
|
50
|
-
const childProcess = spawn(path, args, {
|
|
51
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
52
|
-
env: env ? { ...process.env, ...env } : process.env,
|
|
53
|
-
});
|
|
54
|
-
return new Promise<number>((resolve, reject) => {
|
|
55
|
-
childProcess.on('close', (code: number | null) => resolve(code ?? 0));
|
|
56
|
-
childProcess.on('error', reject);
|
|
57
|
-
childProcess.stdout?.on('data', (data: Buffer) => {
|
|
58
|
-
logger.info(data.toString());
|
|
59
|
-
});
|
|
60
|
-
childProcess.stderr?.on('data', (data: Buffer) => {
|
|
61
|
-
logger.error(data.toString());
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function getAztecBin() {
|
|
67
|
-
return path.join(getGitProjectRoot(), 'yarn-project/aztec/dest/bin/index.js');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Runs the Aztec binary
|
|
72
|
-
* @param args - The arguments to pass to the Aztec binary
|
|
73
|
-
* @param logger - The logger to use
|
|
74
|
-
* @param env - Optional environment variables to set for the process
|
|
75
|
-
* @returns The exit code of the Aztec binary
|
|
76
|
-
*/
|
|
77
|
-
export function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>) {
|
|
78
|
-
return runScript('node', [getAztecBin(), ...args], logger, env);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function runProjectScript(script: string, args: string[], logger: Logger, env?: Record<string, string>) {
|
|
82
|
-
const scriptPath = script.startsWith('/') ? script : path.join(getGitProjectRoot(), script);
|
|
83
|
-
return runScript(scriptPath, args, logger, env);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function startPortForward({
|
|
87
|
-
resource,
|
|
88
|
-
namespace,
|
|
89
|
-
containerPort,
|
|
90
|
-
hostPort,
|
|
91
|
-
}: {
|
|
92
|
-
resource: string;
|
|
93
|
-
namespace: string;
|
|
94
|
-
containerPort: number;
|
|
95
|
-
// If not provided, the port will be chosen automatically
|
|
96
|
-
hostPort?: number;
|
|
97
|
-
}): Promise<{
|
|
98
|
-
process: ChildProcess;
|
|
99
|
-
port: number;
|
|
100
|
-
}> {
|
|
101
|
-
const hostPortAsString = hostPort ? hostPort.toString() : '';
|
|
102
|
-
|
|
103
|
-
logger.debug(`kubectl port-forward -n ${namespace} ${resource} ${hostPortAsString}:${containerPort}`);
|
|
104
|
-
|
|
105
|
-
const process = spawn(
|
|
106
|
-
'kubectl',
|
|
107
|
-
['port-forward', '-n', namespace, resource, `${hostPortAsString}:${containerPort}`],
|
|
108
|
-
{
|
|
109
|
-
detached: true,
|
|
110
|
-
windowsHide: true,
|
|
111
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
112
|
-
},
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
let isResolved = false;
|
|
116
|
-
const connected = new Promise<number>(resolve => {
|
|
117
|
-
process.stdout?.on('data', data => {
|
|
118
|
-
const str = data.toString() as string;
|
|
119
|
-
if (!isResolved && str.includes('Forwarding from')) {
|
|
120
|
-
isResolved = true;
|
|
121
|
-
logger.debug(`Port forward for ${resource}: ${str}`);
|
|
122
|
-
const port = str.search(/:\d+/);
|
|
123
|
-
if (port === -1) {
|
|
124
|
-
throw new Error('Port not found in port forward output');
|
|
125
|
-
}
|
|
126
|
-
const portNumber = parseInt(str.slice(port + 1));
|
|
127
|
-
logger.verbose(`Port forwarded for ${resource} at ${portNumber}:${containerPort}`);
|
|
128
|
-
resolve(portNumber);
|
|
129
|
-
} else {
|
|
130
|
-
logger.silent(str);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
process.stderr?.on('data', data => {
|
|
134
|
-
logger.verbose(`Port forward for ${resource}: ${data.toString()}`);
|
|
135
|
-
// It's a strange thing:
|
|
136
|
-
// If we don't pipe stderr, then the port forwarding does not work.
|
|
137
|
-
// Log to silent because this doesn't actually report errors,
|
|
138
|
-
// just extremely verbose debug logs.
|
|
139
|
-
logger.silent(data.toString());
|
|
140
|
-
});
|
|
141
|
-
process.on('close', () => {
|
|
142
|
-
if (!isResolved) {
|
|
143
|
-
isResolved = true;
|
|
144
|
-
logger.warn(`Port forward for ${resource} closed before connection established`);
|
|
145
|
-
resolve(0);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
process.on('error', error => {
|
|
149
|
-
logger.error(`Port forward for ${resource} error: ${error}`);
|
|
150
|
-
resolve(0);
|
|
151
|
-
});
|
|
152
|
-
process.on('exit', code => {
|
|
153
|
-
logger.verbose(`Port forward for ${resource} exited with code ${code}`);
|
|
154
|
-
resolve(0);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
const port = await connected;
|
|
159
|
-
|
|
160
|
-
return { process, port };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function startPortForwardForRPC(namespace: string, resourceType = 'services', index = 0) {
|
|
164
|
-
return startPortForward({
|
|
165
|
-
resource: `${resourceType}/${namespace}-rpc-aztec-node-${index}`,
|
|
166
|
-
namespace,
|
|
167
|
-
containerPort: 8080,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function startPortForwardForEthereum(namespace: string) {
|
|
172
|
-
return startPortForward({
|
|
173
|
-
resource: `services/${namespace}-eth-execution`,
|
|
174
|
-
namespace,
|
|
175
|
-
containerPort: 8545,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export async function deleteResourceByName({
|
|
180
|
-
resource,
|
|
181
|
-
namespace,
|
|
182
|
-
name,
|
|
183
|
-
force = false,
|
|
184
|
-
}: {
|
|
185
|
-
resource: string;
|
|
186
|
-
namespace: string;
|
|
187
|
-
name: string;
|
|
188
|
-
force?: boolean;
|
|
189
|
-
}) {
|
|
190
|
-
const command = `kubectl delete ${resource} ${name} -n ${namespace} --ignore-not-found=true --wait=true ${
|
|
191
|
-
force ? '--force' : ''
|
|
192
|
-
}`;
|
|
193
|
-
logger.info(`command: ${command}`);
|
|
194
|
-
const { stdout } = await execAsync(command);
|
|
195
|
-
return stdout;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export async function deleteResourceByLabel({
|
|
199
|
-
resource,
|
|
200
|
-
namespace,
|
|
201
|
-
label,
|
|
202
|
-
timeout = '5m',
|
|
203
|
-
force = false,
|
|
204
|
-
}: {
|
|
205
|
-
resource: string;
|
|
206
|
-
namespace: string;
|
|
207
|
-
label: string;
|
|
208
|
-
timeout?: string;
|
|
209
|
-
force?: boolean;
|
|
210
|
-
}) {
|
|
211
|
-
// Check if the resource type exists before attempting to delete
|
|
212
|
-
try {
|
|
213
|
-
await execAsync(
|
|
214
|
-
`kubectl api-resources --api-group="" --no-headers -o name | grep -q "^${resource}$" || kubectl api-resources --no-headers -o name | grep -q "^${resource}$"`,
|
|
215
|
-
);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
logger.warn(`Resource type '${resource}' not found in cluster, skipping deletion ${error}`);
|
|
218
|
-
return '';
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const command = `kubectl delete ${resource} -l ${label} -n ${namespace} --ignore-not-found=true --wait=true --timeout=${timeout} ${
|
|
222
|
-
force ? '--force' : ''
|
|
223
|
-
}`;
|
|
224
|
-
logger.info(`command: ${command}`);
|
|
225
|
-
const { stdout } = await execAsync(command);
|
|
226
|
-
return stdout;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export async function waitForResourceByLabel({
|
|
230
|
-
resource,
|
|
231
|
-
label,
|
|
232
|
-
namespace,
|
|
233
|
-
condition = 'Ready',
|
|
234
|
-
timeout = '10m',
|
|
235
|
-
}: {
|
|
236
|
-
resource: string;
|
|
237
|
-
label: string;
|
|
238
|
-
namespace: string;
|
|
239
|
-
condition?: string;
|
|
240
|
-
timeout?: string;
|
|
241
|
-
}) {
|
|
242
|
-
const command = `kubectl wait ${resource} -l ${label} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
|
|
243
|
-
logger.info(`command: ${command}`);
|
|
244
|
-
const { stdout } = await execAsync(command);
|
|
245
|
-
return stdout;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function getChartDir(spartanDir: string, chartName: string) {
|
|
249
|
-
return path.join(spartanDir.trim(), chartName);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function shellQuote(value: string) {
|
|
253
|
-
// Single-quote safe shell escaping: ' -> '\''
|
|
254
|
-
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function valuesToArgs(values: Record<string, string | number | boolean>) {
|
|
258
|
-
return Object.entries(values)
|
|
259
|
-
.map(([key, value]) =>
|
|
260
|
-
typeof value === 'number' || typeof value === 'boolean'
|
|
261
|
-
? `--set ${key}=${value}`
|
|
262
|
-
: `--set-string ${key}=${shellQuote(String(value))}`,
|
|
263
|
-
)
|
|
264
|
-
.join(' ');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function createHelmCommand({
|
|
268
|
-
instanceName,
|
|
269
|
-
helmChartDir,
|
|
270
|
-
namespace,
|
|
271
|
-
valuesFile,
|
|
272
|
-
timeout,
|
|
273
|
-
values,
|
|
274
|
-
reuseValues = false,
|
|
275
|
-
}: {
|
|
276
|
-
instanceName: string;
|
|
277
|
-
helmChartDir: string;
|
|
278
|
-
namespace: string;
|
|
279
|
-
valuesFile: string | undefined;
|
|
280
|
-
timeout: string;
|
|
281
|
-
values: Record<string, string | number | boolean>;
|
|
282
|
-
reuseValues?: boolean;
|
|
283
|
-
}) {
|
|
284
|
-
const valuesFileArgs = valuesFile ? `--values ${helmChartDir}/values/${valuesFile}` : '';
|
|
285
|
-
const reuseValuesArgs = reuseValues ? '--reuse-values' : '';
|
|
286
|
-
return `helm upgrade --install ${instanceName} ${helmChartDir} --namespace ${namespace} ${valuesFileArgs} ${reuseValuesArgs} --wait --timeout=${timeout} ${valuesToArgs(
|
|
287
|
-
values,
|
|
288
|
-
)}`;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
async function execHelmCommand(args: Parameters<typeof createHelmCommand>[0]) {
|
|
292
|
-
const helmCommand = createHelmCommand(args);
|
|
293
|
-
logger.info(`helm command: ${helmCommand}`);
|
|
294
|
-
const { stdout } = await execAsync(helmCommand);
|
|
295
|
-
return stdout;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Installs a Helm chart with the given parameters.
|
|
300
|
-
* @param instanceName - The name of the Helm chart instance.
|
|
301
|
-
* @param targetNamespace - The namespace with the resources to be affected by the Helm chart.
|
|
302
|
-
* @param valuesFile - The values file to use for the Helm chart.
|
|
303
|
-
* @param chaosMeshNamespace - The namespace to install the Helm chart in.
|
|
304
|
-
* @param timeout - The timeout for the Helm command.
|
|
305
|
-
* @param clean - Whether to clean up the Helm chart before installing it.
|
|
306
|
-
* @returns The stdout of the Helm command.
|
|
307
|
-
* @throws If the Helm command fails.
|
|
308
|
-
*
|
|
309
|
-
* Example usage:
|
|
310
|
-
* ```typescript
|
|
311
|
-
* const stdout = await installChaosMeshChart({ instanceName: 'force-reorg', targetNamespace: 'smoke', valuesFile: 'prover-failure.yaml'});
|
|
312
|
-
* console.log(stdout);
|
|
313
|
-
* ```
|
|
314
|
-
*/
|
|
315
|
-
export async function installChaosMeshChart({
|
|
316
|
-
instanceName,
|
|
317
|
-
targetNamespace,
|
|
318
|
-
valuesFile,
|
|
319
|
-
helmChartDir,
|
|
320
|
-
chaosMeshNamespace = 'chaos-mesh',
|
|
321
|
-
timeout = '10m',
|
|
322
|
-
clean = true,
|
|
323
|
-
values = {},
|
|
324
|
-
logger,
|
|
325
|
-
}: {
|
|
326
|
-
instanceName: string;
|
|
327
|
-
targetNamespace: string;
|
|
328
|
-
valuesFile: string;
|
|
329
|
-
helmChartDir: string;
|
|
330
|
-
chaosMeshNamespace?: string;
|
|
331
|
-
timeout?: string;
|
|
332
|
-
clean?: boolean;
|
|
333
|
-
values?: Record<string, string | number>;
|
|
334
|
-
logger: Logger;
|
|
335
|
-
}) {
|
|
336
|
-
if (clean) {
|
|
337
|
-
// uninstall the helm chart if it exists
|
|
338
|
-
logger.info(`Uninstalling helm chart ${instanceName}`);
|
|
339
|
-
await execAsync(`helm uninstall ${instanceName} --namespace ${chaosMeshNamespace} --wait --ignore-not-found`);
|
|
340
|
-
// and delete the chaos-mesh resources created by this release
|
|
341
|
-
const deleteByLabel = async (resource: string) => {
|
|
342
|
-
const args = {
|
|
343
|
-
resource,
|
|
344
|
-
namespace: chaosMeshNamespace,
|
|
345
|
-
label: `app.kubernetes.io/instance=${instanceName}`,
|
|
346
|
-
} as const;
|
|
347
|
-
logger.info(`Deleting ${resource} resources for release ${instanceName}`);
|
|
348
|
-
await deleteResourceByLabel(args).catch(e => {
|
|
349
|
-
logger.error(`Error deleting ${resource}: ${e}`);
|
|
350
|
-
logger.info(`Force deleting ${resource}`);
|
|
351
|
-
return deleteResourceByLabel({ ...args, force: true });
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
await deleteByLabel('podchaos');
|
|
356
|
-
await deleteByLabel('networkchaos');
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return execHelmCommand({
|
|
360
|
-
instanceName,
|
|
361
|
-
helmChartDir,
|
|
362
|
-
namespace: chaosMeshNamespace,
|
|
363
|
-
valuesFile,
|
|
364
|
-
timeout,
|
|
365
|
-
values: { ...values, 'global.targetNamespace': targetNamespace },
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export function applyProverFailure({
|
|
370
|
-
namespace,
|
|
371
|
-
spartanDir,
|
|
372
|
-
durationSeconds,
|
|
373
|
-
logger,
|
|
374
|
-
}: {
|
|
375
|
-
namespace: string;
|
|
376
|
-
spartanDir: string;
|
|
377
|
-
durationSeconds: number;
|
|
378
|
-
logger: Logger;
|
|
379
|
-
}) {
|
|
380
|
-
return installChaosMeshChart({
|
|
381
|
-
instanceName: 'prover-failure',
|
|
382
|
-
targetNamespace: namespace,
|
|
383
|
-
valuesFile: 'prover-failure.yaml',
|
|
384
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
385
|
-
values: {
|
|
386
|
-
'proverFailure.duration': `${durationSeconds}s`,
|
|
387
|
-
},
|
|
388
|
-
logger,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
export function applyProverKill({
|
|
393
|
-
namespace,
|
|
394
|
-
spartanDir,
|
|
395
|
-
logger,
|
|
396
|
-
}: {
|
|
397
|
-
namespace: string;
|
|
398
|
-
spartanDir: string;
|
|
399
|
-
logger: Logger;
|
|
400
|
-
}) {
|
|
401
|
-
return installChaosMeshChart({
|
|
402
|
-
instanceName: 'prover-kill',
|
|
403
|
-
targetNamespace: namespace,
|
|
404
|
-
valuesFile: 'prover-kill.yaml',
|
|
405
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
406
|
-
clean: true,
|
|
407
|
-
logger,
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
export function applyProverBrokerKill({
|
|
412
|
-
namespace,
|
|
413
|
-
spartanDir,
|
|
414
|
-
logger,
|
|
415
|
-
}: {
|
|
416
|
-
namespace: string;
|
|
417
|
-
spartanDir: string;
|
|
418
|
-
logger: Logger;
|
|
419
|
-
}) {
|
|
420
|
-
return installChaosMeshChart({
|
|
421
|
-
instanceName: 'prover-broker-kill',
|
|
422
|
-
targetNamespace: namespace,
|
|
423
|
-
valuesFile: 'prover-broker-kill.yaml',
|
|
424
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
425
|
-
clean: true,
|
|
426
|
-
logger,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
export function applyBootNodeFailure({
|
|
431
|
-
namespace,
|
|
432
|
-
spartanDir,
|
|
433
|
-
durationSeconds,
|
|
434
|
-
logger,
|
|
435
|
-
}: {
|
|
436
|
-
namespace: string;
|
|
437
|
-
spartanDir: string;
|
|
438
|
-
durationSeconds: number;
|
|
439
|
-
logger: Logger;
|
|
440
|
-
}) {
|
|
441
|
-
return installChaosMeshChart({
|
|
442
|
-
instanceName: 'boot-node-failure',
|
|
443
|
-
targetNamespace: namespace,
|
|
444
|
-
valuesFile: 'boot-node-failure.yaml',
|
|
445
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
446
|
-
values: {
|
|
447
|
-
'bootNodeFailure.duration': `${durationSeconds}s`,
|
|
448
|
-
},
|
|
449
|
-
logger,
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
export function applyValidatorKill({
|
|
454
|
-
namespace,
|
|
455
|
-
spartanDir,
|
|
456
|
-
logger,
|
|
457
|
-
values,
|
|
458
|
-
}: {
|
|
459
|
-
namespace: string;
|
|
460
|
-
spartanDir: string;
|
|
461
|
-
logger: Logger;
|
|
462
|
-
values?: Record<string, string | number>;
|
|
463
|
-
}) {
|
|
464
|
-
return installChaosMeshChart({
|
|
465
|
-
instanceName: 'validator-kill',
|
|
466
|
-
targetNamespace: namespace,
|
|
467
|
-
valuesFile: 'validator-kill.yaml',
|
|
468
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
469
|
-
logger,
|
|
470
|
-
values,
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
export function applyNetworkShaping({
|
|
475
|
-
valuesFile,
|
|
476
|
-
namespace,
|
|
477
|
-
spartanDir,
|
|
478
|
-
logger,
|
|
479
|
-
}: {
|
|
480
|
-
valuesFile: string;
|
|
481
|
-
namespace: string;
|
|
482
|
-
spartanDir: string;
|
|
483
|
-
logger: Logger;
|
|
484
|
-
}) {
|
|
485
|
-
return installChaosMeshChart({
|
|
486
|
-
instanceName: 'network-shaping',
|
|
487
|
-
targetNamespace: namespace,
|
|
488
|
-
valuesFile,
|
|
489
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
|
|
490
|
-
logger,
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export async function awaitL2BlockNumber(
|
|
495
|
-
rollupCheatCodes: RollupCheatCodes,
|
|
496
|
-
blockNumber: bigint,
|
|
497
|
-
timeoutSeconds: number,
|
|
498
|
-
logger: Logger,
|
|
499
|
-
) {
|
|
500
|
-
logger.info(`Waiting for L2 Block ${blockNumber}`);
|
|
501
|
-
let tips = await rollupCheatCodes.getTips();
|
|
502
|
-
const endTime = Date.now() + timeoutSeconds * 1000;
|
|
503
|
-
while (tips.pending < blockNumber && Date.now() < endTime) {
|
|
504
|
-
logger.info(`At L2 Block ${tips.pending}`);
|
|
505
|
-
await sleep(1000);
|
|
506
|
-
tips = await rollupCheatCodes.getTips();
|
|
507
|
-
}
|
|
508
|
-
if (tips.pending < blockNumber) {
|
|
509
|
-
throw new Error(`Timeout waiting for L2 Block ${blockNumber}, only reached ${tips.pending}`);
|
|
510
|
-
} else {
|
|
511
|
-
logger.info(`Reached L2 Block ${tips.pending}`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export async function restartBot(namespace: string, logger: Logger) {
|
|
516
|
-
logger.info(`Restarting bot`);
|
|
517
|
-
await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' });
|
|
518
|
-
await sleep(10 * 1000);
|
|
519
|
-
// Some bot images may take time to report Ready due to heavy boot-time proving.
|
|
520
|
-
// Waiting for PodReadyToStartContainers ensures the pod is scheduled and starting without blocking on full readiness.
|
|
521
|
-
await waitForResourceByLabel({
|
|
522
|
-
resource: 'pods',
|
|
523
|
-
namespace,
|
|
524
|
-
label: 'app.kubernetes.io/name=bot',
|
|
525
|
-
condition: 'PodReadyToStartContainers',
|
|
526
|
-
});
|
|
527
|
-
logger.info(`Bot restarted`);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Installs or upgrades the transfer bot Helm release for the given namespace.
|
|
532
|
-
* Intended for test setup to enable L2 traffic generation only when needed.
|
|
533
|
-
*/
|
|
534
|
-
export async function installTransferBot({
|
|
535
|
-
namespace,
|
|
536
|
-
spartanDir,
|
|
537
|
-
logger,
|
|
538
|
-
replicas = 1,
|
|
539
|
-
txIntervalSeconds = 10,
|
|
540
|
-
followChain = 'PENDING',
|
|
541
|
-
mnemonic = process.env.LABS_INFRA_MNEMONIC ?? 'test test test test test test test test test test test junk',
|
|
542
|
-
mnemonicStartIndex,
|
|
543
|
-
botPrivateKey = process.env.BOT_TRANSFERS_L2_PRIVATE_KEY ?? '0xcafe01',
|
|
544
|
-
nodeUrl,
|
|
545
|
-
timeout = '15m',
|
|
546
|
-
reuseValues = true,
|
|
547
|
-
aztecSlotDuration = Number(process.env.AZTEC_SLOT_DURATION ?? 12),
|
|
548
|
-
}: {
|
|
549
|
-
namespace: string;
|
|
550
|
-
spartanDir: string;
|
|
551
|
-
logger: Logger;
|
|
552
|
-
replicas?: number;
|
|
553
|
-
txIntervalSeconds?: number;
|
|
554
|
-
followChain?: string;
|
|
555
|
-
mnemonic?: string;
|
|
556
|
-
mnemonicStartIndex?: number | string;
|
|
557
|
-
botPrivateKey?: string;
|
|
558
|
-
nodeUrl?: string;
|
|
559
|
-
timeout?: string;
|
|
560
|
-
reuseValues?: boolean;
|
|
561
|
-
aztecSlotDuration?: number;
|
|
562
|
-
}) {
|
|
563
|
-
const instanceName = `${namespace}-bot-transfers`;
|
|
564
|
-
const helmChartDir = getChartDir(spartanDir, 'aztec-bot');
|
|
565
|
-
const resolvedNodeUrl = nodeUrl ?? `http://${namespace}-rpc-aztec-node.${namespace}.svc.cluster.local:8080`;
|
|
566
|
-
|
|
567
|
-
logger.info(`Installing/upgrading transfer bot: replicas=${replicas}, followChain=${followChain}`);
|
|
568
|
-
|
|
569
|
-
const values: Record<string, string | number | boolean> = {
|
|
570
|
-
'bot.replicaCount': replicas,
|
|
571
|
-
'bot.txIntervalSeconds': txIntervalSeconds,
|
|
572
|
-
'bot.followChain': followChain,
|
|
573
|
-
'bot.botPrivateKey': botPrivateKey,
|
|
574
|
-
'bot.nodeUrl': resolvedNodeUrl,
|
|
575
|
-
'bot.mnemonic': mnemonic,
|
|
576
|
-
'bot.feePaymentMethod': 'fee_juice',
|
|
577
|
-
'aztec.slotDuration': aztecSlotDuration,
|
|
578
|
-
// Ensure bot can reach its own PXE started in-process (default rpc.port is 8080)
|
|
579
|
-
// Note: since aztec-bot depends on aztec-node with alias `bot`, env vars go under `bot.node.env`.
|
|
580
|
-
'bot.node.env.BOT_PXE_URL': 'http://127.0.0.1:8080',
|
|
581
|
-
// Provide L1 execution RPC for bridging fee juice
|
|
582
|
-
'bot.node.env.ETHEREUM_HOSTS': `http://${namespace}-eth-execution.${namespace}.svc.cluster.local:8545`,
|
|
583
|
-
// Provide L1 mnemonic for bridging (falls back to labs mnemonic)
|
|
584
|
-
'bot.node.env.BOT_L1_MNEMONIC': mnemonic,
|
|
585
|
-
};
|
|
586
|
-
// Ensure we derive a funded L1 key (index 0 is funded on anvil default mnemonic)
|
|
587
|
-
if (mnemonicStartIndex === undefined) {
|
|
588
|
-
values['bot.mnemonicStartIndex'] = 0;
|
|
589
|
-
}
|
|
590
|
-
// Also pass a funded private key directly if available
|
|
591
|
-
if (process.env.FUNDING_PRIVATE_KEY) {
|
|
592
|
-
values['bot.node.env.BOT_L1_PRIVATE_KEY'] = process.env.FUNDING_PRIVATE_KEY;
|
|
593
|
-
}
|
|
594
|
-
// Align bot image with the running network image: prefer env var, else detect from a validator pod
|
|
595
|
-
let repositoryFromEnv: string | undefined;
|
|
596
|
-
let tagFromEnv: string | undefined;
|
|
597
|
-
const aztecDockerImage = process.env.AZTEC_DOCKER_IMAGE;
|
|
598
|
-
if (aztecDockerImage && aztecDockerImage.includes(':')) {
|
|
599
|
-
const lastColon = aztecDockerImage.lastIndexOf(':');
|
|
600
|
-
repositoryFromEnv = aztecDockerImage.slice(0, lastColon);
|
|
601
|
-
tagFromEnv = aztecDockerImage.slice(lastColon + 1);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
let repository = repositoryFromEnv;
|
|
605
|
-
let tag = tagFromEnv;
|
|
606
|
-
if (!repository || !tag) {
|
|
607
|
-
try {
|
|
608
|
-
const { stdout } = await execAsync(
|
|
609
|
-
`kubectl get pods -l app.kubernetes.io/component=validator -n ${namespace} -o jsonpath='{.items[0].spec.containers[?(@.name=="aztec")].image}' | cat`,
|
|
610
|
-
);
|
|
611
|
-
const image = stdout.trim().replace(/^'|'$/g, '');
|
|
612
|
-
if (image && image.includes(':')) {
|
|
613
|
-
const lastColon = image.lastIndexOf(':');
|
|
614
|
-
repository = image.slice(0, lastColon);
|
|
615
|
-
tag = image.slice(lastColon + 1);
|
|
616
|
-
}
|
|
617
|
-
} catch (err) {
|
|
618
|
-
logger.warn(`Could not detect aztec image from validator pod: ${String(err)}`);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
if (repository && tag) {
|
|
622
|
-
values['global.aztecImage.repository'] = repository;
|
|
623
|
-
values['global.aztecImage.tag'] = tag;
|
|
624
|
-
}
|
|
625
|
-
if (mnemonicStartIndex !== undefined) {
|
|
626
|
-
values['bot.mnemonicStartIndex'] =
|
|
627
|
-
typeof mnemonicStartIndex === 'string' ? mnemonicStartIndex : Number(mnemonicStartIndex);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
await execHelmCommand({
|
|
631
|
-
instanceName,
|
|
632
|
-
helmChartDir,
|
|
633
|
-
namespace,
|
|
634
|
-
valuesFile: undefined,
|
|
635
|
-
timeout,
|
|
636
|
-
values: values as unknown as Record<string, string | number | boolean>,
|
|
637
|
-
reuseValues,
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
if (replicas > 0) {
|
|
641
|
-
await waitForResourceByLabel({
|
|
642
|
-
resource: 'pods',
|
|
643
|
-
namespace,
|
|
644
|
-
label: 'app.kubernetes.io/name=bot',
|
|
645
|
-
condition: 'PodReadyToStartContainers',
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Uninstalls the transfer bot Helm release from the given namespace.
|
|
652
|
-
* Intended for test teardown to clean up bot resources.
|
|
653
|
-
*/
|
|
654
|
-
export async function uninstallTransferBot(namespace: string, logger: Logger) {
|
|
655
|
-
const instanceName = `${namespace}-bot-transfers`;
|
|
656
|
-
logger.info(`Uninstalling transfer bot release ${instanceName}`);
|
|
657
|
-
await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`);
|
|
658
|
-
// Ensure any leftover pods are removed
|
|
659
|
-
await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' }).catch(
|
|
660
|
-
() => undefined,
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* Enables or disables probabilistic transaction dropping on validators and waits for rollout.
|
|
666
|
-
* Wired to env vars P2P_DROP_TX and P2P_DROP_TX_CHANCE via Helm values.
|
|
667
|
-
*/
|
|
668
|
-
export async function setValidatorTxDrop({
|
|
669
|
-
namespace,
|
|
670
|
-
enabled,
|
|
671
|
-
probability,
|
|
672
|
-
logger,
|
|
673
|
-
}: {
|
|
674
|
-
namespace: string;
|
|
675
|
-
enabled: boolean;
|
|
676
|
-
probability: number;
|
|
677
|
-
logger: Logger;
|
|
678
|
-
}) {
|
|
679
|
-
const drop = enabled ? 'true' : 'false';
|
|
680
|
-
const prob = String(probability);
|
|
681
|
-
|
|
682
|
-
const selectors = ['app=validator', 'app.kubernetes.io/component=validator'];
|
|
683
|
-
let updated = false;
|
|
684
|
-
for (const selector of selectors) {
|
|
685
|
-
try {
|
|
686
|
-
const list = await execAsync(`kubectl get statefulset -l ${selector} -n ${namespace} --no-headers -o name | cat`);
|
|
687
|
-
const names = list.stdout
|
|
688
|
-
.split('\n')
|
|
689
|
-
.map(s => s.trim())
|
|
690
|
-
.filter(Boolean);
|
|
691
|
-
if (names.length === 0) {
|
|
692
|
-
continue;
|
|
693
|
-
}
|
|
694
|
-
const cmd = `kubectl set env statefulset -l ${selector} -n ${namespace} P2P_DROP_TX=${drop} P2P_DROP_TX_CHANCE=${prob}`;
|
|
695
|
-
logger.info(`command: ${cmd}`);
|
|
696
|
-
await execAsync(cmd);
|
|
697
|
-
updated = true;
|
|
698
|
-
} catch (e) {
|
|
699
|
-
logger.warn(`Failed to update validators with selector ${selector}: ${String(e)}`);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
if (!updated) {
|
|
704
|
-
logger.warn(`No validator StatefulSets found in ${namespace}. Skipping tx drop toggle.`);
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// Restart validator pods to ensure env vars take effect and wait for readiness
|
|
709
|
-
await restartValidators(namespace, logger);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
export async function restartValidators(namespace: string, logger: Logger) {
|
|
713
|
-
const selectors = ['app=validator', 'app.kubernetes.io/component=validator'];
|
|
714
|
-
let any = false;
|
|
715
|
-
for (const selector of selectors) {
|
|
716
|
-
try {
|
|
717
|
-
const { stdout } = await execAsync(`kubectl get pods -l ${selector} -n ${namespace} --no-headers -o name | cat`);
|
|
718
|
-
if (!stdout || stdout.trim().length === 0) {
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
any = true;
|
|
722
|
-
await deleteResourceByLabel({ resource: 'pods', namespace, label: selector });
|
|
723
|
-
} catch (e) {
|
|
724
|
-
logger.warn(`Error restarting validator pods with selector ${selector}: ${String(e)}`);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
if (!any) {
|
|
729
|
-
logger.warn(`No validator pods found to restart in ${namespace}.`);
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
// Wait for either label to be Ready
|
|
734
|
-
for (const selector of selectors) {
|
|
735
|
-
try {
|
|
736
|
-
await waitForResourceByLabel({ resource: 'pods', namespace, label: selector });
|
|
737
|
-
return;
|
|
738
|
-
} catch {
|
|
739
|
-
// try next
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
logger.warn(`Validator pods did not report Ready; continuing.`);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
export async function enableValidatorDynamicBootNode(
|
|
746
|
-
instanceName: string,
|
|
747
|
-
namespace: string,
|
|
748
|
-
spartanDir: string,
|
|
749
|
-
logger: Logger,
|
|
750
|
-
) {
|
|
751
|
-
logger.info(`Enabling validator dynamic boot node`);
|
|
752
|
-
await execHelmCommand({
|
|
753
|
-
instanceName,
|
|
754
|
-
namespace,
|
|
755
|
-
helmChartDir: getChartDir(spartanDir, 'aztec-network'),
|
|
756
|
-
values: {
|
|
757
|
-
'validator.dynamicBootNode': 'true',
|
|
758
|
-
},
|
|
759
|
-
valuesFile: undefined,
|
|
760
|
-
timeout: '15m',
|
|
761
|
-
reuseValues: true,
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
logger.info(`Validator dynamic boot node enabled`);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
export async function getSequencers(namespace: string) {
|
|
768
|
-
const command = `kubectl get pods -l app.kubernetes.io/component=validator -n ${namespace} -o jsonpath='{.items[*].metadata.name}'`;
|
|
769
|
-
const { stdout } = await execAsync(command);
|
|
770
|
-
const sequencers = stdout.split(' ');
|
|
771
|
-
logger.verbose(`Found sequencer pods ${sequencers.join(', ')}`);
|
|
772
|
-
return sequencers;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
export function updateSequencersConfig(env: TestConfig, config: Partial<AztecNodeAdminConfig>) {
|
|
776
|
-
return withSequencersAdmin(env, async client => {
|
|
777
|
-
await client.setConfig(config);
|
|
778
|
-
return client.getConfig();
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
export function getSequencersConfig(env: TestConfig) {
|
|
783
|
-
return withSequencersAdmin(env, client => client.getConfig());
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
export async function withSequencersAdmin<T>(env: TestConfig, fn: (node: AztecNodeAdmin) => Promise<T>): Promise<T[]> {
|
|
787
|
-
const adminContainerPort = 8880;
|
|
788
|
-
const namespace = env.NAMESPACE;
|
|
789
|
-
const sequencers = await getSequencers(namespace);
|
|
790
|
-
const results = [];
|
|
791
|
-
|
|
792
|
-
for (const sequencer of sequencers) {
|
|
793
|
-
const { process, port } = await startPortForward({
|
|
794
|
-
resource: `pod/${sequencer}`,
|
|
795
|
-
namespace,
|
|
796
|
-
containerPort: adminContainerPort,
|
|
797
|
-
});
|
|
798
|
-
|
|
799
|
-
const url = `http://localhost:${port}`;
|
|
800
|
-
await retry(
|
|
801
|
-
() => fetch(`${url}/status`).then(res => res.status === 200),
|
|
802
|
-
'forward node admin port',
|
|
803
|
-
makeBackoff([1, 1, 2, 6]),
|
|
804
|
-
logger,
|
|
805
|
-
true,
|
|
806
|
-
);
|
|
807
|
-
const client = createAztecNodeAdminClient(url);
|
|
808
|
-
results.push(await fn(client));
|
|
809
|
-
process.kill();
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
return results;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Returns a public viem client to the eth execution node. If it was part of a local eth devnet,
|
|
817
|
-
* it first port-forwards the service and points to it. Otherwise, just uses the external RPC url.
|
|
818
|
-
*/
|
|
819
|
-
export async function getPublicViemClient(
|
|
820
|
-
env: TestConfig,
|
|
821
|
-
/** If set, will push the new process into it */
|
|
822
|
-
processes?: ChildProcess[],
|
|
823
|
-
): Promise<{ url: string; client: ViemPublicClient; process?: ChildProcess }> {
|
|
824
|
-
const { NAMESPACE, CREATE_ETH_DEVNET, L1_RPC_URLS_JSON } = env;
|
|
825
|
-
if (CREATE_ETH_DEVNET) {
|
|
826
|
-
logger.info(`Creating port forward to eth execution node`);
|
|
827
|
-
const { process, port } = await startPortForward({
|
|
828
|
-
resource: `svc/${NAMESPACE}-eth-execution`,
|
|
829
|
-
namespace: NAMESPACE,
|
|
830
|
-
containerPort: 8545,
|
|
831
|
-
});
|
|
832
|
-
const url = `http://127.0.0.1:${port}`;
|
|
833
|
-
const client: ViemPublicClient = createPublicClient({ transport: fallback([http(url)]) });
|
|
834
|
-
if (processes) {
|
|
835
|
-
processes.push(process);
|
|
836
|
-
}
|
|
837
|
-
return { url, client, process };
|
|
838
|
-
} else {
|
|
839
|
-
logger.info(`Connecting to the eth execution node at ${L1_RPC_URLS_JSON}`);
|
|
840
|
-
if (!L1_RPC_URLS_JSON) {
|
|
841
|
-
throw new Error(`L1_RPC_URLS_JSON is not defined`);
|
|
842
|
-
}
|
|
843
|
-
const client: ViemPublicClient = createPublicClient({ transport: fallback([http(L1_RPC_URLS_JSON)]) });
|
|
844
|
-
return { url: L1_RPC_URLS_JSON, client };
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
/** Queries an Aztec node for the L1 deployment addresses */
|
|
849
|
-
export async function getL1DeploymentAddresses(env: TestConfig): Promise<L1ContractAddresses> {
|
|
850
|
-
let forwardProcess: ChildProcess | undefined;
|
|
851
|
-
try {
|
|
852
|
-
const [sequencer] = await getSequencers(env.NAMESPACE);
|
|
853
|
-
const { process, port } = await startPortForward({
|
|
854
|
-
resource: `pod/${sequencer}`,
|
|
855
|
-
namespace: env.NAMESPACE,
|
|
856
|
-
containerPort: 8080,
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
forwardProcess = process;
|
|
860
|
-
const url = `http://127.0.0.1:${port}`;
|
|
861
|
-
const node = createAztecNodeClient(url);
|
|
862
|
-
return await retry(
|
|
863
|
-
() => node.getNodeInfo().then(i => i.l1ContractAddresses),
|
|
864
|
-
'get node info',
|
|
865
|
-
makeBackoff([1, 3, 6]),
|
|
866
|
-
logger,
|
|
867
|
-
);
|
|
868
|
-
} finally {
|
|
869
|
-
forwardProcess?.kill();
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
/**
|
|
874
|
-
* Rolls the Aztec pods in the given namespace.
|
|
875
|
-
* @param namespace - The namespace to roll the Aztec pods in.
|
|
876
|
-
* @dev - IMPORTANT: This function DOES NOT delete the underlying PVCs.
|
|
877
|
-
* This means that the pods will be restarted with the same persistent storage.
|
|
878
|
-
* This is useful for testing, but you should be aware of the implications.
|
|
879
|
-
*/
|
|
880
|
-
export async function rollAztecPods(namespace: string) {
|
|
881
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=boot-node' });
|
|
882
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-node' });
|
|
883
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-broker' });
|
|
884
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-agent' });
|
|
885
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=validator' });
|
|
886
|
-
await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=pxe' });
|
|
887
|
-
await sleep(10 * 1000);
|
|
888
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=boot-node' });
|
|
889
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-node' });
|
|
890
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-broker' });
|
|
891
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-agent' });
|
|
892
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=validator' });
|
|
893
|
-
await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=pxe' });
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Returns the absolute path to the git repository root
|
|
898
|
-
*/
|
|
899
|
-
export function getGitProjectRoot(): string {
|
|
900
|
-
try {
|
|
901
|
-
const rootDir = execSync('git rev-parse --show-toplevel', {
|
|
902
|
-
encoding: 'utf-8',
|
|
903
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
904
|
-
}).trim();
|
|
905
|
-
|
|
906
|
-
return rootDir;
|
|
907
|
-
} catch (error) {
|
|
908
|
-
throw new Error(`Failed to determine git project root: ${error}`);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
/** Returns a client to the RPC of the given sequencer (defaults to first) */
|
|
913
|
-
export async function getNodeClient(
|
|
914
|
-
env: TestConfig,
|
|
915
|
-
index: number = 0,
|
|
916
|
-
): Promise<{ node: ReturnType<typeof createAztecNodeClient>; port: number; process: ChildProcess }> {
|
|
917
|
-
const namespace = env.NAMESPACE;
|
|
918
|
-
const containerPort = 8080;
|
|
919
|
-
const sequencers = await getSequencers(namespace);
|
|
920
|
-
const sequencer = sequencers[index];
|
|
921
|
-
if (!sequencer) {
|
|
922
|
-
throw new Error(`No sequencer found at index ${index} in namespace ${namespace}`);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
const { process, port } = await startPortForward({
|
|
926
|
-
resource: `pod/${sequencer}`,
|
|
927
|
-
namespace,
|
|
928
|
-
containerPort,
|
|
929
|
-
});
|
|
930
|
-
|
|
931
|
-
const url = `http://localhost:${port}`;
|
|
932
|
-
await retry(
|
|
933
|
-
() => fetch(`${url}/status`).then(res => res.status === 200),
|
|
934
|
-
'forward port',
|
|
935
|
-
makeBackoff([1, 1, 2, 6]),
|
|
936
|
-
logger,
|
|
937
|
-
true,
|
|
938
|
-
);
|
|
939
|
-
|
|
940
|
-
const client = createAztecNodeClient(url);
|
|
941
|
-
return { node: client, port, process };
|
|
942
|
-
}
|
|
1
|
+
export * from './utils/index.js';
|