@aztec/end-to-end 4.0.0-nightly.20260120 → 4.0.0-nightly.20260122
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/shared/cross_chain_test_harness.d.ts +3 -4
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/submit-transactions.d.ts +1 -1
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +1 -4
- package/dest/spartan/tx_metrics.d.ts +11 -1
- package/dest/spartan/tx_metrics.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.js +133 -4
- 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 +25 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +101 -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 +59 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +185 -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 +273 -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 -260
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -942
- package/package.json +39 -39
- package/src/shared/cross_chain_test_harness.ts +2 -3
- package/src/shared/submit-transactions.ts +1 -6
- package/src/spartan/tx_metrics.ts +82 -4
- package/src/spartan/utils/bot.ts +185 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +106 -0
- package/src/spartan/utils/config.ts +26 -0
- package/src/spartan/utils/health.ts +256 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +58 -0
- package/src/spartan/utils/k8s.ts +279 -0
- package/src/spartan/utils/nodes.ts +308 -0
- package/src/spartan/utils/scripts.ts +63 -0
- package/src/spartan/utils.ts +1 -1246
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import type { RollupCheatCodes } from '@aztec/aztec/testing';
|
|
3
|
+
import type { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
+
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
6
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
7
|
+
import {
|
|
8
|
+
type AztecNodeAdmin,
|
|
9
|
+
type AztecNodeAdminConfig,
|
|
10
|
+
createAztecNodeAdminClient,
|
|
11
|
+
} from '@aztec/stdlib/interfaces/client';
|
|
12
|
+
|
|
13
|
+
import { exec } from 'child_process';
|
|
14
|
+
import { promisify } from 'util';
|
|
15
|
+
|
|
16
|
+
import type { TestConfig } from './config.js';
|
|
17
|
+
import { execHelmCommand } from './helm.js';
|
|
18
|
+
import { deleteResourceByLabel, getChartDir, startPortForward, waitForResourceByLabel } from './k8s.js';
|
|
19
|
+
|
|
20
|
+
const execAsync = promisify(exec);
|
|
21
|
+
|
|
22
|
+
const logger = createLogger('e2e:k8s-utils');
|
|
23
|
+
|
|
24
|
+
export async function awaitCheckpointNumber(
|
|
25
|
+
rollupCheatCodes: RollupCheatCodes,
|
|
26
|
+
checkpointNumber: CheckpointNumber,
|
|
27
|
+
timeoutSeconds: number,
|
|
28
|
+
log: Logger,
|
|
29
|
+
) {
|
|
30
|
+
log.info(`Waiting for checkpoint ${checkpointNumber}`);
|
|
31
|
+
let tips = await rollupCheatCodes.getTips();
|
|
32
|
+
const endTime = Date.now() + timeoutSeconds * 1000;
|
|
33
|
+
while (tips.pending < checkpointNumber && Date.now() < endTime) {
|
|
34
|
+
log.info(`At checkpoint ${tips.pending}`);
|
|
35
|
+
await sleep(1000);
|
|
36
|
+
tips = await rollupCheatCodes.getTips();
|
|
37
|
+
}
|
|
38
|
+
if (tips.pending < checkpointNumber) {
|
|
39
|
+
throw new Error(`Timeout waiting for checkpoint ${checkpointNumber}, only reached ${tips.pending}`);
|
|
40
|
+
} else {
|
|
41
|
+
log.info(`Reached checkpoint ${tips.pending}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function getSequencers(namespace: string) {
|
|
46
|
+
const selectors = [
|
|
47
|
+
'app.kubernetes.io/name=validator',
|
|
48
|
+
'app.kubernetes.io/component=validator',
|
|
49
|
+
'app.kubernetes.io/component=sequencer-node',
|
|
50
|
+
'app=validator',
|
|
51
|
+
];
|
|
52
|
+
for (const selector of selectors) {
|
|
53
|
+
try {
|
|
54
|
+
const command = `kubectl get pods -l ${selector} -n ${namespace} -o jsonpath='{.items[*].metadata.name}'`;
|
|
55
|
+
const { stdout } = await execAsync(command);
|
|
56
|
+
const sequencers = stdout
|
|
57
|
+
.split(' ')
|
|
58
|
+
.map(s => s.trim())
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
if (sequencers.length > 0) {
|
|
61
|
+
logger.verbose(`Found sequencer pods ${sequencers.join(', ')} (selector=${selector})`);
|
|
62
|
+
return sequencers;
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// try next selector
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Fail fast instead of returning [''] which leads to attempts to port-forward `pod/`.
|
|
70
|
+
throw new Error(
|
|
71
|
+
`No sequencer/validator pods found in namespace ${namespace}. Tried selectors: ${selectors.join(', ')}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function updateSequencersConfig(env: TestConfig, config: Partial<AztecNodeAdminConfig>) {
|
|
76
|
+
return withSequencersAdmin(env, async client => {
|
|
77
|
+
await client.setConfig(config);
|
|
78
|
+
return client.getConfig();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getSequencersConfig(env: TestConfig) {
|
|
83
|
+
return withSequencersAdmin(env, client => client.getConfig());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function withSequencersAdmin<T>(env: TestConfig, fn: (node: AztecNodeAdmin) => Promise<T>): Promise<T[]> {
|
|
87
|
+
const adminContainerPort = 8880;
|
|
88
|
+
const namespace = env.NAMESPACE;
|
|
89
|
+
const sequencers = await getSequencers(namespace);
|
|
90
|
+
const results = [];
|
|
91
|
+
|
|
92
|
+
for (const sequencer of sequencers) {
|
|
93
|
+
const { process, port } = await startPortForward({
|
|
94
|
+
resource: `pod/${sequencer}`,
|
|
95
|
+
namespace,
|
|
96
|
+
containerPort: adminContainerPort,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const url = `http://localhost:${port}`;
|
|
100
|
+
await retry(
|
|
101
|
+
() => fetch(`${url}/status`).then(res => res.status === 200),
|
|
102
|
+
'forward node admin port',
|
|
103
|
+
makeBackoff([1, 1, 2, 6]),
|
|
104
|
+
logger,
|
|
105
|
+
true,
|
|
106
|
+
);
|
|
107
|
+
const client = createAztecNodeAdminClient(url);
|
|
108
|
+
results.push(await fn(client));
|
|
109
|
+
process.kill();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return results;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Enables or disables probabilistic transaction dropping on validators and waits for rollout.
|
|
117
|
+
* Wired to env vars P2P_DROP_TX and P2P_DROP_TX_CHANCE via Helm values.
|
|
118
|
+
*/
|
|
119
|
+
export async function setValidatorTxDrop({
|
|
120
|
+
namespace,
|
|
121
|
+
enabled,
|
|
122
|
+
probability,
|
|
123
|
+
logger: log,
|
|
124
|
+
}: {
|
|
125
|
+
namespace: string;
|
|
126
|
+
enabled: boolean;
|
|
127
|
+
probability: number;
|
|
128
|
+
logger: Logger;
|
|
129
|
+
}) {
|
|
130
|
+
const drop = enabled ? 'true' : 'false';
|
|
131
|
+
const prob = String(probability);
|
|
132
|
+
|
|
133
|
+
const selectors = ['app.kubernetes.io/name=validator', 'app.kubernetes.io/component=validator', 'app=validator'];
|
|
134
|
+
let updated = false;
|
|
135
|
+
for (const selector of selectors) {
|
|
136
|
+
try {
|
|
137
|
+
const list = await execAsync(`kubectl get statefulset -l ${selector} -n ${namespace} --no-headers -o name | cat`);
|
|
138
|
+
const names = list.stdout
|
|
139
|
+
.split('\n')
|
|
140
|
+
.map(s => s.trim())
|
|
141
|
+
.filter(Boolean);
|
|
142
|
+
if (names.length === 0) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const cmd = `kubectl set env statefulset -l ${selector} -n ${namespace} P2P_DROP_TX=${drop} P2P_DROP_TX_CHANCE=${prob}`;
|
|
146
|
+
log.info(`command: ${cmd}`);
|
|
147
|
+
await execAsync(cmd);
|
|
148
|
+
updated = true;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
log.warn(`Failed to update validators with selector ${selector}: ${String(e)}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!updated) {
|
|
155
|
+
log.warn(`No validator StatefulSets found in ${namespace}. Skipping tx drop toggle.`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Restart validator pods to ensure env vars take effect and wait for readiness
|
|
160
|
+
await restartValidators(namespace, log);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function restartValidators(namespace: string, log: Logger) {
|
|
164
|
+
const selectors = ['app.kubernetes.io/name=validator', 'app.kubernetes.io/component=validator', 'app=validator'];
|
|
165
|
+
let any = false;
|
|
166
|
+
for (const selector of selectors) {
|
|
167
|
+
try {
|
|
168
|
+
const { stdout } = await execAsync(`kubectl get pods -l ${selector} -n ${namespace} --no-headers -o name | cat`);
|
|
169
|
+
if (!stdout || stdout.trim().length === 0) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
any = true;
|
|
173
|
+
await deleteResourceByLabel({ resource: 'pods', namespace, label: selector });
|
|
174
|
+
} catch (e) {
|
|
175
|
+
log.warn(`Error restarting validator pods with selector ${selector}: ${String(e)}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!any) {
|
|
180
|
+
log.warn(`No validator pods found to restart in ${namespace}.`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Wait for either label to be Ready
|
|
185
|
+
for (const selector of selectors) {
|
|
186
|
+
try {
|
|
187
|
+
await waitForResourceByLabel({ resource: 'pods', namespace, label: selector });
|
|
188
|
+
return;
|
|
189
|
+
} catch {
|
|
190
|
+
// try next
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
log.warn(`Validator pods did not report Ready; continuing.`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export async function enableValidatorDynamicBootNode(
|
|
197
|
+
instanceName: string,
|
|
198
|
+
namespace: string,
|
|
199
|
+
spartanDir: string,
|
|
200
|
+
log: Logger,
|
|
201
|
+
) {
|
|
202
|
+
log.info(`Enabling validator dynamic boot node`);
|
|
203
|
+
await execHelmCommand({
|
|
204
|
+
instanceName,
|
|
205
|
+
namespace,
|
|
206
|
+
helmChartDir: getChartDir(spartanDir, 'aztec-network'),
|
|
207
|
+
values: {
|
|
208
|
+
'validator.dynamicBootNode': 'true',
|
|
209
|
+
},
|
|
210
|
+
valuesFile: undefined,
|
|
211
|
+
timeout: '15m',
|
|
212
|
+
reuseValues: true,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
log.info(`Validator dynamic boot node enabled`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Rolls the Aztec pods in the given namespace.
|
|
220
|
+
* @param namespace - The namespace to roll the Aztec pods in.
|
|
221
|
+
* @param clearState - If true, also deletes the underlying PVCs to clear persistent storage.
|
|
222
|
+
* This is required for rollup upgrades where the old state is incompatible with the new rollup.
|
|
223
|
+
* Defaults to false, which preserves the existing storage.
|
|
224
|
+
*/
|
|
225
|
+
export async function rollAztecPods(namespace: string, clearState: boolean = false) {
|
|
226
|
+
// Pod components use 'validator', but StatefulSets and PVCs use 'sequencer-node' for validators
|
|
227
|
+
const podComponents = ['p2p-bootstrap', 'prover-node', 'prover-broker', 'prover-agent', 'sequencer-node', 'rpc'];
|
|
228
|
+
const pvcComponents = ['p2p-bootstrap', 'prover-node', 'prover-broker', 'sequencer-node', 'rpc'];
|
|
229
|
+
// StatefulSet components that need to be scaled down before PVC deletion
|
|
230
|
+
// Note: validators use 'sequencer-node' as component label, not 'validator'
|
|
231
|
+
const statefulSetComponents = ['p2p-bootstrap', 'prover-node', 'prover-broker', 'sequencer-node', 'rpc'];
|
|
232
|
+
|
|
233
|
+
if (clearState) {
|
|
234
|
+
// To delete PVCs, we must first scale down StatefulSets so pods release the volumes
|
|
235
|
+
// Otherwise PVC deletion will hang waiting for pods to terminate
|
|
236
|
+
|
|
237
|
+
// First, save original replica counts
|
|
238
|
+
const originalReplicas: Map<string, number> = new Map();
|
|
239
|
+
for (const component of statefulSetComponents) {
|
|
240
|
+
try {
|
|
241
|
+
const getCmd = `kubectl get statefulset -l app.kubernetes.io/component=${component} -n ${namespace} -o jsonpath='{.items[0].spec.replicas}'`;
|
|
242
|
+
const { stdout } = await execAsync(getCmd);
|
|
243
|
+
const replicas = parseInt(stdout.replace(/'/g, '').trim(), 10);
|
|
244
|
+
if (!isNaN(replicas) && replicas > 0) {
|
|
245
|
+
originalReplicas.set(component, replicas);
|
|
246
|
+
}
|
|
247
|
+
} catch {
|
|
248
|
+
// Component might not exist, continue
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Scale down to 0
|
|
253
|
+
for (const component of statefulSetComponents) {
|
|
254
|
+
try {
|
|
255
|
+
const scaleCmd = `kubectl scale statefulset -l app.kubernetes.io/component=${component} -n ${namespace} --replicas=0 --timeout=2m`;
|
|
256
|
+
logger.info(`command: ${scaleCmd}`);
|
|
257
|
+
await execAsync(scaleCmd);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
// Component might not exist or might be a Deployment, continue
|
|
260
|
+
logger.verbose(`Scale down ${component} skipped: ${e}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Wait for pods to terminate
|
|
265
|
+
await sleep(15 * 1000);
|
|
266
|
+
|
|
267
|
+
// Now delete PVCs (they should no longer be in use)
|
|
268
|
+
for (const component of pvcComponents) {
|
|
269
|
+
await deleteResourceByLabel({
|
|
270
|
+
resource: 'persistentvolumeclaims',
|
|
271
|
+
namespace: namespace,
|
|
272
|
+
label: `app.kubernetes.io/component=${component}`,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Scale StatefulSets back up to original replica counts
|
|
277
|
+
for (const component of statefulSetComponents) {
|
|
278
|
+
const replicas = originalReplicas.get(component) ?? 1;
|
|
279
|
+
try {
|
|
280
|
+
const scaleCmd = `kubectl scale statefulset -l app.kubernetes.io/component=${component} -n ${namespace} --replicas=${replicas} --timeout=2m`;
|
|
281
|
+
logger.info(`command: ${scaleCmd}`);
|
|
282
|
+
await execAsync(scaleCmd);
|
|
283
|
+
} catch (e) {
|
|
284
|
+
logger.verbose(`Scale up ${component} skipped: ${e}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
// Just delete pods (no state clearing)
|
|
289
|
+
for (const component of podComponents) {
|
|
290
|
+
await deleteResourceByLabel({
|
|
291
|
+
resource: 'pods',
|
|
292
|
+
namespace: namespace,
|
|
293
|
+
label: `app.kubernetes.io/component=${component}`,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
await sleep(10 * 1000);
|
|
299
|
+
|
|
300
|
+
// Wait for pods to come back
|
|
301
|
+
for (const component of podComponents) {
|
|
302
|
+
await waitForResourceByLabel({
|
|
303
|
+
resource: 'pods',
|
|
304
|
+
namespace: namespace,
|
|
305
|
+
label: `app.kubernetes.io/component=${component}`,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import { execSync, spawn } from 'child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param scriptPath - The path to the script, relative to the project root
|
|
8
|
+
* @param args - The arguments to pass to the script
|
|
9
|
+
* @param logger - The logger to use
|
|
10
|
+
* @returns The exit code of the script
|
|
11
|
+
*/
|
|
12
|
+
function runScript(scriptPath: string, args: string[], logger: Logger, env?: Record<string, string>) {
|
|
13
|
+
const childProcess = spawn(scriptPath, args, {
|
|
14
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
16
|
+
});
|
|
17
|
+
return new Promise<number>((resolve, reject) => {
|
|
18
|
+
childProcess.on('close', (code: number | null) => resolve(code ?? 0));
|
|
19
|
+
childProcess.on('error', reject);
|
|
20
|
+
childProcess.stdout?.on('data', (data: Buffer) => {
|
|
21
|
+
logger.info(data.toString());
|
|
22
|
+
});
|
|
23
|
+
childProcess.stderr?.on('data', (data: Buffer) => {
|
|
24
|
+
logger.error(data.toString());
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the absolute path to the git repository root
|
|
31
|
+
*/
|
|
32
|
+
export function getGitProjectRoot(): string {
|
|
33
|
+
try {
|
|
34
|
+
const rootDir = execSync('git rev-parse --show-toplevel', {
|
|
35
|
+
encoding: 'utf-8',
|
|
36
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
37
|
+
}).trim();
|
|
38
|
+
|
|
39
|
+
return rootDir;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error(`Failed to determine git project root: ${error}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getAztecBin() {
|
|
46
|
+
return path.join(getGitProjectRoot(), 'yarn-project/aztec/dest/bin/index.js');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Runs the Aztec binary
|
|
51
|
+
* @param args - The arguments to pass to the Aztec binary
|
|
52
|
+
* @param logger - The logger to use
|
|
53
|
+
* @param env - Optional environment variables to set for the process
|
|
54
|
+
* @returns The exit code of the Aztec binary
|
|
55
|
+
*/
|
|
56
|
+
export function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>) {
|
|
57
|
+
return runScript('node', [getAztecBin(), ...args], logger, env);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function runProjectScript(script: string, args: string[], logger: Logger, env?: Record<string, string>) {
|
|
61
|
+
const scriptPath = script.startsWith('/') ? script : path.join(getGitProjectRoot(), script);
|
|
62
|
+
return runScript(scriptPath, args, logger, env);
|
|
63
|
+
}
|