@aztec/end-to-end 0.0.1-commit.b655e406 → 0.0.1-commit.c2595eba

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.
Files changed (209) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +3 -2
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/benchmark.js +21 -1
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +21 -15
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  6. package/dest/bench/client_flows/client_flows_benchmark.js +129 -119
  7. package/dest/bench/client_flows/config.d.ts +1 -1
  8. package/dest/bench/client_flows/data_extractor.d.ts +1 -1
  9. package/dest/bench/client_flows/data_extractor.js +7 -27
  10. package/dest/bench/utils.d.ts +8 -7
  11. package/dest/bench/utils.d.ts.map +1 -1
  12. package/dest/bench/utils.js +27 -18
  13. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
  14. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  15. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +96 -112
  16. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +19 -13
  17. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  18. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +91 -70
  19. package/dest/e2e_deploy_contract/deploy_test.d.ts +5 -4
  20. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  21. package/dest/e2e_deploy_contract/deploy_test.js +18 -13
  22. package/dest/e2e_epochs/epochs_test.d.ts +17 -9
  23. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  24. package/dest/e2e_epochs/epochs_test.js +48 -23
  25. package/dest/e2e_fees/bridging_race.notest.d.ts +1 -1
  26. package/dest/e2e_fees/bridging_race.notest.js +5 -7
  27. package/dest/e2e_fees/fees_test.d.ts +20 -16
  28. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  29. package/dest/e2e_fees/fees_test.js +127 -139
  30. package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
  31. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  32. package/dest/e2e_l1_publisher/write_json.js +18 -19
  33. package/dest/e2e_multi_validator/utils.d.ts +1 -1
  34. package/dest/e2e_multi_validator/utils.js +1 -1
  35. package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
  36. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  37. package/dest/e2e_nested_contract/nested_contract_test.js +31 -38
  38. package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
  39. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  40. package/dest/e2e_p2p/inactivity_slash_test.js +7 -6
  41. package/dest/e2e_p2p/p2p_network.d.ts +225 -18
  42. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  43. package/dest/e2e_p2p/p2p_network.js +121 -110
  44. package/dest/e2e_p2p/shared.d.ts +11 -11
  45. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  46. package/dest/e2e_p2p/shared.js +15 -21
  47. package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
  48. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  49. package/dest/e2e_token_contract/token_contract_test.js +89 -91
  50. package/dest/fixtures/e2e_prover_test.d.ts +12 -18
  51. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  52. package/dest/fixtures/e2e_prover_test.js +101 -109
  53. package/dest/fixtures/fixtures.d.ts +2 -3
  54. package/dest/fixtures/fixtures.d.ts.map +1 -1
  55. package/dest/fixtures/fixtures.js +2 -3
  56. package/dest/fixtures/get_acvm_config.d.ts +1 -1
  57. package/dest/fixtures/get_acvm_config.js +1 -1
  58. package/dest/fixtures/get_bb_config.d.ts +1 -1
  59. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  60. package/dest/fixtures/index.d.ts +1 -1
  61. package/dest/fixtures/l1_to_l2_messaging.d.ts +4 -3
  62. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  63. package/dest/fixtures/l1_to_l2_messaging.js +2 -2
  64. package/dest/fixtures/logging.d.ts +1 -1
  65. package/dest/fixtures/setup.d.ts +218 -0
  66. package/dest/fixtures/setup.d.ts.map +1 -0
  67. package/dest/fixtures/setup.js +695 -0
  68. package/dest/fixtures/setup_p2p_test.d.ts +6 -7
  69. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  70. package/dest/fixtures/setup_p2p_test.js +41 -28
  71. package/dest/fixtures/token_utils.d.ts +5 -2
  72. package/dest/fixtures/token_utils.d.ts.map +1 -1
  73. package/dest/fixtures/token_utils.js +13 -7
  74. package/dest/fixtures/utils.d.ts +5 -192
  75. package/dest/fixtures/utils.d.ts.map +1 -1
  76. package/dest/fixtures/utils.js +4 -648
  77. package/dest/fixtures/web3signer.d.ts +1 -1
  78. package/dest/fixtures/web3signer.js +1 -1
  79. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  80. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  81. package/dest/fixtures/with_telemetry_utils.js +2 -2
  82. package/dest/index.d.ts +1 -1
  83. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  84. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  85. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  86. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  87. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  88. package/dest/quality_of_service/prometheus_client.js +67 -0
  89. package/dest/shared/cross_chain_test_harness.d.ts +7 -6
  90. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  91. package/dest/shared/cross_chain_test_harness.js +14 -14
  92. package/dest/shared/gas_portal_test_harness.d.ts +2 -2
  93. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  94. package/dest/shared/gas_portal_test_harness.js +2 -2
  95. package/dest/shared/index.d.ts +2 -2
  96. package/dest/shared/index.d.ts.map +1 -1
  97. package/dest/shared/jest_setup.d.ts +1 -1
  98. package/dest/shared/submit-transactions.d.ts +3 -3
  99. package/dest/shared/submit-transactions.d.ts.map +1 -1
  100. package/dest/shared/submit-transactions.js +9 -11
  101. package/dest/shared/uniswap_l1_l2.d.ts +3 -27
  102. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  103. package/dest/shared/uniswap_l1_l2.js +55 -35
  104. package/dest/simulators/index.d.ts +1 -1
  105. package/dest/simulators/lending_simulator.d.ts +2 -2
  106. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  107. package/dest/simulators/lending_simulator.js +6 -4
  108. package/dest/simulators/token_simulator.d.ts +1 -1
  109. package/dest/simulators/token_simulator.d.ts.map +1 -1
  110. package/dest/spartan/setup_test_wallets.d.ts +8 -5
  111. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  112. package/dest/spartan/setup_test_wallets.js +85 -23
  113. package/dest/spartan/tx_metrics.d.ts +88 -0
  114. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  115. package/dest/spartan/tx_metrics.js +422 -0
  116. package/dest/spartan/utils/bot.d.ts +27 -0
  117. package/dest/spartan/utils/bot.d.ts.map +1 -0
  118. package/dest/spartan/utils/bot.js +141 -0
  119. package/dest/spartan/utils/chaos.d.ts +79 -0
  120. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  121. package/dest/spartan/utils/chaos.js +142 -0
  122. package/dest/spartan/utils/clients.d.ts +39 -0
  123. package/dest/spartan/utils/clients.d.ts.map +1 -0
  124. package/dest/spartan/utils/clients.js +90 -0
  125. package/dest/spartan/utils/config.d.ts +36 -0
  126. package/dest/spartan/utils/config.d.ts.map +1 -0
  127. package/dest/spartan/utils/config.js +20 -0
  128. package/dest/spartan/utils/health.d.ts +63 -0
  129. package/dest/spartan/utils/health.d.ts.map +1 -0
  130. package/dest/spartan/utils/health.js +202 -0
  131. package/dest/spartan/utils/helm.d.ts +15 -0
  132. package/dest/spartan/utils/helm.d.ts.map +1 -0
  133. package/dest/spartan/utils/helm.js +47 -0
  134. package/dest/spartan/utils/index.d.ts +9 -0
  135. package/dest/spartan/utils/index.d.ts.map +1 -0
  136. package/dest/spartan/utils/index.js +18 -0
  137. package/dest/spartan/utils/k8s.d.ts +126 -0
  138. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  139. package/dest/spartan/utils/k8s.js +375 -0
  140. package/dest/spartan/utils/nodes.d.ts +41 -0
  141. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  142. package/dest/spartan/utils/nodes.js +455 -0
  143. package/dest/spartan/utils/scripts.d.ts +16 -0
  144. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  145. package/dest/spartan/utils/scripts.js +66 -0
  146. package/dest/spartan/utils.d.ts +2 -218
  147. package/dest/spartan/utils.d.ts.map +1 -1
  148. package/dest/spartan/utils.js +1 -749
  149. package/package.json +43 -40
  150. package/src/bench/client_flows/benchmark.ts +24 -2
  151. package/src/bench/client_flows/client_flows_benchmark.ts +152 -170
  152. package/src/bench/client_flows/data_extractor.ts +6 -28
  153. package/src/bench/utils.ts +30 -20
  154. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +104 -142
  155. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +140 -124
  156. package/src/e2e_deploy_contract/deploy_test.ts +22 -15
  157. package/src/e2e_epochs/epochs_test.ts +96 -56
  158. package/src/e2e_fees/bridging_race.notest.ts +5 -11
  159. package/src/e2e_fees/fees_test.ts +180 -219
  160. package/src/e2e_l1_publisher/write_json.ts +20 -19
  161. package/src/e2e_multi_validator/utils.ts +1 -1
  162. package/src/e2e_nested_contract/nested_contract_test.ts +33 -55
  163. package/src/e2e_p2p/inactivity_slash_test.ts +10 -9
  164. package/src/e2e_p2p/p2p_network.ts +181 -180
  165. package/src/e2e_p2p/shared.ts +35 -29
  166. package/src/e2e_token_contract/token_contract_test.ts +103 -118
  167. package/src/fixtures/e2e_prover_test.ts +112 -150
  168. package/src/fixtures/fixtures.ts +2 -5
  169. package/src/fixtures/get_acvm_config.ts +1 -1
  170. package/src/fixtures/l1_to_l2_messaging.ts +4 -2
  171. package/src/fixtures/setup.ts +1017 -0
  172. package/src/fixtures/setup_p2p_test.ts +38 -29
  173. package/src/fixtures/token_utils.ts +8 -7
  174. package/src/fixtures/utils.ts +27 -947
  175. package/src/fixtures/web3signer.ts +1 -1
  176. package/src/fixtures/with_telemetry_utils.ts +2 -2
  177. package/src/guides/up_quick_start.sh +1 -1
  178. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
  179. package/src/quality_of_service/prometheus_client.ts +113 -0
  180. package/src/shared/cross_chain_test_harness.ts +19 -36
  181. package/src/shared/gas_portal_test_harness.ts +3 -3
  182. package/src/shared/index.ts +1 -1
  183. package/src/shared/submit-transactions.ts +9 -15
  184. package/src/shared/uniswap_l1_l2.ts +65 -86
  185. package/src/simulators/lending_simulator.ts +7 -5
  186. package/src/spartan/DEVELOP.md +7 -0
  187. package/src/spartan/setup_test_wallets.ts +119 -28
  188. package/src/spartan/tx_metrics.ts +376 -0
  189. package/src/spartan/utils/bot.ts +185 -0
  190. package/src/spartan/utils/chaos.ts +253 -0
  191. package/src/spartan/utils/clients.ts +100 -0
  192. package/src/spartan/utils/config.ts +26 -0
  193. package/src/spartan/utils/health.ts +255 -0
  194. package/src/spartan/utils/helm.ts +84 -0
  195. package/src/spartan/utils/index.ts +64 -0
  196. package/src/spartan/utils/k8s.ts +527 -0
  197. package/src/spartan/utils/nodes.ts +535 -0
  198. package/src/spartan/utils/scripts.ts +63 -0
  199. package/src/spartan/utils.ts +1 -942
  200. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  201. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  202. package/dest/fixtures/setup_l1_contracts.js +0 -17
  203. package/dest/fixtures/snapshot_manager.d.ts +0 -95
  204. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  205. package/dest/fixtures/snapshot_manager.js +0 -505
  206. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  207. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  208. package/src/fixtures/setup_l1_contracts.ts +0 -26
  209. package/src/fixtures/snapshot_manager.ts +0 -665
@@ -0,0 +1,455 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
3
+ import { makeBackoff, retry, retryUntil } from '@aztec/foundation/retry';
4
+ import { sleep } from '@aztec/foundation/sleep';
5
+ import { createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client';
6
+ import { exec } from 'child_process';
7
+ import { promisify } from 'util';
8
+ import { execHelmCommand } from './helm.js';
9
+ import { deleteResourceByLabel, getChartDir, startPortForward, waitForResourceByLabel, waitForStatefulSetsReady } from './k8s.js';
10
+ const execAsync = promisify(exec);
11
+ const logger = createLogger('e2e:k8s-utils');
12
+ export async function awaitCheckpointNumber(rollupCheatCodes, checkpointNumber, timeoutSeconds, log) {
13
+ log.info(`Waiting for checkpoint ${checkpointNumber}`);
14
+ let tips = await rollupCheatCodes.getTips();
15
+ const endTime = Date.now() + timeoutSeconds * 1000;
16
+ while(tips.pending < checkpointNumber && Date.now() < endTime){
17
+ log.info(`At checkpoint ${tips.pending}`);
18
+ await sleep(1000);
19
+ tips = await rollupCheatCodes.getTips();
20
+ }
21
+ if (tips.pending < checkpointNumber) {
22
+ throw new Error(`Timeout waiting for checkpoint ${checkpointNumber}, only reached ${tips.pending}`);
23
+ } else {
24
+ log.info(`Reached checkpoint ${tips.pending}`);
25
+ }
26
+ }
27
+ /**
28
+ * Waits until the proven block number increases.
29
+ *
30
+ * @param rpcUrl - URL of an Aztec RPC node to query
31
+ * @param log - Logger instance
32
+ * @param timeoutSeconds - Maximum time to wait
33
+ * @param pollIntervalSeconds - How often to check
34
+ */ export async function waitForProvenToAdvance(rpcUrl, log, timeoutSeconds = 300, pollIntervalSeconds = 12) {
35
+ const node = createAztecNodeClient(rpcUrl);
36
+ log.info('Waiting for proven block to advance (indicating epoch proof just submitted)...');
37
+ // Get current proven block number
38
+ let initialProvenBlock;
39
+ try {
40
+ const tips = await node.getL2Tips();
41
+ initialProvenBlock = Number(tips.proven.block.number);
42
+ log.info(`Current proven block: ${initialProvenBlock}. Waiting for it to increase...`);
43
+ } catch (err) {
44
+ log.warn(`Error getting initial tips: ${err}. Will poll until successful.`);
45
+ initialProvenBlock = 0;
46
+ }
47
+ await retryUntil(async ()=>{
48
+ try {
49
+ const tips = await node.getL2Tips();
50
+ const currentProvenBlock = Number(tips.proven.block.number);
51
+ const proposedBlock = Number(tips.proposed.number);
52
+ log.verbose(`Chain state: proposed=${proposedBlock}, proven=${currentProvenBlock} (waiting for > ${initialProvenBlock})`);
53
+ if (currentProvenBlock > initialProvenBlock) {
54
+ log.info(`Proven block advanced from ${initialProvenBlock} to ${currentProvenBlock}.`);
55
+ return true;
56
+ }
57
+ return false;
58
+ } catch (err) {
59
+ log.verbose(`Error checking tips: ${err}`);
60
+ return false;
61
+ }
62
+ }, 'proven block to advance', timeoutSeconds, pollIntervalSeconds);
63
+ }
64
+ export async function getSequencers(namespace) {
65
+ const selectors = [
66
+ 'app.kubernetes.io/name=validator',
67
+ 'app.kubernetes.io/component=validator',
68
+ 'app.kubernetes.io/component=sequencer-node',
69
+ 'app=validator'
70
+ ];
71
+ for (const selector of selectors){
72
+ try {
73
+ const command = `kubectl get pods -l ${selector} -n ${namespace} -o jsonpath='{.items[*].metadata.name}'`;
74
+ const { stdout } = await execAsync(command);
75
+ const sequencers = stdout.split(' ').map((s)=>s.trim()).filter(Boolean);
76
+ if (sequencers.length > 0) {
77
+ logger.verbose(`Found sequencer pods ${sequencers.join(', ')} (selector=${selector})`);
78
+ return sequencers;
79
+ }
80
+ } catch {
81
+ // try next selector
82
+ }
83
+ }
84
+ // Fail fast instead of returning [''] which leads to attempts to port-forward `pod/`.
85
+ throw new Error(`No sequencer/validator pods found in namespace ${namespace}. Tried selectors: ${selectors.join(', ')}`);
86
+ }
87
+ export function updateSequencersConfig(env, config) {
88
+ return withSequencersAdmin(env, async (client)=>{
89
+ await client.setConfig(config);
90
+ return client.getConfig();
91
+ });
92
+ }
93
+ export function getSequencersConfig(env) {
94
+ return withSequencersAdmin(env, (client)=>client.getConfig());
95
+ }
96
+ export async function withSequencersAdmin(env, fn) {
97
+ const adminContainerPort = 8880;
98
+ const namespace = env.NAMESPACE;
99
+ const sequencers = await getSequencers(namespace);
100
+ const results = [];
101
+ for (const sequencer of sequencers){
102
+ // Wrap port-forward + fetch in a retry to handle flaky port-forwards
103
+ const result = await retry(async ()=>{
104
+ const { process: process1, port } = await startPortForward({
105
+ resource: `pod/${sequencer}`,
106
+ namespace,
107
+ containerPort: adminContainerPort
108
+ });
109
+ try {
110
+ const url = `http://localhost:${port}`;
111
+ // Quick health check before using the connection
112
+ const statusRes = await fetch(`${url}/status`);
113
+ if (statusRes.status !== 200) {
114
+ throw new Error(`Admin endpoint returned status ${statusRes.status}`);
115
+ }
116
+ const client = createAztecNodeAdminClient(url);
117
+ return {
118
+ result: await fn(client),
119
+ process: process1
120
+ };
121
+ } catch (err) {
122
+ // Kill the port-forward before retrying
123
+ process1.kill();
124
+ throw err;
125
+ }
126
+ }, 'connect to node admin', makeBackoff([
127
+ 1,
128
+ 2,
129
+ 4,
130
+ 8
131
+ ]), logger, true);
132
+ results.push(result.result);
133
+ result.process.kill();
134
+ }
135
+ return results;
136
+ }
137
+ async function getAztecImageForMigrations(namespace) {
138
+ const aztecDockerImage = process.env.AZTEC_DOCKER_IMAGE;
139
+ if (aztecDockerImage) {
140
+ return aztecDockerImage;
141
+ }
142
+ const { stdout } = await execAsync(`kubectl get pods -l app.kubernetes.io/name=validator -n ${namespace} -o jsonpath='{.items[0].spec.containers[?(@.name=="aztec")].image}' | cat`);
143
+ const image = stdout.trim().replace(/^'|'$/g, '');
144
+ if (!image) {
145
+ throw new Error(`Could not detect aztec image from validator pod in namespace ${namespace}`);
146
+ }
147
+ return image;
148
+ }
149
+ async function getHaDbConnectionUrl(namespace) {
150
+ const secretName = `${namespace}-validator-ha-db-postgres`;
151
+ const { stdout } = await execAsync(`kubectl get secret ${secretName} -n ${namespace} -o json`);
152
+ const secret = JSON.parse(stdout);
153
+ const data = secret?.data ?? {};
154
+ const decode = (value)=>value ? Buffer.from(value, 'base64').toString('utf8') : '';
155
+ const user = decode(data.POSTGRES_USER);
156
+ const password = decode(data.POSTGRES_PASSWORD);
157
+ const database = decode(data.POSTGRES_DB);
158
+ if (!user || !password || !database) {
159
+ throw new Error(`Missing HA DB credentials in secret ${secretName}`);
160
+ }
161
+ const host = `${namespace}-validator-ha-db-postgres.${namespace}.svc.cluster.local`;
162
+ return `postgresql://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:5432/${database}`;
163
+ }
164
+ export async function initHADb(namespace) {
165
+ const databaseUrl = await getHaDbConnectionUrl(namespace);
166
+ const image = await getAztecImageForMigrations(namespace);
167
+ const jobName = `${namespace}-validator-ha-db-migrate`;
168
+ await execAsync(`kubectl delete pod ${jobName} -n ${namespace} --ignore-not-found=true`).catch(()=>undefined);
169
+ const migrateCmd = [
170
+ `kubectl run ${jobName} -n ${namespace}`,
171
+ '--rm -i',
172
+ '--restart=Never',
173
+ `--image=${image}`,
174
+ `--env=DATABASE_URL=${databaseUrl}`,
175
+ '--command -- node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js migrate-ha-db up'
176
+ ].join(' ');
177
+ const migrateCmdForLog = migrateCmd.replace(/--env=DATABASE_URL=\S+/, '--env=DATABASE_URL=<redacted>');
178
+ await retry(async ()=>{
179
+ logger.info(`command: ${migrateCmdForLog}`);
180
+ await execAsync(migrateCmd);
181
+ }, 'run HA DB migrations', makeBackoff([
182
+ 1,
183
+ 2,
184
+ 4,
185
+ 8,
186
+ 16
187
+ ]), logger, true);
188
+ }
189
+ /**
190
+ * Enables or disables probabilistic transaction dropping on validators and waits for rollout.
191
+ * Wired to env vars P2P_DROP_TX and P2P_DROP_TX_CHANCE via Helm values.
192
+ */ export async function setValidatorTxDrop({ namespace, enabled, probability, logger: log }) {
193
+ const drop = enabled ? 'true' : 'false';
194
+ const prob = String(probability);
195
+ const selectors = [
196
+ 'app.kubernetes.io/name=validator',
197
+ 'app.kubernetes.io/component=validator',
198
+ 'app=validator'
199
+ ];
200
+ let updated = false;
201
+ for (const selector of selectors){
202
+ try {
203
+ const list = await execAsync(`kubectl get statefulset -l ${selector} -n ${namespace} --no-headers -o name | cat`);
204
+ const names = list.stdout.split('\n').map((s)=>s.trim()).filter(Boolean);
205
+ if (names.length === 0) {
206
+ continue;
207
+ }
208
+ const cmd = `kubectl set env statefulset -l ${selector} -n ${namespace} P2P_DROP_TX=${drop} P2P_DROP_TX_CHANCE=${prob}`;
209
+ log.info(`command: ${cmd}`);
210
+ await execAsync(cmd);
211
+ updated = true;
212
+ } catch (e) {
213
+ log.warn(`Failed to update validators with selector ${selector}: ${String(e)}`);
214
+ }
215
+ }
216
+ if (!updated) {
217
+ log.warn(`No validator StatefulSets found in ${namespace}. Skipping tx drop toggle.`);
218
+ return;
219
+ }
220
+ // Restart validator pods to ensure env vars take effect and wait for readiness
221
+ await restartValidators(namespace, log);
222
+ }
223
+ export async function restartValidators(namespace, log) {
224
+ const selectors = [
225
+ 'app.kubernetes.io/name=validator',
226
+ 'app.kubernetes.io/component=validator',
227
+ 'app=validator'
228
+ ];
229
+ let any = false;
230
+ for (const selector of selectors){
231
+ try {
232
+ const { stdout } = await execAsync(`kubectl get pods -l ${selector} -n ${namespace} --no-headers -o name | cat`);
233
+ if (!stdout || stdout.trim().length === 0) {
234
+ continue;
235
+ }
236
+ any = true;
237
+ await deleteResourceByLabel({
238
+ resource: 'pods',
239
+ namespace,
240
+ label: selector
241
+ });
242
+ } catch (e) {
243
+ log.warn(`Error restarting validator pods with selector ${selector}: ${String(e)}`);
244
+ }
245
+ }
246
+ if (!any) {
247
+ log.warn(`No validator pods found to restart in ${namespace}.`);
248
+ return;
249
+ }
250
+ // Wait for either label to be Ready
251
+ for (const selector of selectors){
252
+ try {
253
+ await waitForResourceByLabel({
254
+ resource: 'pods',
255
+ namespace,
256
+ label: selector
257
+ });
258
+ return;
259
+ } catch {
260
+ // try next
261
+ }
262
+ }
263
+ log.warn(`Validator pods did not report Ready; continuing.`);
264
+ }
265
+ export async function enableValidatorDynamicBootNode(instanceName, namespace, spartanDir, log) {
266
+ log.info(`Enabling validator dynamic boot node`);
267
+ await execHelmCommand({
268
+ instanceName,
269
+ namespace,
270
+ helmChartDir: getChartDir(spartanDir, 'aztec-network'),
271
+ values: {
272
+ 'validator.dynamicBootNode': 'true'
273
+ },
274
+ valuesFile: undefined,
275
+ timeout: '15m',
276
+ reuseValues: true
277
+ });
278
+ log.info(`Validator dynamic boot node enabled`);
279
+ }
280
+ /**
281
+ * Rolls the Aztec pods in the given namespace.
282
+ * @param namespace - The namespace to roll the Aztec pods in.
283
+ * @param clearState - If true, also deletes the underlying PVCs to clear persistent storage.
284
+ * This is required for rollup upgrades where the old state is incompatible with the new rollup.
285
+ * Defaults to false, which preserves the existing storage.
286
+ */ export async function rollAztecPods(namespace, clearState = false) {
287
+ // Pod components use 'validator', but StatefulSets and PVCs use 'sequencer-node' for validators
288
+ const podComponents = [
289
+ 'p2p-bootstrap',
290
+ 'prover-node',
291
+ 'prover-broker',
292
+ 'prover-agent',
293
+ 'sequencer-node',
294
+ 'rpc',
295
+ 'validator-ha-db'
296
+ ];
297
+ const pvcComponents = [
298
+ 'p2p-bootstrap',
299
+ 'prover-node',
300
+ 'prover-broker',
301
+ 'sequencer-node',
302
+ 'rpc',
303
+ 'validator-ha-db'
304
+ ];
305
+ // StatefulSet components that need to be scaled down before PVC deletion
306
+ // Note: validators use 'sequencer-node' as component label, not 'validator'
307
+ const statefulSetComponents = [
308
+ 'p2p-bootstrap',
309
+ 'prover-node',
310
+ 'prover-broker',
311
+ 'sequencer-node',
312
+ 'rpc',
313
+ 'validator-ha-db'
314
+ ];
315
+ if (clearState) {
316
+ // To delete PVCs, we must first scale down StatefulSets so pods release the volumes
317
+ // Otherwise PVC deletion will hang waiting for pods to terminate
318
+ // Save original replica counts for all StatefulSets
319
+ const originalReplicas = new Map();
320
+ for (const component of statefulSetComponents){
321
+ try {
322
+ // Get all StatefulSets that match the component label
323
+ const getCmd = `kubectl get statefulset -l app.kubernetes.io/component=${component} -n ${namespace} -o json`;
324
+ const { stdout } = await execAsync(getCmd);
325
+ const result = JSON.parse(stdout);
326
+ for (const sts of result.items || []){
327
+ const name = sts.metadata.name;
328
+ const replicas = sts.spec.replicas ?? 1;
329
+ if (replicas > 0) {
330
+ originalReplicas.set(name, replicas);
331
+ logger.debug(`Saved replica count for StatefulSet ${name}: ${replicas}`);
332
+ }
333
+ }
334
+ } catch {
335
+ // Component might not exist, continue
336
+ }
337
+ }
338
+ // Scale down to 0
339
+ for (const component of statefulSetComponents){
340
+ try {
341
+ const scaleCmd = `kubectl scale statefulset -l app.kubernetes.io/component=${component} -n ${namespace} --replicas=0 --timeout=2m`;
342
+ logger.info(`command: ${scaleCmd}`);
343
+ await execAsync(scaleCmd);
344
+ } catch (e) {
345
+ // Component might not exist or might be a Deployment, continue
346
+ logger.verbose(`Scale down ${component} skipped: ${e}`);
347
+ }
348
+ }
349
+ // Wait for all pods to fully terminate before deleting PVCs.
350
+ // terminationGracePeriodSeconds default is 30s.
351
+ logger.info('Waiting for pods to fully terminate before deleting PVCs...');
352
+ for (const component of statefulSetComponents){
353
+ try {
354
+ // Wait for all pods with this component label to be deleted
355
+ const waitCmd = `kubectl wait pods -l app.kubernetes.io/component=${component} --for=delete -n ${namespace} --timeout=2m`;
356
+ logger.info(`command: ${waitCmd}`);
357
+ await execAsync(waitCmd);
358
+ } catch (e) {
359
+ logger.verbose(`Wait for pod deletion ${component} skipped: ${e}`);
360
+ }
361
+ }
362
+ // Extra buffer to ensure PVC protection finalizers are cleared
363
+ await sleep(5 * 1000);
364
+ // Now delete PVCs (they should no longer be in use)
365
+ for (const component of pvcComponents){
366
+ try {
367
+ await deleteResourceByLabel({
368
+ resource: 'persistentvolumeclaims',
369
+ namespace: namespace,
370
+ label: `app.kubernetes.io/component=${component}`
371
+ });
372
+ } catch (e) {
373
+ logger.warn(`Failed to delete PVCs for ${component}: ${e}`);
374
+ }
375
+ }
376
+ // Verify PVCs are deleted
377
+ for (const component of pvcComponents){
378
+ try {
379
+ const waitCmd = `kubectl wait pvc -l app.kubernetes.io/component=${component} --for=delete -n ${namespace} --timeout=2m`;
380
+ logger.info(`command: ${waitCmd}`);
381
+ await execAsync(waitCmd);
382
+ } catch (e) {
383
+ logger.verbose(`Wait for PVC deletion ${component} skipped: ${e}`);
384
+ }
385
+ }
386
+ const haDbStatefulSets = [
387
+ ...originalReplicas.entries()
388
+ ].filter(([name])=>name.includes('validator-ha-db'));
389
+ const otherStatefulSets = [
390
+ ...originalReplicas.entries()
391
+ ].filter(([name])=>!name.includes('validator-ha-db'));
392
+ // Bring up HA DB first so we can run migrations before validators start
393
+ for (const [stsName, replicas] of haDbStatefulSets){
394
+ try {
395
+ const scaleCmd = `kubectl scale statefulset ${stsName} -n ${namespace} --replicas=${replicas} --timeout=2m`;
396
+ logger.info(`command: ${scaleCmd}`);
397
+ await execAsync(scaleCmd);
398
+ } catch (e) {
399
+ logger.verbose(`Scale up ${stsName} skipped: ${e}`);
400
+ }
401
+ }
402
+ if (haDbStatefulSets.length > 0) {
403
+ try {
404
+ await waitForStatefulSetsReady({
405
+ namespace,
406
+ label: 'app.kubernetes.io/component=validator-ha-db',
407
+ timeoutSeconds: 600
408
+ });
409
+ await initHADb(namespace);
410
+ } catch (e) {
411
+ logger.warn(`HA DB migration step skipped or failed: ${e}`);
412
+ }
413
+ }
414
+ // Scale remaining StatefulSets back up to original replica counts (by name, not label)
415
+ for (const [stsName, replicas] of otherStatefulSets){
416
+ try {
417
+ const scaleCmd = `kubectl scale statefulset ${stsName} -n ${namespace} --replicas=${replicas} --timeout=2m`;
418
+ logger.info(`command: ${scaleCmd}`);
419
+ await execAsync(scaleCmd);
420
+ } catch (e) {
421
+ logger.verbose(`Scale up ${stsName} skipped: ${e}`);
422
+ }
423
+ }
424
+ } else {
425
+ // Just delete pods (no state clearing)
426
+ for (const component of podComponents){
427
+ await deleteResourceByLabel({
428
+ resource: 'pods',
429
+ namespace: namespace,
430
+ label: `app.kubernetes.io/component=${component}`
431
+ });
432
+ }
433
+ }
434
+ await sleep(10 * 1000);
435
+ // Wait for StatefulSets to have all replicas ready.
436
+ for (const component of statefulSetComponents){
437
+ try {
438
+ await waitForStatefulSetsReady({
439
+ namespace,
440
+ label: `app.kubernetes.io/component=${component}`,
441
+ timeoutSeconds: 600
442
+ });
443
+ } catch (e) {
444
+ logger.warn(`StatefulSet component ${component} may not be fully ready: ${e}`);
445
+ }
446
+ }
447
+ const nonStatefulSetComponents = podComponents.filter((c)=>!statefulSetComponents.includes(c));
448
+ for (const component of nonStatefulSetComponents){
449
+ await waitForResourceByLabel({
450
+ resource: 'pods',
451
+ namespace: namespace,
452
+ label: `app.kubernetes.io/component=${component}`
453
+ });
454
+ }
455
+ }
@@ -0,0 +1,16 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ /**
3
+ * Returns the absolute path to the git repository root
4
+ */
5
+ export declare function getGitProjectRoot(): string;
6
+ export declare function getAztecBin(): string;
7
+ /**
8
+ * Runs the Aztec binary
9
+ * @param args - The arguments to pass to the Aztec binary
10
+ * @param logger - The logger to use
11
+ * @param env - Optional environment variables to set for the process
12
+ * @returns The exit code of the Aztec binary
13
+ */
14
+ export declare function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>): Promise<number>;
15
+ export declare function runProjectScript(script: string, args: string[], logger: Logger, env?: Record<string, string>): Promise<number>;
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0cy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NwYXJ0YW4vdXRpbHMvc2NyaXB0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQTRCcEQ7O0dBRUc7QUFDSCx3QkFBZ0IsaUJBQWlCLElBQUksTUFBTSxDQVcxQztBQUVELHdCQUFnQixXQUFXLFdBRTFCO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsd0JBQWdCLFdBQVcsQ0FBQyxJQUFJLEVBQUUsTUFBTSxFQUFFLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxHQUFHLENBQUMsRUFBRSxNQUFNLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxtQkFFdkY7QUFFRCx3QkFBZ0IsZ0JBQWdCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUFFLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxHQUFHLENBQUMsRUFBRSxNQUFNLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxtQkFHNUcifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/spartan/utils/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA4BpD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAW1C;AAED,wBAAgB,WAAW,WAE1B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,mBAEvF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,mBAG5G"}
@@ -0,0 +1,66 @@
1
+ import { execSync, spawn } from 'child_process';
2
+ import path from 'path';
3
+ /**
4
+ * @param scriptPath - The path to the script, relative to the project root
5
+ * @param args - The arguments to pass to the script
6
+ * @param logger - The logger to use
7
+ * @returns The exit code of the script
8
+ */ function runScript(scriptPath, args, logger, env) {
9
+ const childProcess = spawn(scriptPath, args, {
10
+ stdio: [
11
+ 'ignore',
12
+ 'pipe',
13
+ 'pipe'
14
+ ],
15
+ env: env ? {
16
+ ...process.env,
17
+ ...env
18
+ } : process.env
19
+ });
20
+ return new Promise((resolve, reject)=>{
21
+ childProcess.on('close', (code)=>resolve(code ?? 0));
22
+ childProcess.on('error', reject);
23
+ childProcess.stdout?.on('data', (data)=>{
24
+ logger.info(data.toString());
25
+ });
26
+ childProcess.stderr?.on('data', (data)=>{
27
+ logger.error(data.toString());
28
+ });
29
+ });
30
+ }
31
+ /**
32
+ * Returns the absolute path to the git repository root
33
+ */ export function getGitProjectRoot() {
34
+ try {
35
+ const rootDir = execSync('git rev-parse --show-toplevel', {
36
+ encoding: 'utf-8',
37
+ stdio: [
38
+ 'ignore',
39
+ 'pipe',
40
+ 'ignore'
41
+ ]
42
+ }).trim();
43
+ return rootDir;
44
+ } catch (error) {
45
+ throw new Error(`Failed to determine git project root: ${error}`);
46
+ }
47
+ }
48
+ export function getAztecBin() {
49
+ return path.join(getGitProjectRoot(), 'yarn-project/aztec/dest/bin/index.js');
50
+ }
51
+ /**
52
+ * Runs the Aztec binary
53
+ * @param args - The arguments to pass to the Aztec binary
54
+ * @param logger - The logger to use
55
+ * @param env - Optional environment variables to set for the process
56
+ * @returns The exit code of the Aztec binary
57
+ */ export function runAztecBin(args, logger, env) {
58
+ return runScript('node', [
59
+ getAztecBin(),
60
+ ...args
61
+ ], logger, env);
62
+ }
63
+ export function runProjectScript(script, args, logger, env) {
64
+ const scriptPath = script.startsWith('/') ? script : path.join(getGitProjectRoot(), script);
65
+ return runScript(scriptPath, args, logger, env);
66
+ }